
    VhM                       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m	Z	m
Z
mZmZ ddlmZ ddlmZmZmZmZmZ ddlmZmZ dd	lmZ dd
lmZmZ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*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1  G d dejd                        Z3	 	 	 	 	 	 	 	 	 	 d*dZ4	 	 	 	 d+dZ5	 	 	 	 	 	 	 	 	 	 d,dZ6	 	 	 	 	 	 d-dZ7	 	 	 	 	 	 d.dZ8	 	 	 	 	 	 	 	 d/dZ9	 	 	 	 d0dZ:	 	 	 	 d0dZ;	 	 	 	 d1dZ<	 	 	 	 	 	 d2dZ=	 	 	 	 	 	 d3dZ>	 	 	 	 	 	 	 	 d4dZ?	 	 	 	 	 	 d3d Z@	 	 	 	 	 	 	 	 d4d!ZAd5d"ZBd6d#ZCd6d$ZDd6d%ZEd6d&ZFd7d8d'ZGd9d(ZHd9d)ZIy):z+Command line parsing for test environments.    )annotationsN   )CONTROLLER_PYTHON_VERSIONSREMOTE_PROVIDERSSECCOMP_CHOICESSUPPORTED_PYTHON_VERSIONS)REMOTE_ARCHITECTURES)docker_completionnetwork_completionremote_completionwindows_completionfilter_completion)CompositeActionCompositeActionCompletionFinder)
EnumAction)
DelegatedControllerActionNetworkSshTargetActionNetworkTargetActionOriginControllerActionPosixSshTargetActionPosixTargetActionSanityPythonTargetActionUnitsPythonTargetActionWindowsSshTargetActionWindowsTargetAction)
TargetMode)TerminateMode   )complete_choicesregister_completer)key_value_type)
get_epilog)get_ci_providerc                  v    e Zd ZdZ ej
                         Z ej
                         Z ej
                         Zy)ControllerModez/Type of provisioning to use for the controller.N)	__name__
__module____qualname____doc__enumautoNO_DELEGATIONORIGIN	DELEGATED     W/home/dcms/DCMS/lib/python3.12/site-packages/ansible_test/_internal/cli/environments.pyr%   r%   L   s,    9DIIKMTYY[F		Ir0   r%   c           
        |t         j                  k(  xr |t        j                  k(  }| j	                  |       |ry| j	                  |       t        | |       t        | ||       t        | |||      }t        j                  j                         D 	cg c]2  \  }}||v r)|j                  j                         D ]  \  }}	| d|	  4 }
}}}}	t               j                         s|
j                  d       |
j                  t        |             t         j"                  | _        dj'                  |
      | _        yc c}	}}}w )zTAdd arguments for the environments used to run ansible-test and commands it invokes.)no_environmentN)target_mode
