Merge "NSX|P: Do not wait for realization on DHCP ports"

This commit is contained in:
Zuul 2020-04-13 06:29:23 +00:00 committed by Gerrit Code Review
commit d78b178635
3 changed files with 58 additions and 29 deletions

View File

@ -1160,6 +1160,10 @@ class NsxPluginV3Base(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
if db_entry: if db_entry:
return True if db_entry.vlan_transparent else False 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): def _extend_nsx_port_dict_binding(self, context, port_data):
# Not using the register api for this because we need the context # Not using the register api for this because we need the context
# Some attributes were already initialized by _extend_port_portbinding # Some attributes were already initialized by _extend_port_portbinding
@ -1176,6 +1180,9 @@ class NsxPluginV3Base(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
constants.DEVICE_OWNER_FLOATINGIP): constants.DEVICE_OWNER_FLOATINGIP):
# floatingip belongs to an external net without nsx-id # floatingip belongs to an external net without nsx-id
port_data[pbin.VIF_DETAILS]['nsx-logical-switch-id'] = None 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: else:
port_data[pbin.VIF_DETAILS]['nsx-logical-switch-id'] = ( port_data[pbin.VIF_DETAILS]['nsx-logical-switch-id'] = (
self._get_network_nsx_id(context, net_id)) self._get_network_nsx_id(context, net_id))

View File

@ -1539,6 +1539,9 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
If it was not realized or timed out retrying, it will return None If it was not realized or timed out retrying, it will return None
The nova api will use this to attach to the instance. 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: if network_id in NET_NEUTRON_2_NSX_ID_CACHE:
return NET_NEUTRON_2_NSX_ID_CACHE[network_id] return NET_NEUTRON_2_NSX_ID_CACHE[network_id]
@ -1722,7 +1725,8 @@ class NsxPolicyPlugin(nsx_plugin_common.NsxPluginV3Base):
device_owner = port_data.get('device_owner') device_owner = port_data.get('device_owner')
is_router_interface = (device_owner == l3_db.DEVICE_OWNER_ROUTER_INTF) 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) is_octavia_port = (device_owner == oct_const.DEVICE_OWNER_OCTAVIA)
if is_external_net or is_router_interface or is_dhcp_port: if is_external_net or is_router_interface or is_dhcp_port:

View File

