|
|
@ -15,7 +15,9 @@
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import pytest
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
import asyncio
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
from unittest.mock import MagicMock
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -24,6 +26,8 @@ from gns3server.controller.vm import VM
|
|
|
|
from gns3server.controller.compute import Compute
|
|
|
|
from gns3server.controller.compute import Compute
|
|
|
|
from gns3server.controller.project import Project
|
|
|
|
from gns3server.controller.project import Project
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from tests.utils import AsyncioBytesIO
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
@pytest.fixture
|
|
|
|
def project():
|
|
|
|
def project():
|
|
|
@ -35,6 +39,17 @@ def compute():
|
|
|
|
return Compute("example.com", controller=MagicMock())
|
|
|
|
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):
|
|
|
|
def test_addVM(async_run, project, compute):
|
|
|
|
vm1 = VM(project, compute)
|
|
|
|
vm1 = VM(project, compute)
|
|
|
|
|
|
|
|
|
|
|
@ -70,15 +85,33 @@ def test_json(async_run, project, compute):
|
|
|
|
"port_number": 3
|
|
|
|
"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@")
|
|
|
|
vm1 = VM(project, compute, name="Hello@")
|
|
|
|
vm2 = VM(project, compute, name="w0.rld")
|
|
|
|
vm2 = VM(project, compute, name="w0.rld")
|
|
|
|
|
|
|
|
|
|
|
|
link = Link(project)
|
|
|
|
link = Link(project)
|
|
|
|
async_run(link.addVM(vm1, 0, 4))
|
|
|
|
async_run(link.addVM(vm1, 0, 4))
|
|
|
|
async_run(link.addVM(vm2, 1, 3))
|
|
|
|
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"
|
|
|
|