From 94a709cb42927f2e59e7c17dc986dc5a14fd822f Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Mon, 30 May 2016 10:52:39 +0200 Subject: [PATCH] Fix tests around Qemu mac address Ref #522 --- tests/modules/qemu/test_qemu_vm.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/tests/modules/qemu/test_qemu_vm.py b/tests/modules/qemu/test_qemu_vm.py index a56aa9bd..0c0a3f3c 100644 --- a/tests/modules/qemu/test_qemu_vm.py +++ b/tests/modules/qemu/test_qemu_vm.py @@ -31,7 +31,7 @@ from unittest.mock import patch, MagicMock from gns3server.modules.qemu.qemu_vm import QemuVM from gns3server.modules.qemu.qemu_error import QemuError from gns3server.modules.qemu import Qemu -from gns3server.utils import force_unix_path +from gns3server.utils import force_unix_path, macaddress_to_int, int_to_macaddress @pytest.fixture(scope="module") @@ -430,7 +430,7 @@ def test_build_command(vm, loop, fake_qemu_binary, port_manager): "-net", "none", "-device", - "e1000,mac=00:00:ab:0e:0f:00" + "e1000,mac={}".format(vm._mac_address) ] @@ -445,6 +445,7 @@ def test_build_command_without_display(vm, loop, fake_qemu_binary): def test_build_command_two_adapters(vm, loop, fake_qemu_binary, port_manager): + os.environ["DISPLAY"] = "0:0" vm.adapters = 2 with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process: cmd = loop.run_until_complete(asyncio.async(vm._build_command())) @@ -463,27 +464,35 @@ def test_build_command_two_adapters(vm, loop, fake_qemu_binary, port_manager): "-net", "none", "-device", - "e1000,mac=00:00:ab:0e:0f:00", + "e1000,mac={}".format(vm.mac_address), "-device", - "e1000,mac=00:00:ab:0e:0f:01", - "-nographic" + "e1000,mac={}".format(int_to_macaddress(macaddress_to_int(vm._mac_address) + 1)) ] def test_build_command_two_adapters_mac_address(vm, loop, fake_qemu_binary, port_manager): + """ + Should support multiple base vmac address + """ vm.adapters = 2 vm.mac_address = "00:00:ab:0e:0f:09" + mac_0 = vm._mac_address + mac_1 = int_to_macaddress(macaddress_to_int(vm._mac_address)) + assert mac_0[:8] == "00:00:ab" with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process: cmd = loop.run_until_complete(asyncio.async(vm._build_command())) - assert "e1000,mac=00:00:ab:0e:0f:09" in cmd - assert "e1000,mac=00:00:ab:0e:0f:0a" in cmd + assert "e1000,mac={}".format(mac_0) in cmd + assert "e1000,mac={}".format(mac_1) in cmd - vm.mac_address = "00:00:ab:0e:0f:0a" + vm.mac_address = "00:42:ab:0e:0f:0a" + mac_0 = vm._mac_address + mac_1 = int_to_macaddress(macaddress_to_int(vm._mac_address)) + assert mac_0[:8] == "00:42:ab" with asyncio_patch("asyncio.create_subprocess_exec", return_value=MagicMock()) as process: cmd = loop.run_until_complete(asyncio.async(vm._build_command())) - assert "e1000,mac=00:00:ab:0e:0f:0a" in cmd - assert "e1000,mac=00:00:ab:0e:0f:0b" in cmd + assert "e1000,mac={}".format(mac_0) in cmd + assert "e1000,mac={}".format(mac_1) in cmd # Windows accept this kind of mistake