@ -26,6 +26,7 @@ from .util import (
MODE_FILE_EXECUTE ,
MODE_FILE_EXECUTE ,
PYTHON_PATHS ,
PYTHON_PATHS ,
raw_command ,
raw_command ,
read_lines_without_comments ,
ANSIBLE_TEST_DATA_ROOT ,
ANSIBLE_TEST_DATA_ROOT ,
ApplicationError ,
ApplicationError ,
)
)
@ -43,6 +44,10 @@ from .provider.layout import (
LayoutMessages ,
LayoutMessages ,
)
)
DOCKER_COMPLETION = { } # type: t.Dict[str, t.Dict[str, str]]
REMOTE_COMPLETION = { } # type: t.Dict[str, t.Dict[str, str]]
NETWORK_COMPLETION = { } # type: t.Dict[str, t.Dict[str, str]]
class ResultType :
class ResultType :
""" Test result type. """
""" Test result type. """
@ -110,6 +115,93 @@ class CommonConfig:
return os . path . join ( ANSIBLE_TEST_DATA_ROOT , ' ansible.cfg ' )
return os . path . join ( ANSIBLE_TEST_DATA_ROOT , ' ansible.cfg ' )
class NetworkPlatformSettings :
""" Settings required for provisioning a network platform. """
def __init__ ( self , collection , inventory_vars ) : # type: (str, t.Type[str, str]) -> None
self . collection = collection
self . inventory_vars = inventory_vars
def get_docker_completion ( ) :
"""
: rtype : dict [ str , dict [ str , str ] ]
"""
return get_parameterized_completion ( DOCKER_COMPLETION , ' docker ' )
def get_remote_completion ( ) :
"""
: rtype : dict [ str , dict [ str , str ] ]
"""
return get_parameterized_completion ( REMOTE_COMPLETION , ' remote ' )
def get_network_completion ( ) :
"""
: rtype : dict [ str , dict [ str , str ] ]
"""
return get_parameterized_completion ( NETWORK_COMPLETION , ' network ' )
def get_parameterized_completion ( cache , name ) :
"""
: type cache : dict [ str , dict [ str , str ] ]
: type name : str
: rtype : dict [ str , dict [ str , str ] ]
"""
if not cache :
if data_context ( ) . content . collection :
context = ' collection '
else :
context = ' ansible-base '
images = read_lines_without_comments ( os . path . join ( ANSIBLE_TEST_DATA_ROOT , ' completion ' , ' %s .txt ' % name ) , remove_blank_lines = True )
cache . update ( dict ( kvp for kvp in [ parse_parameterized_completion ( i ) for i in images ] if kvp and kvp [ 1 ] . get ( ' context ' , context ) == context ) )
return cache
def parse_parameterized_completion ( value ) : # type: (str) -> t.Optional[t.Tuple[str, t.Dict[str, str]]]
""" Parse the given completion entry, returning the entry name and a dictionary of key/value settings. """
values = value . split ( )
if not values :
return None
name = values [ 0 ]
data = dict ( ( kvp [ 0 ] , kvp [ 1 ] if len ( kvp ) > 1 else ' ' ) for kvp in [ item . split ( ' = ' , 1 ) for item in values [ 1 : ] ] )
return name , data
def docker_qualify_image ( name ) :
"""
: type name : str
: rtype : str
"""
config = get_docker_completion ( ) . get ( name , { } )
return config . get ( ' name ' , name )
def get_network_settings ( args , platform , version ) : # type: (NetworkIntegrationConfig, str, str) -> NetworkPlatformSettings
""" Returns settings for the given network platform and version. """
platform_version = ' %s / %s ' % ( platform , version )
completion = get_network_completion ( ) . get ( platform_version , { } )
collection = args . platform_collection . get ( platform , completion . get ( ' collection ' ) )
settings = NetworkPlatformSettings (
collection ,
dict (
ansible_connection = args . platform_connection . get ( platform , completion . get ( ' connection ' ) ) ,
ansible_network_os = ' %s . %s ' % ( collection , platform ) if collection else platform ,
)
)
return settings
def handle_layout_messages ( messages ) : # type: (t.Optional[LayoutMessages]) -> None
def handle_layout_messages ( messages ) : # type: (t.Optional[LayoutMessages]) -> None
""" Display the given layout messages. """
""" Display the given layout messages. """
if not messages :
if not messages :