Stop using plugin _get_subnet

Subnets are now only consumed via OVO, see commit I57a4508f42820db7876a9a8a63bb4d46e7b7ac28

Change-Id: Ibdbfcc8561861157564ad1cfcc9d73b6c4f5cfb6
This commit is contained in:
asarfaty 2020-07-26 08:13:49 +02:00 committed by Adit Sarfaty
parent cd16e6bf8c
commit 06fee9c0d2
8 changed files with 54 additions and 26 deletions

View File

@ -645,7 +645,7 @@ class NsxPluginV3Base(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
subnet_ids = (fixed_ip['subnet_id']
for fixed_ip in port_data['fixed_ips'])
return (self._get_subnet(context.elevated(), subnet_id)
return (self._get_subnet_object(context.elevated(), subnet_id)
for subnet_id in subnet_ids)
return []

View File

@ -525,8 +525,8 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
[db_utils.resource_fields(port, fields) for port in ports])
def _get_subnet_plugin_by_id(self, context, subnet_id):
db_subnet = self._get_subnet(context, subnet_id)
return self._get_plugin_from_net_id(context, db_subnet['network_id'])
db_subnet = self._get_subnet_object(context, subnet_id)
return self._get_plugin_from_net_id(context, db_subnet.network_id)
def get_subnet(self, context, id, fields=None):
p = self._get_subnet_plugin_by_id(context, id)
@ -615,8 +615,8 @@ class NsxTVDPlugin(agentschedulers_db.AZDhcpAgentSchedulerDbMixin,
net_id = self._get_port(
context, interface_info['port_id'])['network_id']
elif is_sub:
net_id = self._get_subnet(
context, interface_info['subnet_id'])['network_id']
net_id = self._get_subnet_object(
context, interface_info['subnet_id']).network_id
net_plugin = self._get_plugin_from_net_id(context, net_id)
if net_plugin.plugin_type() != router_plugin.plugin_type():
err_msg = (_('Router interface should belong to the %s plugin '

View File

@ -105,6 +105,7 @@ from vmware_nsxlib.v3.policy import transaction as policy_trans
from vmware_nsxlib.v3.policy import utils as p_utils
from vmware_nsxlib.v3 import utils as nsxlib_utils
# DEBUG ADIT
LOG = log.getLogger(__name__)
NSX_P_SECURITY_GROUP_TAG = 'os-security-group'
NSX_P_GLOBAL_DOMAIN_ID = policy_constants.DEFAULT_DOMAIN

View File

@ -2225,7 +2225,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
def _get_port_subnet_mask(self, context, port):
if len(port['fixed_ips']) > 0 and 'subnet_id' in port['fixed_ips'][0]:
subnet_id = port['fixed_ips'][0]['subnet_id']
subnet = self._get_subnet(context, subnet_id)
subnet = self._get_subnet_object(context, subnet_id)
return str(netaddr.IPNetwork(subnet.cidr).netmask)
def _get_port_fixed_ip_addr(self, port):
@ -2829,7 +2829,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
super(NsxVPluginV2, self).delete_subnet(context, subnet_id)
def delete_subnet(self, context, id):
subnet = self._get_subnet(context, id)
subnet = self._get_subnet_object(context, id)
filters = {'fixed_ips': {'subnet_id': [id]}}
ports = self.get_ports(context, filters=filters)
@ -2839,7 +2839,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
# subnet's edge and send update dhcp interface rest call before
# deleting subnet's corresponding dhcp interface rest call and lead to
# overlap response from backend.
network_id = subnet['network_id']
network_id = subnet.network_id
self._validate_internal_network(context, network_id)
with locking.LockManager.get_lock(network_id):
@ -2848,7 +2848,7 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
with db_api.CONTEXT_WRITER.using(context):
self.base_delete_subnet(context, id)
if subnet['enable_dhcp']:
if subnet.enable_dhcp:
# There is only DHCP port available
if len(ports) == 1:
port = ports.pop()
@ -3034,10 +3034,11 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
def _safe_update_subnet(self, context, id, subnet):
s = subnet['subnet']
orig = self._get_subnet(context, id)
subnet_obj = self._get_subnet_object(context, id)
orig = self._make_subnet_dict(subnet_obj, fields=None, context=context)
gateway_ip = orig['gateway_ip']
enable_dhcp = orig['enable_dhcp']
orig_host_routes = orig['routes']
orig_host_routes = orig['host_routes']
self._validate_external_subnet(context, orig['network_id'])
self._validate_host_routes_input(subnet,
orig_enable_dhcp=enable_dhcp,
@ -4125,12 +4126,12 @@ class NsxVPluginV2(addr_pair_db.AllowedAddressPairsMixin,
port_id = interface_info.get('port_id')
if not port_id:
subnet_id = interface_info['subnet_id']
subnet = self._get_subnet(context, subnet_id)
subnet = self._get_subnet_object(context, subnet_id)
rport_qry = context.session.query(models_v2.Port)
ports = rport_qry.filter_by(
device_id=router_id,
device_owner=l3_db.DEVICE_OWNER_ROUTER_INTF,
network_id=subnet['network_id'])
network_id=subnet.network_id)
for p in ports:
if p['fixed_ips'][0]['subnet_id'] == subnet_id:
port_id = p['id']

View File

@ -999,7 +999,10 @@ class EdgeManager(object):
# Query the subnet to get gateway and DNS
try:
subnet_id = fixed_ip['subnet_id']
subnet = self.nsxv_plugin._get_subnet(context, subnet_id)
subnet_obj = self.nsxv_plugin._get_subnet_object(
context, subnet_id)
subnet = self.nsxv_plugin._make_subnet_dict(
subnet_obj, fields=None, context=context)
except n_exc.SubnetNotFound:
LOG.debug("No related subnet for port %s", port['id'])
continue
@ -1037,7 +1040,7 @@ class EdgeManager(object):
self.handle_meta_static_route(
context, subnet_id, [static_config])
for host_route in subnet['routes']:
for host_route in subnet['host_routes']:
self.add_host_route_on_static_bindings(
[static_config],
host_route['destination'],

View File

@ -1424,10 +1424,10 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base,
return
# check only dhcp enabled subnets
subnets = (subnet for subnet in subnets if subnet['enable_dhcp'])
subnets = (subnet for subnet in subnets if subnet.enable_dhcp)
if not subnets:
return
subnet_ids = (subnet['id'] for subnet in subnets)
subnet_ids = (subnet.id for subnet in subnets)
# check if the subnet is attached to a router
interfaces = self._get_network_interface_ports(
@ -2636,7 +2636,9 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base,
subnet_id = interface_info['subnet_id']
self._confirm_router_interface_not_in_use(
context, router_id, subnet_id)
subnet = self._get_subnet(context, subnet_id)
subnet_obj = self._get_subnet_object(context, subnet_id)
subnet = self._make_subnet_dict(subnet_obj, fields=None,
context=context)
network_id = subnet['network_id']
ports = self._get_router_interface_ports_by_network(
context, router_id, network_id)
@ -2659,7 +2661,9 @@ class NsxV3Plugin(nsx_plugin_common.NsxPluginV3Base,
nsx_net_id, _nsx_port_id = nsx_db.get_nsx_switch_and_port_id(
context.session, port_id)
if not subnet:
subnet = self._get_subnet(context, subnet_id)
subnet_obj = self._get_subnet_object(context, subnet_id)
subnet = self._make_subnet_dict(subnet_obj, fields=None,
context=context)
ports, address_groups = self._get_ports_and_address_groups(
context, router_id, network_id,
exclude_sub_ids=[subnet_id])

View File

@ -63,7 +63,7 @@ class NsxIpamBase(object, metaclass=abc.ABCMeta):
@classmethod
def _fetch_subnet(cls, context, id):
p = cls.get_core_plugin()
return p._get_subnet(context, id)
return p._get_subnet_object(context, id)
@classmethod
def _fetch_network(cls, context, id):

View File

@ -18,6 +18,7 @@ from unittest import mock
from oslo_config import cfg
from oslo_utils import uuidutils
from neutron.objects import subnet as subnet_obj
from neutron_lib import context
from neutron_lib import exceptions as n_exc
from neutron_lib.plugins import directory
@ -138,9 +139,15 @@ class NsxTVDPluginTestCase(v_tests.NsxVPluginV2TestCase,
func_to_call = getattr(self.core_plugin, method_name)
obj_id = _uuid()
net_id = _uuid()
if obj_name == 'subnet':
mock_name = '_get_subnet_object'
ret_val = subnet_obj.Subnet(network_id=net_id)
else:
mock_name = '_get_%s' % obj_name
ret_val = {field_name: net_id}
with mock.patch.object(self.sub_plugin, method_name) as sub_func,\
mock.patch.object(self.core_plugin, '_get_%s' % obj_name,
return_value={field_name: net_id}),\
mock.patch.object(self.core_plugin, mock_name,
return_value=ret_val),\
mock.patch.object(self.core_plugin, '_get_network',
return_value={'tenant_id': self.project_id}):
func_to_call(self.context, obj_id)
@ -161,9 +168,15 @@ class NsxTVDPluginTestCase(v_tests.NsxVPluginV2TestCase,
func_to_call = getattr(self.core_plugin, method_name)
obj_id = _uuid()
net_id = _uuid()
if obj_name == 'subnet':
mock_name = '_get_subnet_object'
ret_val = subnet_obj.Subnet(network_id=net_id)
else:
mock_name = '_get_%s' % obj_name
ret_val = {field_name: net_id}
with mock.patch.object(self.sub_plugin, method_name) as sub_func,\
mock.patch.object(self.core_plugin, '_get_%s' % obj_name,
return_value={field_name: net_id}),\
mock.patch.object(self.core_plugin, mock_name,
return_value=ret_val),\
mock.patch.object(self.core_plugin, '_get_network',
return_value={'tenant_id': self.project_id}):
func_to_call(self.context, obj_id, {obj_name: {}})
@ -184,9 +197,15 @@ class NsxTVDPluginTestCase(v_tests.NsxVPluginV2TestCase,
func_to_call = getattr(self.core_plugin, method_name)
obj_id = _uuid()
net_id = _uuid()
if obj_name == 'subnet':
mock_name = '_get_subnet_object'
ret_val = subnet_obj.Subnet(network_id=net_id)
else:
mock_name = '_get_%s' % obj_name
ret_val = {field_name: net_id}
with mock.patch.object(self.sub_plugin, method_name) as sub_func,\
mock.patch.object(self.core_plugin, '_get_%s' % obj_name,
return_value={field_name: net_id}),\
mock.patch.object(self.core_plugin, mock_name,
return_value=ret_val),\
mock.patch.object(self.core_plugin, '_get_network',
return_value={'tenant_id': self.project_id}):
func_to_call(self.context, obj_id)