diff --git a/.gitignore b/.gitignore index d63cf29f..3673d13e 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,7 @@ pip-log.txt # Unit test / coverage reports .coverage .tox +.cache nosetests.xml # Translations diff --git a/dev-requirements.txt b/dev-requirements.txt index 45c6d0e3..366dee02 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,7 +1,7 @@ -rrequirements.txt sphinx==1.2.3 -pytest==2.6.4 +pytest==2.8.2 pep8==1.5.7 pytest-timeout pytest-capturelog diff --git a/gns3server/modules/qemu/qemu_vm.py b/gns3server/modules/qemu/qemu_vm.py index 1c16f657..dff946d5 100644 --- a/gns3server/modules/qemu/qemu_vm.py +++ b/gns3server/modules/qemu/qemu_vm.py @@ -1426,6 +1426,8 @@ class QemuVM(BaseVM): :returns: Boolean True if we need to enable KVM """ + print(sys.platform.startswith("linux")) + print(self.manager.config.get_section_config("Qemu").getboolean("enable_kvm", True)) if sys.platform.startswith("linux") and self.manager.config.get_section_config("Qemu").getboolean("enable_kvm", True) \ and "-no-kvm" not in options: diff --git a/tests/conftest.py b/tests/conftest.py index 2d8547f1..d3c38ecd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -77,7 +77,7 @@ def _get_unused_port(): return port -@pytest.fixture(scope="session") +@pytest.fixture def server(request, loop, port_manager, monkeypatch): """A GNS3 server""" diff --git a/tests/modules/qemu/test_qemu_vm.py b/tests/modules/qemu/test_qemu_vm.py index d66cd32b..eb08929f 100644 --- a/tests/modules/qemu/test_qemu_vm.py +++ b/tests/modules/qemu/test_qemu_vm.py @@ -389,45 +389,50 @@ def test_build_command_with_invalid_options(vm, loop, fake_qemu_binary): def test_hda_disk_image(vm, tmpdir): - with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}): - vm.hda_disk_image = "/tmp/test" - assert vm.hda_disk_image == "/tmp/test" - vm.hda_disk_image = "test" - assert vm.hda_disk_image == str(tmpdir / "QEMU" / "test") + vm.manager.config.set("Server", "images_path", str(tmpdir)) + + vm.hda_disk_image = "/tmp/test" + assert vm.hda_disk_image == "/tmp/test" + vm.hda_disk_image = "test" + assert vm.hda_disk_image == str(tmpdir / "QEMU" / "test") def test_hda_disk_image_ova(vm, tmpdir): - with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}): - vm.hda_disk_image = "test.ovf/test.vmdk" - assert vm.hda_disk_image == str(tmpdir / "QEMU" / "test.ovf" / "test.vmdk") + vm.manager.config.set("Server", "images_path", str(tmpdir)) + + vm.hda_disk_image = "test.ovf/test.vmdk" + assert vm.hda_disk_image == str(tmpdir / "QEMU" / "test.ovf" / "test.vmdk") def test_hdb_disk_image(vm, tmpdir): - with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}): - vm.hdb_disk_image = "/tmp/test" - assert vm.hdb_disk_image == "/tmp/test" - vm.hdb_disk_image = "test" - assert vm.hdb_disk_image == str(tmpdir / "QEMU" / "test") + vm.manager.config.set("Server", "images_path", str(tmpdir)) + + vm.hdb_disk_image = "/tmp/test" + assert vm.hdb_disk_image == "/tmp/test" + vm.hdb_disk_image = "test" + assert vm.hdb_disk_image == str(tmpdir / "QEMU" / "test") def test_hdc_disk_image(vm, tmpdir): - with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}): - vm.hdc_disk_image = "/tmp/test" - assert vm.hdc_disk_image == "/tmp/test" - vm.hdc_disk_image = "test" - assert vm.hdc_disk_image == str(tmpdir / "QEMU" / "test") + vm.manager.config.set("Server", "images_path", str(tmpdir)) + + vm.hdc_disk_image = "/tmp/test" + assert vm.hdc_disk_image == "/tmp/test" + vm.hdc_disk_image = "test" + assert vm.hdc_disk_image == str(tmpdir / "QEMU" / "test") def test_hdd_disk_image(vm, tmpdir): - with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir)}): - vm.hdd_disk_image = "/tmp/test" - assert vm.hdd_disk_image == "/tmp/test" - vm.hdd_disk_image = "test" - assert vm.hdd_disk_image == str(tmpdir / "QEMU" / "test") + vm.manager.config.set("Server", "images_path", str(tmpdir)) + + vm.hdd_disk_image = "/tmp/test" + assert vm.hdd_disk_image == "/tmp/test" + vm.hdd_disk_image = "test" + assert vm.hdd_disk_image == str(tmpdir / "QEMU" / "test") def test_options(vm): @@ -455,48 +460,41 @@ def test_get_qemu_img_not_exist(vm, tmpdir): def test_run_with_kvm_darwin(darwin_platform, vm): - with patch("configparser.SectionProxy.getboolean", return_value=True): - assert vm._run_with_kvm("qemu-system-x86_64", "") is False + vm.manager.config.set("Qemu", "enable_kvm", False) + assert vm._run_with_kvm("qemu-system-x86_64", "") is False def test_run_with_kvm_windows(windows_platform, vm): - with patch("configparser.SectionProxy.getboolean", return_value=True): - assert vm._run_with_kvm("qemu-system-x86_64.exe", "") is False + vm.manager.config.set("Qemu", "enable_kvm", False) + assert vm._run_with_kvm("qemu-system-x86_64.exe", "") is False def test_run_with_kvm_linux(linux_platform, vm): with patch("os.path.exists", return_value=True) as os_path: - with patch("configparser.SectionProxy.getboolean", return_value=True): - assert vm._run_with_kvm("qemu-system-x86_64", "") is True - os_path.assert_called_with("/dev/kvm") - - -def test_run_with_kvm_linux_config_desactivated(linux_platform, vm): - - with patch("os.path.exists", return_value=True) as os_path: - with patch("configparser.SectionProxy.getboolean", return_value=False): - assert vm._run_with_kvm("qemu-system-x86_64", "") is False + vm.manager.config.set("Qemu", "enable_kvm", True) + assert vm._run_with_kvm("qemu-system-x86_64", "") is True + os_path.assert_called_with("/dev/kvm") def test_run_with_kvm_linux_options_no_kvm(linux_platform, vm): with patch("os.path.exists", return_value=True) as os_path: - with patch("configparser.SectionProxy.getboolean", return_value=True): - assert vm._run_with_kvm("qemu-system-x86_64", "-no-kvm") is False + vm.manager.config.set("Qemu", "enable_kvm", True) + assert vm._run_with_kvm("qemu-system-x86_64", "-no-kvm") is False def test_run_with_kvm_not_x86(linux_platform, vm): with patch("os.path.exists", return_value=True) as os_path: - with patch("configparser.SectionProxy.getboolean", return_value=True): - assert vm._run_with_kvm("qemu-system-arm", "") is False + vm.manager.config.set("Qemu", "enable_kvm", True) + assert vm._run_with_kvm("qemu-system-arm", "") is False def test_run_with_kvm_linux_dev_kvm_missing(linux_platform, vm): with patch("os.path.exists", return_value=False) as os_path: - with patch("configparser.SectionProxy.getboolean", return_value=True): - with pytest.raises(QemuError): - vm._run_with_kvm("qemu-system-x86_64", "") + vm.manager.config.set("Qemu", "enable_kvm", True) + with pytest.raises(QemuError): + vm._run_with_kvm("qemu-system-x86_64", "")