Merge "Fix bug that resources in attr_map may point to same object"

This commit is contained in:
Jenkins 2015-07-17 02:56:29 +00:00 committed by Gerrit Code Review
commit faae843313
2 changed files with 41 additions and 1 deletions

View File

@ -455,7 +455,7 @@ class ExtensionManager(object):
if attr_map.get(res, None):
attr_map[res].update(resource_attrs)
else:
attr_map[res] = resource_attrs
attr_map[res] = resource_attrs.copy()
except AttributeError:
LOG.exception(_LE("Error fetching extended attributes for "
"extension '%s'"), ext.get_name())

View File

@ -486,6 +486,46 @@ class ExtensionManagerTest(base.BaseTestCase):
self.assertIn('valid_extension', ext_mgr.extensions)
self.assertNotIn('invalid_extension', ext_mgr.extensions)
def test_assignment_of_attr_map(self):
class ExtendResourceExtension(object):
"""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,
'is_visible': True}}
EXTENDED_RESOURCES = ["ext1", "ext2"]
attrs = {}
for resources in EXTENDED_RESOURCES:
attrs[resources] = EXTENDED_TIMESTAMP
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.extend_resources("2.0", attr_map)
self.assertNotEqual(id(attr_map['ext1']), id(attr_map['ext2']))
class PluginAwareExtensionManagerTest(base.BaseTestCase):