
    Vh                    .   d Z ddlmZ ddlZddlZddlZddlZddlZddlZ	ddl
mZmZmZmZmZmZmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZmZmZm Z  ddl!m"Z"m#Z#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z2  G d de      Z3y)#Sanity test using validate-modules.    )annotationsN   )DOCUMENTABLE_PLUGINSMULTI_FILE_PLUGINSSanitySingleVersionSanityMessageSanityFailureSanitySuccessSanityTargetsSANITY_ROOT   )	make_dirs)
TestResult)
TestTarget)SubprocessErrordisplay)ExitHandler"process_scoped_temporary_directoryrun_command
ResultType)ansible_environmentget_collection_detailCollectionDetailError)SanityConfig)get_ci_provider)data_contextPayloadConfig)PythonConfig)Git)SourceProviderc                  h     e Zd ZdZd	 fdZed
d       ZddZddZddZ	ddZ
edd       Z xZS )ValidateModulesTestr   c                   t         |           | j                  j                  dg       t	               j
                  j                  j                         D ci c]  \  }}|t        v r||dz    c}}| _	        t               | _        t	               j
                  j                  s| j                  j                  d       y y c c}}w )Nzdeprecated-date/z!lib/ansible/plugins/cache/base.py)super__init__optional_error_codesupdater   contentplugin_pathsitemsr   	_prefixesset_exclusions
collectionadd)selfplugin_typeplugin_path	__class__s      g/home/dcms/DCMS/lib/python3.12/site-packages/ansible_test/_internal/commands/sanity/validate_modules.pyr'   zValidateModulesTest.__init__Q   s    !!((*
 	 -9N,B,B,O,O,U,U,W
([22 s**
 5~%%00  !DE 1
s   Cc                     y)zError code for ansible-test matching the format used by the underlying test program, or None if the program does not use error codes.A100 )r2   s    r6   
error_codezValidateModulesTest.error_codec   s         c                    |j                   j                  d      ry|j                   | j                  v ry| j                  j	                         D ]$  \  }}|j                   j                  |      s"|c S  y)zTReturn the plugin type of the given target, or None if it is not a plugin or module.z/__init__.pyN)pathendswithr/   r-   r,   
startswith)r2   targetr3   prefixs       r6   get_plugin_typez#ValidateModulesTest.get_plugin_typeh   sj    ;;/;;$***#'>>#7#7#9 	#K{{%%f-""	# r;   c                P    |D cg c]  }| j                  |      | c}S c c}w )z\Return the given list of test targets, filtered to include only those relevant for the test.)rB   )r2   targetsr@   s      r6   filter_targetsz"ValidateModulesTest.filter_targetsv   s&    %,Y60D0DV0L0XYYYs   ##c                ,   t        |d      }| j                  |      }t        j                  t              }|j
                  D ]%  }|| j                  |         j                  |       ' t        D ]  }|j                  |d         |j                  t        j                  j                  t        dd      dddg}	t               j                  j                   r|	j#                  dt               j                  j                   j$                  g       	 t'        |      }
|
j(                  r|	j#                  d	|
j(                  g       nt+        j,                  d
       n| j3                  |      }t        j                  j5                  |      rqt7        |      }t9        j:                  |      5 }t=        t8        d      r|j?                  |d       n|j?                  |       d d d        |	j#                  d|g       g }tA        |jC                               D ]  \  }}|D cg c]  }|j                   }}t	        |	      }|dk7  r|d|gz  }||z  }	 tE        |||d      \  }}d}|s|dvrtG        ||||      |jN                  rrtQ        jR                  |      }|D ]]  }||   }|d   D ]N  }|j                  tU        |d|v rtW        |d         ndd|v rtW        |d         ndd|d   z  |d                P _  |j
                  D cg c]  }|j                   }}|jY                  ||      }|jN                  rt[        | j\                        S |rt_        | j\                  |      S t[        | j\                        S # t.        $ r-}t+        j,                  d|j0                  z         Y d }~d }~ww xY w# 1 sw Y   xY wc c}w # tF        $ r/}|jH                  }|jJ                  }|jL                  }Y d }~d }~ww xY wc c}w )NF)colorzvalidate-moduleszvalidate.pyz--formatjsonz
--arg-specz--collectionz--collection-versionzZSkipping validate-modules collection version checks since no collection version was found.z^Skipping validate-modules collection version checks since collection detail loading failed: %sdata_filterdata)filterz--original-pluginsmodulesz--plugin-typeT)envcapturer   )r   r   )cmdstatusstderrstdouterrorslinecolumnz%scodemsg)r=   rT   rU   rV   message)messages)0r   load_processorcollectionsdefaultdictlistincluderB   appendr   popr=   osjoinr   r   r*   r0   extend	directoryr   versionr   warningr   reasonget_archive_pathexistsr   tarfileopenhasattr
extractallsortedr,   r   r   rR   rQ   rP   explainrH   loadsr	   intprocess_errorsr   namer
   )r2   argsrD   pythonrM   settingstarget_per_typer@   r3   rO   collection_detailexr=   temp_dirfilerS   plugin_targetspaths
