def vm(project, manager, fake_qemu_binary, fake_qemu_img_binary): manager.port_manager.console_host = "127.0.0.1" vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, qemu_path=fake_qemu_binary) vm._process_priority = "normal" # Avoid complexity for Windows tests vm._start_ubridge = AsyncioMagicMock() vm._ubridge_hypervisor = MagicMock() vm._ubridge_hypervisor.is_running.return_value = True return vm
def vm(project, manager, fake_qemu_binary, fake_qemu_img_binary): manager.port_manager.console_host = "127.0.0.1" vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, qemu_path=fake_qemu_binary) vm._process_priority = "normal" # Avoid complexity for Windows tests return vm
async def vm(compute_project, manager, fake_qemu_binary, fake_qemu_img_binary): manager.port_manager.console_host = "127.0.0.1" vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager, qemu_path=fake_qemu_binary) vm._process_priority = "normal" # Avoid complexity for Windows tests vm._start_ubridge = AsyncioMagicMock() vm._ubridge_hypervisor = MagicMock() vm._ubridge_hypervisor.is_running.return_value = True vm.manager.config.set("Qemu", "enable_hardware_acceleration", False) return vm
def test_hda_disk_image_non_linked_clone(vm, images_dir, project, manager, fake_qemu_binary, fake_qemu_img_binary): """ Two non linked can't use the same image at the same time """ open(os.path.join(images_dir, "test1"), "w+").close() vm.linked_clone = False vm.hda_disk_image = os.path.join(images_dir, "test1") vm.manager._nodes[vm.id] = vm vm2 = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0eaa", project, manager, qemu_path=fake_qemu_binary) vm2.linked_clone = False with pytest.raises(QemuError): vm2.hda_disk_image = os.path.join(images_dir, "test1")
async def test_vm_create(tmpdir, compute_project, manager, fake_qemu_binary): fake_img = str(tmpdir / 'hello') with open(fake_img, 'w+') as f: f.write('hello') vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager, qemu_path=fake_qemu_binary) vm._hda_disk_image = fake_img await vm.create() # tests if `create` created md5sums assert os.path.exists(str(tmpdir / 'hello.md5sum'))
async def test_hda_disk_image_non_linked_clone(vm, images_dir, compute_project, manager, fake_qemu_binary): """ Two non linked can't use the same image at the same time """ open(os.path.join(images_dir, "test1"), "w+").close() vm.linked_clone = False vm.hda_disk_image = os.path.join(images_dir, "test1") vm.manager._nodes[vm.id] = vm vm2 = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0eaa", compute_project, manager, qemu_path=fake_qemu_binary) vm2.linked_clone = False with pytest.raises(QemuError): vm2.hda_disk_image = os.path.join(images_dir, "test1")
def test_vm_create(loop, tmpdir, project, manager, fake_qemu_binary): fake_img = str(tmpdir / 'hello') with open(fake_img, 'w+') as f: f.write('hello') vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, qemu_path=fake_qemu_binary) vm._hda_disk_image = fake_img loop.run_until_complete(asyncio.ensure_future(vm.create())) # tests if `create` created md5sums assert os.path.exists(str(tmpdir / 'hello.md5sum'))
def test_vm(project, manager, fake_qemu_binary): vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, qemu_path=fake_qemu_binary) assert vm.name == "test" assert vm.id == "00010203-0405-0607-0809-0a0b0c0d0e0f"
def test_vm_invalid_qemu_without_platform(project, manager, fake_qemu_binary): vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, qemu_path="/usr/fake/bin/qemu-system-x86_64") assert vm.qemu_path == fake_qemu_binary assert vm.platform == "x86_64"
async def test_set_platform(compute_project, manager): with patch("shutil.which", return_value="/bin/qemu-system-x86_64") as which_mock: with patch("gns3server.compute.qemu.QemuVM._check_qemu_path"): vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", compute_project, manager, platform="x86_64") if sys.platform.startswith("win"): which_mock.assert_called_with("qemu-system-x86_64w.exe", path=mock.ANY) else: which_mock.assert_called_with("qemu-system-x86_64", path=mock.ANY) assert vm.platform == "x86_64" assert vm.qemu_path == "/bin/qemu-system-x86_64"