zXRemote provisioning options have been hidden since no Ansible Core CI API key was found.z

)r%   r,   r   
NO_TARGETSset_defaultsadd_global_optionsadd_legacy_environment_options!add_composite_environment_optionsr   documentation_stateitemssectionsr#   supports_core_ci_authappendr"   argparseRawDescriptionHelpFormatterformatter_classjoinepilog)parser	completercontroller_moder4   r3   action_typesaction_typer;   headingcontentr=   s              r1   add_environmentsrL   T   sH    %(D(DDmXbXmXmImN
~6
K0v/"6?KH4VYYdeL 9H8[8[8a8a8cN N4K!4gr  wC  hC(;(D(D(J(J(LN$GW )2gY' N' NH N 224rsOOJy)*%AAFKK)FMNs   7E
c                   t        j                  t        j                  | j	                  d            }|j                  ddt        j                         |j                  ddt        j                         |j                  d	d
t        j                         |j                  dddd       t        ||       t        ||       y)zmAdd global options for controlling the test environment that work with both the legacy and composite options.zglobal environment argumentstitlez--containersJSONmetavarhelpz--pypi-proxy
store_trueactionrS   z--pypi-endpointURIz--requirementsFzinstall command requirements)rV   defaultrS   N)	tcastr@   ArgumentParseradd_argument_groupadd_argumentSUPPRESSadd_global_remoteadd_global_docker)rE   rG   global_parsers      r1   r8   r8   u   s    
 FF822F4M4MTr4M4stM         +	   m_5m_5r0   c           
        t        j                  t        j                  | j	                  d            }|j                  dt        j                         g dfd}|t        j                  k(  r|j                  d       nLt        |j                  dd	 ||t        j                  k(  rt        nt              d
      |j                         |t        j                   k(  r|j                  g        S |t        j"                  k(  r|j%                         }t        |j                  dd	 |t&              d      |j                         t)               j+                         rdnt        j                  }t        |j                  dd	|rt,        n |t,              |xs d      |j                         t        |j                  dd	|rt.        n |t.              |xs d      |j                         S |j0                  rd}d}	n|t        j2                  k(  rd}d}	nd}d}	t        j2                  t4        t        j6                  t8        t        j:                  t<        t        j>                  t@        t        jB                  tD        i}
|
|   }t        |j                  |d	 ||      |	      |j                         S )z;Add composite options for controlling the test environment.zWcomposite environment arguments (mutually exclusive with "environment arguments" above)rN   z--host-path)rS   c                *    j                  |        | S )z:Register the provided composite action type and return it.)r?   )rI   rH   s    r1   register_action_typez?add_composite_environment_options.<locals>.register_action_type   s    K(r0   N
controllerz--controllerOPTz configuration for the controllerrR   rV   rS   )targetsz--target-posixzconfiguration for the targetz--target-windowsz--target-networkz--target-pythonz2configuration for the target python interpreter(s)z--targetzconfiguration for the target(s))rI   t.Type[CompositeAction]returnrj   )#rY   rZ   r@   r[   r\   r]   r^   r%   r,   r7   r    r.   r   r   rF   r   r6   SHELLadd_mutually_exclusive_groupr   r#   r>   r   r   multiple_pythonsPOSIX_INTEGRATIONr   WINDOWS_INTEGRATIONr   NETWORK_INTEGRATIONr   SANITYr   UNITSr   )rE   rF   rG   r4   composite_parserrd   groupsuppresstarget_optiontarget_helptarget_actionstarget_actionrH   s               @r1   r:   r:      s    vvh55v7P7Pg 8Q 8i j !! " 
 35L
 .666%%%6+88'_XfXpXpEp(A  wM  N3	 9 

 	  j+++%%b%1l k 

((	( ==?5--'(<=/	 . 

 	  +,BBD4(J[J[5---5);OPf;g;;	 . 

 	  	5---5);OPf;g;;	 . 

 	 D 7 ''-MNKJ888&M8K&M;K ((*;**,?**,?75
 '{3+88'6	 9 

 	  r0   c                Z    | j                  d      }t        ||       t        |||       y)z8Add legacy options for controlling the test environment.zWenvironment arguments (mutually exclusive with "composite environment arguments" below)rN   N)r\   add_environments_pythonadd_environments_host)rE   rG   r4   environments       r1   r9   r9      s5     ,2+D+Dg ,E ,K K5+Dr0   c           	         |j                   rt        }nt        }| j                  dd|dz   ddj	                  |      z         | j                  ddd	
       y)z@Add environment arguments to control the Python version(s) used.z--pythonzX.Y)rX   zpython version: %sz, rR   choicesrS   z--python-interpreterPATHzpath to the python interpreterrQ   N)
has_pythonr   r   r]   rC   )environments_parserr4   python_versionss      r1   r|   r|     sg     34$$,.!DIIo$>>	 %  $$- % r0   c                &   | j                         }t        |       t        ||        |t        j                  k(  rt        || |       t        || |       |t        j                  k(  rt        |        |t        j                  k(  rt        |        yy)z@Add environment arguments for the given host and argument modes.N)rm   add_environment_localadd_environment_venvr%   r.   add_environment_remoteadd_environment_dockerr   rp   add_environment_windowsrq   add_environment_network)r   rG   r4   environments_exclusive_groups       r1   r}   r}     s     =P<l<l<n 6757JK.222;=PR]^;=PR]^j444 34j444 34 5r0   c           	        t        | j                  dddd      t               t        | j                  dt        ddd	      t               t        | j                  d
t        ddd	      t
               | j                  ddd       y)8Add environment arguments for running on a windows host.z
