@ -27,6 +27,13 @@ os.chdir(
)
)
)
)
IMAGE_TEMPLATE = os . environ . get (
' MITOGEN_TEST_IMAGE_TEMPLATE ' ,
' public.ecr.aws/n5z0e8q9/ %(distro)s -test ' ,
)
_print = print
_print = print
def print ( * args , * * kwargs ) :
def print ( * args , * * kwargs ) :
file = kwargs . get ( ' file ' , sys . stdout )
file = kwargs . get ( ' file ' , sys . stdout )
@ -193,8 +200,6 @@ GIT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
DISTRO = os . environ . get ( ' DISTRO ' , ' debian9 ' )
DISTRO = os . environ . get ( ' DISTRO ' , ' debian9 ' )
# Used only when MODE=ansible
# Used only when MODE=ansible
DISTROS = os . environ . get ( ' DISTROS ' , ' centos6 centos8 debian9 debian11 ubuntu1604 ubuntu2004 ' ) . split ( )
DISTROS = os . environ . get ( ' DISTROS ' , ' centos6 centos8 debian9 debian11 ubuntu1604 ubuntu2004 ' ) . split ( )
TARGET_COUNT = int ( os . environ . get ( ' TARGET_COUNT ' , ' 2 ' ) )
BASE_PORT = 2200
TMP = TempDir ( ) . path
TMP = TempDir ( ) . path
@ -217,6 +222,7 @@ os.environ['PYTHONPATH'] = '%s:%s' % (
def get_docker_hostname ( ) :
def get_docker_hostname ( ) :
""" Return the hostname where the docker daemon is running.
""" Return the hostname where the docker daemon is running.
"""
"""
# Duplicated in testlib
url = os . environ . get ( ' DOCKER_HOST ' )
url = os . environ . get ( ' DOCKER_HOST ' )
if url in ( None , ' http+docker://localunixsocket ' ) :
if url in ( None , ' http+docker://localunixsocket ' ) :
return ' localhost '
return ' localhost '
@ -225,27 +231,34 @@ def get_docker_hostname():
return parsed . netloc . partition ( ' : ' ) [ 0 ]
return parsed . netloc . partition ( ' : ' ) [ 0 ]
def make_containers ( name_prefix = ' ' , port_offset = 0 ) :
def container_specs (
distros ,
base_port = 2200 ,
image_template = IMAGE_TEMPLATE ,
name_template = ' target- %(distro)s - %(index)d ' ,
) :
"""
"""
>> > import pprint
>> > import pprint
>> > BASE_PORT = 2200 ; DISTROS = [ ' debian11 ' , ' centos6 ' ]
>> > pprint . pprint ( container_specs ( [ ' debian11-py3 ' , ' centos6 ' ] ) )
>> > pprint . pprint ( make_containers ( ) )
[ { ' distro ' : ' debian11 ' ,
[ { ' distro ' : ' debian11 ' ,
' family ' : ' debian ' ,
' family ' : ' debian ' ,
' hostname ' : ' localhost ' ,
' hostname ' : ' localhost ' ,
' image ' : ' public.ecr.aws/n5z0e8q9/debian11-test ' ,
' image ' : ' public.ecr.aws/n5z0e8q9/debian11-test ' ,
' index ' : 1 ,
' name ' : ' target-debian11-1 ' ,
' name ' : ' target-debian11-1 ' ,
' port ' : 2201 ,
' port ' : 2201 ,
' python_path ' : ' /usr/bin/python ' } ,
' python_path ' : ' /usr/bin/python 3 ' } ,
{ ' distro ' : ' centos6 ' ,
{ ' distro ' : ' centos6 ' ,
' family ' : ' centos ' ,
' family ' : ' centos ' ,
' hostname ' : ' localhost ' ,
' hostname ' : ' localhost ' ,
' image ' : ' public.ecr.aws/n5z0e8q9/centos6-test ' ,
' image ' : ' public.ecr.aws/n5z0e8q9/centos6-test ' ,
' index ' : 2 ,
' name ' : ' target-centos6-2 ' ,
' name ' : ' target-centos6-2 ' ,
' port ' : 2202 ,
' port ' : 2202 ,
' python_path ' : ' /usr/bin/python ' } ]
' python_path ' : ' /usr/bin/python ' } ]
"""
"""
docker_hostname = get_docker_hostname ( )
docker_hostname = get_docker_hostname ( )
# Code duplicated in testlib.py, both should be updated together
distro_pattern = re . compile ( r '''
distro_pattern = re . compile ( r '''
( ? P < distro > ( ? P < family > [ a - z ] + ) [ 0 - 9 ] + )
( ? P < distro > ( ? P < family > [ a - z ] + ) [ 0 - 9 ] + )
( ? : - ( ? P < py > py3 ) ) ?
( ? : - ( ? P < py > py3 ) ) ?
@ -256,30 +269,27 @@ def make_containers(name_prefix='', port_offset=0):
i = 1
i = 1
lst = [ ]
lst = [ ]
for distro in DISTROS :
for distro in distros :
# Code duplicated in testlib.py, both should be updated together
d = distro_pattern . match ( distro ) . groupdict ( default = None )
d = distro_pattern . match ( distro ) . groupdict ( default = None )
distro = d [ ' distro ' ]
family = d [ ' family ' ]
image = ' public.ecr.aws/n5z0e8q9/ %s -test ' % ( distro , )
if d [ ' py ' ] == ' py3 ' :
if d . pop ( ' py ' ) == ' py3 ' :
python_path = ' /usr/bin/python3 '
python_path = ' /usr/bin/python3 '
else :
else :
python_path = ' /usr/bin/python '
python_path = ' /usr/bin/python '
if d [ ' count ' ] :
count = int ( d . pop ( ' count ' ) or ' 1 ' , 10 )
count = int ( count )
else :
count = 1
for x in range ( count ) :
for x in range ( count ) :
lst . append ( {
d [ ' index ' ] = i
" distro " : distro , " family " : family , " image " : image ,
d . update ( {
" name " : name_prefix + ( " target- %s - %s " % ( distro , i ) ) ,
' image ' : image_template % d ,
' name ' : name_template % d ,
" hostname " : docker_hostname ,
" hostname " : docker_hostname ,
" port " : BASE_PORT + i + port_offset ,
' port ' : base_port + i ,
" python_path " : python_path ,
" python_path " : python_path ,
} )
} )
lst . append ( d )
i + = 1
i + = 1
return lst
return lst