From 8cc8269842ab4bdf35b55f443dc9497512547031 Mon Sep 17 00:00:00 2001 From: grossmj Date: Thu, 28 Feb 2019 17:25:05 +0700 Subject: [PATCH] Use aiozipstream for snapshots. Fix tests. --- gns3server/controller/project.py | 1 - gns3server/controller/snapshot.py | 26 +++--- .../api/controller/project_handler.py | 2 +- tests/controller/test_export_project.py | 92 +++++++++---------- tests/handlers/api/compute/test_cloud.py | 6 +- tests/handlers/api/compute/test_docker.py | 6 +- tests/handlers/api/compute/test_iou.py | 12 +-- tests/handlers/api/compute/test_nat.py | 6 +- tests/handlers/api/compute/test_qemu.py | 6 +- tests/handlers/api/compute/test_traceng.py | 6 +- tests/handlers/api/compute/test_virtualbox.py | 6 +- tests/handlers/api/compute/test_vmware.py | 6 +- tests/handlers/api/compute/test_vpcs.py | 6 +- 13 files changed, 91 insertions(+), 90 deletions(-) diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index ddf6f2cf..a2208877 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -40,7 +40,6 @@ from ..config import Config from ..utils.path import check_path_allowed, get_default_project_directory from ..utils.asyncio.pool import Pool from ..utils.asyncio import locking -from ..utils.asyncio import wait_run_in_executor from ..utils.asyncio import aiozipstream from .export_project import export_project from .import_project import import_project diff --git a/gns3server/controller/snapshot.py b/gns3server/controller/snapshot.py index ebe22b58..9fa5e1f2 100644 --- a/gns3server/controller/snapshot.py +++ b/gns3server/controller/snapshot.py @@ -20,14 +20,20 @@ import os import uuid import shutil import tempfile -import asyncio +import aiofiles +import zipfile +import time import aiohttp.web from datetime import datetime, timezone from ..utils.asyncio import wait_run_in_executor +from ..utils.asyncio import aiozipstream from .export_project import export_project from .import_project import import_project +import logging +log = logging.getLogger(__name__) + # The string use to extract the date from the filename FILENAME_TIME_FORMAT = "%d%m%y_%H%M%S" @@ -73,15 +79,6 @@ class Snapshot: def created_at(self): return int(self._created_at) - def _create_snapshot_file(self, zipstream): - """ - Creates the snapshot file (to be run in its own thread) - """ - - with open(self.path, "wb") as f: - for data in zipstream: - f.write(data) - async def create(self): """ Create the snapshot @@ -97,9 +94,14 @@ class Snapshot: raise aiohttp.web.HTTPInternalServerError(text="Could not create the snapshot directory '{}': {}".format(snapshot_directory, e)) try: + begin = time.time() with tempfile.TemporaryDirectory() as tmpdir: - zipstream = await export_project(self._project, tmpdir, keep_compute_id=True, allow_all_nodes=True) - await wait_run_in_executor(self._create_snapshot_file, zipstream) + with aiozipstream.ZipFile(compression=zipfile.ZIP_STORED) as zstream: + await export_project(zstream, self._project, tmpdir, keep_compute_id=True, allow_all_nodes=True) + async with aiofiles.open(self.path, 'wb') as f: + async for chunk in zstream: + await f.write(chunk) + log.info("Snapshot '{}' created in {:.4f} seconds".format(self.path, time.time() - begin)) except (ValueError, OSError, RuntimeError) as e: raise aiohttp.web.HTTPConflict(text="Could not create snapshot file '{}': {}".format(self.path, e)) diff --git a/gns3server/handlers/api/controller/project_handler.py b/gns3server/handlers/api/controller/project_handler.py index a59802d5..5b40a13f 100644 --- a/gns3server/handlers/api/controller/project_handler.py +++ b/gns3server/handlers/api/controller/project_handler.py @@ -313,7 +313,7 @@ class ProjectHandler: # We need to do that now because export could failed and raise an HTTP error # that why response start need to be the later possible - response.content_type = 'application/octet-stream' + response.content_type = 'application/gns3project' response.headers['CONTENT-DISPOSITION'] = 'attachment; filename="{}.gns3project"'.format(project.name) response.enable_chunked_encoding() await response.prepare(request) diff --git a/tests/controller/test_export_project.py b/tests/controller/test_export_project.py index c3532d9e..b562a8bc 100644 --- a/tests/controller/test_export_project.py +++ b/tests/controller/test_export_project.py @@ -29,6 +29,7 @@ from tests.utils import AsyncioMagicMock, AsyncioBytesIO from gns3server.controller.project import Project from gns3server.controller.export_project import export_project, _is_exportable +from gns3server.utils.asyncio import aiozipstream @pytest.fixture @@ -51,6 +52,13 @@ def node(controller, project, async_run): return node +async def write_file(path, z): + + with open(path, 'wb') as f: + async for chunk in z: + f.write(chunk) + + def test_exportable_files(): assert _is_exportable("hello/world") assert not _is_exportable("project-files/tmp") @@ -103,12 +111,10 @@ def test_export(tmpdir, project, async_run): with open(os.path.join(path, "project-files", "snapshots", "test"), 'w+') as f: f.write("WORLD") - with patch("gns3server.compute.Dynamips.get_images_directory", return_value=str(tmpdir / "IOS"),): - z = async_run(export_project(project, str(tmpdir), include_images=False)) - - with open(str(tmpdir / 'zipfile.zip'), 'wb') as f: - for data in z: - f.write(data) + with aiozipstream.ZipFile() as z: + with patch("gns3server.compute.Dynamips.get_images_directory", return_value=str(tmpdir / "IOS"),): + async_run(export_project(z, project, str(tmpdir), include_images=False)) + async_run(write_file(str(tmpdir / 'zipfile.zip'), z)) with zipfile.ZipFile(str(tmpdir / 'zipfile.zip')) as myzip: with myzip.open("vm-1/dynamips/test") as myfile: @@ -128,7 +134,7 @@ def test_export(tmpdir, project, async_run): assert topo["computes"] == [] -def test_export_vm(tmpdir, project, async_run, controller): +def test_export_vm(tmpdir, project, async_run): """ If data is on a remote server export it locally before sending it in the archive. @@ -154,12 +160,10 @@ def test_export_vm(tmpdir, project, async_run, controller): with open(os.path.join(path, "test.gns3"), 'w+') as f: f.write("{}") - z = async_run(export_project(project, str(tmpdir))) - assert compute.list_files.called - - with open(str(tmpdir / 'zipfile.zip'), 'wb') as f: - for data in z: - f.write(data) + with aiozipstream.ZipFile() as z: + async_run(export_project(z, project, str(tmpdir))) + assert compute.list_files.called + async_run(write_file(str(tmpdir / 'zipfile.zip'), z)) with zipfile.ZipFile(str(tmpdir / 'zipfile.zip')) as myzip: with myzip.open("vm-1/dynamips/test") as myfile: @@ -169,7 +173,7 @@ def test_export_vm(tmpdir, project, async_run, controller): def test_export_disallow_running(tmpdir, project, node, async_run): """ - Dissallow export when a node is running + Disallow export when a node is running """ path = project.path @@ -189,12 +193,13 @@ def test_export_disallow_running(tmpdir, project, node, async_run): node._status = "started" with pytest.raises(aiohttp.web.HTTPConflict): - async_run(export_project(project, str(tmpdir))) + with aiozipstream.ZipFile() as z: + async_run(export_project(z, project, str(tmpdir))) def test_export_disallow_some_type(tmpdir, project, async_run): """ - Dissalow export for some node type + Disallow export for some node type """ path = project.path @@ -213,8 +218,10 @@ def test_export_disallow_some_type(tmpdir, project, async_run): json.dump(topology, f) with pytest.raises(aiohttp.web.HTTPConflict): - z = async_run(export_project(project, str(tmpdir))) - z = async_run(export_project(project, str(tmpdir), allow_all_nodes=True)) + with aiozipstream.ZipFile() as z: + async_run(export_project(z, project, str(tmpdir))) + with aiozipstream.ZipFile() as z: + async_run(export_project(z, project, str(tmpdir), allow_all_nodes=True)) # VirtualBox is always disallowed topology = { @@ -232,7 +239,8 @@ def test_export_disallow_some_type(tmpdir, project, async_run): with open(os.path.join(path, "test.gns3"), 'w+') as f: json.dump(topology, f) with pytest.raises(aiohttp.web.HTTPConflict): - z = async_run(export_project(project, str(tmpdir), allow_all_nodes=True)) + with aiozipstream.ZipFile() as z: + async_run(export_project(z, project, str(tmpdir), allow_all_nodes=True)) def test_export_fix_path(tmpdir, project, async_run): @@ -264,10 +272,9 @@ def test_export_fix_path(tmpdir, project, async_run): with open(os.path.join(path, "test.gns3"), 'w+') as f: json.dump(topology, f) - z = async_run(export_project(project, str(tmpdir))) - with open(str(tmpdir / 'zipfile.zip'), 'wb') as f: - for data in z: - f.write(data) + with aiozipstream.ZipFile() as z: + async_run(export_project(z, project, str(tmpdir))) + async_run(write_file(str(tmpdir / 'zipfile.zip'), z)) with zipfile.ZipFile(str(tmpdir / 'zipfile.zip')) as myzip: with myzip.open("project.gns3") as myfile: @@ -303,11 +310,10 @@ def test_export_with_images(tmpdir, project, async_run): with open(os.path.join(path, "test.gns3"), 'w+') as f: json.dump(topology, f) - with patch("gns3server.compute.Dynamips.get_images_directory", return_value=str(tmpdir / "IOS"),): - z = async_run(export_project(project, str(tmpdir), include_images=True)) - with open(str(tmpdir / 'zipfile.zip'), 'wb') as f: - for data in z: - f.write(data) + with aiozipstream.ZipFile() as z: + with patch("gns3server.compute.Dynamips.get_images_directory", return_value=str(tmpdir / "IOS"),): + async_run(export_project(z, project, str(tmpdir), include_images=True)) + async_run(write_file(str(tmpdir / 'zipfile.zip'), z)) with zipfile.ZipFile(str(tmpdir / 'zipfile.zip')) as myzip: myzip.getinfo("images/IOS/test.image") @@ -341,11 +347,9 @@ def test_export_keep_compute_id(tmpdir, project, async_run): } json.dump(data, f) - z = async_run(export_project(project, str(tmpdir), keep_compute_id=True)) - - with open(str(tmpdir / 'zipfile.zip'), 'wb') as f: - for data in z: - f.write(data) + with aiozipstream.ZipFile() as z: + async_run(export_project(z, project, str(tmpdir), keep_compute_id=True)) + async_run(write_file(str(tmpdir / 'zipfile.zip'), z)) with zipfile.ZipFile(str(tmpdir / 'zipfile.zip')) as myzip: with myzip.open("project.gns3") as myfile: @@ -353,7 +357,8 @@ def test_export_keep_compute_id(tmpdir, project, async_run): assert topo["nodes"][0]["compute_id"] == "6b7149c8-7d6e-4ca0-ab6b-daa8ab567be0" assert len(topo["computes"]) == 1 -def test_export_images_from_vm(tmpdir, project, async_run, controller): + +def test_export_images_from_vm(tmpdir, project, async_run): """ If data is on a remote server export it locally before sending it in the archive. @@ -405,12 +410,10 @@ def test_export_images_from_vm(tmpdir, project, async_run, controller): with open(os.path.join(path, "test.gns3"), 'w+') as f: f.write(json.dumps(topology)) - z = async_run(export_project(project, str(tmpdir), include_images=True)) - assert compute.list_files.called - - with open(str(tmpdir / 'zipfile.zip'), 'wb') as f: - for data in z: - f.write(data) + with aiozipstream.ZipFile() as z: + async_run(export_project(z, project, str(tmpdir), include_images=True)) + assert compute.list_files.called + async_run(write_file(str(tmpdir / 'zipfile.zip'), z)) with zipfile.ZipFile(str(tmpdir / 'zipfile.zip')) as myzip: with myzip.open("vm-1/dynamips/test") as myfile: @@ -450,12 +453,9 @@ def test_export_with_ignoring_snapshots(tmpdir, project, async_run): os.makedirs(snapshots_dir) Path(os.path.join(snapshots_dir, 'snap.gns3project')).touch() - z = async_run(export_project(project, str(tmpdir), keep_compute_id=True)) - - with open(str(tmpdir / 'zipfile.zip'), 'wb') as f: - for data in z: - f.write(data) + with aiozipstream.ZipFile() as z: + async_run(export_project(z, project, str(tmpdir), keep_compute_id=True)) + async_run(write_file(str(tmpdir / 'zipfile.zip'), z)) with zipfile.ZipFile(str(tmpdir / 'zipfile.zip')) as myzip: assert not os.path.join('snapshots', 'snap.gns3project') in [f.filename for f in myzip.filelist] - diff --git a/tests/handlers/api/compute/test_cloud.py b/tests/handlers/api/compute/test_cloud.py index 0d96a80b..38f8b426 100644 --- a/tests/handlers/api/compute/test_cloud.py +++ b/tests/handlers/api/compute/test_cloud.py @@ -64,7 +64,7 @@ def test_cloud_nio_create_udp(http_compute, vm): "rhost": "127.0.0.1"}, example=True) assert response.status == 201 - assert response.route == "/projects/{project_id}/cloud/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/cloud/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_udp" @@ -82,7 +82,7 @@ def test_cloud_nio_update_udp(http_compute, vm): "filters": {}}, example=True) assert response.status == 201, response.body.decode() - assert response.route == "/projects/{project_id}/cloud/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/cloud/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_udp" @@ -93,7 +93,7 @@ def test_cloud_delete_nio(http_compute, vm): "rhost": "127.0.0.1"}) response = http_compute.delete("/projects/{project_id}/cloud/nodes/{node_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), example=True) assert response.status == 204 - assert response.route == "/projects/{project_id}/cloud/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/cloud/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" def test_cloud_delete(http_compute, vm): diff --git a/tests/handlers/api/compute/test_docker.py b/tests/handlers/api/compute/test_docker.py index 3f9c3618..b584109e 100644 --- a/tests/handlers/api/compute/test_docker.py +++ b/tests/handlers/api/compute/test_docker.py @@ -120,7 +120,7 @@ def test_docker_nio_create_udp(http_compute, vm): "rhost": "127.0.0.1"}, example=True) assert response.status == 201 - assert response.route == "/projects/{project_id}/docker/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/docker/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_udp" @@ -141,14 +141,14 @@ def test_docker_update_nio(http_compute, vm): }, example=True) assert response.status == 201, response.body.decode() - assert response.route == "/projects/{project_id}/docker/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/docker/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" def test_docker_delete_nio(http_compute, vm): with asyncio_patch("gns3server.compute.docker.docker_vm.DockerVM.adapter_remove_nio_binding") as mock: response = http_compute.delete("/projects/{project_id}/docker/nodes/{node_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), example=True) assert response.status == 204 - assert response.route == "/projects/{project_id}/docker/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/docker/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" def test_docker_update(http_compute, vm, tmpdir, free_console_port): diff --git a/tests/handlers/api/compute/test_iou.py b/tests/handlers/api/compute/test_iou.py index 5365f921..9058a9d7 100644 --- a/tests/handlers/api/compute/test_iou.py +++ b/tests/handlers/api/compute/test_iou.py @@ -201,7 +201,7 @@ def test_iou_nio_create_udp(http_compute, vm): "rhost": "127.0.0.1"}, 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" + assert response.route == r"/projects/{project_id}/iou/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_udp" @@ -219,7 +219,7 @@ def test_iou_nio_update_udp(http_compute, vm): "filters": {}}, example=True) assert response.status == 201, response.body.decode() - assert response.route == "/projects/{project_id}/iou/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/iou/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_udp" @@ -229,7 +229,7 @@ def test_iou_nio_create_ethernet(http_compute, vm, 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" + assert response.route == r"/projects/{project_id}/iou/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_ethernet" assert response.json["ethernet_device"] == ethernet_device @@ -240,7 +240,7 @@ def test_iou_nio_create_ethernet_different_port(http_compute, vm, ethernet_devic }, 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" + assert response.route == r"/projects/{project_id}/iou/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_ethernet" assert response.json["ethernet_device"] == ethernet_device @@ -250,7 +250,7 @@ def test_iou_nio_create_tap(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_tap", "tap_device": ethernet_device}) assert response.status == 201 - assert response.route == "/projects/{project_id}/iou/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/iou/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_tap" @@ -261,7 +261,7 @@ def test_iou_delete_nio(http_compute, vm): "rhost": "127.0.0.1"}) response = http_compute.delete("/projects/{project_id}/iou/nodes/{node_id}/adapters/1/ports/0/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), example=True) assert response.status == 204 - assert response.route == "/projects/{project_id}/iou/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/iou/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" def test_iou_start_capture(http_compute, vm, tmpdir, project): diff --git a/tests/handlers/api/compute/test_nat.py b/tests/handlers/api/compute/test_nat.py index f0ff7776..7e0da71c 100644 --- a/tests/handlers/api/compute/test_nat.py +++ b/tests/handlers/api/compute/test_nat.py @@ -65,7 +65,7 @@ def test_nat_nio_create_udp(http_compute, vm): "rhost": "127.0.0.1"}, example=True) assert response.status == 201 - assert response.route == "/projects/{project_id}/nat/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/nat/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_udp" @@ -83,7 +83,7 @@ def test_nat_nio_update_udp(http_compute, vm): "filters": {}}, example=True) assert response.status == 201, response.body.decode() - assert response.route == "/projects/{project_id}/nat/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/nat/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_udp" @@ -97,7 +97,7 @@ def test_nat_delete_nio(http_compute, vm): response = http_compute.delete("/projects/{project_id}/nat/nodes/{node_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), example=True) assert mock_remove_nio.called assert response.status == 204 - assert response.route == "/projects/{project_id}/nat/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/nat/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" def test_nat_delete(http_compute, vm): diff --git a/tests/handlers/api/compute/test_qemu.py b/tests/handlers/api/compute/test_qemu.py index 352db57a..c5c1f033 100644 --- a/tests/handlers/api/compute/test_qemu.py +++ b/tests/handlers/api/compute/test_qemu.py @@ -189,7 +189,7 @@ def test_qemu_nio_create_udp(http_compute, vm): "rhost": "127.0.0.1"}, example=True) assert response.status == 201 - assert response.route == "/projects/{project_id}/qemu/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/qemu/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_udp" @@ -208,7 +208,7 @@ def test_qemu_nio_update_udp(http_compute, vm): "filters": {}}, example=True) assert response.status == 201, response.body.decode() - assert response.route == "/projects/{project_id}/qemu/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/qemu/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_udp" @@ -221,7 +221,7 @@ def test_qemu_delete_nio(http_compute, vm): "rhost": "127.0.0.1"}) response = http_compute.delete("/projects/{project_id}/qemu/nodes/{node_id}/adapters/1/ports/0/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), example=True) assert response.status == 204 - assert response.route == "/projects/{project_id}/qemu/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/qemu/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" def test_qemu_list_binaries(http_compute, vm): diff --git a/tests/handlers/api/compute/test_traceng.py b/tests/handlers/api/compute/test_traceng.py index f9ece5e5..ce93e2fb 100644 --- a/tests/handlers/api/compute/test_traceng.py +++ b/tests/handlers/api/compute/test_traceng.py @@ -55,7 +55,7 @@ def test_traceng_nio_create_udp(http_compute, vm): "rhost": "127.0.0.1"}, example=True) assert response.status == 201 - assert response.route == "/projects/{project_id}/traceng/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/traceng/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_udp" @@ -76,7 +76,7 @@ def test_traceng_nio_update_udp(http_compute, vm): "filters": {}}, example=True) assert response.status == 201, response.body.decode("utf-8") - assert response.route == "/projects/{project_id}/traceng/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/traceng/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_udp" @@ -88,7 +88,7 @@ def test_traceng_delete_nio(http_compute, vm): "rhost": "127.0.0.1"}) response = http_compute.delete("/projects/{project_id}/traceng/nodes/{node_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), example=True) assert response.status == 204, response.body.decode() - assert response.route == "/projects/{project_id}/traceng/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/traceng/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" def test_traceng_start(http_compute, vm): diff --git a/tests/handlers/api/compute/test_virtualbox.py b/tests/handlers/api/compute/test_virtualbox.py index 743141c7..91ec22f1 100644 --- a/tests/handlers/api/compute/test_virtualbox.py +++ b/tests/handlers/api/compute/test_virtualbox.py @@ -108,7 +108,7 @@ def test_vbox_nio_create_udp(http_compute, vm): assert args[0] == 0 assert response.status == 201 - assert response.route == "/projects/{project_id}/virtualbox/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/virtualbox/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_udp" @@ -127,7 +127,7 @@ def test_virtualbox_nio_update_udp(http_compute, vm): "filters": {}}, example=True) assert response.status == 201, response.body.decode() - assert response.route == "/projects/{project_id}/virtualbox/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/virtualbox/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_udp" @@ -141,7 +141,7 @@ def test_vbox_delete_nio(http_compute, vm): assert args[0] == 0 assert response.status == 204 - assert response.route == "/projects/{project_id}/virtualbox/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/virtualbox/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" def test_vbox_update(http_compute, vm, free_console_port): diff --git a/tests/handlers/api/compute/test_vmware.py b/tests/handlers/api/compute/test_vmware.py index 3cca7cd1..1dc9d070 100644 --- a/tests/handlers/api/compute/test_vmware.py +++ b/tests/handlers/api/compute/test_vmware.py @@ -116,7 +116,7 @@ def test_vmware_nio_create_udp(http_compute, vm): assert args[0] == 0 assert response.status == 201 - assert response.route == "/projects/{project_id}/vmware/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/vmware/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_udp" @@ -135,7 +135,7 @@ def test_vmware_nio_update_udp(http_compute, vm): "filters": {}}, example=True) assert response.status == 201, response.body.decode() - assert response.route == "/projects/{project_id}/vmware/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/vmware/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_udp" @@ -149,7 +149,7 @@ def test_vmware_delete_nio(http_compute, vm): assert args[0] == 0 assert response.status == 204 - assert response.route == "/projects/{project_id}/vmware/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/vmware/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" def test_vmware_update(http_compute, vm, free_console_port): diff --git a/tests/handlers/api/compute/test_vpcs.py b/tests/handlers/api/compute/test_vpcs.py index 9cd4ce13..a42cd3fe 100644 --- a/tests/handlers/api/compute/test_vpcs.py +++ b/tests/handlers/api/compute/test_vpcs.py @@ -70,7 +70,7 @@ def test_vpcs_nio_create_udp(http_compute, vm): "rhost": "127.0.0.1"}, example=True) assert response.status == 201 - assert response.route == "/projects/{project_id}/vpcs/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/vpcs/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_udp" @@ -91,7 +91,7 @@ def test_vpcs_nio_update_udp(http_compute, vm): "filters": {}}, example=True) assert response.status == 201, response.body.decode("utf-8") - assert response.route == "/projects/{project_id}/vpcs/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/vpcs/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" assert response.json["type"] == "nio_udp" @@ -103,7 +103,7 @@ def test_vpcs_delete_nio(http_compute, vm): "rhost": "127.0.0.1"}) response = http_compute.delete("/projects/{project_id}/vpcs/nodes/{node_id}/adapters/0/ports/0/nio".format(project_id=vm["project_id"], node_id=vm["node_id"]), example=True) assert response.status == 204, response.body.decode() - assert response.route == "/projects/{project_id}/vpcs/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" + assert response.route == r"/projects/{project_id}/vpcs/nodes/{node_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio" def test_vpcs_start(http_compute, vm):