--platformPLATFORMr?   znetwork platform/versionrh   z--platform-collectionzPLATFORM=COLLECTIONz collection used to test platform)typerR   rV   rS   z--platform-connectionzPLATFORM=CONNECTIONz connection used to test platform--inventoryr    path to inventory used for testsrQ   N)r    r]   complete_network_platformr!   $complete_network_platform_collection$complete_network_platform_connectionr   s    r1   r   r   1  s     *77'	 8 
 !" *77%/ 8  ,- *77%/ 8  ,- $$/ % r0   c                r    t        | j                  dddd      t               | j                  ddd	       y
)r   z	--windowsVERSIONr?   zwindows versionrh   r   r   r   rQ   N)r    r]   complete_windowsr   s    r1   r   r   S  sN     *77	 8 
  $$/ % r0   c                ,    | j                  ddd       y)zAAdd environment arguments for running on the local (origin) host.z--localrT   zrun from the local environmentrU   Nr]   )exclusive_parsers    r1   r   r   e  s      !!- " r0   c                T    | j                  ddd       |j                  ddd       y)zSAdd environment arguments for running in ansible-test managed virtual environments.z--venvrT   zrun from a virtual environmentrU   z--venv-system-site-packageszenable system site packagesNr   )r   r   s     r1   r   r   p  s>    
 !!- "  $$%* % r0   c                   |t         j                  k7  r| j                  ddddd       y| j                  ddd       | j                  dd	t        j
                  t        t        d
       | j                  ddd       t               j                         rdnt        j                  }| j                  dd|xs d       | j                  dddd|xs d       y)zAdd global options for Docker.NF)docker_networkdocker_terminateprime_containersdev_systemd_debugdev_probe_cgroupsz--docker-networkNETzrun using the specified networkrQ   z--docker-terminateTz;terminate the container: %(choices)s (default: %(default)s)rR   rX   r   rV   rS   z--prime-containersrT   z)download containers without running testsrU   z--dev-systemd-debugz&enable systemd debugging in containersz--dev-probe-cgroupsDIR? z.probe container cgroups, with optional log dirrR   nargsconstrS   )r%   r.   r7   r]   r   ALWAYSr   r#   r>   r@   r^   rE   rG   rv   s      r1   r`   r`     s	   
 .222!"#" 	 	
 	
.   $$J   8   '(>>@thFWFWH
AA   II  r0   c           	        |t         j                  t         j                  fv rt        t	        t                           }nt        t	        t               d            }t        | j                  ddddd      t        j                  t        |             |j                  d	d
d       |j                  ddt        d       |j                  ddt        d       y)z;Add environment arguments for running in docker containers.Tcontroller_onlyz--dockerIMAGEr   rX   zrun from a docker containerr   z--docker-privilegedrT   z'run docker container in privileged moderU   z--docker-seccompSCz;set seccomp confinement for the test container: %(choices)sr   z--docker-memoryINTz memory limit for docker in bytes)rR   r   rS   N)r   ro   rl   sortedr   r
   r    r]   	functoolspartialr   r   int)r   r   r4   docker_imagess       r1   r   r     s     z33Z5E5EFF01B1DEF01B1DVZ[\'44* 5  )=9; $$6 %  $$J	 %  $$/	 % r0   c           	        |t         j                  k7  r| j                  ddd       yt               j	                         rdnt
        j                  }t        | j                  ddd|xs d      t               | j                  dd	|xs d
       | j                  ddt        j                  t        t        |xs d       y)z(Add global options for remote instances.N)remote_stageremote_endpointremote_terminatez--remote-stageSTAGEprodzremote stage to use: prod, dev)rR   rX   rS   z--remote-endpointEPz#remote provisioning endpoint to userQ   z--remote-terminater   zAterminate the remote instance: %(choices)s (default: %(default)s)r   )r%   r.   r7   r#   r>   r@   r^   r    r]   complete_remote_stager   NEVERr   r   s      r1   r_   r_     s    
 .222 ! 	 	
 	&(>>@thFWFWHv**99	 + 
  >>   ##\\  r0   c                   |t         j                  k(  rt               }nO|t         j                  k(  r1t	        t        t                     t        t                     z        }nt        d      }t               j                         rdnt        j                  }t        | j                  dd|xs d      t        j                  t        |             |j                  ddt         |xs d	
       |j                  ddt"        |xs d
       y)z]Add environment arguments for running in ansible-core-ci provisioned remote virtual machines.TNz--remoteNAMEzrun from a remote instancerQ   z--remote-providerPRz#remote provider to use: %(choices)sr   z--remote-archARCHzremote arch to use: %(choices)s)r   ro   get_remote_platform_choicesrl   r   setget_windows_platform_choicesr#   r>   r@   r^   r    r]   r   r   r   r   r	   )r   r   r4   remote_platformsrv   s        r1   r   r   	  s     j22268	
