Refactor how clients access PCAP capture files. Fixes https://github.com/GNS3/gns3-gui/issues/2438.

* The PCAP file is directly accessed if controller and client are on the same host.
* The PCAP file is streamed from the compute server to the client with the controller as a proxy when the controller is remote for the client.
This commit is contained in:
grossmj
2018-10-27 14:47:17 +07:00
parent bf1b801cc0
commit 2764828f38
47 changed files with 1071 additions and 473 deletions

View File

@ -112,3 +112,29 @@ def test_nat_update(http_compute, vm, tmpdir):
example=True)
assert response.status == 200
assert response.json["name"] == "test"
def test_nat_start_capture(http_compute, vm):
with asyncio_patch("gns3server.compute.builtin.nodes.nat.Nat.start_capture") as start_capture:
params = {"capture_file_name": "test.pcap", "data_link_type": "DLT_EN10MB"}
response = http_compute.post("/projects/{project_id}/nat/nodes/{node_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]), body=params, example=True)
assert response.status == 200
assert start_capture.called
assert "test.pcap" in response.json["pcap_file_path"]
def test_nat_stop_capture(http_compute, vm):
with asyncio_patch("gns3server.compute.builtin.nodes.nat.Nat.stop_capture") as stop_capture:
response = http_compute.post("/projects/{project_id}/nat/nodes/{node_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], node_id=vm["node_id"]), example=True)
assert response.status == 204
assert stop_capture.called
def test_nat_pcap(http_compute, vm, project):
with asyncio_patch("gns3server.compute.builtin.nodes.nat.Nat.get_nio"):
with asyncio_patch("gns3server.compute.builtin.Builtin.stream_pcap_file"):
response = http_compute.get("/projects/{project_id}/nat/nodes/{node_id}/adapters/0/ports/0/pcap".format(project_id=project.id, node_id=vm["node_id"]), raw=True)
assert response.status == 200