1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-13 20:08:55 +00:00

Fix an issue with Docker and IOU packet capture

Fix https://github.com/GNS3/gns3-gui/issues/1727
This commit is contained in:
Julien Duponchelle 2016-12-19 12:26:34 +01:00
parent 3bc78f61df
commit 2011aca43a
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
4 changed files with 1 additions and 56 deletions

View File

@ -284,8 +284,6 @@ class DockerHandler:
adapter_number = int(request.match_info["adapter_number"])
pcap_file_path = os.path.join(container.project.capture_working_directory(), request.json["capture_file_name"])
if not container.is_running():
raise HTTPConflict(text="Cannot capture traffic on a non started Docker container")
yield from container.start_capture(adapter_number, pcap_file_path)
response.json({"pcap_file_path": str(pcap_file_path)})
@ -309,9 +307,6 @@ class DockerHandler:
docker_manager = Docker.instance()
container = docker_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
if not container.is_running():
raise HTTPConflict(text="Cannot capture traffic on a non started Docker container")
adapter_number = int(request.match_info["adapter_number"])
yield from container.stop_capture(adapter_number)
response.set_status(204)

View File

@ -270,8 +270,6 @@ class IOUHandler:
adapter_number = int(request.match_info["adapter_number"])
port_number = int(request.match_info["port_number"])
pcap_file_path = os.path.join(vm.project.capture_working_directory(), request.json["capture_file_name"])
if not vm.is_running():
raise HTTPConflict(text="Cannot capture traffic on a non started VM")
yield from vm.start_capture(adapter_number, port_number, pcap_file_path, request.json["data_link_type"])
response.json({"pcap_file_path": str(pcap_file_path)})
@ -295,9 +293,6 @@ class IOUHandler:
iou_manager = IOU.instance()
vm = iou_manager.get_node(request.match_info["node_id"], project_id=request.match_info["project_id"])
if not vm.is_running():
raise HTTPConflict(text="Cannot capture traffic on a non started VM")
adapter_number = int(request.match_info["adapter_number"])
port_number = int(request.match_info["port_number"])
yield from vm.stop_capture(adapter_number, port_number)

View File

@ -28,6 +28,7 @@ from gns3server.compute.docker import Docker
pytestmark = pytest.mark.skipif(sys.platform.startswith("win"), reason="Not supported on Windows")
@pytest.fixture
def base_params():
"""Return standard parameters"""
@ -159,18 +160,6 @@ def test_docker_start_capture(http_compute, vm, tmpdir, project):
assert "test.pcap" in response.json["pcap_file_path"]
def test_docker_start_capture_not_started(http_compute, vm, tmpdir):
with patch("gns3server.compute.docker.docker_vm.DockerVM.is_running", return_value=False) as mock:
with asyncio_patch("gns3server.compute.docker.docker_vm.DockerVM.start_capture") as start_capture:
params = {"capture_file_name": "test.pcap", "data_link_type": "DLT_EN10MB"}
response = http_compute.post("/projects/{project_id}/docker/nodes/{node_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]), body=params)
assert not start_capture.called
assert response.status == 409
def test_docker_stop_capture(http_compute, vm, tmpdir, project):
with patch("gns3server.compute.docker.docker_vm.DockerVM.is_running", return_value=True) as mock:
@ -181,14 +170,3 @@ def test_docker_stop_capture(http_compute, vm, tmpdir, project):
assert response.status == 204
assert stop_capture.called
def test_docker_stop_capture_not_started(http_compute, vm, tmpdir):
with patch("gns3server.compute.docker.docker_vm.DockerVM.is_running", return_value=False) as mock:
with asyncio_patch("gns3server.compute.docker.docker_vm.DockerVM.stop_capture") as stop_capture:
response = http_compute.post("/projects/{project_id}/docker/nodes/{node_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]))
assert not stop_capture.called
assert response.status == 409

View File

@ -268,18 +268,6 @@ def test_iou_start_capture(http_compute, vm, tmpdir, project):
assert "test.pcap" in response.json["pcap_file_path"]
def test_iou_start_capture_not_started(http_compute, vm, tmpdir):
with patch("gns3server.compute.iou.iou_vm.IOUVM.is_running", return_value=False) as mock:
with asyncio_patch("gns3server.compute.iou.iou_vm.IOUVM.start_capture") as start_capture:
params = {"capture_file_name": "test.pcap", "data_link_type": "DLT_EN10MB"}
response = http_compute.post("/projects/{project_id}/iou/nodes/{node_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]), body=params)
assert not start_capture.called
assert response.status == 409
def test_iou_stop_capture(http_compute, vm, tmpdir, project):
with patch("gns3server.compute.iou.iou_vm.IOUVM.is_running", return_value=True) as mock:
@ -292,17 +280,6 @@ def test_iou_stop_capture(http_compute, vm, tmpdir, project):
assert stop_capture.called
def test_iou_stop_capture_not_started(http_compute, vm, tmpdir):
with patch("gns3server.compute.iou.iou_vm.IOUVM.is_running", return_value=False) as mock:
with asyncio_patch("gns3server.compute.iou.iou_vm.IOUVM.stop_capture") as stop_capture:
response = http_compute.post("/projects/{project_id}/iou/nodes/{node_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]))
assert not stop_capture.called
assert response.status == 409
def test_images(http_compute, fake_iou_bin):
response = http_compute.get("/iou/images", example=True)