mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-20 05:05:14 +02:00
Captures written in the captures directory on the controller
This commit is contained in:
9 files changed
+155
-40
No files matched your search
@@ -15,7 +15,9 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import pytest
|
||||
import asyncio
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
|
||||
@@ -24,6 +26,8 @@ from gns3server.controller.vm import VM
|
||||
from gns3server.controller.compute import Compute
|
||||
from gns3server.controller.project import Project
|
||||
|
||||
from tests.utils import AsyncioBytesIO
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def project():
|
||||
@@ -35,6 +39,17 @@ def compute():
|
||||
return Compute("example.com", controller=MagicMock())
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def link(async_run, project, compute):
|
||||
vm1 = VM(project, compute)
|
||||
vm2 = VM(project, compute)
|
||||
|
||||
link = Link(project)
|
||||
async_run(link.addVM(vm1, 0, 4))
|
||||
async_run(link.addVM(vm2, 1, 3))
|
||||
return link
|
||||
|
||||
|
||||
def test_addVM(async_run, project, compute):
|
||||
vm1 = VM(project, compute)
|
||||
|
||||
@@ -70,15 +85,33 @@ def test_json(async_run, project, compute):
|
||||
"port_number": 3
|
||||
}
|
||||
],
|
||||
"capturing": False
|
||||
"capturing": False,
|
||||
"capture_file_name": None
|
||||
}
|
||||
|
||||
|
||||
def test_capture_filename(project, compute, async_run):
|
||||
def test_start_streaming_pcap(link, async_run, tmpdir, project):
|
||||
@asyncio.coroutine
|
||||
def fake_reader():
|
||||
output = AsyncioBytesIO()
|
||||
yield from output.write(b"hello")
|
||||
output.seek(0)
|
||||
return output
|
||||
|
||||
link._capture_file_name = "test.pcap"
|
||||
link._capturing = True
|
||||
link.read_pcap_from_source = fake_reader
|
||||
async_run(link._start_streaming_pcap())
|
||||
with open(os.path.join(project.captures_directory, "test.pcap"), "rb") as f:
|
||||
c = f.read()
|
||||
assert c == b"hello"
|
||||
|
||||
|
||||
def test_default_capture_file_name(project, compute, async_run):
|
||||
vm1 = VM(project, compute, name="Hello@")
|
||||
vm2 = VM(project, compute, name="w0.rld")
|
||||
|
||||
link = Link(project)
|
||||
async_run(link.addVM(vm1, 0, 4))
|
||||
async_run(link.addVM(vm2, 1, 3))
|
||||
assert link.capture_file_name() == "Hello_0-4_to_w0rld_1-3.pcap"
|
||||
assert link.default_capture_file_name() == "Hello_0-4_to_w0rld_1-3.pcap"
|
||||
Reference in new issue
Block a user