|
|
@ -18,8 +18,9 @@
|
|
|
|
import pytest
|
|
|
|
import pytest
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import stat
|
|
|
|
import stat
|
|
|
|
|
|
|
|
|
|
|
|
from tests.utils import asyncio_patch
|
|
|
|
from tests.utils import asyncio_patch
|
|
|
|
from unittest.mock import patch
|
|
|
|
from unittest.mock import patch, MagicMock, PropertyMock
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
@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"
|
|
|
|
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"}
|
|
|
|
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)
|
|
|
|
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 response.status == 200
|
|
|
|
|
|
|
|
assert "test.pcap" in response.json["pcap_file_path"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assert start_capture.called
|
|
|
|
|
|
|
|
assert "test.pcap" in response.json["pcap_file_path"]
|
|
|
|
|
|
|
|
|
|
|
|
def test_iou_stop_capture(server, vm):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
with asyncio_patch("gns3server.modules.iou.iou_vm.IOUVM.stop_capture", return_value=True) as mock:
|
|
|
|
def test_iou_start_capture_not_started(server, vm, tmpdir):
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
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:
|
|
|
|
|
|
|
|
|
|
|
|
assert mock.called
|
|
|
|
params = {"capture_file_name": "test.pcap", "data_link_type": "DLT_EN10MB"}
|
|
|
|
assert response.status == 204
|
|
|
|
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 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):
|
|
|
|
def test_get_initial_config_without_config_file(server, vm):
|
|
|
|