]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
NSX: add nsx switch lookup to dhcp and metadata operations
authorarmando-migliaccio <armamig@gmail.com>
Thu, 24 Apr 2014 19:11:41 +0000 (12:11 -0700)
committerThomas Goirand <thomas@goirand.fr>
Mon, 9 Jun 2014 15:06:54 +0000 (23:06 +0800)
The operations in questions were still using the neutron network
uuid as the nsx switch uuid, but this is no longer valid.

Close-bug: #1312439

Change-Id: I0f4bf02bb176c5c3914c7dd7e8249121af1b5a79
(cherry picked from commit 0f2f768578900a7ca74091ab400bd9facce9eaf9)

neutron/plugins/vmware/dhcp_meta/lsnmanager.py
neutron/tests/unit/vmware/test_dhcpmeta.py

index 03a2af61ec31b3442531aff827e61d9e78f899e0..cc69641e03f389a658abf159e8177c48bf258709 100644 (file)
@@ -23,6 +23,7 @@ from neutron.openstack.common import excutils
 from neutron.openstack.common import log as logging
 from neutron.plugins.vmware.api_client import exception as api_exc
 from neutron.plugins.vmware.common import exceptions as p_exc
+from neutron.plugins.vmware.common import nsx_utils
 from neutron.plugins.vmware.dbexts import lsn_db
 from neutron.plugins.vmware.dhcp_meta import constants as const
 from neutron.plugins.vmware.nsxlib import lsn as lsn_api
@@ -181,8 +182,10 @@ class LsnManager(object):
         """Connect network to LSN via specified port and port_data."""
         try:
             lsn_id = None
+            switch_id = nsx_utils.get_nsx_switch_ids(
+                context.session, self.cluster, network_id)[0]
             lswitch_port_id = switch_api.get_port_by_neutron_tag(
-                self.cluster, network_id, port_id)['uuid']
+                self.cluster, switch_id, port_id)['uuid']
             lsn_id = self.lsn_get(context, network_id)
             lsn_port_id = self.lsn_port_create(context, lsn_id, port_data)
         except (n_exc.NotFound, p_exc.NsxPluginException):
@@ -213,8 +216,10 @@ class LsnManager(object):
         tenant_id = subnet['tenant_id']
         lswitch_port_id = None
         try:
+            switch_id = nsx_utils.get_nsx_switch_ids(
+                context.session, self.cluster, network_id)[0]
             lswitch_port_id = switch_api.create_lport(
-                self.cluster, network_id, tenant_id,
+                self.cluster, switch_id, tenant_id,
                 const.METADATA_PORT_ID, const.METADATA_PORT_NAME,
                 const.METADATA_DEVICE_ID, True)['uuid']
             lsn_port_id = self.lsn_port_create(self.cluster, lsn_id, data)
index 5b737bde90352ce437b2b8ada599fcfe216cfd3c..66079d75a3b77a554c6daf513697b6cefcda8680 100644 (file)
@@ -261,11 +261,14 @@ class LsnManagerTestCase(base.BaseTestCase):
         self.port_id = 'foo_port_id'
         self.lsn_id = 'foo_lsn_id'
         self.mac = 'aa:bb:cc:dd:ee:ff'
+        self.switch_id = 'foo_switch_id'
         self.lsn_port_id = 'foo_lsn_port_id'
         self.tenant_id = 'foo_tenant_id'
         self.manager = lsn_man.LsnManager(mock.Mock())
         self.mock_lsn_api_p = mock.patch.object(lsn_man, 'lsn_api')
         self.mock_lsn_api = self.mock_lsn_api_p.start()
+        self.mock_nsx_utils_p = mock.patch.object(lsn_man, 'nsx_utils')
+        self.mock_nsx_utils = self.mock_nsx_utils_p.start()
         nsx.register_dhcp_opts(cfg)
         nsx.register_metadata_opts(cfg)
         self.addCleanup(self.mock_lsn_api_p.stop)
@@ -432,13 +435,15 @@ class LsnManagerTestCase(base.BaseTestCase):
         self._test_lsn_port_delete_with_exc(NsxApiException)
 
     def _test_lsn_port_dhcp_setup(self, ret_val, sub):
