@ -105,8 +105,9 @@ def test_create(loop, project, manager):
" Hostname " : " test " ,
" Image " : " ubuntu:latest " ,
" Env " : [
" GNS3_MAX_ETHERNET=eth0 "
] ,
" GNS3_MAX_ETHERNET=eth0 " ,
" GNS3_VOLUMES=/etc/network "
] ,
" Entrypoint " : [ " /gns3/init.sh " ] ,
" Cmd " : [ " /bin/sh " ]
} )
@ -142,8 +143,9 @@ def test_create_with_tag(loop, project, manager):
" Hostname " : " test " ,
" Image " : " ubuntu:16.04 " ,
" Env " : [
" GNS3_MAX_ETHERNET=eth0 "
] ,
" GNS3_MAX_ETHERNET=eth0 " ,
" GNS3_VOLUMES=/etc/network "
] ,
" Entrypoint " : [ " /gns3/init.sh " ] ,
" Cmd " : [ " /bin/sh " ]
} )
@ -184,8 +186,9 @@ def test_create_vnc(loop, project, manager):
" Image " : " ubuntu:latest " ,
" Env " : [
" GNS3_MAX_ETHERNET=eth0 " ,
" GNS3_VOLUMES=/etc/network " ,
" DISPLAY=:42 "
] ,
] ,
" Entrypoint " : [ " /gns3/init.sh " ] ,
" Cmd " : [ " /bin/sh " ]
} )
@ -226,8 +229,9 @@ def test_create_start_cmd(loop, project, manager):
" Hostname " : " test " ,
" Image " : " ubuntu:latest " ,
" Env " : [
" GNS3_MAX_ETHERNET=eth0 "
]
" GNS3_MAX_ETHERNET=eth0 " ,
" GNS3_VOLUMES=/etc/network "
]
} )
assert vm . _cid == " e90e34656806 "
@ -258,6 +262,7 @@ def test_create_environment(loop, project, manager):
} ,
" Env " : [
" GNS3_MAX_ETHERNET=eth0 " ,
" GNS3_VOLUMES=/etc/network " ,
" YES=1 " ,
" NO=0 "
] ,
@ -315,8 +320,9 @@ def test_create_image_not_available(loop, project, manager):
" Hostname " : " test " ,
" Image " : " ubuntu:latest " ,
" Env " : [
" GNS3_MAX_ETHERNET=eth0 "
] ,
" GNS3_MAX_ETHERNET=eth0 " ,
" GNS3_VOLUMES=/etc/network "
] ,
" Entrypoint " : [ " /gns3/init.sh " ] ,
" Cmd " : [ " /bin/sh " ]
} )
@ -479,12 +485,14 @@ def test_restart(loop, vm):
def test_stop ( loop , vm ) :
vm . _ubridge_hypervisor = MagicMock ( )
vm . _ubridge_hypervisor . is_running . return_value = True
vm . _fix_permissions = MagicMock ( )
with asyncio_patch ( " gns3server.compute.docker.DockerVM._get_container_state " , return_value = " running " ) :
with asyncio_patch ( " gns3server.compute.docker.Docker.query " ) as mock_query :
loop . run_until_complete ( asyncio . async ( vm . stop ( ) ) )
mock_query . assert_called_with ( " POST " , " containers/e90e34656842/stop " , params = { " t " : 5 } )
assert vm . _ubridge_hypervisor . stop . called
assert vm . _fix_permissions . called
def test_stop_paused_container ( loop , vm ) :
@ -532,7 +540,8 @@ def test_update(loop, vm):
" Hostname " : " test " ,
" Image " : " ubuntu:latest " ,
" Env " : [
" GNS3_MAX_ETHERNET=eth0 "
" GNS3_MAX_ETHERNET=eth0 " ,
" GNS3_VOLUMES=/etc/network "
] ,
" Entrypoint " : [ " /gns3/init.sh " ] ,
" Cmd " : [ " /bin/sh " ]
@ -599,7 +608,8 @@ def test_update_running(loop, vm):
" Hostname " : " test " ,
" Image " : " ubuntu:latest " ,
" Env " : [
" GNS3_MAX_ETHERNET=eth0 "
" GNS3_MAX_ETHERNET=eth0 " ,
" GNS3_VOLUMES=/etc/network "
] ,
" Entrypoint " : [ " /gns3/init.sh " ] ,
" Cmd " : [ " /bin/sh " ]
@ -869,6 +879,7 @@ def test_mount_binds(vm, tmpdir):
" {} : {} " . format ( dst , " /test/experimental " )
]
assert vm . _volumes == [ " /etc/network " , " /test/experimental " ]
assert os . path . exists ( dst )
@ -893,6 +904,7 @@ def test_start_aux(vm, loop):
with asyncio_patch ( " asyncio.subprocess.create_subprocess_exec " , return_value = MagicMock ( ) ) as mock_exec :
loop . run_until_complete ( asyncio . async ( vm . _start_aux ( ) ) )
mock_exec . assert_called_with ( ' docker ' , ' exec ' , ' -i ' , ' e90e34656842 ' , ' /gns3/bin/busybox ' , ' script ' , ' -qfc ' , ' /gns3/bin/busybox sh ' , ' /dev/null ' , stderr = asyncio . subprocess . STDOUT , stdin = asyncio . subprocess . PIPE , stdout = asyncio . subprocess . PIPE )
def test_create_network_interfaces ( vm ) :
@ -907,3 +919,12 @@ def test_create_network_interfaces(vm):
assert " eth0 " in content
assert " eth4 " in content
assert " eth5 " not in content
def test_fix_permission ( vm , loop ) :
vm . _volumes = [ " /etc " ]
process = MagicMock ( )
with asyncio_patch ( " asyncio.subprocess.create_subprocess_exec " , return_value = process ) as mock_exec :
loop . run_until_complete ( vm . _fix_permissions ( ) )
mock_exec . assert_called_with ( ' docker ' , ' exec ' , ' e90e34656842 ' , ' /gns3/bin/busybox ' , ' sh ' , ' -c ' , ' (/gns3/bin/busybox find " /etc " -depth -print0 | /gns3/bin/busybox xargs -0 /gns3/bin/busybox stat -c \' %a : %u : %g : % n \' > " /etc/.gns3_perms " ) && /gns3/bin/busybox chmod -R u+rX " /etc " && /gns3/bin/busybox chown {} : {} -R " /etc " ' . format ( os . getuid ( ) , os . getgid ( ) ) )
assert process . wait . called