plugin_cmdrR   rQ   rP   rY   filenameoutputitem	all_paths
all_errorss                               r6   testzValidateModulesTest.testz   s   !$e4&&t,%11$7oo 	IFD0089@@H	I . 	3KT2	3 KKGGLL&8-H	
 >!!,,JJ(>(>(I(I(S(STUN$9&$A!$,,JJ 68I8Q8QRSOO  %A  B ((.Dww~~d#=dC\\$' 24w6@12 

((  +1/2G2G2I+J #	'K/=>VV[[>E>cJi'<<
%J#!,T:3PT!U v-%*VF[abb||zz&)H$ 
!(+"8, DMM-%28D.Sf.a6>$6Fs4>2A!DL0 $U# 
3#	J 07?VV[[?	?,,VY?
<< ++ Z@@TYY''G ) N  !A  DF  DM  DM  !M  N  NN2 2 ? # ##2 @sI   A
N 06O&OOP	O"N<<OO	P$P		Pc                Z   t               j                  j                  syt        t               j                  t
              st        j                  d       y|j                  xs t               j                  |      }|st        j                  d       y| j                  |      d
fd}dfd}t        j                  |       t               j                  |       t        t         j"                  j%                               t'               }|j)                  dd|dd	g       y)zOThis method is called on the origin, before the test runs or delegation occurs.NzfThe validate-modules sanity test cannot compare against the base commit because git is not being used.zdThe validate-modules sanity test cannot compare against the base commit because it was not detected.c                     t        j                  t              5  t        j                          ddd       y# 1 sw Y   yxY w)z/Cleanup callback called when the process exits.N)
contextlibsuppressFileNotFoundErrorra   unlink)r=   s   r6   cleanupz0ValidateModulesTest.origin_hook.<locals>.cleanup   s2    $$%67  		$     s	   :Ac                    | j                   }|j                  t        j                  j	                  t               j                  j                        f       y)z;Include the previous plugin content archive in the payload.N)filesr_   ra   r=   relpathr   r*   root)payload_configr   r=   s     r6   git_callbackz5ValidateModulesTest.origin_hook.<locals>.git_callback   s<    "((ELL$ln6L6L6Q6Q RSTr;   archivez--outputzlib/ansible/modules/zlib/ansible/plugins/returnNone)r   r   r   r   )r   r*   
is_ansible
isinstancesource_providerGitSourceProviderr   rf   base_branchr   get_base_commitrh   r   registerregister_payload_callbackr   ra   r=   dirnamer    run_git)r2   rt   base_commitr   r   gitr=   s         @r6   origin_hookzValidateModulesTest.origin_hook   s    ~%%00,.88:KLOO  E  F&&Q/*;*K*KD*QOO  C  D$$T*	 
	U
 	W%00>"''//$'(eY
D+?UWmnor;   c                    t         j                  j                  t        j                  j                  d| j
                  j                   d      S )z7Return the path to the original plugin content archive.zvalidate-modules-z.tar)ra   r=   rb   r   TMPmetadata
session_id)rt   s    r6   rh   z$ValidateModulesTest.get_archive_path  s9     ww||JNN//3DT]]E]E]D^^b1cddr;   r   )r   t.Optional[str])r@   r   r   r   )rD   list[TestTarget]r   r   )rt   r   rD   r   ru   r   r   r   )rt   r   r   r   )rt   r   r   str)__name__
__module____qualname____doc__r'   propertyr:   rB   rE   r   r   staticmethodrh   __classcell__)r5   s   @r6   r#   r#   N   sO    -F$  Zb(H!pF e er;   r#   )4r   
__future__r   r[   r   rH   ra   rj   typingt r   r   r   r	   r
   r   r   r   ior   r   r   r@   r   utilr   r   util_commonr   r   r   r   ansible_utilr   r   r   configr   cir   rJ   r   r   host_configsr   r   r    provider.sourcer!   r   r#   r9   r;   r6   <module>r      s    ) "    	  	 	 	
  

ve- ver;   