@ -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.extensions import advancedserviceproviders as as_providers
from vmware_nsx.plugins.nsx_p import availability_zones as nsx_az from vmware_nsx.plugins.nsx_p import availability_zones as nsx_az
from vmware_nsx.tests.unit.nsx_p import test_plugin 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.policy import core_resources as nsx_resources
from vmware_nsxlib.v3 import utils as nsxlib_utils 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' self.az_metadata_route = '3.3.3.3'
set_az_in_config(self._az_name, set_az_in_config(self._az_name,
native_metadata_route=self.az_metadata_route) native_metadata_route=self.az_metadata_route)
self._patcher = mock.patch.object(core_resources.NsxLibDhcpProfile,
'get')
self._patcher.start()
self._initialize_azs() self._initialize_azs()
self.plugin._init_dhcp_metadata() self.plugin._init_dhcp_metadata()
def tearDown(self): def tearDown(self):
self._patcher.stop()
cfg.CONF.set_override('dhcp_agent_notification', cfg.CONF.set_override('dhcp_agent_notification',
self._orig_dhcp_agent_notification) self._orig_dhcp_agent_notification)
super(NsxPolicyDhcpTestCase, self).tearDown() super(NsxPolicyDhcpTestCase, self).tearDown()
@ -217,7 +212,10 @@ class NsxPolicyDhcpTestCase(test_plugin.NsxPPluginTestCaseMixin):
# Test if DHCP service is disabled when directly deleting a network # Test if DHCP service is disabled when directly deleting a network
# with a DHCP-enabled subnet. # with a DHCP-enabled subnet.
with self.network() as network: 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(), self.plugin.delete_network(context.get_admin_context(),
network['network']['id']) network['network']['id'])
self._verify_dhcp_service(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 # Test if DHCP service is enabled on a network when a DHCP-enabled
# subnet is created. # subnet is created.
with self.network() as network: 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'], self._verify_dhcp_service(network['network']['id'],
network['network']['tenant_id'], network['network']['tenant_id'],
True) True)
@ -257,8 +258,11 @@ class NsxPolicyDhcpTestCase(test_plugin.NsxPPluginTestCaseMixin):
def test_dhcp_service_with_create_multiple_dhcp_subnets(self): def test_dhcp_service_with_create_multiple_dhcp_subnets(self):
# Test if multiple DHCP-enabled subnets cannot be created in a network. # Test if multiple DHCP-enabled subnets cannot be created in a network.
with self.network() as network: with self.network() as network:
with self.subnet(network=network, cidr='10.0.0.0/24', # make sure the plugin does not wait for segment realization
enable_dhcp=True): 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'], subnet = {'subnet': {'network_id': network['network']['id'],
'cidr': '20.0.0.0/24', 'cidr': '20.0.0.0/24',
'enable_dhcp': True}} '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 # Test if DHCP service is disabled on a network when a DHCP-disabled
# subnet is deleted. # subnet is deleted.
with self.network() as network: 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'], self._verify_dhcp_service(network['network']['id'],
network['network']['tenant_id'], network['network']['tenant_id'],
True) True)
@ -284,7 +291,10 @@ class NsxPolicyDhcpTestCase(test_plugin.NsxPPluginTestCaseMixin):
# Test if DHCP service is enabled on a network when a DHCP-disabled # Test if DHCP service is enabled on a network when a DHCP-disabled
# subnet is updated to DHCP-enabled. # subnet is updated to DHCP-enabled.
with self.network() as network: 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'], self._verify_dhcp_service(network['network']['id'],
network['network']['tenant_id'], network['network']['tenant_id'],
False) False)
@ -299,18 +309,21 @@ class NsxPolicyDhcpTestCase(test_plugin.NsxPPluginTestCaseMixin):
# Test if a DHCP-disabled subnet cannot be updated to DHCP-enabled # Test if a DHCP-disabled subnet cannot be updated to DHCP-enabled
# if a DHCP-enabled subnet already exists in the same network. # if a DHCP-enabled subnet already exists in the same network.
with self.network() as network: with self.network() as network:
with self.subnet(network=network, cidr='10.0.0.0/24', # make sure the plugin does not wait for segment realization
enable_dhcp=True): with mock.patch.object(self.plugin, '_get_network_nsx_id',
with self.subnet(network=network, cidr='20.0.0.0/24', side_effect=Exception),\
enable_dhcp=False) as subnet: self.subnet(network=network, cidr='10.0.0.0/24',
self._verify_dhcp_service(network['network']['id'], enable_dhcp=True),\
network['network']['tenant_id'], self.subnet(network=network, cidr='20.0.0.0/24',
True) enable_dhcp=False) as subnet:
data = {'subnet': {'enable_dhcp': True}} self._verify_dhcp_service(network['network']['id'],
self.assertRaises( network['network']['tenant_id'],
n_exc.InvalidInput, self.plugin.update_subnet, True)
context.get_admin_context(), subnet['subnet']['id'], data = {'subnet': {'enable_dhcp': True}}
data) 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): def test_dhcp_service_with_update_dhcp_port(self):
# Test if DHCP server IP is updated when the corresponding DHCP port # 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.' with mock.patch('vmware_nsxlib.v3.policy.core_resources.'
'NsxPolicySegmentApi.' 'NsxPolicySegmentApi.'
'update') as update_segment_dhcp: '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 = { filters = {
'network_id': [subnet['subnet']['network_id']], 'network_id': [subnet['subnet']['network_id']],
'device_owner': [constants.DEVICE_OWNER_DHCP] 'device_owner': [constants.DEVICE_OWNER_DHCP]
@ -888,14 +904,16 @@ class NsxPolicyMetadataTestCase(test_plugin.NsxPPluginTestCaseMixin):
self._az_name = 'zone1' self._az_name = 'zone1'
self._az_metadata_proxy = 'dummy' self._az_metadata_proxy = 'dummy'
set_az_in_config(self._az_name, metadata_proxy=self._az_metadata_proxy) 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._initialize_azs()
self.plugin._init_dhcp_metadata() 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): def tearDown(self):
self._patcher.stop() self.realization_patcher.stop()
cfg.CONF.set_override('dhcp_agent_notification', cfg.CONF.set_override('dhcp_agent_notification',
self._orig_dhcp_agent_notification) self._orig_dhcp_agent_notification)
super(NsxPolicyMetadataTestCase, self).tearDown() super(NsxPolicyMetadataTestCase, self).tearDown()