Defer setting 'ha'/'distributed' flags in L3 code
Both DVR and the HA code were setting the 'ha' and 'distributed' flags in the API body before it was being sent into the core L3 code. This meant that it could not distinguish between user-requested flags and config-defaults, which is important for flavor validation. This patch just adjusts it so they aren't set until after the core create method is called. Long term these will be refactored to live in their corresponding driver anyway and will not need to be responsible for setting these flags to get them stored in the DB. Closes-Bug: #1621430 Change-Id: I9945920d5540653cf5b86e8f1a2ba7b073595921
This commit is contained in:
parent
3783dea6b2
commit
b4b12f7ace
@ -71,11 +71,11 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
|
||||
|
||||
def _create_router_db(self, context, router, tenant_id):
|
||||
"""Create a router db object with dvr additions."""
|
||||
router['distributed'] = is_distributed_router(router)
|
||||
with context.session.begin(subtransactions=True):
|
||||
router_db = super(
|
||||
L3_NAT_with_dvr_db_mixin, self)._create_router_db(
|
||||
context, router, tenant_id)
|
||||
router['distributed'] = is_distributed_router(router)
|
||||
self._process_extra_attr_router_create(context, router_db, router)
|
||||
return router_db
|
||||
|
||||
|
@ -466,10 +466,15 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
|
||||
return n_utils.create_object_with_dependency(
|
||||
creator, dep_getter, dep_creator, dep_id_attr, dep_deleter)
|
||||
|
||||
def _process_extra_attr_router_create(self, context, router_db,
|
||||
router_res):
|
||||
router_res['ha'] = self._is_ha(router_res)
|
||||
super(L3_HA_NAT_db_mixin, self)._process_extra_attr_router_create(
|
||||
context, router_db, router_res)
|
||||
|
||||
@db_api.retry_if_session_inactive()
|
||||
def create_router(self, context, router):
|
||||
is_ha = self._is_ha(router['router'])
|
||||
router['router']['ha'] = is_ha
|
||||
if is_ha:
|
||||
# we set the allocating status to hide it from the L3 agents
|
||||
# until we have created all of the requisite interfaces/networks
|
||||
|
@ -171,8 +171,9 @@ class DriverController(object):
|
||||
|
||||
def _attrs_to_driver(self, router):
|
||||
"""Get a provider driver handle based on the ha/distributed flags."""
|
||||
distributed = _is_distributed(router['distributed'])
|
||||
ha = _is_ha(router['ha'])
|
||||
distributed = _is_distributed(
|
||||
router.get('distributed', lib_const.ATTR_NOT_SPECIFIED))
|
||||
ha = _is_ha(router.get('ha', lib_const.ATTR_NOT_SPECIFIED))
|
||||
drivers = self.drivers.values()
|
||||
# make sure default is tried before the rest if defined
|
||||
if self.default_provider:
|
||||
|
@ -44,6 +44,19 @@ class RoutersFlavorTestCase(base.BaseRouterTest):
|
||||
cls.flavor['id'], sp['service_profile']['id'])
|
||||
cls.flavor_service_profiles.append((cls.flavor['id'],
|
||||
sp['service_profile']['id']))
|
||||
# make another with a different driver
|
||||
driver = ('neutron.services.l3_router.service_providers.'
|
||||
'dvr.DvrDriver')
|
||||
sp = cls.admin_client.create_service_profile(driver=driver)
|
||||
cls.service_profiles.append(sp['service_profile'])
|
||||
cls.prem_flavor = cls.create_flavor(
|
||||
name='better_special_flavor',
|
||||
description='econonomy comfort',
|
||||
service_type='L3_ROUTER_NAT')
|
||||
cls.admin_client.create_flavor_service_profile(
|
||||
cls.prem_flavor['id'], sp['service_profile']['id'])
|
||||
cls.flavor_service_profiles.append((cls.prem_flavor['id'],
|
||||
sp['service_profile']['id']))
|
||||
|
||||
@classmethod
|
||||
def resource_cleanup(cls):
|
||||
@ -61,10 +74,15 @@ class RoutersFlavorTestCase(base.BaseRouterTest):
|
||||
flavors = self.client.list_flavors(id=self.flavor['id'])
|
||||
flavor = flavors['flavors'][0]
|
||||
self.assertEqual('special_flavor', flavor['name'])
|
||||
flavors = self.client.list_flavors(id=self.prem_flavor['id'])
|
||||
prem_flavor = flavors['flavors'][0]
|
||||
self.assertEqual('better_special_flavor', prem_flavor['name'])
|
||||
|
||||
# ensure client can create router with flavor
|
||||
# ensure client can create router with both flavors
|
||||
router = self.create_router('name', flavor_id=flavor['id'])
|
||||
self.assertEqual(flavor['id'], router['flavor_id'])
|
||||
router = self.create_router('name', flavor_id=prem_flavor['id'])
|
||||
self.assertEqual(prem_flavor['id'], router['flavor_id'])
|
||||
|
||||
@test.idempotent_id('30e73858-a0fc-409c-a2e0-e9cd2826f6a2')
|
||||
def test_delete_router_flavor_in_use(self):
|
||||
|
Loading…
Reference in New Issue
Block a user