def test_delete_port_to_agent(self):
        self.netns_mgr = NetnsManager('fake_vm_uuid', NIC1, NIC2)
        self.netns_mgr.vrouter_client = mock.Mock()

        self.netns_mgr._delete_port_to_agent(NIC1)
        self.netns_mgr.vrouter_client.delete_port.assert_called_with(
            NIC1['uuid'])
class NetnsManagerTest(unittest.TestCase):
    def setUp(self):
        self.ip_cls_p = mock.patch('opencontrail_vrouter_netns.linux.ip_lib.'
                                   'IPWrapper')
        ip_cls = self.ip_cls_p.start()
        self.mock_ip = mock.MagicMock()
        ip_cls.return_value = self.mock_ip

    def test_add_port_to_agent(self):
        self.netns_mgr = NetnsManager('fake_vm_uuid', NIC1, NIC2)
        self.netns_mgr.vrouter_client = mock.Mock()
        self.netns_mgr._get_tap_name = mock.Mock()
        self.netns_mgr._get_tap_name.return_value = 'tap1234'

        self.netns_mgr._add_port_to_agent(NIC1)
        kwargs = {}
        kwargs['ip_address'] = str(NIC1['ip'].ip)
        kwargs['port_type'] = 'NameSpacePort'
        self.netns_mgr.vrouter_client.add_port.assert_called_with(
            'fake_vm_uuid', NIC1['uuid'], 'tap1234', str(NIC1['mac']),
            **kwargs)

    def test_delete_port_to_agent(self):
        self.netns_mgr = NetnsManager('fake_vm_uuid', NIC1, NIC2)
        self.netns_mgr.vrouter_client = mock.Mock()

        self.netns_mgr._delete_port_to_agent(NIC1)
        self.netns_mgr.vrouter_client.delete_port.assert_called_with(
            NIC1['uuid'])
class NetnsManagerTest(unittest.TestCase):
    def setUp(self):
        self.ip_cls_p = mock.patch("opencontrail_vrouter_netns.linux.ip_lib." "IPWrapper")
        ip_cls = self.ip_cls_p.start()
        self.mock_ip = mock.MagicMock()
        ip_cls.return_value = self.mock_ip

    def test_add_port_to_agent(self):
        self.netns_mgr = NetnsManager("fake_vm_uuid", NIC1, NIC2)
        self.netns_mgr.vrouter_client = mock.Mock()
        self.netns_mgr._get_tap_name = mock.Mock()
        self.netns_mgr._get_tap_name.return_value = "tap1234"

        self.netns_mgr._add_port_to_agent(NIC1)
        kwargs = {}
        kwargs["ip_address"] = str(NIC1["ip"].ip)
        kwargs["port_type"] = "NameSpacePort"
        self.netns_mgr.vrouter_client.add_port.assert_called_with(
            "fake_vm_uuid", NIC1["uuid"], "tap1234", str(NIC1["mac"]), **kwargs
        )

    def test_delete_port_to_agent(self):
        self.netns_mgr = NetnsManager("fake_vm_uuid", NIC1, NIC2)
        self.netns_mgr.vrouter_client = mock.Mock()

        self.netns_mgr._delete_port_to_agent(NIC1)
        self.netns_mgr.vrouter_client.delete_port.assert_called_with(NIC1["uuid"])
Beispiel #4
0
    def _delete_port_from_agent(self, status_code=200):
        self.netns_mgr = NetnsManager('fake_vm_uuid', NIC1, NIC2)
        self.netns_mgr.vrouter_client = mock.Mock()

        resp = requests.Response()
        resp.status_code = status_code
        self.mock_delete.return_value = resp

        self.netns_mgr._delete_port_to_agent(NIC1)