+        self.mock_nsx_utils.get_nsx_switch_ids.return_value = [self.switch_id]
         self.mock_lsn_api.lsn_port_create.return_value = self.lsn_port_id
         with mock.patch.object(
             self.manager, 'lsn_get', return_value=self.lsn_id):
             with mock.patch.object(lsn_man.switch_api,
                                    'get_port_by_neutron_tag'):
                 expected = self.manager.lsn_port_dhcp_setup(
-                    mock.ANY, mock.ANY, mock.ANY, mock.ANY, subnet_config=sub)
+                    mock.Mock(), mock.ANY, mock.ANY,
+                    mock.ANY, subnet_config=sub)
                 self.assertEqual(
                     1, self.mock_lsn_api.lsn_port_create.call_count)
                 self.assertEqual(
@@ -454,21 +459,23 @@ class LsnManagerTestCase(base.BaseTestCase):
             self.assertEqual(1, f.call_count)
 
     def test_lsn_port_dhcp_setup_with_not_found(self):
+        self.mock_nsx_utils.get_nsx_switch_ids.return_value = [self.switch_id]
         with mock.patch.object(lsn_man.switch_api,
                                'get_port_by_neutron_tag') as f:
             f.side_effect = n_exc.NotFound
             self.assertRaises(p_exc.PortConfigurationError,
                               self.manager.lsn_port_dhcp_setup,
-                              mock.ANY, mock.ANY, mock.ANY, mock.ANY)
+                              mock.Mock(), mock.ANY, mock.ANY, mock.ANY)
 
     def test_lsn_port_dhcp_setup_with_conflict(self):
         self.mock_lsn_api.lsn_port_plug_network.side_effect = (
             p_exc.LsnConfigurationConflict(lsn_id=self.lsn_id))
+        self.mock_nsx_utils.get_nsx_switch_ids.return_value = [self.switch_id]
         with mock.patch.object(lsn_man.switch_api, 'get_port_by_neutron_tag'):
             with mock.patch.object(self.manager, 'lsn_port_delete') as g:
                 self.assertRaises(p_exc.PortConfigurationError,
                                   self.manager.lsn_port_dhcp_setup,
-                                  mock.ANY, mock.ANY, mock.ANY, mock.ANY)
+                                  mock.Mock(), mock.ANY, mock.ANY, mock.ANY)
                 self.assertEqual(1, g.call_count)
 
     def _test_lsn_port_dhcp_configure_with_subnet(
@@ -560,9 +567,11 @@ class LsnManagerTestCase(base.BaseTestCase):
             'network_id': self.net_id,
             'tenant_id': self.tenant_id
         }
+        self.mock_nsx_utils.get_nsx_switch_ids.return_value = [self.switch_id]
         with mock.patch.object(lsn_man.switch_api, 'create_lport') as f:
             f.return_value = {'uuid': self.port_id}
-            self.manager.lsn_port_metadata_setup(mock.ANY, self.lsn_id, subnet)
+            self.manager.lsn_port_metadata_setup(
+                mock.Mock(), self.lsn_id, subnet)
             self.assertEqual(1, self.mock_lsn_api.lsn_port_create.call_count)
             self.mock_lsn_api.lsn_port_plug_network.assert_called_once_with(
                 mock.ANY, self.lsn_id, mock.ANY, self.port_id)
@@ -574,11 +583,12 @@ class LsnManagerTestCase(base.BaseTestCase):
             'network_id': self.net_id,
             'tenant_id': self.tenant_id
         }
+        self.mock_nsx_utils.get_nsx_switch_ids.return_value = [self.switch_id]
         with mock.patch.object(lsn_man.switch_api, 'create_lport') as f:
             f.side_effect = n_exc.NotFound
             self.assertRaises(p_exc.PortConfigurationError,
                               self.manager.lsn_port_metadata_setup,
-                              mock.ANY, self.lsn_id, subnet)
+                              mock.Mock(), self.lsn_id, subnet)
 
     def test_lsn_port_metadata_setup_raise_conflict(self):
         subnet = {
@@ -587,6 +597,7 @@ class LsnManagerTestCase(base.BaseTestCase):
             'network_id': self.net_id,
             'tenant_id': self.tenant_id
         }
+        self.mock_nsx_utils.get_nsx_switch_ids.return_value = [self.switch_id]
         with mock.patch.object(lsn_man.switch_api, 'create_lport') as f:
             with mock.patch.object(lsn_man.switch_api, 'delete_port') as g:
                 f.return_value = {'uuid': self.port_id}
@@ -594,7 +605,7 @@ class LsnManagerTestCase(base.BaseTestCase):
                     p_exc.LsnConfigurationConflict(lsn_id=self.lsn_id))
                 self.assertRaises(p_exc.PortConfigurationError,
                                   self.manager.lsn_port_metadata_setup,
-                                  mock.ANY, self.lsn_id, subnet)
+                                  mock.Mock(), self.lsn_id, subnet)
                 self.assertEqual(1,
                                  self.mock_lsn_api.lsn_port_delete.call_count)
                 self.assertEqual(1, g.call_count)