diff --git a/gns3server/compute/docker/docker_vm.py b/gns3server/compute/docker/docker_vm.py index 20a8a716..ac9b6014 100644 --- a/gns3server/compute/docker/docker_vm.py +++ b/gns3server/compute/docker/docker_vm.py @@ -465,6 +465,7 @@ class DockerVM(BaseNode): "Memory": self._memory * (1024 * 1024), # convert memory to bytes "NanoCpus": int(self._cpus * 1e9), # convert cpus to nano cpus }, + "UsernsMode": "host", "Volumes": {}, "Env": ["container=docker"], # Systemd compliant: https://github.com/GNS3/gns3-server/issues/573 "Cmd": [], diff --git a/gns3server/compute/dynamips/nodes/router.py b/gns3server/compute/dynamips/nodes/router.py index 97bcbbd0..1eea64e3 100644 --- a/gns3server/compute/dynamips/nodes/router.py +++ b/gns3server/compute/dynamips/nodes/router.py @@ -1030,6 +1030,26 @@ class Router(BaseNode): self.aux = aux await self._hypervisor.send(f'vm set_aux_tcp_port "{self._name}" {aux}') + async def set_aux_type(self, aux_type): + """ + Sets the aux type. + + :param aux_type: auxiliary console type + """ + + if self.aux_type != aux_type: + status = await self.get_status() + if status == "running": + raise DynamipsError('"{name}" must be stopped to change the auxiliary console type to {aux_type}'.format( + name=self._name, + aux_type=aux_type) + ) + + self.aux_type = aux_type + + if self._aux and aux_type == "telnet": + await self._hypervisor.send(f'vm set_aux_tcp_port "{self._name}" {self._aux}') + async def reset_console(self): """ Reset console diff --git a/tests/compute/docker/test_docker_vm.py b/tests/compute/docker/test_docker_vm.py index 8c66ef95..842818a6 100644 --- a/tests/compute/docker/test_docker_vm.py +++ b/tests/compute/docker/test_docker_vm.py @@ -123,6 +123,7 @@ async def test_create(compute_project, manager): "Memory": 0, "NanoCpus": 0 }, + "UsernsMode": "host", "Volumes": {}, "NetworkDisabled": True, "Hostname": "test", @@ -173,6 +174,7 @@ async def test_create_with_tag(compute_project, manager): "Memory": 0, "NanoCpus": 0 }, + "UsernsMode": "host", "Volumes": {}, "NetworkDisabled": True, "Hostname": "test", @@ -232,6 +234,7 @@ async def test_create_vnc(compute_project, manager): "Memory": 0, "NanoCpus": 0 }, + "UsernsMode": "host", "Volumes": {}, "NetworkDisabled": True, "Hostname": "test", @@ -377,6 +380,7 @@ async def test_create_start_cmd(compute_project, manager): "Memory": 0, "NanoCpus": 0 }, + "UsernsMode": "host", "Volumes": {}, "Entrypoint": ["/gns3/init.sh"], "Cmd": ["/bin/ls"], @@ -489,6 +493,7 @@ async def test_create_image_not_available(compute_project, manager): "Memory": 0, "NanoCpus": 0 }, + "UsernsMode": "host", "Volumes": {}, "NetworkDisabled": True, "Hostname": "test", @@ -544,6 +549,7 @@ async def test_create_with_user(compute_project, manager): "Memory": 0, "NanoCpus": 0 }, + "UsernsMode": "host", "Volumes": {}, "NetworkDisabled": True, "Hostname": "test", @@ -647,6 +653,7 @@ async def test_create_with_extra_volumes_duplicate_1_image(compute_project, mana "Memory": 0, "NanoCpus": 0 }, + "UsernsMode": "host", "Volumes": {}, "NetworkDisabled": True, "Hostname": "test", @@ -702,6 +709,7 @@ async def test_create_with_extra_volumes_duplicate_2_user(compute_project, manag "Memory": 0, "NanoCpus": 0 }, + "UsernsMode": "host", "Volumes": {}, "NetworkDisabled": True, "Hostname": "test", @@ -757,6 +765,7 @@ async def test_create_with_extra_volumes_duplicate_3_subdir(compute_project, man "Memory": 0, "NanoCpus": 0 }, + "UsernsMode": "host", "Volumes": {}, "NetworkDisabled": True, "Hostname": "test", @@ -812,6 +821,7 @@ async def test_create_with_extra_volumes_duplicate_4_backslash(compute_project, "Memory": 0, "NanoCpus": 0 }, + "UsernsMode": "host", "Volumes": {}, "NetworkDisabled": True, "Hostname": "test", @@ -862,6 +872,7 @@ async def test_create_with_extra_volumes_duplicate_5_subdir_issue_1595(compute_p "Memory": 0, "NanoCpus": 0 }, + "UsernsMode": "host", "Volumes": {}, "NetworkDisabled": True, "Hostname": "test", @@ -912,6 +923,7 @@ async def test_create_with_extra_volumes_duplicate_6_subdir_issue_1595(compute_p "Memory": 0, "NanoCpus": 0 }, + "UsernsMode": "host", "Volumes": {}, "NetworkDisabled": True, "Hostname": "test", @@ -978,6 +990,7 @@ async def test_create_with_extra_volumes(compute_project, manager): "Memory": 0, "NanoCpus": 0 }, + "UsernsMode": "host", "Volumes": {}, "NetworkDisabled": True, "Hostname": "test", @@ -1254,6 +1267,7 @@ async def test_update(vm): "Memory": 0, "NanoCpus": 0 }, + "UsernsMode": "host", "Volumes": {}, "NetworkDisabled": True, "Hostname": "test", @@ -1335,6 +1349,7 @@ async def test_update_running(vm): "Memory": 0, "NanoCpus": 0 }, + "UsernsMode": "host", "Volumes": {}, "NetworkDisabled": True, "Hostname": "test", @@ -1430,7 +1445,37 @@ async def test_add_ubridge_connection(vm): call.send('bridge start bridge0') ] assert 'bridge0' in vm._bridges - # We need to check any_order ortherwise mock is confused by asyncio + # We need to check any_order otherwise mock is confused by asyncio + vm._ubridge_hypervisor.assert_has_calls(calls, any_order=True) + + +async def test_add_ubridge_connections_with_base_mac_address(vm): + + vm._ubridge_hypervisor = MagicMock() + vm._namespace = 42 + vm.adapters = 2 + vm.mac_address = "02:42:42:42:42:00" + + nio_params = { + "type": "nio_udp", + "lport": 4242, + "rport": 4343, + "rhost": "127.0.0.1"} + + nio = vm.manager.create_nio(nio_params) + await vm._add_ubridge_connection(nio, 0) + + nio = vm.manager.create_nio(nio_params) + await vm._add_ubridge_connection(nio, 1) + + calls = [ + call.send('bridge create bridge0'), + call.send('bridge create bridge1'), + call.send('docker set_mac_addr tap-gns3-e0 02:42:42:42:42:00'), + call.send('docker set_mac_addr tap-gns3-e0 02:42:42:42:42:01') + ] + + # We need to check any_order otherwise mock is confused by asyncio vm._ubridge_hypervisor.assert_has_calls(calls, any_order=True) @@ -1654,6 +1699,7 @@ async def test_start_vnc_missing(vm): @pytest.mark.asyncio async def test_start_aux(vm): + vm.aux_type = "telnet" with asyncio_patch("asyncio.subprocess.create_subprocess_exec", return_value=MagicMock()) as mock_exec: await vm._start_aux() mock_exec.assert_called_with(