mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Fix crash when you start capture on a non running IOU
This commit is contained in:
1 parent
18f3859e87
commit
d657f94c18
2 files changed
+54
-17
No files matched your search
@@ -18,8 +18,9 @@
|
||||
import pytest
|
||||
import os
|
||||
import stat
|
||||
|
||||
from tests.utils import asyncio_patch
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import patch, MagicMock, PropertyMock
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -207,26 +208,53 @@ def test_iou_delete_nio(server, vm):
|
||||
assert response.route == "/projects/{project_id}/iou/vms/{vm_id}/adapters/{adapter_number:\d+}/ports/{port_number:\d+}/nio"
|
||||
|
||||
|
||||
def test_iou_start_capture(server, vm, tmpdir):
|
||||
def test_iou_start_capture(server, vm, tmpdir, project):
|
||||
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.start_capture", return_value=True) as mock:
|
||||
with patch("gns3server.modules.iou.iou_vm.IOUVM.is_running", return_value=True) as mock:
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.start_capture") as start_capture:
|
||||
|
||||
params = {"capture_file_name": "test.pcap", "data_link_type": "DLT_EN10MB"}
|
||||
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), body=params, example=True)
|
||||
params = {"capture_file_name": "test.pcap", "data_link_type": "DLT_EN10MB"}
|
||||
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), body=params, example=True)
|
||||
|
||||
assert mock.called
|
||||
assert response.status == 200
|
||||
assert "test.pcap" in response.json["pcap_file_path"]
|
||||
assert response.status == 200
|
||||
|
||||
assert start_capture.called
|
||||
assert "test.pcap" in response.json["pcap_file_path"]
|
||||
|
||||
|
||||
def test_iou_stop_capture(server, vm):
|
||||
def test_iou_start_capture_not_started(server, vm, tmpdir):
|
||||
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.stop_capture", return_value=True) as mock:
|
||||
with patch("gns3server.modules.iou.iou_vm.IOUVM.is_running", return_value=False) as mock:
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.start_capture") as start_capture:
|
||||
|
||||
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
|
||||
params = {"capture_file_name": "test.pcap", "data_link_type": "DLT_EN10MB"}
|
||||
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/0/ports/0/start_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), body=params)
|
||||
|
||||
assert mock.called
|
||||
assert response.status == 204
|
||||
assert not start_capture.called
|
||||
assert response.status == 409
|
||||
|
||||
|
||||
def test_iou_stop_capture(server, vm, tmpdir, project):
|
||||
|
||||
with patch("gns3server.modules.iou.iou_vm.IOUVM.is_running", return_value=True) as mock:
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.stop_capture") as stop_capture:
|
||||
|
||||
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]), example=True)
|
||||
|
||||
assert response.status == 204
|
||||
|
||||
assert stop_capture.called
|
||||
|
||||
|
||||
def test_iou_stop_capture_not_started(server, vm, tmpdir):
|
||||
|
||||
with patch("gns3server.modules.iou.iou_vm.IOUVM.is_running", return_value=False) as mock:
|
||||
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.stop_capture") as stop_capture:
|
||||
|
||||
response = server.post("/projects/{project_id}/iou/vms/{vm_id}/adapters/0/ports/0/stop_capture".format(project_id=vm["project_id"], vm_id=vm["vm_id"]))
|
||||
|
||||
assert not stop_capture.called
|
||||
assert response.status == 409
|
||||
|
||||
|
||||
def test_get_initial_config_without_config_file(server, vm):
|
||||
|
||||
Reference in new issue
Block a user