Support a platform parameter for Qemu

I'm sure we will discover a distribution with a different
naming conventions...

Fix #220
This commit is contained in:
Julien Duponchelle committed 2015-06-10 15:49:24 +02:00
1 parent fb79543342
commit 2da0b36ee7
5 files changed
+123 -20

No files matched your search

+18 -3
View File
@@ -25,7 +25,7 @@ from unittest.mock import patch
@pytest.fixture
def fake_qemu_bin():
bin_path = os.path.join(os.environ["PATH"], "qemu_x42")
bin_path = os.path.join(os.environ["PATH"], "qemu_x86_64")
with open(bin_path, "w+") as f:
f.write("1")
os.chmod(bin_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
@@ -51,7 +51,7 @@ def base_params(tmpdir, fake_qemu_bin):
@pytest.fixture
def fake_qemu_bin():
bin_path = os.path.join(os.environ["PATH"], "qemu_x42")
bin_path = os.path.join(os.environ["PATH"], "qemu-system-x86_64")
with open(bin_path, "w+") as f:
f.write("1")
os.chmod(bin_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
@@ -65,12 +65,27 @@ def vm(server, project, base_params):
return response.json
def test_qemu_create(server, project, base_params):
def test_qemu_create(server, project, base_params, fake_qemu_bin):
response = server.post("/projects/{project_id}/qemu/vms".format(project_id=project.id), base_params)
assert response.status == 201
assert response.route == "/projects/{project_id}/qemu/vms"
assert response.json["name"] == "PC TEST 1"
assert response.json["project_id"] == project.id
assert response.json["qemu_path"] == fake_qemu_bin
assert response.json["platform"] == "x86_64"
def test_qemu_create_platform(server, project, base_params, fake_qemu_bin):
base_params["qemu_path"] = None
base_params["platform"] = "x86_64"
response = server.post("/projects/{project_id}/qemu/vms".format(project_id=project.id), base_params)
assert response.status == 201
assert response.route == "/projects/{project_id}/qemu/vms"
assert response.json["name"] == "PC TEST 1"
assert response.json["project_id"] == project.id
assert response.json["qemu_path"] == fake_qemu_bin
assert response.json["platform"] == "x86_64"
def test_qemu_create_with_params(server, project, base_params):
+37 -4
View File
@@ -52,9 +52,9 @@ def fake_qemu_img_binary():
def fake_qemu_binary():
if sys.platform.startswith("win"):
bin_path = os.path.join(os.environ["PATH"], "qemu_x42.EXE")
bin_path = os.path.join(os.environ["PATH"], "qemu-system-x86_64.EXE")
else:
bin_path = os.path.join(os.environ["PATH"], "qemu_x42")
bin_path = os.path.join(os.environ["PATH"], "qemu-system-x86_64")
with open(bin_path, "w+") as f:
f.write("1")
os.chmod(bin_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
@@ -171,7 +171,9 @@ def test_set_qemu_path(vm, tmpdir, fake_qemu_binary):
vm.qemu_path = None
# Should not crash with unicode characters
path = str(tmpdir / "bla\u62FF")
path = str(tmpdir / "\u62FF" / "qemu-system-mips")
os.makedirs( str(tmpdir / "\u62FF") )
# Raise because file doesn't exists
with pytest.raises(QemuError):
@@ -189,14 +191,45 @@ def test_set_qemu_path(vm, tmpdir, fake_qemu_binary):
vm.qemu_path = path
assert vm.qemu_path == path
assert vm.platform == "mips"
def test_set_qemu_path_environ(vm, tmpdir, fake_qemu_binary):
# It should find the binary in the path
vm.qemu_path = "qemu_x42"
vm.qemu_path = "qemu-system-x86_64"
assert vm.qemu_path == fake_qemu_binary
assert vm.platform == "x86_64"
@pytest.mark.skipif(sys.platform.startswith("linux") is False, reason="Supported only on linux")
def test_set_qemu_path_kvm_binary(vm, tmpdir, fake_qemu_binary):
bin_path = os.path.join(os.environ["PATH"], "qemu-kvm")
with open(bin_path, "w+") as f:
f.write("1")
os.chmod(bin_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
return bin_path
# It should find the binary in the path
vm.qemu_path = "qemu-kvm"
assert vm.qemu_path == fake_qemu_binary
assert vm.platform == "x86_64"
def test_set_platform(project, manager):
with patch("shutil.which", return_value="/bin/qemu-system-x86_64") as which_mock:
with patch("gns3server.modules.qemu.QemuVM._check_qemu_path"):
vm = QemuVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, platform="x86_64")
if sys.platform.startswith("win"):
which_mock.assert_called_with("qemu-system-x86_64w.exe")
else:
which_mock.assert_called_with("qemu-system-x86_64")
assert vm.platform == "x86_64"
assert vm.qemu_path == "/bin/qemu-system-x86_64"
def test_disk_options(vm, loop, fake_qemu_img_binary):