Switch to Subnet OVO in ipam_backend_mixin _save_subnet method
This patch switch to use Subnet OVO in ipam_backend_mixin.IpamBackendMixin._save_subnet method. To use Subnet OVO there, additional changes in _make_subnet_args() method are also required. Now this method returns: * 'project_id' instead of 'tenant_id', * 'cidr' as instance of netaddr.IPNetwork, * 'gateway_ip' as instance of netaddr.IPAddress Change-Id: I9fb284e98394b1a41ec8af919b65dc512663ff6a Partially-Implements: blueprint adopt-oslo-versioned-objects-for-db
This commit is contained in:
parent
639b83264c
commit
d795fc9471
|
@ -308,16 +308,15 @@ class DbBasePluginCommon(common_db_mixin.CommonDbMixin):
|
|||
return False
|
||||
|
||||
def _make_subnet_args(self, detail, subnet, subnetpool_id):
|
||||
gateway_ip = str(detail.gateway_ip) if detail.gateway_ip else None
|
||||
args = {'tenant_id': detail.tenant_id,
|
||||
args = {'project_id': detail.tenant_id,
|
||||
'id': detail.subnet_id,
|
||||
'name': subnet['name'],
|
||||
'network_id': subnet['network_id'],
|
||||
'ip_version': subnet['ip_version'],
|
||||
'cidr': str(detail.subnet_cidr),
|
||||
'cidr': detail.subnet_cidr,
|
||||
'subnetpool_id': subnetpool_id,
|
||||
'enable_dhcp': subnet['enable_dhcp'],
|
||||
'gateway_ip': gateway_ip,
|
||||
'gateway_ip': detail.gateway_ip,
|
||||
'description': subnet.get('description')}
|
||||
if subnet['ip_version'] == 6 and subnet['enable_dhcp']:
|
||||
if validators.is_attr_set(subnet['ipv6_ra_mode']):
|
||||
|
|
|
@ -24,7 +24,6 @@ from neutron_lib.api import validators
|
|||
from neutron_lib import constants as const
|
||||
from neutron_lib import exceptions as exc
|
||||
from oslo_config import cfg
|
||||
from oslo_db import exception as db_exc
|
||||
from oslo_log import log as logging
|
||||
from sqlalchemy import and_, or_
|
||||
from sqlalchemy.orm import exc as orm_exc
|
||||
|
@ -508,13 +507,20 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
|
|||
|
||||
service_types = subnet_args.pop('service_types', [])
|
||||
|
||||
subnet = models_v2.Subnet(**subnet_args)
|
||||
segment_id = subnet_args.get('segment_id')
|
||||
try:
|
||||
context.session.add(subnet)
|
||||
context.session.flush()
|
||||
except db_exc.DBReferenceError:
|
||||
raise segment_exc.SegmentNotFound(segment_id=segment_id)
|
||||
if segment_id:
|
||||
# TODO(slaweq): integrate check if segment exists in
|
||||
# self._validate_segment() method
|
||||
segment = network_obj.NetworkSegment.get_object(context,
|
||||
id=segment_id)
|
||||
if not segment:
|
||||
raise segment_exc.SegmentNotFound(segment_id=segment_id)
|
||||
|
||||
subnet = subnet_obj.Subnet(context, **subnet_args)
|
||||
subnet.create()
|
||||
# TODO(slaweq): when check is segment exists will be integrated in
|
||||
# self._validate_segment() method, it should be moved to be done before
|
||||
# subnet object is created
|
||||
self._validate_segment(context, network['id'], segment_id)
|
||||
|
||||
# NOTE(changzhi) Store DNS nameservers with order into DB one
|
||||
|
@ -546,7 +552,7 @@ class IpamBackendMixin(db_base_plugin_common.DbBasePluginCommon):
|
|||
self.save_allocation_pools(context, subnet,
|
||||
subnet_request.allocation_pools)
|
||||
|
||||
return subnet
|
||||
return subnet_obj.Subnet.get_object(context, id=subnet.id)
|
||||
|
||||
def _classify_subnets(self, context, subnets):
|
||||
"""Split into v4, v6 stateless and v6 stateful subnets"""
|
||||
|
|
|
@ -17,6 +17,7 @@ import functools
|
|||
|
||||
import fixtures
|
||||
import mock
|
||||
import netaddr
|
||||
from neutron_lib.api.definitions import availability_zone as az_def
|
||||
from neutron_lib.api.definitions import external_net as extnet_apidef
|
||||
from neutron_lib.api.definitions import portbindings
|
||||
|
@ -2588,9 +2589,9 @@ class TestML2PluggableIPAM(test_ipam.UseIpamMixin, TestMl2SubnetsV2):
|
|||
with mock.patch(driver) as driver_mock:
|
||||
request = mock.Mock()
|
||||
request.subnet_id = uuidutils.generate_uuid()
|
||||
request.subnet_cidr = cidr
|
||||
request.subnet_cidr = netaddr.IPNetwork(cidr)
|
||||
request.allocation_pools = []
|
||||
request.gateway_ip = gateway_ip
|
||||
request.gateway_ip = netaddr.IPAddress(gateway_ip)
|
||||
request.tenant_id = uuidutils.generate_uuid()
|
||||
|
||||
ipam_subnet = mock.Mock()
|
||||
|
|
Loading…
Reference in New Issue