Merge branch '2.1' into 2.2

# Conflicts:
#	gns3server/version.py
#	tests/compute/docker/test_docker_vm.py
This commit is contained in:
grossmj 2018-03-14 18:40:37 +07:00
commit 88674455a3
5 changed files with 120 additions and 84 deletions

View File

@ -16,6 +16,8 @@ before_deploy:
deploy: deploy:
provider: pypi provider: pypi
edge:
branch: v1.8.45
user: noplay user: noplay
password: password:
secure: Fa66zp8ML4oSGwzkUMZi07MIYfO3tbS5gHFUaLN2mk2MBknhCjDYexmFJqT//sC/+xqv6sSJE6rz1EPoy/THbxj8R96ZgIyiUZIbDCbzgdy92d7J/eusrDoNdpApBLke8NqQqtFETb3addMZZNofQ3IDANFD2m2jY+KECU8z8NI= secure: Fa66zp8ML4oSGwzkUMZi07MIYfO3tbS5gHFUaLN2mk2MBknhCjDYexmFJqT//sC/+xqv6sSJE6rz1EPoy/THbxj8R96ZgIyiUZIbDCbzgdy92d7J/eusrDoNdpApBLke8NqQqtFETb3addMZZNofQ3IDANFD2m2jY+KECU8z8NI=

View File

@ -1,5 +1,37 @@
# Change Log # Change Log
## 2.1.4 12/03/2018
* Add Juniper JunOS space appliance.
* Sync checkpoint gaia appliance template.
* Sync appliance templates.
* Make sure we use an IPv4 address in the remote install script.
* Delete old pcap file when starting a new packet capture.
* Fix bug preventing to export portable projects with IOU images.
* Ignore invalid BPF filters. Ref #1290.
* Different approach to handle no data returned by uBridge hypervisors. Fixes #1289.
* Do not raise exception if Dynamips or uBridge hypervisor don't return data and are still running. Fixes #1289
* Fix Dynamips private config not loaded into nvram when starting a router. Fixes #1313.
* Make sure we don't try to read when opening a file in binary more. Fixes #1301.
* Compatybility with controller, default_symbol and hover_symbol, Fixes: #2444
* Filter snapshots directory during the snapshot, Fixes: #1297
* Handle docker env with last empty line, Fixes: #2420
* Require uBridge version 0.9.14 on Linux
* Pywin32 instead of pypiwin32, Ref. #1276
* Fix missing 'locales' package in base image
* Implement a minimum interval between psutil calls. Fixes #2262
* Fix error when appliance template is broken (missing fields). Fixes #1287.
* Fix "Change of linked base VM doesn't work with templates migrated from 2.0"
* Fix "Unable to override non-custom VMware adapter".
* Let a project be opened when a port cannot be found (can happens if a project is corrupted).
* Add an error message when Docker container is not ready to be started. Ref #1281.
* Update documentation.
* Sync appliance files.
* Fix issue when running multiple project containing IOU nodes on the same server. Ref #1239.
* Set first byte to 52 when generating a random MAC address for a Qemu VM. Ref #1267.
* Update link state and save project when a link is suspended or filters are added/removed (without node properties set).
* More generic dependency for pypiwin32, Ref. #1276
## 2.1.3 19/01/2018 ## 2.1.3 19/01/2018
* Update appliance files. * Update appliance files.

View File

@ -57,7 +57,7 @@ class CrashReport:
Report crash to a third party service Report crash to a third party service
""" """
DSN = "sync+https://9bd029d7f92b48178b01868465532d6e:9f4a6a513bd1452fbfd1771ae2ca8b66@sentry.io/38482" DSN = "sync+https://6b6c2ce19b8545278f7ee00c333175a6:be17229ec8da460e9a126d02b82de5dc@sentry.io/38482"
if hasattr(sys, "frozen"): if hasattr(sys, "frozen"):
cacert = get_resource("cacert.pem") cacert = get_resource("cacert.pem")
if cacert is not None and os.path.isfile(cacert): if cacert is not None and os.path.isfile(cacert):

View File

