@ -87,7 +87,7 @@ def test_create(loop, project, manager):
with asyncio_patch ( " gns3server.compute.docker.Docker.list_images " , return_value = [ { " image " : " ubuntu " } ] ) as mock_list_images :
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) as mock :
vm = DockerVM ( " test " , str ( uuid . uuid4 ( ) ) , project , manager , " ubuntu:latest " )
loop . run_until_complete ( asyncio . async ( vm . create ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . create ( ) ) )
mock . assert_called_with ( " POST " , " containers/create " , data = {
" Tty " : True ,
" OpenStdin " : True ,
@ -126,7 +126,7 @@ def test_create_with_tag(loop, project, manager):
with asyncio_patch ( " gns3server.compute.docker.Docker.list_images " , return_value = [ { " image " : " ubuntu " } ] ) as mock_list_images :
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) as mock :
vm = DockerVM ( " test " , str ( uuid . uuid4 ( ) ) , project , manager , " ubuntu:16.04 " )
loop . run_until_complete ( asyncio . async ( vm . create ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . create ( ) ) )
mock . assert_called_with ( " POST " , " containers/create " , data = {
" Tty " : True ,
" OpenStdin " : True ,
@ -168,7 +168,7 @@ def test_create_vnc(loop, project, manager):
vm = DockerVM ( " test " , str ( uuid . uuid4 ( ) ) , project , manager , " ubuntu " , console_type = " vnc " , console = 5900 )
vm . _start_vnc = MagicMock ( )
vm . _display = 42
loop . run_until_complete ( asyncio . async ( vm . create ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . create ( ) ) )
mock . assert_called_with ( " POST " , " containers/create " , data = {
" Tty " : True ,
" OpenStdin " : True ,
@ -214,7 +214,7 @@ def test_create_with_extra_hosts(loop, project, manager):
with asyncio_patch ( " gns3server.compute.docker.Docker.list_images " , return_value = [ { " image " : " ubuntu " } ] ) :
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) as mock :
vm = DockerVM ( " test " , str ( uuid . uuid4 ( ) ) , project , manager , " ubuntu " , extra_hosts = extra_hosts )
loop . run_until_complete ( asyncio . async ( vm . create ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . create ( ) ) )
called_kwargs = mock . call_args [ 1 ]
assert " GNS3_EXTRA_HOSTS=199.199.199.1 \t test \n 199.199.199.1 \t test2 " in called_kwargs [ " data " ] [ " Env " ]
assert vm . _extra_hosts == extra_hosts
@ -232,7 +232,7 @@ def test_create_with_extra_hosts_wrong_format(loop, project, manager):
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) :
vm = DockerVM ( " test " , str ( uuid . uuid4 ( ) ) , project , manager , " ubuntu " , extra_hosts = extra_hosts )
with pytest . raises ( DockerError ) :
loop . run_until_complete ( asyncio . async ( vm . create ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . create ( ) ) )
def test_create_with_empty_extra_hosts ( loop , project , manager ) :
@ -246,7 +246,7 @@ def test_create_with_empty_extra_hosts(loop, project, manager):
with asyncio_patch ( " gns3server.compute.docker.Docker.list_images " , return_value = [ { " image " : " ubuntu " } ] ) :
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) as mock :
vm = DockerVM ( " test " , str ( uuid . uuid4 ( ) ) , project , manager , " ubuntu " , extra_hosts = extra_hosts )
loop . run_until_complete ( asyncio . async ( vm . create ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . create ( ) ) )
called_kwargs = mock . call_args [ 1 ]
assert len ( [ e for e in called_kwargs [ " data " ] [ " Env " ] if " GNS3_EXTRA_HOSTS " in e ] ) == 0
@ -266,7 +266,7 @@ def test_create_with_project_variables(loop, project, manager):
with asyncio_patch ( " gns3server.compute.docker.Docker.list_images " , return_value = [ { " image " : " ubuntu " } ] ) :
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) as mock :
vm = DockerVM ( " test " , str ( uuid . uuid4 ( ) ) , project , manager , " ubuntu " )
loop . run_until_complete ( asyncio . async ( vm . create ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . create ( ) ) )
called_kwargs = mock . call_args [ 1 ]
assert " VAR1= " in called_kwargs [ " data " ] [ " Env " ]
assert " VAR2=VAL1 " in called_kwargs [ " data " ] [ " Env " ]
@ -284,7 +284,7 @@ def test_create_start_cmd(loop, project, manager):
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) as mock :
vm = DockerVM ( " test " , str ( uuid . uuid4 ( ) ) , project , manager , " ubuntu:latest " )
vm . _start_command = " /bin/ls "
loop . run_until_complete ( asyncio . async ( vm . create ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . create ( ) ) )
mock . assert_called_with ( " POST " , " containers/create " , data = {
" Tty " : True ,
" OpenStdin " : True ,
@ -328,7 +328,7 @@ def test_create_environment(loop, project, manager):
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) as mock :
vm = DockerVM ( " test " , str ( uuid . uuid4 ( ) ) , project , manager , " ubuntu " )
vm . environment = " YES=1 \n NO=0 \n GNS3_MAX_ETHERNET=eth2 "
loop . run_until_complete ( asyncio . async ( vm . create ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . create ( ) ) )
assert mock . call_args [ 1 ] [ ' data ' ] [ ' Env ' ] == [
" container=docker " ,
" GNS3_MAX_ETHERNET=eth0 " ,
@ -352,7 +352,7 @@ def test_create_environment_with_last_new_line_character(loop, project, manager)
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) as mock :
vm = DockerVM ( " test " , str ( uuid . uuid4 ( ) ) , project , manager , " ubuntu " )
vm . environment = " YES=1 \n NO=0 \n GNS3_MAX_ETHERNET=eth2 \n "
loop . run_until_complete ( asyncio . async ( vm . create ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . create ( ) ) )
assert mock . call_args [ 1 ] [ ' data ' ] [ ' Env ' ] == [
" container=docker " ,
" GNS3_MAX_ETHERNET=eth0 " ,
@ -385,7 +385,7 @@ def test_create_image_not_available(loop, project, manager):
vm . _get_image_information . side_effect = information
with asyncio_patch ( " gns3server.compute.docker.DockerVM.pull_image " , return_value = True ) as mock_pull :
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) as mock :
loop . run_until_complete ( asyncio . async ( vm . create ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . create ( ) ) )
mock . assert_called_with ( " POST " , " containers/create " , data = {
" Tty " : True ,
" OpenStdin " : True ,
@ -431,17 +431,17 @@ def test_get_container_state(loop, vm):
}
}
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) as mock :
assert loop . run_until_complete ( asyncio . async ( vm . _get_container_state ( ) ) ) == " running "
assert loop . run_until_complete ( asyncio . ensure_future ( vm . _get_container_state ( ) ) ) == " running "
response [ " State " ] [ " Running " ] = False
response [ " State " ] [ " Paused " ] = True
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) as mock :
assert loop . run_until_complete ( asyncio . async ( vm . _get_container_state ( ) ) ) == " paused "
assert loop . run_until_complete ( asyncio . ensure_future ( vm . _get_container_state ( ) ) ) == " paused "
response [ " State " ] [ " Running " ] = False
response [ " State " ] [ " Paused " ] = False
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) as mock :
assert loop . run_until_complete ( asyncio . async ( vm . _get_container_state ( ) ) ) == " exited "
assert loop . run_until_complete ( asyncio . ensure_future ( vm . _get_container_state ( ) ) ) == " exited "
def test_is_running ( loop , vm ) :
@ -452,17 +452,17 @@ def test_is_running(loop, vm):
}
}
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) as mock :
assert loop . run_until_complete ( asyncio . async ( vm . is_running ( ) ) ) is False
assert loop . run_until_complete ( asyncio . ensure_future ( vm . is_running ( ) ) ) is False
response [ " State " ] [ " Running " ] = True
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) as mock :
assert loop . run_until_complete ( asyncio . async ( vm . is_running ( ) ) ) is True
assert loop . run_until_complete ( asyncio . ensure_future ( vm . is_running ( ) ) ) is True
def test_pause ( loop , vm ) :
with asyncio_patch ( " gns3server.compute.docker.Docker.query " ) as mock :
loop . run_until_complete ( asyncio . async ( vm . pause ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . pause ( ) ) )
mock . assert_called_with ( " POST " , " containers/e90e34656842/pause " )
assert vm . status == " suspended "
@ -471,7 +471,7 @@ def test_pause(loop, vm):
def test_unpause ( loop , vm ) :
with asyncio_patch ( " gns3server.compute.docker.Docker.query " ) as mock :
loop . run_until_complete ( asyncio . async ( vm . unpause ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . unpause ( ) ) )
mock . assert_called_with ( " POST " , " containers/e90e34656842/unpause " )
@ -491,10 +491,10 @@ def test_start(loop, vm, manager, free_console_port):
vm . _start_console = AsyncioMagicMock ( )
nio = manager . create_nio ( { " type " : " nio_udp " , " lport " : free_console_port , " rport " : free_console_port , " rhost " : " 127.0.0.1 " } )
loop . run_until_complete ( asyncio . async ( vm . adapter_add_nio_binding ( 0 , nio ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . adapter_add_nio_binding ( 0 , nio ) ) )
with asyncio_patch ( " gns3server.compute.docker.Docker.query " ) as mock_query :
loop . run_until_complete ( asyncio . async ( vm . start ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . start ( ) ) )
mock_query . assert_called_with ( " POST " , " containers/e90e34656842/start " )
vm . _add_ubridge_connection . assert_called_once_with ( nio , 0 )
@ -510,7 +510,7 @@ def test_start_namespace_failed(loop, vm, manager, free_console_port):
vm . adapters = 1
nio = manager . create_nio ( { " type " : " nio_udp " , " lport " : free_console_port , " rport " : free_console_port , " rhost " : " 127.0.0.1 " } )
loop . run_until_complete ( asyncio . async ( vm . adapter_add_nio_binding ( 0 , nio ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . adapter_add_nio_binding ( 0 , nio ) ) )
with asyncio_patch ( " gns3server.compute.docker.DockerVM._get_container_state " , return_value = " stopped " ) :
with asyncio_patch ( " gns3server.compute.docker.Docker.query " ) as mock_query :
@ -520,7 +520,7 @@ def test_start_namespace_failed(loop, vm, manager, free_console_port):
with asyncio_patch ( " gns3server.compute.docker.DockerVM._get_log " , return_value = ' Hello not available ' ) as mock_log :
with pytest . raises ( DockerError ) :
loop . run_until_complete ( asyncio . async ( vm . start ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . start ( ) ) )
mock_query . assert_any_call ( " POST " , " containers/e90e34656842/start " )
mock_add_ubridge_connection . assert_called_once_with ( nio , 0 )
@ -542,7 +542,7 @@ def test_start_without_nio(loop, vm, manager, free_console_port):
with asyncio_patch ( " gns3server.compute.docker.DockerVM._get_namespace " , return_value = 42 ) as mock_namespace :
with asyncio_patch ( " gns3server.compute.docker.DockerVM._add_ubridge_connection " ) as mock_add_ubridge_connection :
with asyncio_patch ( " gns3server.compute.docker.DockerVM._start_console " ) as mock_start_console :
loop . run_until_complete ( asyncio . async ( vm . start ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . start ( ) ) )
mock_query . assert_called_with ( " POST " , " containers/e90e34656842/start " )
assert mock_add_ubridge_connection . called
@ -555,7 +555,7 @@ def test_start_unpause(loop, vm, manager, free_console_port):
with asyncio_patch ( " gns3server.compute.docker.DockerVM._get_container_state " , return_value = " paused " ) :
with asyncio_patch ( " gns3server.compute.docker.DockerVM.unpause " , return_value = " paused " ) as mock :
loop . run_until_complete ( asyncio . async ( vm . start ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . start ( ) ) )
assert mock . called
assert vm . status == " started "
@ -563,7 +563,7 @@ def test_start_unpause(loop, vm, manager, free_console_port):
def test_restart ( loop , vm ) :
with asyncio_patch ( " gns3server.compute.docker.Docker.query " ) as mock :
loop . run_until_complete ( asyncio . async ( vm . restart ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . restart ( ) ) )
mock . assert_called_with ( " POST " , " containers/e90e34656842/restart " )
@ -576,7 +576,7 @@ def test_stop(loop, vm):
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 ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . stop ( ) ) )
mock_query . assert_called_with ( " POST " , " containers/e90e34656842/stop " , params = { " t " : 5 } )
assert mock . stop . called
assert vm . _ubridge_hypervisor is None
@ -588,7 +588,7 @@ def test_stop_paused_container(loop, vm):
with asyncio_patch ( " gns3server.compute.docker.DockerVM._get_container_state " , return_value = " paused " ) :
with asyncio_patch ( " gns3server.compute.docker.DockerVM.unpause " ) as mock_unpause :
with asyncio_patch ( " gns3server.compute.docker.Docker.query " ) as mock_query :
loop . run_until_complete ( asyncio . async ( vm . stop ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . stop ( ) ) )
mock_query . assert_called_with ( " POST " , " containers/e90e34656842/stop " , params = { " t " : 5 } )
assert mock_unpause . called
@ -606,7 +606,7 @@ def test_update(loop, vm):
with asyncio_patch ( " gns3server.compute.docker.Docker.list_images " , return_value = [ { " image " : " ubuntu " } ] ) as mock_list_images :
with asyncio_patch ( " gns3server.compute.docker.DockerVM._get_container_state " , return_value = " stopped " ) :
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) as mock_query :
loop . run_until_complete ( asyncio . async ( vm . update ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . update ( ) ) )
mock_query . assert_any_call ( " DELETE " , " containers/e90e34656842 " , params = { " force " : 1 , " v " : 1 } )
mock_query . assert_any_call ( " POST " , " containers/create " , data = {
@ -656,7 +656,7 @@ def test_update_vnc(loop, vm):
with asyncio_patch ( " gns3server.compute.docker.Docker.list_images " , return_value = [ { " image " : " ubuntu " } ] ) as mock_list_images :
with asyncio_patch ( " gns3server.compute.docker.DockerVM._get_container_state " , return_value = " stopped " ) :
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) as mock_query :
loop . run_until_complete ( asyncio . async ( vm . update ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . update ( ) ) )
assert vm . console == original_console
assert vm . aux == original_aux
@ -675,7 +675,7 @@ def test_update_running(loop, vm):
with asyncio_patch ( " gns3server.compute.docker.Docker.list_images " , return_value = [ { " image " : " ubuntu " } ] ) as mock_list_images :
with asyncio_patch ( " gns3server.compute.docker.DockerVM._get_container_state " , return_value = " running " ) :
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) as mock_query :
loop . run_until_complete ( asyncio . async ( vm . update ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . update ( ) ) )
mock_query . assert_any_call ( " DELETE " , " containers/e90e34656842 " , params = { " force " : 1 , " v " : 1 } )
mock_query . assert_any_call ( " POST " , " containers/create " , data = {
@ -713,7 +713,7 @@ def test_delete(loop, vm):
with asyncio_patch ( " gns3server.compute.docker.DockerVM._get_container_state " , return_value = " stopped " ) :
with asyncio_patch ( " gns3server.compute.docker.Docker.query " ) as mock_query :
loop . run_until_complete ( asyncio . async ( vm . delete ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . delete ( ) ) )
mock_query . assert_called_with ( " DELETE " , " containers/e90e34656842 " , params = { " force " : 1 , " v " : 1 } )
@ -723,11 +723,11 @@ def test_close(loop, vm, port_manager):
" rport " : 4343 ,
" rhost " : " 127.0.0.1 " }
nio = vm . manager . create_nio ( nio )
loop . run_until_complete ( asyncio . async ( vm . adapter_add_nio_binding ( 0 , nio ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . adapter_add_nio_binding ( 0 , nio ) ) )
with asyncio_patch ( " gns3server.compute.docker.DockerVM._get_container_state " , return_value = " stopped " ) :
with asyncio_patch ( " gns3server.compute.docker.Docker.query " ) as mock_query :
loop . run_until_complete ( asyncio . async ( vm . close ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . close ( ) ) )
mock_query . assert_called_with ( " DELETE " , " containers/e90e34656842 " , params = { " force " : 1 , " v " : 1 } )
assert vm . _closed is True
@ -742,7 +742,7 @@ def test_close_vnc(loop, vm, port_manager):
with asyncio_patch ( " gns3server.compute.docker.DockerVM._get_container_state " , return_value = " stopped " ) :
with asyncio_patch ( " gns3server.compute.docker.Docker.query " ) as mock_query :
loop . run_until_complete ( asyncio . async ( vm . close ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . close ( ) ) )
mock_query . assert_called_with ( " DELETE " , " containers/e90e34656842 " , params = { " force " : 1 , " v " : 1 } )
assert vm . _closed is True
@ -756,7 +756,7 @@ def test_get_namespace(loop, vm):
}
}
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) as mock_query :
assert loop . run_until_complete ( asyncio . async ( vm . _get_namespace ( ) ) ) == 42
assert loop . run_until_complete ( asyncio . ensure_future ( vm . _get_namespace ( ) ) ) == 42
mock_query . assert_called_with ( " GET " , " containers/e90e34656842/json " )
@ -771,7 +771,7 @@ def test_add_ubridge_connection(loop, vm):
vm . _ubridge_hypervisor = MagicMock ( )
vm . _namespace = 42
loop . run_until_complete ( asyncio . async ( vm . _add_ubridge_connection ( nio , 0 ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . _add_ubridge_connection ( nio , 0 ) ) )
calls = [
call . send ( ' bridge create bridge0 ' ) ,
@ -792,7 +792,7 @@ def test_add_ubridge_connection_none_nio(loop, vm):
vm . _ubridge_hypervisor = MagicMock ( )
vm . _namespace = 42
loop . run_until_complete ( asyncio . async ( vm . _add_ubridge_connection ( nio , 0 ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . _add_ubridge_connection ( nio , 0 ) ) )
calls = [
call . send ( ' bridge create bridge0 ' ) ,
@ -813,7 +813,7 @@ def test_add_ubridge_connection_invalid_adapter_number(loop, vm):
" rhost " : " 127.0.0.1 " }
nio = vm . manager . create_nio ( nio )
with pytest . raises ( DockerError ) :
loop . run_until_complete ( asyncio . async ( vm . _add_ubridge_connection ( nio , 12 ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . _add_ubridge_connection ( nio , 12 ) ) )
def test_add_ubridge_connection_no_free_interface ( loop , vm ) :
@ -829,7 +829,7 @@ def test_add_ubridge_connection_no_free_interface(loop, vm):
interfaces = [ " tap-gns3-e {} " . format ( index ) for index in range ( 4096 ) ]
with patch ( " psutil.net_if_addrs " , return_value = interfaces ) :
loop . run_until_complete ( asyncio . async ( vm . _add_ubridge_connection ( nio , 0 ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . _add_ubridge_connection ( nio , 0 ) ) )
def test_adapter_add_nio_binding ( vm , loop ) :
@ -838,7 +838,7 @@ def test_adapter_add_nio_binding(vm, loop):
" rport " : 4343 ,
" rhost " : " 127.0.0.1 " }
nio = vm . manager . create_nio ( nio )
loop . run_until_complete ( asyncio . async ( vm . adapter_add_nio_binding ( 0 , nio ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . adapter_add_nio_binding ( 0 , nio ) ) )
assert vm . _ethernet_adapters [ 0 ] . get_nio ( 0 ) == nio
@ -853,9 +853,9 @@ def test_adapter_udpate_nio_binding(vm, loop):
" rhost " : " 127.0.0.1 " }
nio = vm . manager . create_nio ( nio )
with asyncio_patch ( " gns3server.compute.docker.DockerVM._get_container_state " , return_value = " running " ) :
loop . run_until_complete ( asyncio . async ( vm . adapter_add_nio_binding ( 0 , nio ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . adapter_add_nio_binding ( 0 , nio ) ) )
loop . run_until_complete ( asyncio . async ( vm . adapter_update_nio_binding ( 0 , nio ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . adapter_update_nio_binding ( 0 , nio ) ) )
assert vm . _ubridge_apply_filters . called
@ -867,9 +867,9 @@ def test_adapter_udpate_nio_binding_bridge_not_started(vm, loop):
" rhost " : " 127.0.0.1 " }
nio = vm . manager . create_nio ( nio )
with asyncio_patch ( " gns3server.compute.docker.DockerVM._get_container_state " , return_value = " running " ) :
loop . run_until_complete ( asyncio . async ( vm . adapter_add_nio_binding ( 0 , nio ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . adapter_add_nio_binding ( 0 , nio ) ) )
loop . run_until_complete ( asyncio . async ( vm . adapter_update_nio_binding ( 0 , nio ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . adapter_update_nio_binding ( 0 , nio ) ) )
assert vm . _ubridge_apply_filters . called is False
@ -880,7 +880,7 @@ def test_adapter_add_nio_binding_invalid_adapter(vm, loop):
" rhost " : " 127.0.0.1 " }
nio = vm . manager . create_nio ( nio )
with pytest . raises ( DockerError ) :
loop . run_until_complete ( asyncio . async ( vm . adapter_add_nio_binding ( 12 , nio ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . adapter_add_nio_binding ( 12 , nio ) ) )
def test_adapter_remove_nio_binding ( vm , loop ) :
@ -892,10 +892,10 @@ def test_adapter_remove_nio_binding(vm, loop):
" rport " : 4343 ,
" rhost " : " 127.0.0.1 " }
nio = vm . manager . create_nio ( nio )
loop . run_until_complete ( asyncio . async ( vm . adapter_add_nio_binding ( 0 , nio ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . adapter_add_nio_binding ( 0 , nio ) ) )
with asyncio_patch ( " gns3server.compute.docker.DockerVM._ubridge_send " ) as delete_ubridge_mock :
loop . run_until_complete ( asyncio . async ( vm . adapter_remove_nio_binding ( 0 ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . adapter_remove_nio_binding ( 0 ) ) )
assert vm . _ethernet_adapters [ 0 ] . get_nio ( 0 ) is None
delete_ubridge_mock . assert_any_call ( ' bridge stop bridge0 ' )
delete_ubridge_mock . assert_any_call ( ' bridge remove_nio_udp bridge0 4242 127.0.0.1 4343 ' )
@ -903,15 +903,15 @@ def test_adapter_remove_nio_binding(vm, loop):
def test_adapter_remove_nio_binding_invalid_adapter ( vm , loop ) :
with pytest . raises ( DockerError ) :
loop . run_until_complete ( asyncio . async ( vm . adapter_remove_nio_binding ( 12 ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . adapter_remove_nio_binding ( 12 ) ) )
def test_start_capture ( vm , tmpdir , manager , free_console_port , loop ) :
output_file = str ( tmpdir / " test.pcap " )
nio = manager . create_nio ( { " type " : " nio_udp " , " lport " : free_console_port , " rport " : free_console_port , " rhost " : " 127.0.0.1 " } )
loop . run_until_complete ( asyncio . async ( vm . adapter_add_nio_binding ( 0 , nio ) ) )
loop . run_until_complete ( asyncio . async ( vm . start_capture ( 0 , output_file ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . adapter_add_nio_binding ( 0 , nio ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . start_capture ( 0 , output_file ) ) )
assert vm . _ethernet_adapters [ 0 ] . get_nio ( 0 ) . capturing
@ -919,10 +919,10 @@ def test_stop_capture(vm, tmpdir, manager, free_console_port, loop):
output_file = str ( tmpdir / " test.pcap " )
nio = manager . create_nio ( { " type " : " nio_udp " , " lport " : free_console_port , " rport " : free_console_port , " rhost " : " 127.0.0.1 " } )
loop . run_until_complete ( asyncio . async ( vm . adapter_add_nio_binding ( 0 , nio ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . adapter_add_nio_binding ( 0 , nio ) ) )
loop . run_until_complete ( vm . start_capture ( 0 , output_file ) )
assert vm . _ethernet_adapters [ 0 ] . get_nio ( 0 ) . capturing
loop . run_until_complete ( asyncio . async ( vm . stop_capture ( 0 ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . stop_capture ( 0 ) ) )
assert vm . _ethernet_adapters [ 0 ] . get_nio ( 0 ) . capturing is False
@ -935,7 +935,7 @@ def test_get_log(loop, vm):
mock_query . read = read
with asyncio_patch ( " gns3server.compute.docker.Docker.http_query " , return_value = mock_query ) as mock :
images = loop . run_until_complete ( asyncio . async ( vm . _get_log ( ) ) )
images = loop . run_until_complete ( asyncio . ensure_future ( vm . _get_log ( ) ) )
mock . assert_called_with ( " GET " , " containers/e90e34656842/logs " , params = { " stderr " : 1 , " stdout " : 1 } , data = { } )
@ -944,7 +944,7 @@ def test_get_image_informations(project, manager, loop):
}
with asyncio_patch ( " gns3server.compute.docker.Docker.query " , return_value = response ) as mock :
vm = DockerVM ( " test " , str ( uuid . uuid4 ( ) ) , project , manager , " ubuntu " )
loop . run_until_complete ( asyncio . async ( vm . _get_image_information ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . _get_image_information ( ) ) )
mock . assert_called_with ( " GET " , " images/ubuntu:latest/json " )
@ -974,7 +974,7 @@ def test_start_vnc(vm, loop):
with patch ( " shutil.which " , return_value = " /bin/x " ) :
with asyncio_patch ( " gns3server.compute.docker.docker_vm.wait_for_file_creation " ) as mock_wait :
with asyncio_patch ( " asyncio.create_subprocess_exec " ) as mock_exec :
loop . run_until_complete ( asyncio . async ( vm . _start_vnc ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . _start_vnc ( ) ) )
assert vm . _display is not None
mock_exec . assert_any_call ( " Xvfb " , " -nolisten " , " tcp " , " : {} " . format ( vm . _display ) , " -screen " , " 0 " , " 1280x1024x16 " )
mock_exec . assert_any_call ( " x11vnc " , " -forever " , " -nopw " , " -shared " , " -geometry " , " 1280x1024 " , " -display " , " WAIT: {} " . format ( vm . _display ) , " -rfbport " , str ( vm . console ) , " -rfbportv6 " , str ( vm . console ) , " -noncache " , " -listen " , " 127.0.0.1 " )
@ -983,13 +983,13 @@ def test_start_vnc(vm, loop):
def test_start_vnc_xvfb_missing ( vm , loop ) :
with pytest . raises ( DockerError ) :
loop . run_until_complete ( asyncio . async ( vm . _start_vnc ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . _start_vnc ( ) ) )
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 ( ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . _start_aux ( ) ) )
mock_exec . assert_called_with ( ' docker ' , ' exec ' , ' -i ' , ' e90e34656842 ' , ' /gns3/bin/busybox ' , ' script ' , ' -qfc ' , ' while true; do TERM=vt100 /gns3/bin/busybox sh; done ' , ' /dev/null ' , stderr = asyncio . subprocess . STDOUT , stdin = asyncio . subprocess . PIPE , stdout = asyncio . subprocess . PIPE )
@ -1051,5 +1051,5 @@ def test_read_console_output_with_binary_mode(vm, loop):
output_stream = MagicMock ( )
with asyncio_patch ( ' gns3server.compute.docker.docker_vm.DockerVM.stop ' ) :
loop . run_until_complete ( asyncio . async ( vm . _read_console_output ( input_stream , output_stream ) ) )
loop . run_until_complete ( asyncio . ensure_future ( vm . _read_console_output ( input_stream , output_stream ) ) )
output_stream . feed_data . assert_called_once_with ( b " test " )