NSX: add nsx switch lookup to dhcp and metadata operations

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
This commit is contained in:
armando-migliaccio 2014-04-24 12:11:41 -07:00
parent e768ee4173
commit 0f2f768578
2 changed files with 24 additions and 8 deletions

View 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)

View File

@ -260,11 +260,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)
@ -430,13 +433,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(
@ -452,21 +457,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(
@ -558,9 +565,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)
@ -572,11 +581,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 = {
@ -585,6 +595,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}
@ -592,7 +603,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)