Beispiel #5
0
    def _add_port_to_agent(self, status_code=200):
        self.netns_mgr = NetnsManager('fake_vm_uuid', NIC1, NIC2)
        self.netns_mgr.vrouter_client = mock.Mock()
        self.netns_mgr._get_tap_name = mock.Mock()
        self.netns_mgr._get_tap_name.return_value = 'tap1234'

        resp = requests.Response()
        resp.status_code = status_code
        self.mock_post.return_value = resp

        self.netns_mgr._add_port_to_agent(NIC1)
    def test_add_port_to_agent(self):
        self.netns_mgr = NetnsManager('fake_vm_uuid', NIC1, NIC2)
        self.netns_mgr.vrouter_client = mock.Mock()
        self.netns_mgr._get_tap_name = mock.Mock()
        self.netns_mgr._get_tap_name.return_value = 'tap1234'

        self.netns_mgr._add_port_to_agent(NIC1)
        kwargs = {}
        kwargs['ip_address'] = str(NIC1['ip'].ip)
        self.netns_mgr.vrouter_client.add_port.assert_called_with(
            'fake_vm_uuid', NIC1['uuid'], 'tap1234', str(NIC1['mac']),
            **kwargs)
    def _delete_port_from_agent(self, status_code=200):
        self.netns_mgr = NetnsManager('fake_vm_uuid', NIC1, NIC2)
        self.netns_mgr.vrouter_client = mock.Mock()

        resp = requests.Response()
        resp.status_code = status_code
        self.mock_delete.return_value = resp

        self.netns_mgr._delete_port_to_agent(NIC1)
    def _add_port_to_agent(self, status_code=200):
        self.netns_mgr = NetnsManager('fake_vm_uuid', NIC1, NIC2)
        self.netns_mgr.vrouter_client = mock.Mock()
        self.netns_mgr._get_tap_name = mock.Mock()
        self.netns_mgr._get_tap_name.return_value = 'tap1234'

        resp = requests.Response()
        resp.status_code = status_code
        self.mock_post.return_value = resp

        self.netns_mgr._add_port_to_agent(NIC1)
    def test_add_port_to_agent(self):
        self.netns_mgr = NetnsManager("fake_vm_uuid", NIC1, NIC2)
        self.netns_mgr.vrouter_client = mock.Mock()
        self.netns_mgr._get_tap_name = mock.Mock()
        self.netns_mgr._get_tap_name.return_value = "tap1234"

        self.netns_mgr._add_port_to_agent(NIC1)
        kwargs = {}
        kwargs["ip_address"] = str(NIC1["ip"].ip)
        kwargs["port_type"] = "NameSpacePort"
        self.netns_mgr.vrouter_client.add_port.assert_called_with(
            "fake_vm_uuid", NIC1["uuid"], "tap1234", str(NIC1["mac"]), **kwargs
        )
Beispiel #10
0
class NetnsManagerTest(unittest.TestCase):
    def setUp(self):
        self.ip_cls_p = mock.patch('opencontrail_vrouter_netns.linux.ip_lib.'
                                   'IPWrapper')
        self.ip_cls_p.start()

        self.post_p = mock.patch('requests.post')
        self.mock_post = self.post_p.start()

        self.delete_p = mock.patch('requests.delete')
        self.mock_delete = self.delete_p.start()

    def tearDown(self):
        self.ip_cls_p.stop()
        self.post_p.stop()
        self.delete_p.stop()

    def _add_port_to_agent(self, status_code=200):
        self.netns_mgr = NetnsManager('fake_vm_uuid', NIC1, NIC2)
        self.netns_mgr.vrouter_client = mock.Mock()
        self.netns_mgr._get_tap_name = mock.Mock()
        self.netns_mgr._get_tap_name.return_value = 'tap1234'

        resp = requests.Response()
        resp.status_code = status_code
        self.mock_post.return_value = resp

        self.netns_mgr._add_port_to_agent(NIC1)

    def test_add_port_to_agent(self):
        self._add_port_to_agent()

        self.mock_post.assert_called_with(
            'http://localhost:9091/port',
            headers={'content-type': 'application/json'},
            data=('{"tx-vlan-id": -1, '
                  '"ip-address": "172.16.0.12", '
                  '"display-name": null, '
                  '"id": "%s", '
                  '"instance-id": "fake_vm_uuid", '
                  '"ip6-address": "", '
                  '"rx-vlan-id": -1, '
                  '"vn-id": "", '
                  '"vm-project-id": "", '
                  '"type": 1, '
                  '"mac-address": "00-11-22-33-44-55", '
                  '"system-name": "tap1234"}') % NIC1_UUID)

    def test_add_port_to_agent_fails(self):
        self.assertRaises(ValueError, self._add_port_to_agent, 500)

    def _delete_port_from_agent(self, status_code=200):
        self.netns_mgr = NetnsManager('fake_vm_uuid', NIC1, NIC2)
        self.netns_mgr.vrouter_client = mock.Mock()

        resp = requests.Response()
        resp.status_code = status_code
        self.mock_delete.return_value = resp

        self.netns_mgr._delete_port_to_agent(NIC1)

    def test_delete_port_from_agent(self):
        self._delete_port_from_agent()

        self.mock_delete.assert_called_with(
            'http://localhost:9091/port/%s' % NIC1_UUID,
            headers={'content-type': 'application/json'},
            data=None)

    def test_delete_port_to_agent_fails(self):
        self.assertRaises(ValueError, self._delete_port_from_agent, 500)
