]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix bug that resources in attr_map may point to same object
authorWei Wang <wangwei@unitedstack.com>
Mon, 13 Apr 2015 10:25:11 +0000 (18:25 +0800)
committerWei Wang <wangwei@unitedstack.com>
Sat, 11 Jul 2015 16:48:51 +0000 (00:48 +0800)
The assignment of attr_map may cause resources' attr_map point
to a same object. So once one resource's attr_map update, it maybe
affecte others.

Change-Id: Ica2c3082f9579b297f8c6323e04f8fd17c4da222
Closes-Bug: #1443342

neutron/api/extensions.py
neutron/tests/unit/api/test_extensions.py

index 01bdf45129ffb8146ff889fde27c8b777f62b68e..8c2e4e2b0f60c0851a36582bd80f7f6edb9696ab 100644 (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())
index 0730f3e321daa742bcb5d6867a9b19af58d5c7b0..cc3f71c05790dfd63e20f1e58a296efc5ed94a7c 100644 (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):