Handle bool correctly during _extend_extra_router_dict
Ensure that extension attributes are always used to override the chosen defaults. This was not working in the case of default boolean True, as the testing condition was wrong. Closes-bug: #1348479 Change-Id: I22bce82c6078a96c0eb4a67e6decb6e9205721a8
This commit is contained in:
parent
7a5df446ee
commit
37e6efae88
@ -48,12 +48,12 @@ class ExtraAttributesMixin(object):
|
||||
extra_attributes = []
|
||||
|
||||
def _extend_extra_router_dict(self, router_res, router_db):
|
||||
extra_attrs = router_db['extra_attributes']
|
||||
extra_attrs = router_db['extra_attributes'] or {}
|
||||
for attr in self.extra_attributes:
|
||||
name = attr['name']
|
||||
default = attr['default']
|
||||
router_res[name] = (
|
||||
extra_attrs and extra_attrs[name] or default)
|
||||
extra_attrs[name] if name in extra_attrs else default)
|
||||
|
||||
def _get_extra_attributes(self, router, extra_attributes):
|
||||
return (dict((attr['name'],
|
||||
|
@ -31,6 +31,7 @@ from neutron.db import common_db_mixin
|
||||
from neutron.db import db_base_plugin_v2
|
||||
from neutron.db import external_net_db
|
||||
from neutron.db import l3_agentschedulers_db
|
||||
from neutron.db import l3_attrs_db
|
||||
from neutron.db import l3_db
|
||||
from neutron.db import l3_dvr_db
|
||||
from neutron.db import l3_rpc_base
|
||||
@ -42,6 +43,7 @@ from neutron.openstack.common import importutils
|
||||
from neutron.openstack.common import log as logging
|
||||
from neutron.openstack.common import uuidutils
|
||||
from neutron.plugins.common import constants as service_constants
|
||||
from neutron.tests import base
|
||||
from neutron.tests import fake_notifier
|
||||
from neutron.tests.unit import test_agent_ext_plugin
|
||||
from neutron.tests.unit import test_api_v2
|
||||
@ -510,6 +512,57 @@ class L3NatTestCaseMixin(object):
|
||||
yield f
|
||||
|
||||
|
||||
class ExtraAttributesMixinTestCase(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ExtraAttributesMixinTestCase, self).setUp()
|
||||
self.mixin = l3_attrs_db.ExtraAttributesMixin()
|
||||
|
||||
def _test__extend_extra_router_dict(
|
||||
self, extra_attributes, attributes, expected_attributes):
|
||||
self.mixin._extend_extra_router_dict(
|
||||
attributes, {'extra_attributes': extra_attributes})
|
||||
self.assertEqual(expected_attributes, attributes)
|
||||
|
||||
def test__extend_extra_router_dict_string_default(self):
|
||||
self.mixin.extra_attributes = [{
|
||||
'name': "foo_key",
|
||||
'default': 'foo_default'
|
||||
}]
|
||||
extension_attributes = {'foo_key': 'my_fancy_value'}
|
||||
self._test__extend_extra_router_dict(
|
||||
extension_attributes, {}, extension_attributes)
|
||||
|
||||
def test__extend_extra_router_dict_booleans_false_default(self):
|
||||
self.mixin.extra_attributes = [{
|
||||
'name': "foo_key",
|
||||
'default': False
|
||||
}]
|
||||
extension_attributes = {'foo_key': True}
|
||||
self._test__extend_extra_router_dict(
|
||||
extension_attributes, {}, extension_attributes)
|
||||
|
||||
def test__extend_extra_router_dict_booleans_true_default(self):
|
||||
self.mixin.extra_attributes = [{
|
||||
'name': "foo_key",
|
||||
'default': True
|
||||
}]
|
||||
# Test that the default is overridden
|
||||
extension_attributes = {'foo_key': False}
|
||||
self._test__extend_extra_router_dict(
|
||||
extension_attributes, {}, extension_attributes)
|
||||
|
||||
def test__extend_extra_router_dict_no_extension_attributes(self):
|
||||
self.mixin.extra_attributes = [{
|
||||
'name': "foo_key",
|
||||
'default': 'foo_value'
|
||||
}]
|
||||
self._test__extend_extra_router_dict({}, {}, {'foo_key': 'foo_value'})
|
||||
|
||||
def test__extend_extra_router_dict_none_extension_attributes(self):
|
||||
self._test__extend_extra_router_dict(None, {}, {})
|
||||
|
||||
|
||||
class L3NatTestCaseBase(L3NatTestCaseMixin):
|
||||
|
||||
def test_router_create(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user