class NetnsManagerTest(unittest.TestCase):
    def setUp(self):
        self.ip_cls_p = mock.patch('opencontrail_vrouter_netns.linux.ip_lib.'
                                   'IPWrapper')
        self.ip_cls_p.start()

        self.post_p = mock.patch('requests.post')
        self.mock_post = self.post_p.start()

        self.delete_p = mock.patch('requests.delete')
        self.mock_delete = self.delete_p.start()

    def tearDown(self):
        self.ip_cls_p.stop()
        self.post_p.stop()
        self.delete_p.stop()

    def _add_port_to_agent(self, status_code=200):
        self.netns_mgr = NetnsManager('fake_vm_uuid', NIC1, NIC2)
        self.netns_mgr.vrouter_client = mock.Mock()
        self.netns_mgr._get_tap_name = mock.Mock()
        self.netns_mgr._get_tap_name.return_value = 'tap1234'

        resp = requests.Response()
        resp.status_code = status_code
        self.mock_post.return_value = resp

        self.netns_mgr._add_port_to_agent(NIC1)

    def test_add_port_to_agent(self):
        self._add_port_to_agent()

        self.mock_post.assert_called_with(
            'http://localhost:9091/port',
            headers={'content-type': 'application/json'},
            data=('{"tx-vlan-id": -1, '
                  '"ip-address": "172.16.0.12", '
                  '"display-name": null, '
                  '"id": "%s", '
                  '"instance-id": "fake_vm_uuid", '
                  '"ip6-address": "", '
                  '"rx-vlan-id": -1, '
                  '"vn-id": "", '
                  '"vm-project-id": "", '
                  '"type": 1, '
                  '"mac-address": "00-11-22-33-44-55", '
                  '"system-name": "tap1234"}') % NIC1_UUID)

    def test_add_port_to_agent_fails(self):
        self.assertRaises(ValueError,
                          self._add_port_to_agent,
                          500)

    def _delete_port_from_agent(self, status_code=200):
        self.netns_mgr = NetnsManager('fake_vm_uuid', NIC1, NIC2)
        self.netns_mgr.vrouter_client = mock.Mock()

        resp = requests.Response()
        resp.status_code = status_code
        self.mock_delete.return_value = resp

        self.netns_mgr._delete_port_to_agent(NIC1)

    def test_delete_port_from_agent(self):
        self._delete_port_from_agent()

        self.mock_delete.assert_called_with(
            'http://localhost:9091/port/%s' % NIC1_UUID,
            headers={'content-type': 'application/json'},
            data=None)

    def test_delete_port_to_agent_fails(self):
        self.assertRaises(ValueError,
                          self._delete_port_from_agent,
                          500)
    def test_delete_port_to_agent(self):
        self.netns_mgr = NetnsManager("fake_vm_uuid", NIC1, NIC2)
        self.netns_mgr.vrouter_client = mock.Mock()

        self.netns_mgr._delete_port_to_agent(NIC1)
        self.netns_mgr.vrouter_client.delete_port.assert_called_with(NIC1["uuid"])