Пример #1
0
def test_capture(async_run, project):
    compute1 = MagicMock()

    node_vpcs = Node(project, compute1, "V1", node_type="vpcs")
    node_vpcs._status = "started"
    node_vpcs._ports = [EthernetPort("E0", 0, 0, 4)]
    node_iou = Node(project, compute1, "I1", node_type="iou")
    node_iou._ports = [EthernetPort("E0", 0, 3, 1)]

    link = UDPLink(project)
    link.create = AsyncioMagicMock()
    async_run(link.add_node(node_vpcs, 0, 4))
    async_run(link.add_node(node_iou, 3, 1))

    capture = async_run(link.start_capture())
    assert link.capturing

    compute1.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/start_capture".format(project.id, node_vpcs.id), data={
        "capture_file_name": link.default_capture_file_name(),
        "data_link_type": "DLT_EN10MB"
    })

    capture = async_run(link.stop_capture())
    assert link.capturing is False

    compute1.post.assert_any_call("/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/stop_capture".format(project.id, node_vpcs.id))
Пример #2
0
def test_capture(async_run, project):
    compute1 = MagicMock()

    node_vpcs = Node(project, compute1, "V1", node_type="vpcs")
    node_vpcs._status = "started"
    node_vpcs._ports = [EthernetPort("E0", 0, 0, 4)]
    node_iou = Node(project, compute1, "I1", node_type="iou")
    node_iou._ports = [EthernetPort("E0", 0, 3, 1)]

    link = UDPLink(project)
    link.create = AsyncioMagicMock()
    async_run(link.add_node(node_vpcs, 0, 4))
    async_run(link.add_node(node_iou, 3, 1))

    capture = async_run(link.start_capture())
    assert link.capturing

    compute1.post.assert_any_call(
        "/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/start_capture".format(
            project.id, node_vpcs.id),
        data={
            "capture_file_name": link.default_capture_file_name(),
            "data_link_type": "DLT_EN10MB"
        })

    capture = async_run(link.stop_capture())
    assert link.capturing is False

    compute1.post.assert_any_call(
        "/projects/{}/vpcs/nodes/{}/adapters/0/ports/4/stop_capture".format(
            project.id, node_vpcs.id))
Пример #3
0
def test_node_updated(project, async_run):
    """
    If a node stop when capturing we stop the capture
    """
    compute1 = MagicMock()
    node_vpcs = Node(project, compute1, "V1", node_type="vpcs")
    node_vpcs._status = "started"

    link = UDPLink(project)
    link._capture_node = {"node": node_vpcs}
    link.stop_capture = AsyncioMagicMock()

    async_run(link.node_updated(node_vpcs))
    assert not link.stop_capture.called

    node_vpcs._status = "stopped"
    async_run(link.node_updated(node_vpcs))
    assert link.stop_capture.called
Пример #4
0
def test_node_updated(project, async_run):
    """
    If a node stop when capturing we stop the capture
    """
    compute1 = MagicMock()
    node_vpcs = Node(project, compute1, "V1", node_type="vpcs")
    node_vpcs._status = "started"

    link = UDPLink(project)
    link._capture_node = {"node": node_vpcs}
    link.stop_capture = AsyncioMagicMock()

    async_run(link.node_updated(node_vpcs))
    assert not link.stop_capture.called

    node_vpcs._status = "stopped"
    async_run(link.node_updated(node_vpcs))
    assert link.stop_capture.called