try:
extended_attrs = ext.get_extended_resources(version)
for res, resource_attrs in six.iteritems(extended_attrs):
- if attr_map.get(res, None):
- attr_map[res].update(resource_attrs)
- else:
- attr_map[res] = resource_attrs.copy()
+ attr_map.setdefault(res, {}).update(resource_attrs)
except AttributeError:
LOG.exception(_LE("Error fetching extended attributes for "
"extension '%s'"), ext.get_name())
self.assertNotIn('invalid_extension', ext_mgr.extensions)
def test_assignment_of_attr_map(self):
+ """Unit test for bug 1443342
- class ExtendResourceExtension(object):
+ In this bug, an extension that extended multiple resources with the
+ same dict would cause future extensions to inadvertently modify the
+ resources of all of the resources since they were referencing the same
+ dictionary.
+ """
+
+ class MultiResourceExtension(ext_stubs.StubExtension):
"""Generated Extended Resources.
This extension's extended resource will assign
to more than one resource.
"""
- def get_name(self):
- return "extension"
-
- def get_alias(self):
- return "extension"
-
- def get_description(self):
- return "Extension for test"
-
- def get_updated(self):
- return "2013-07-23T10:00:00-00:00"
-
def get_extended_resources(self, version):
EXTENDED_TIMESTAMP = {
'created_at': {'allow_post': False, 'allow_put': False,
return attrs
+ class AttrExtension(ext_stubs.StubExtension):
+ def get_extended_resources(self, version):
+ attrs = {
+ self.alias: {
+ '%s-attr' % self.alias: {'allow_post': False,
+ 'allow_put': False,
+ 'is_visible': True}}}
+ return attrs
+
ext_mgr = extensions.ExtensionManager('')
- ext_mgr.add_extension(ExtendResourceExtension())
- ext_mgr.add_extension(ext_stubs.StubExtension("ext1"))
- ext_mgr.add_extension(ext_stubs.StubExtension("ext2"))
attr_map = {}
+ ext_mgr.add_extension(MultiResourceExtension('timestamp'))
+ ext_mgr.extend_resources("2.0", attr_map)
+ ext_mgr.add_extension(AttrExtension("ext1"))
+ ext_mgr.add_extension(AttrExtension("ext2"))
ext_mgr.extend_resources("2.0", attr_map)
- self.assertNotEqual(id(attr_map['ext1']), id(attr_map['ext2']))
+ self.assertIn('created_at', attr_map['ext2'])
+ self.assertIn('created_at', attr_map['ext1'])
+ # now we need to make sure the attrextensions didn't leak across
+ self.assertNotIn('ext1-attr', attr_map['ext2'])
+ self.assertNotIn('ext2-attr', attr_map['ext1'])
class PluginAwareExtensionManagerTest(base.BaseTestCase):