@ -86,7 +86,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.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:latest") vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:latest")
loop.run_until_complete(asyncio.ensure_future(vm.create())) loop.run_until_complete(asyncio.async(vm.create()))
mock.assert_called_with("POST", "containers/create", data={ mock.assert_called_with("POST", "containers/create", data={
"Tty": True, "Tty": True,
"OpenStdin": True, "OpenStdin": True,
@ -125,7 +125,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.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:16.04") vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:16.04")
loop.run_until_complete(asyncio.ensure_future(vm.create())) loop.run_until_complete(asyncio.async(vm.create()))
mock.assert_called_with("POST", "containers/create", data={ mock.assert_called_with("POST", "containers/create", data={
"Tty": True, "Tty": True,
"OpenStdin": True, "OpenStdin": True,
@ -167,7 +167,7 @@ def test_create_vnc(loop, project, manager):
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu", console_type="vnc", console=5900) vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu", console_type="vnc", console=5900)
vm._start_vnc = MagicMock() vm._start_vnc = MagicMock()
vm._display = 42 vm._display = 42
loop.run_until_complete(asyncio.ensure_future(vm.create())) loop.run_until_complete(asyncio.async(vm.create()))
mock.assert_called_with("POST", "containers/create", data={ mock.assert_called_with("POST", "containers/create", data={
"Tty": True, "Tty": True,
"OpenStdin": True, "OpenStdin": True,
@ -212,7 +212,7 @@ def test_create_start_cmd(loop, project, manager):
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:latest") vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu:latest")
vm._start_command = "/bin/ls" vm._start_command = "/bin/ls"
loop.run_until_complete(asyncio.ensure_future(vm.create())) loop.run_until_complete(asyncio.async(vm.create()))
mock.assert_called_with("POST", "containers/create", data={ mock.assert_called_with("POST", "containers/create", data={
"Tty": True, "Tty": True,
"OpenStdin": True, "OpenStdin": True,
@ -256,36 +256,38 @@ def test_create_environment(loop, project, manager):
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu") vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
vm.environment = "YES=1\nNO=0\nGNS3_MAX_ETHERNET=eth2" vm.environment = "YES=1\nNO=0\nGNS3_MAX_ETHERNET=eth2"
loop.run_until_complete(asyncio.ensure_future(vm.create())) loop.run_until_complete(asyncio.async(vm.create()))
mock.assert_called_with("POST", "containers/create", data={ assert mock.call_args[1]['data']['Env'] == [
"Tty": True, "container=docker",
"OpenStdin": True, "GNS3_MAX_ETHERNET=eth0",
"StdinOnce": False, "GNS3_VOLUMES=/etc/network",
"HostConfig": "YES=1",
{ "NO=0"
"CapAdd": ["ALL"], ]
"Binds": [
"{}:/gns3:ro".format(get_resource("compute/docker/resources")),
"{}:/gns3volumes/etc/network:rw".format(os.path.join(vm.working_dir, "etc", "network")) def test_create_environment_with_last_new_line_character(loop, project, manager):
], """
"Privileged": True Allow user to pass an environnement. User can't override our
}, internal variables
"Env": [ """
"container=docker",
"GNS3_MAX_ETHERNET=eth0", response = {
"GNS3_VOLUMES=/etc/network", "Id": "e90e34656806",
"YES=1", "Warnings": []
"NO=0" }
], with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]):
"Volumes": {}, with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
"NetworkDisabled": True, vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
"Name": "test", vm.environment = "YES=1\nNO=0\nGNS3_MAX_ETHERNET=eth2\n"
"Hostname": "test", loop.run_until_complete(asyncio.async(vm.create()))
"Image": "ubuntu:latest", assert mock.call_args[1]['data']['Env'] == [
"Entrypoint": ["/gns3/init.sh"], "container=docker",
"Cmd": ["/bin/sh"] "GNS3_MAX_ETHERNET=eth0",
}) "GNS3_VOLUMES=/etc/network",
assert vm._cid == "e90e34656806" "YES=1",
"NO=0"
]
def test_create_image_not_available(loop, project, manager): def test_create_image_not_available(loop, project, manager):
@ -311,7 +313,7 @@ def test_create_image_not_available(loop, project, manager):
vm._get_image_information.side_effect = information 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.DockerVM.pull_image", return_value=True) as mock_pull:
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
loop.run_until_complete(asyncio.ensure_future(vm.create())) loop.run_until_complete(asyncio.async(vm.create()))
mock.assert_called_with("POST", "containers/create", data={ mock.assert_called_with("POST", "containers/create", data={
"Tty": True, "Tty": True,
"OpenStdin": True, "OpenStdin": True,
@ -357,17 +359,17 @@ def test_get_container_state(loop, vm):
} }
} }
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
assert loop.run_until_complete(asyncio.ensure_future(vm._get_container_state())) == "running" assert loop.run_until_complete(asyncio.async(vm._get_container_state())) == "running"
response["State"]["Running"] = False response["State"]["Running"] = False
response["State"]["Paused"] = True response["State"]["Paused"] = True
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
assert loop.run_until_complete(asyncio.ensure_future(vm._get_container_state())) == "paused" assert loop.run_until_complete(asyncio.async(vm._get_container_state())) == "paused"
response["State"]["Running"] = False response["State"]["Running"] = False
response["State"]["Paused"] = False response["State"]["Paused"] = False
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
assert loop.run_until_complete(asyncio.ensure_future(vm._get_container_state())) == "exited" assert loop.run_until_complete(asyncio.async(vm._get_container_state())) == "exited"
def test_is_running(loop, vm): def test_is_running(loop, vm):
@ -378,17 +380,17 @@ def test_is_running(loop, vm):
} }
} }
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
assert loop.run_until_complete(asyncio.ensure_future(vm.is_running())) is False assert loop.run_until_complete(asyncio.async(vm.is_running())) is False
response["State"]["Running"] = True response["State"]["Running"] = True
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
assert loop.run_until_complete(asyncio.ensure_future(vm.is_running())) is True assert loop.run_until_complete(asyncio.async(vm.is_running())) is True
def test_pause(loop, vm): def test_pause(loop, vm):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock: with asyncio_patch("gns3server.compute.docker.Docker.query") as mock:
loop.run_until_complete(asyncio.ensure_future(vm.pause())) loop.run_until_complete(asyncio.async(vm.pause()))
mock.assert_called_with("POST", "containers/e90e34656842/pause") mock.assert_called_with("POST", "containers/e90e34656842/pause")
assert vm.status == "suspended" assert vm.status == "suspended"
@ -397,7 +399,7 @@ def test_pause(loop, vm):
def test_unpause(loop, vm): def test_unpause(loop, vm):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock: with asyncio_patch("gns3server.compute.docker.Docker.query") as mock:
loop.run_until_complete(asyncio.ensure_future(vm.unpause())) loop.run_until_complete(asyncio.async(vm.unpause()))
mock.assert_called_with("POST", "containers/e90e34656842/unpause") mock.assert_called_with("POST", "containers/e90e34656842/unpause")
@ -417,10 +419,10 @@ def test_start(loop, vm, manager, free_console_port):
vm._start_console = AsyncioMagicMock() vm._start_console = AsyncioMagicMock()
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.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.ensure_future(vm.adapter_add_nio_binding(0, nio))) loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query: with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
loop.run_until_complete(asyncio.ensure_future(vm.start())) loop.run_until_complete(asyncio.async(vm.start()))
mock_query.assert_called_with("POST", "containers/e90e34656842/start") mock_query.assert_called_with("POST", "containers/e90e34656842/start")
vm._add_ubridge_connection.assert_called_once_with(nio, 0) vm._add_ubridge_connection.assert_called_once_with(nio, 0)
@ -436,7 +438,7 @@ def test_start_namespace_failed(loop, vm, manager, free_console_port):
vm.adapters = 1 vm.adapters = 1
nio = manager.create_nio({"type": "nio_udp", "lport": free_console_port, "rport": free_console_port, "rhost": "127.0.0.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.ensure_future(vm.adapter_add_nio_binding(0, nio))) loop.run_until_complete(asyncio.async(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.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query: with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
@ -446,7 +448,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 asyncio_patch("gns3server.compute.docker.DockerVM._get_log", return_value='Hello not available') as mock_log:
with pytest.raises(DockerError): with pytest.raises(DockerError):
loop.run_until_complete(asyncio.ensure_future(vm.start())) loop.run_until_complete(asyncio.async(vm.start()))
mock_query.assert_any_call("POST", "containers/e90e34656842/start") mock_query.assert_any_call("POST", "containers/e90e34656842/start")
mock_add_ubridge_connection.assert_called_once_with(nio, 0) mock_add_ubridge_connection.assert_called_once_with(nio, 0)
@ -468,7 +470,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._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._add_ubridge_connection") as mock_add_ubridge_connection:
with asyncio_patch("gns3server.compute.docker.DockerVM._start_console") as mock_start_console: with asyncio_patch("gns3server.compute.docker.DockerVM._start_console") as mock_start_console:
loop.run_until_complete(asyncio.ensure_future(vm.start())) loop.run_until_complete(asyncio.async(vm.start()))
mock_query.assert_called_with("POST", "containers/e90e34656842/start") mock_query.assert_called_with("POST", "containers/e90e34656842/start")
assert mock_add_ubridge_connection.called assert mock_add_ubridge_connection.called
@ -481,7 +483,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._get_container_state", return_value="paused"):
with asyncio_patch("gns3server.compute.docker.DockerVM.unpause", return_value="paused") as mock: with asyncio_patch("gns3server.compute.docker.DockerVM.unpause", return_value="paused") as mock:
loop.run_until_complete(asyncio.ensure_future(vm.start())) loop.run_until_complete(asyncio.async(vm.start()))
assert mock.called assert mock.called
assert vm.status == "started" assert vm.status == "started"
@ -489,7 +491,7 @@ def test_start_unpause(loop, vm, manager, free_console_port):
def test_restart(loop, vm): def test_restart(loop, vm):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock: with asyncio_patch("gns3server.compute.docker.Docker.query") as mock:
loop.run_until_complete(asyncio.ensure_future(vm.restart())) loop.run_until_complete(asyncio.async(vm.restart()))
mock.assert_called_with("POST", "containers/e90e34656842/restart") mock.assert_called_with("POST", "containers/e90e34656842/restart")
@ -502,7 +504,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.DockerVM._get_container_state", return_value="running"):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query: with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
loop.run_until_complete(asyncio.ensure_future(vm.stop())) loop.run_until_complete(asyncio.async(vm.stop()))
mock_query.assert_called_with("POST", "containers/e90e34656842/stop", params={"t": 5}) mock_query.assert_called_with("POST", "containers/e90e34656842/stop", params={"t": 5})
assert mock.stop.called assert mock.stop.called
assert vm._ubridge_hypervisor is None assert vm._ubridge_hypervisor is None
@ -514,7 +516,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._get_container_state", return_value="paused"):
with asyncio_patch("gns3server.compute.docker.DockerVM.unpause") as mock_unpause: with asyncio_patch("gns3server.compute.docker.DockerVM.unpause") as mock_unpause:
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query: with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
loop.run_until_complete(asyncio.ensure_future(vm.stop())) loop.run_until_complete(asyncio.async(vm.stop()))
mock_query.assert_called_with("POST", "containers/e90e34656842/stop", params={"t": 5}) mock_query.assert_called_with("POST", "containers/e90e34656842/stop", params={"t": 5})
assert mock_unpause.called assert mock_unpause.called
@ -532,7 +534,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.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.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query:
loop.run_until_complete(asyncio.ensure_future(vm.update())) loop.run_until_complete(asyncio.async(vm.update()))
mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1}) mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
mock_query.assert_any_call("POST", "containers/create", data={ mock_query.assert_any_call("POST", "containers/create", data={
@ -582,7 +584,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.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.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query:
loop.run_until_complete(asyncio.ensure_future(vm.update())) loop.run_until_complete(asyncio.async(vm.update()))
assert vm.console == original_console assert vm.console == original_console
assert vm.aux == original_aux assert vm.aux == original_aux
@ -601,7 +603,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.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.DockerVM._get_container_state", return_value="running"):
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query:
loop.run_until_complete(asyncio.ensure_future(vm.update())) loop.run_until_complete(asyncio.async(vm.update()))
mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1}) mock_query.assert_any_call("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
mock_query.assert_any_call("POST", "containers/create", data={ mock_query.assert_any_call("POST", "containers/create", data={
@ -639,7 +641,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.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query: with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
loop.run_until_complete(asyncio.ensure_future(vm.delete())) loop.run_until_complete(asyncio.async(vm.delete()))
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1}) mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
@ -649,11 +651,11 @@ def test_close(loop, vm, port_manager):
"rport": 4343, "rport": 4343,
"rhost": "127.0.0.1"} "rhost": "127.0.0.1"}
nio = vm.manager.create_nio(nio) nio = vm.manager.create_nio(nio)
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio))) loop.run_until_complete(asyncio.async(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.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query: with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
loop.run_until_complete(asyncio.ensure_future(vm.close())) loop.run_until_complete(asyncio.async(vm.close()))
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1}) mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
assert vm._closed is True assert vm._closed is True
@ -668,7 +670,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.DockerVM._get_container_state", return_value="stopped"):
with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query: with asyncio_patch("gns3server.compute.docker.Docker.query") as mock_query:
loop.run_until_complete(asyncio.ensure_future(vm.close())) loop.run_until_complete(asyncio.async(vm.close()))
mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1}) mock_query.assert_called_with("DELETE", "containers/e90e34656842", params={"force": 1, "v": 1})
assert vm._closed is True assert vm._closed is True
@ -682,7 +684,7 @@ def test_get_namespace(loop, vm):
} }
} }
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock_query:
assert loop.run_until_complete(asyncio.ensure_future(vm._get_namespace())) == 42 assert loop.run_until_complete(asyncio.async(vm._get_namespace())) == 42
mock_query.assert_called_with("GET", "containers/e90e34656842/json") mock_query.assert_called_with("GET", "containers/e90e34656842/json")
@ -697,7 +699,7 @@ def test_add_ubridge_connection(loop, vm):
vm._ubridge_hypervisor = MagicMock() vm._ubridge_hypervisor = MagicMock()
vm._namespace = 42 vm._namespace = 42
loop.run_until_complete(asyncio.ensure_future(vm._add_ubridge_connection(nio, 0))) loop.run_until_complete(asyncio.async(vm._add_ubridge_connection(nio, 0)))
calls = [ calls = [
call.send('bridge create bridge0'), call.send('bridge create bridge0'),
@ -718,7 +720,7 @@ def test_add_ubridge_connection_none_nio(loop, vm):
vm._ubridge_hypervisor = MagicMock() vm._ubridge_hypervisor = MagicMock()
vm._namespace = 42 vm._namespace = 42
loop.run_until_complete(asyncio.ensure_future(vm._add_ubridge_connection(nio, 0))) loop.run_until_complete(asyncio.async(vm._add_ubridge_connection(nio, 0)))
calls = [ calls = [
call.send('bridge create bridge0'), call.send('bridge create bridge0'),
@ -739,7 +741,7 @@ def test_add_ubridge_connection_invalid_adapter_number(loop, vm):
"rhost": "127.0.0.1"} "rhost": "127.0.0.1"}
nio = vm.manager.create_nio(nio) nio = vm.manager.create_nio(nio)
with pytest.raises(DockerError): with pytest.raises(DockerError):
loop.run_until_complete(asyncio.ensure_future(vm._add_ubridge_connection(nio, 12))) loop.run_until_complete(asyncio.async(vm._add_ubridge_connection(nio, 12)))
def test_add_ubridge_connection_no_free_interface(loop, vm): def test_add_ubridge_connection_no_free_interface(loop, vm):
@ -755,7 +757,7 @@ def test_add_ubridge_connection_no_free_interface(loop, vm):
interfaces = ["tap-gns3-e{}".format(index) for index in range(4096)] interfaces = ["tap-gns3-e{}".format(index) for index in range(4096)]
with patch("psutil.net_if_addrs", return_value=interfaces): with patch("psutil.net_if_addrs", return_value=interfaces):
loop.run_until_complete(asyncio.ensure_future(vm._add_ubridge_connection(nio, 0))) loop.run_until_complete(asyncio.async(vm._add_ubridge_connection(nio, 0)))
def test_adapter_add_nio_binding(vm, loop): def test_adapter_add_nio_binding(vm, loop):
@ -764,7 +766,7 @@ def test_adapter_add_nio_binding(vm, loop):
"rport": 4343, "rport": 4343,
"rhost": "127.0.0.1"} "rhost": "127.0.0.1"}
nio = vm.manager.create_nio(nio) nio = vm.manager.create_nio(nio)
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio))) loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
assert vm._ethernet_adapters[0].get_nio(0) == nio assert vm._ethernet_adapters[0].get_nio(0) == nio
@ -779,9 +781,9 @@ def test_adapter_udpate_nio_binding(vm, loop):
"rhost": "127.0.0.1"} "rhost": "127.0.0.1"}
nio = vm.manager.create_nio(nio) nio = vm.manager.create_nio(nio)
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="running"): with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="running"):
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio))) loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_update_nio_binding(0, nio))) loop.run_until_complete(asyncio.async(vm.adapter_update_nio_binding(0, nio)))
assert vm._ubridge_apply_filters.called assert vm._ubridge_apply_filters.called
@ -793,9 +795,9 @@ def test_adapter_udpate_nio_binding_bridge_not_started(vm, loop):
"rhost": "127.0.0.1"} "rhost": "127.0.0.1"}
nio = vm.manager.create_nio(nio) nio = vm.manager.create_nio(nio)
with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="running"): with asyncio_patch("gns3server.compute.docker.DockerVM._get_container_state", return_value="running"):
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio))) loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.adapter_update_nio_binding(0, nio))) loop.run_until_complete(asyncio.async(vm.adapter_update_nio_binding(0, nio)))
assert vm._ubridge_apply_filters.called is False assert vm._ubridge_apply_filters.called is False
@ -806,7 +808,7 @@ def test_adapter_add_nio_binding_invalid_adapter(vm, loop):
"rhost": "127.0.0.1"} "rhost": "127.0.0.1"}
nio = vm.manager.create_nio(nio) nio = vm.manager.create_nio(nio)
with pytest.raises(DockerError): with pytest.raises(DockerError):
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(12, nio))) loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(12, nio)))
def test_adapter_remove_nio_binding(vm, loop): def test_adapter_remove_nio_binding(vm, loop):
@ -818,10 +820,10 @@ def test_adapter_remove_nio_binding(vm, loop):
"rport": 4343, "rport": 4343,
"rhost": "127.0.0.1"} "rhost": "127.0.0.1"}
nio = vm.manager.create_nio(nio) nio = vm.manager.create_nio(nio)
loop.run_until_complete(asyncio.ensure_future(vm.adapter_add_nio_binding(0, nio))) loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
with asyncio_patch("gns3server.compute.docker.DockerVM._ubridge_send") as delete_ubridge_mock: with asyncio_patch("gns3server.compute.docker.DockerVM._ubridge_send") as delete_ubridge_mock:
loop.run_until_complete(asyncio.ensure_future(vm.adapter_remove_nio_binding(0))) loop.run_until_complete(asyncio.async(vm.adapter_remove_nio_binding(0)))
assert vm._ethernet_adapters[0].get_nio(0) is None 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 stop bridge0')
delete_ubridge_mock.assert_any_call('bridge remove_nio_udp bridge0 4242 127.0.0.1 4343') delete_ubridge_mock.assert_any_call('bridge remove_nio_udp bridge0 4242 127.0.0.1 4343')
@ -829,15 +831,15 @@ def test_adapter_remove_nio_binding(vm, loop):
def test_adapter_remove_nio_binding_invalid_adapter(vm, loop): def test_adapter_remove_nio_binding_invalid_adapter(vm, loop):
with pytest.raises(DockerError): with pytest.raises(DockerError):
loop.run_until_complete(asyncio.ensure_future(vm.adapter_remove_nio_binding(12))) loop.run_until_complete(asyncio.async(vm.adapter_remove_nio_binding(12)))
def test_start_capture(vm, tmpdir, manager, free_console_port, loop): def test_start_capture(vm, tmpdir, manager, free_console_port, loop):
output_file = str(tmpdir / "test.pcap") 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"}) 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.ensure_future(vm.adapter_add_nio_binding(0, nio))) loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(asyncio.ensure_future(vm.start_capture(0, output_file))) loop.run_until_complete(asyncio.async(vm.start_capture(0, output_file)))
assert vm._ethernet_adapters[0].get_nio(0).capturing assert vm._ethernet_adapters[0].get_nio(0).capturing
@ -845,10 +847,10 @@ def test_stop_capture(vm, tmpdir, manager, free_console_port, loop):
output_file = str(tmpdir / "test.pcap") 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"}) 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.ensure_future(vm.adapter_add_nio_binding(0, nio))) loop.run_until_complete(asyncio.async(vm.adapter_add_nio_binding(0, nio)))
loop.run_until_complete(vm.start_capture(0, output_file)) loop.run_until_complete(vm.start_capture(0, output_file))
assert vm._ethernet_adapters[0].get_nio(0).capturing assert vm._ethernet_adapters[0].get_nio(0).capturing
loop.run_until_complete(asyncio.ensure_future(vm.stop_capture(0))) loop.run_until_complete(asyncio.async(vm.stop_capture(0)))
assert vm._ethernet_adapters[0].get_nio(0).capturing is False assert vm._ethernet_adapters[0].get_nio(0).capturing is False
@ -861,7 +863,7 @@ def test_get_log(loop, vm):
mock_query.read = read mock_query.read = read
with asyncio_patch("gns3server.compute.docker.Docker.http_query", return_value=mock_query) as mock: with asyncio_patch("gns3server.compute.docker.Docker.http_query", return_value=mock_query) as mock:
images = loop.run_until_complete(asyncio.ensure_future(vm._get_log())) images = loop.run_until_complete(asyncio.async(vm._get_log()))
mock.assert_called_with("GET", "containers/e90e34656842/logs", params={"stderr": 1, "stdout": 1}, data={}) mock.assert_called_with("GET", "containers/e90e34656842/logs", params={"stderr": 1, "stdout": 1}, data={})
@ -870,7 +872,7 @@ def test_get_image_informations(project, manager, loop):
} }
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock: with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu") vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
loop.run_until_complete(asyncio.ensure_future(vm._get_image_information())) loop.run_until_complete(asyncio.async(vm._get_image_information()))
mock.assert_called_with("GET", "images/ubuntu:latest/json") mock.assert_called_with("GET", "images/ubuntu:latest/json")
@ -900,7 +902,7 @@ def test_start_vnc(vm, loop):
with patch("shutil.which", return_value="/bin/x"): 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("gns3server.compute.docker.docker_vm.wait_for_file_creation") as mock_wait:
with asyncio_patch("asyncio.create_subprocess_exec") as mock_exec: with asyncio_patch("asyncio.create_subprocess_exec") as mock_exec:
loop.run_until_complete(asyncio.ensure_future(vm._start_vnc())) loop.run_until_complete(asyncio.async(vm._start_vnc()))
assert vm._display is not None 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("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") 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")
@ -909,13 +911,13 @@ def test_start_vnc(vm, loop):
def test_start_vnc_xvfb_missing(vm, loop): def test_start_vnc_xvfb_missing(vm, loop):
with pytest.raises(DockerError): with pytest.raises(DockerError):
loop.run_until_complete(asyncio.ensure_future(vm._start_vnc())) loop.run_until_complete(asyncio.async(vm._start_vnc()))
def test_start_aux(vm, loop): def test_start_aux(vm, loop):
with asyncio_patch("asyncio.subprocess.create_subprocess_exec", return_value=MagicMock()) as mock_exec: with asyncio_patch("asyncio.subprocess.create_subprocess_exec", return_value=MagicMock()) as mock_exec:
loop.run_until_complete(asyncio.ensure_future(vm._start_aux())) loop.run_until_complete(asyncio.async(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) 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)
@ -977,5 +979,5 @@ def test_read_console_output_with_binary_mode(vm, loop):
output_stream = MagicMock() output_stream = MagicMock()
with asyncio_patch('gns3server.compute.docker.docker_vm.DockerVM.stop'): with asyncio_patch('gns3server.compute.docker.docker_vm.DockerVM.stop'):
loop.run_until_complete(asyncio.ensure_future(vm._read_console_output(input_stream, output_stream))) loop.run_until_complete(asyncio.async(vm._read_console_output(input_stream, output_stream)))
output_stream.feed_data.assert_called_once_with(b"test") output_stream.feed_data.assert_called_once_with(b"test")

View File

@ -1,3 +1,3 @@
-rrequirements.txt -rrequirements.txt
pypiwin32<222 # pyup: ignore pywin32>=223 # pyup: ignore