Raise an error if image is missing on compute

This commit is contained in:
Julien Duponchelle committed 2016-06-07 15:34:04 +02:00
1 parent dcebaf61b8
commit d8bdd16e13
23 files changed
+108 -108

No files matched your search

+6 -7
View File
@@ -29,10 +29,10 @@ pytestmark = pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supp
@pytest.fixture
def fake_iou_bin(tmpdir):
def fake_iou_bin(images_dir):
"""Create a fake IOU image on disk"""
path = str(tmpdir / "iou.bin")
path = os.path.join(images_dir, "IOU", "iou.bin")
with open(path, "w+") as f:
f.write('\x7fELF\x01\x01\x01')
os.chmod(path, stat.S_IREAD | stat.S_IEXEC)
@@ -222,7 +222,7 @@ def test_iou_nio_create_udp(http_compute, vm):
def test_iou_nio_create_ethernet(http_compute, vm, ethernet_device):
response = http_compute.post("/projects/{project_id}/iou/nodes/{node_id}/adapters/1/ports/0/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), {"type": "nio_ethernet",
"ethernet_device": ethernet_device,
},
},
example=True)
assert response.status == 201
assert response.route == "/projects/{project_id}/iou/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio"
@@ -233,7 +233,7 @@ def test_iou_nio_create_ethernet(http_compute, vm, ethernet_device):
def test_iou_nio_create_ethernet_different_port(http_compute, vm, ethernet_device):
response = http_compute.post("/projects/{project_id}/iou/nodes/{node_id}/adapters/0/ports/3/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), {"type": "nio_ethernet",
"ethernet_device": ethernet_device,
},
},
example=False)
assert response.status == 201
assert response.route == "/projects/{project_id}/iou/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio"
@@ -328,10 +328,9 @@ def test_get_configs_with_startup_config_file(http_compute, project, vm):
assert response.json["startup_config_content"] == "TEST"
def test_images(http_compute, tmpdir, fake_iou_bin):
def test_images(http_compute, fake_iou_bin):
with patch("gns3server.compute.IOU.get_images_directory", return_value=str(tmpdir)):
response = http_compute.get("/iou/images", example=True)
response = http_compute.get("/iou/images", example=True)
assert response.status == 200
assert response.json == [{"filename": "iou.bin", "path": "iou.bin"}]
+5 -7
View File
@@ -38,11 +38,9 @@ def fake_qemu_bin():
@pytest.fixture
def fake_qemu_vm(tmpdir):
def fake_qemu_vm(images_dir):
img_dir = Config.instance().get_section_config("Server").get("images_path")
img_dir = os.path.join(img_dir, "QEMU")
os.makedirs(img_dir)
img_dir = os.path.join(images_dir, "QEMU")
bin_path = os.path.join(img_dir, "linux载.img")
with open(bin_path, "w+") as f:
f.write("1")
@@ -154,18 +152,18 @@ def test_qemu_delete(http_compute, vm):
assert response.status == 204
def test_qemu_update(http_compute, vm, tmpdir, free_console_port, project, fake_qemu_vm):
def test_qemu_update(http_compute, vm, free_console_port, project, fake_qemu_vm):
params = {
"name": "test",
"console": free_console_port,
"ram": 1024,
"hdb_disk_image": "linux.img"
"hdb_disk_image": "linux载.img"
}
response = http_compute.put("/projects/{project_id}/qemu/nodes/{node_id}".format(project_id=vm["project_id"], node_id=vm["node_id"]), params, example=True)
assert response.status == 200
assert response.json["name"] == "test"
assert response.json["console"] == free_console_port
assert response.json["hdb_disk_image"] == "linux.img"
assert response.json["hdb_disk_image"] == "linux载.img"
assert response.json["ram"] == 1024