NSX|P: Do not wait for realization on DHCP ports
When getting policy DHCP ports, there is no need to wait for the segment realization and add the nsx id to the port data. Change-Id: I1d03b50960c33b1f1de1b66dca6026b6ef1ee3dd
This commit is contained in:
parent
75cfea2619
commit
826e859bec
|
@ -1160,6 +1160,10 @@ class NsxPluginV3Base(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||
if db_entry:
|
||||
return True if db_entry.vlan_transparent else False
|
||||
|
||||
def _is_backend_port(self, context, port_data, delete=False):
|
||||
# Can be implemented by each plugin
|
||||
return True
|
||||
|
||||
def _extend_nsx_port_dict_binding(self, context, port_data):
|
||||
# Not using the register api for this because we need the context
|
||||
# Some attributes were already initialized by _extend_port_portbinding
|
||||
|
@ -1176,6 +1180,9 @@ class NsxPluginV3Base(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
|
|||
constants.DEVICE_OWNER_FLOATINGIP):
|
||||
# floatingip belongs to an external net without nsx-id
|
||||
port_data[pbin.VIF_DETAILS]['nsx-logical-switch-id'] = None
|
||||
elif not self._is_backend_port(context, port_data):
|
||||
# this port is not relevant for Nova
|
||||
port_data[pbin.VIF_DETAILS]['nsx-logical-switch-id'] = None
|
||||
else:
|
||||
port_data[pbin.VIF_DETAILS]['nsx-logical-switch-id'] = (
|
||||
self._get_network_nsx_id(context, net_id))
|
||||
|
|
|
@ -1536,6 +1536,9 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
|
|||
If it was not realized or timed out retrying, it will return None
|
||||
The nova api will use this to attach to the instance.
|
||||
"""
|
||||
# DEBUG ADIT
|
||||
#LOG.error("DEBUG ADIT _get_network_nsx_id called")
|
||||
#raise Exception
|
||||
if network_id in NET_NEUTRON_2_NSX_ID_CACHE:
|
||||
return NET_NEUTRON_2_NSX_ID_CACHE[network_id]
|
||||
|
||||
|
@ -1719,7 +1722,8 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
|
|||
|
||||
device_owner = port_data.get('device_owner')
|
||||
is_router_interface = (device_owner == l3_db.DEVICE_OWNER_ROUTER_INTF)
|
||||
is_dhcp_port = (device_owner == const.DEVICE_OWNER_DHCP)
|
||||
is_dhcp_port = (device_owner == const.DEVICE_OWNER_DHCP and
|
||||
self.use_policy_dhcp)
|
||||
is_octavia_port = (device_owner == oct_const.DEVICE_OWNER_OCTAVIA)
|
||||
|
||||
if is_external_net or is_router_interface or is_dhcp_port:
|
||||
|
|
|
@ -30,7 +30,6 @@ from vmware_nsx.common import exceptions as nsx_exc
|
|||
from vmware_nsx.extensions import advancedserviceproviders as as_providers
|
||||
from vmware_nsx.plugins.nsx_p import availability_zones as nsx_az
|
||||
from vmware_nsx.tests.unit.nsx_p import test_plugin
|
||||
from vmware_nsxlib.v3 import core_resources
|
||||
from vmware_nsxlib.v3.policy import core_resources as nsx_resources
|
||||
from vmware_nsxlib.v3 import utils as nsxlib_utils
|
||||
|
||||
|
@ -67,14 +66,10 @@ class NsxPolicyDhcpTestCase(test_plugin.NsxPPluginTestCaseMixin):
|
|||
self.az_metadata_route = '3.3.3.3'
|
||||
set_az_in_config(self._az_name,
|
||||
native_metadata_route=self.az_metadata_route)
|
||||
self._patcher = mock.patch.object(core_resources.NsxLibDhcpProfile,
|
||||
'get')
|
||||
self._patcher.start()
|
||||
self._initialize_azs()
|
||||
self.plugin._init_dhcp_metadata()
|
||||
|
||||
def tearDown(self):
|
||||
self._patcher.stop()
|
||||
cfg.CONF.set_override('dhcp_agent_notification',
|
||||
self._orig_dhcp_agent_notification)
|
||||
super(NsxPolicyDhcpTestCase, self).tearDown()
|
||||
|
@ -217,7 +212,10 @@ class NsxPolicyDhcpTestCase(test_plugin.NsxPPluginTestCaseMixin):
|
|||
# Test if DHCP service is disabled when directly deleting a network
|
||||
# with a DHCP-enabled subnet.
|
||||
with self.network() as network:
|
||||
with self.subnet(network=network, enable_dhcp=True):
|
||||
# make sure the plugin does not wait for segment realization
|
||||
with mock.patch.object(self.plugin, '_get_network_nsx_id',
|
||||
side_effect=Exception),\
|
||||
self.subnet(network=network, enable_dhcp=True):
|
||||
self.plugin.delete_network(context.get_admin_context(),
|
||||
network['network']['id'])
|
||||
self._verify_dhcp_service(network['network']['id'],
|
||||
|
@ -249,7 +247,10 @@ class NsxPolicyDhcpTestCase(test_plugin.NsxPPluginTestCaseMixin):
|
|||
# Test if DHCP service is enabled on a network when a DHCP-enabled
|
||||
# subnet is created.
|
||||
with self.network() as network:
|
||||
with self.subnet(network=network, enable_dhcp=True):
|
||||
# make sure the plugin does not wait for segment realization
|
||||
with mock.patch.object(self.plugin, '_get_network_nsx_id',
|
||||
side_effect=Exception),\
|
||||
self.subnet(network=network, enable_dhcp=True):
|
||||
self._verify_dhcp_service(network['network']['id'],
|
||||
network['network']['tenant_id'],
|
||||
True)
|
||||
|
@ -257,8 +258,11 @@ class NsxPolicyDhcpTestCase(test_plugin.NsxPPluginTestCaseMixin):
|
|||
def test_dhcp_service_with_create_multiple_dhcp_subnets(self):
|
||||
# Test if multiple DHCP-enabled subnets cannot be created in a network.
|
||||
with self.network() as network:
|
||||
with self.subnet(network=network, cidr='10.0.0.0/24',
|
||||
enable_dhcp=True):
|
||||
# make sure the plugin does not wait for segment realization
|
||||
with mock.patch.object(self.plugin, '_get_network_nsx_id',
|
||||
side_effect=Exception),\
|
||||
self.subnet(network=network, cidr='10.0.0.0/24',
|
||||
enable_dhcp=True):
|
||||
subnet = {'subnet': {'network_id': network['network']['id'],
|
||||
'cidr': '20.0.0.0/24',
|
||||
'enable_dhcp': True}}
|
||||
|
@ -270,7 +274,10 @@ class NsxPolicyDhcpTestCase(test_plugin.NsxPPluginTestCaseMixin):
|
|||
# Test if DHCP service is disabled on a network when a DHCP-disabled
|
||||
# subnet is deleted.
|
||||
with self.network() as network:
|
||||
with self.subnet(network=network, enable_dhcp=True) as subnet:
|
||||
# make sure the plugin does not wait for segment realization
|
||||
with mock.patch.object(self.plugin, '_get_network_nsx_id',
|
||||
side_effect=Exception),\
|
||||
self.subnet(network=network, enable_dhcp=True) as subnet:
|
||||
self._verify_dhcp_service(network['network']['id'],
|
||||
network['network']['tenant_id'],
|
||||
True)
|
||||
|
@ -284,7 +291,10 @@ class NsxPolicyDhcpTestCase(test_plugin.NsxPPluginTestCaseMixin):
|
|||
# Test if DHCP service is enabled on a network when a DHCP-disabled
|
||||
# subnet is updated to DHCP-enabled.
|
||||
with self.network() as network:
|
||||
with self.subnet(network=network, enable_dhcp=False) as subnet:
|
||||
# make sure the plugin does not wait for segment realization
|
||||
with mock.patch.object(self.plugin, '_get_network_nsx_id',
|
||||
side_effect=Exception),\
|
||||
self.subnet(network=network, enable_dhcp=False) as subnet:
|
||||
self._verify_dhcp_service(network['network']['id'],
|
||||
network['network']['tenant_id'],
|
||||
False)
|
||||
|
@ -299,18 +309,21 @@ class NsxPolicyDhcpTestCase(test_plugin.NsxPPluginTestCaseMixin):
|
|||
# Test if a DHCP-disabled subnet cannot be updated to DHCP-enabled
|
||||
# if a DHCP-enabled subnet already exists in the same network.
|
||||
with self.network() as network:
|
||||
with self.subnet(network=network, cidr='10.0.0.0/24',
|
||||
enable_dhcp=True):
|
||||
with self.subnet(network=network, cidr='20.0.0.0/24',
|
||||
enable_dhcp=False) as subnet:
|
||||
self._verify_dhcp_service(network['network']['id'],
|
||||
network['network']['tenant_id'],
|
||||
True)
|
||||
data = {'subnet': {'enable_dhcp': True}}
|
||||
self.assertRaises(
|
||||
n_exc.InvalidInput, self.plugin.update_subnet,
|
||||
context.get_admin_context(), subnet['subnet']['id'],
|
||||
data)
|
||||
# make sure the plugin does not wait for segment realization
|
||||
with mock.patch.object(self.plugin, '_get_network_nsx_id',
|
||||
side_effect=Exception),\
|
||||
self.subnet(network=network, cidr='10.0.0.0/24',
|
||||
enable_dhcp=True),\
|
||||
self.subnet(network=network, cidr='20.0.0.0/24',
|
||||
enable_dhcp=False) as subnet:
|
||||
self._verify_dhcp_service(network['network']['id'],
|
||||
network['network']['tenant_id'],
|
||||
True)
|
||||
data = {'subnet': {'enable_dhcp': True}}
|
||||
self.assertRaises(
|
||||
n_exc.InvalidInput, self.plugin.update_subnet,
|
||||
context.get_admin_context(), subnet['subnet']['id'],
|
||||
data)
|
||||
|
||||
def test_dhcp_service_with_update_dhcp_port(self):
|
||||
# Test if DHCP server IP is updated when the corresponding DHCP port
|
||||
|
@ -318,7 +331,10 @@ class NsxPolicyDhcpTestCase(test_plugin.NsxPPluginTestCaseMixin):
|
|||
with mock.patch('vmware_nsxlib.v3.policy.core_resources.'
|
||||
'NsxPolicySegmentApi.'
|
||||
'update') as update_segment_dhcp:
|
||||
with self.subnet(cidr='10.0.0.0/24', enable_dhcp=True) as subnet:
|
||||
# make sure the plugin does not wait for segment realization
|
||||
with mock.patch.object(self.plugin, '_get_network_nsx_id',
|
||||
side_effect=Exception),\
|
||||
self.subnet(cidr='10.0.0.0/24', enable_dhcp=True) as subnet:
|
||||
filters = {
|
||||
'network_id': [subnet['subnet']['network_id']],
|
||||
'device_owner': [constants.DEVICE_OWNER_DHCP]
|
||||
|
@ -888,14 +904,16 @@ class NsxPolicyMetadataTestCase(test_plugin.NsxPPluginTestCaseMixin):
|
|||
self._az_name = 'zone1'
|
||||
self._az_metadata_proxy = 'dummy'
|
||||
set_az_in_config(self._az_name, metadata_proxy=self._az_metadata_proxy)
|
||||
self._patcher = mock.patch.object(core_resources.NsxLibMetadataProxy,
|
||||
'get')
|
||||
self._patcher.start()
|
||||
self._initialize_azs()
|
||||
self.plugin._init_dhcp_metadata()
|
||||
|
||||
# make sure the plugin does not wait for segment realization
|
||||
self.realization_patcher = mock.patch.object(
|
||||
self.plugin, '_get_network_nsx_id', side_effect=Exception)
|
||||
self.realization_patcher.start()
|
||||
|
||||
def tearDown(self):
|
||||
self._patcher.stop()
|
||||
self.realization_patcher.stop()
|
||||
cfg.CONF.set_override('dhcp_agent_notification',
|
||||
self._orig_dhcp_agent_notification)
|
||||
super(NsxPolicyMetadataTestCase, self).tearDown()
|
||||
|
|
Loading…
Reference in New Issue