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
"""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):
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)
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)
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(
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(
'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)
'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 = {
'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}
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)