Esempio n. 1
0
def test_addNIO(vpcs_device):

    with patch('gns3.node.Node.httpPost') as mock:
        port = Port("Port 1")
        port.setPortNumber(0)
        port.setAdapterNumber(0)
        nio = NIOUDP(4242, "127.0.0.1", 4243)
        vpcs_device.addNIO(port, nio)
        assert mock.called
        args, kwargs = mock.call_args
        assert args[0] == "/vpcs/vms/{vm_id}/adapters/0/ports/0/nio".format(
            vm_id=vpcs_device.vm_id())

        # Connect the signal
        signal_mock = Mock()
        vpcs_device.nio_signal.connect(signal_mock)

        # Callback
        args[1]({}, context=kwargs["context"])

        # Check the signal
        assert signal_mock.called
        args, kwargs = signal_mock.call_args
        assert args[0] == vpcs_device.id()
        assert args[1] == port.id()
Esempio n. 2
0
def test_startPacketCapture(iou_device):

    port = Port("test")
    port.setAdapterNumber(2)
    port.setPortNumber(1)

    with patch("gns3.node.Node.httpPost") as mock:
        iou_device.startPacketCapture(port, "test.pcap", "DLT_EN10MB")
        assert mock.called
        args, kwargs = mock.call_args
        assert args[
            0] == "/iou/vms/{vm_id}/adapters/2/ports/1/start_capture".format(
                vm_id=iou_device.vm_id())
        assert kwargs["body"] == {
            "data_link_type": "DLT_EN10MB",
            "capture_file_name": "test.pcap"
        }

        with patch("gns3.ports.port.Port.startPacketCapture") as port_mock:

            # Callback
            args[1]({
                "pcap_file_path": "/tmp/test.pcap"
            },
                    context=kwargs["context"])

            assert port_mock.called_with("/tmp/test.pcap")
Esempio n. 3
0
def test_deleteNIO(vpcs_device):

    with patch('gns3.node.Node.httpPost') as mock_post:
        with patch('gns3.node.Node.httpDelete') as mock_delete:
            port = Port("Port 1")
            port.setPortNumber(0)
            port.setAdapterNumber(0)
            nio = NIOUDP(4242, "127.0.0.1", 4243)
            vpcs_device.addNIO(port, nio)

            vpcs_device.deleteNIO(port)
            assert mock_delete.called

            args, kwargs = mock_delete.call_args
            assert args[0] == "/vpcs/vms/{vm_id}/adapters/0/ports/0/nio".format(vm_id=vpcs_device.vm_id())
Esempio n. 4
0
def test_stopPacketCapture(iou_device):

    port = Port("test")
    port.setAdapterNumber(2)
    port.setPortNumber(1)

    with patch("gns3.node.Node.httpPost") as mock:
        iou_device.stopPacketCapture(port)
        assert mock.called
        args, kwargs = mock.call_args
        assert args[0] == "/iou/vms/{vm_id}/adapters/2/ports/1/stop_capture".format(vm_id=iou_device.vm_id())

        with patch("gns3.ports.port.Port.stopPacketCapture") as port_mock:

            # Callback
            args[1]({}, context=kwargs["context"])

            assert port_mock.called
Esempio n. 5
0
def test_stopPacketCapture(iou_device):

    port = Port("test")
    port.setAdapterNumber(2)
    port.setPortNumber(1)

    with patch("gns3.node.Node.httpPost") as mock:
        iou_device.stopPacketCapture(port)
        assert mock.called
        args, kwargs = mock.call_args
        assert args[0] == "/iou/vms/{vm_id}/adapters/2/ports/1/stop_capture".format(vm_id=iou_device.vm_id())

        with patch("gns3.ports.port.Port.stopPacketCapture") as port_mock:

            # Callback
            args[1]({}, context=kwargs["context"])

            assert port_mock.called
Esempio n. 6
0
def test_startPacketCapture(iou_device):

    port = Port("test")
    port.setAdapterNumber(2)
    port.setPortNumber(1)

    with patch("gns3.node.Node.httpPost") as mock:
        iou_device.startPacketCapture(port, "test.pcap", "DLT_EN10MB")
        assert mock.called
        args, kwargs = mock.call_args
        assert args[0] == "/iou/vms/{vm_id}/adapters/2/ports/1/start_capture".format(vm_id=iou_device.vm_id())
        assert kwargs["body"] == {"data_link_type": "DLT_EN10MB", "capture_file_name": "test.pcap"}

        with patch("gns3.ports.port.Port.startPacketCapture") as port_mock:

            # Callback
            args[1]({"pcap_file_path": "/tmp/test.pcap"}, context=kwargs["context"])

            assert port_mock.called_with("/tmp/test.pcap")
Esempio n. 7
0
def test_addNIO(vpcs_device):

    with patch('gns3.node.Node.httpPost') as mock:
        port = Port("Port 1")
        port.setPortNumber(0)
        port.setAdapterNumber(0)
        nio = NIOUDP(4242, "127.0.0.1", 4243)
        vpcs_device.addNIO(port, nio)
        assert mock.called
        args, kwargs = mock.call_args
        assert args[0] == "/vpcs/vms/{vm_id}/adapters/0/ports/0/nio".format(vm_id=vpcs_device.vm_id())

        # Connect the signal
        signal_mock = Mock()
        vpcs_device.nio_signal.connect(signal_mock)

        # Callback
        args[1]({}, context=kwargs["context"])

        # Check the signal
        assert signal_mock.called
        args, kwargs = signal_mock.call_args
        assert args[0] == vpcs_device.id()
        assert args[1] == port.id()