((	(!#&A&C"DsKgKiGj"jk6t<&(>>@thFWFWH'4455 5  )+;<	> $$ >>	 %  $$$::	 % r0   c                P    dD cg c]  }|j                  |       s| c}S c c}w )z<Return a list of supported stages matching the given prefix.)r   dev)
startswith)prefix_stages      r1   r   r   -  s#    .Ke%2B2B62JEKKKs   ##c                    t               D cg c]1  }|j                  |       s|j                  r||j                  vs0|3 c}S c c}w )zReturn a list of supported Windows versions matching the given prefix, excluding versions already parsed from the command line.)get_windows_version_choicesr   windows)r   parsed_argsr   is       r1   r   r   2  sX    24  L!V8LVaViVimn  wB  wJ  wJ  nJA  L  L  Ls   AAAc                    t        t        t                           }|D cg c]1  }|j                  |       s|j                  r||j                  vs0|3 c}S c c}w )zReturn a list of supported network platforms matching the given prefix, excluding platforms already parsed from the command line.)r   r   r   r   platform)r   r   r   imagesr   s        r1   r   r   7  sL    %&8&:;<Fv!f!5{?S?SWX`k`t`tWtAvvvs   AAAc           
     Z   | j                  d      d   }t        t        d t        t	                     j                         D                    }|D cg c]E  }|j                  |      s|j                  r ||j                  D cg c]  }|d   	 c}vsA|dz   G c}}S c c}w c c}}w )zReturn a list of supported network platforms matching the given prefix, excluding collection platforms already parsed from the command line.=r   c              3  4   K   | ]  }|j                     y wNr   .0images     r1   	<genexpr>z7complete_network_platform_collection.<locals>.<genexpr>A       e5e   )splitr   r   r   r   valuesr   platform_collectionr   r   r   leftr   r   xs          r1   r   r   >      <<QDCe4EFXFZ4[4b4b4deefF#  aq||D'9;CbCbfg  J  ^  ^  p_yzpqrspt  p_  g_AG  a  a  p_  a$   B'+B'B"B'B'"B'c           
     Z   | j                  d      d   }t        t        d t        t	                     j                         D                    }|D cg c]E  }|j                  |      s|j                  r ||j                  D cg c]  }|d   	 c}vsA|dz   G c}}S c c}w c c}}w )zReturn a list of supported network platforms matching the given prefix, excluding connection platforms already parsed from the command line.r   r   c              3  4   K   | ]  }|j                     y wr   r   r   s     r1   r   z7complete_network_platform_connection.<locals>.<genexpr>I  r   r   )r   r   r   r   r   r   r   platform_connectionr   s          r1   r   r   F  r   r   c                >    t        t        t               |             S )zFReturn a list of supported remote platforms matching the given prefix.r   )r   r   r   re   s    r1   r   r   N  s    #$5$7TUUr0   c                 d    t        d t        t                     j                         D              S )zFReturn a list of supported Windows versions matching the given prefix.c              3  :   K   | ]  }d |j                      yw)zwindows/Nversionr   r   s     r1   r   z/get_windows_platform_choices.<locals>.<genexpr>U  s     o7HW__-.os   r   r   r   r   r/   r0   r1   r   r   S  s&    o>OPbPd>e>l>l>nooor0   c                 d    t        d t        t                     j                         D              S )z,Return a list of supported Windows versions.c              3  4   K   | ]  }|j                     y wr   r   r   s     r1   r   z.get_windows_version_choices.<locals>.<genexpr>Z  s     bg'//br   r   r/   r0   r1   r   r   X  s&    b1BCUCW1X1_1_1abbbr0   )
rE   argparse.ArgumentParserrF   r   rG   r%   r4   r   rk   None)rE   r   rG   r%   )
rE   r   rF   r   rG   r%   r4   r   rk   zlist[t.Type[CompositeAction]])rE   r   rG   r%   r4   r   )r   r   r4   r   rk   r   )r   r   rG   r%   r4   r   rk   r   )r   r   rk   r   )r   r   rk   r   )r   r   r   r   rk   r   )rE   r   rG   r%   rk   r   )r   r   r   r   r4   r   rk   r   )r   strrk   	list[str])r   r   r   zargparse.Namespacerk   r   )F)rf   boolrk   r   )rk   r   )Jr)   
__future__r   r@   r*   r   typingrY   	constantsr   r   r   r   utilr	   
completionr
   r   r   r   r   cli.argparsingr   r   cli.argparsing.actionsr   cli.actionsr   r   r   r   r   r   r   r   r   r   
cli.compatr   configr   
completersr   r    
convertersr!   rD   r"   cir#   Enumr%   rL   r8   r:   r9   r|   r}   r   r   r   r   r`   r   r_   r   r   r   r   r   r   r   r   r   r/   r0   r1   <module>r     s   1 "      
  

TYY *#*.* $* 	*
 
*B!6#!6#!6HW#W.W $W 	W
 #WtE#E#E E0 
4505#5 5 
	5,0	D0	$-	-0 
$5#5#5 
5p%-%0% % 
	%P$#$#$ 
$N!-!0! ! 
	!HL
L
waaV
p
cr0   