]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Only create user_creds row on initial stack store
authorSteven Hardy <shardy@redhat.com>
Fri, 23 Aug 2013 12:26:35 +0000 (13:26 +0100)
committerSteven Hardy <shardy@redhat.com>
Fri, 23 Aug 2013 12:26:35 +0000 (13:26 +0100)
We should only store the credentials on inital stack store,
otherwise we end up creating orphan user_creds rows every
time the stack status is updated.

Fixes bug #1197074

Change-Id: Ib8414dd774386578dbc4d654b1773727d2998f80

heat/engine/parser.py
heat/tests/test_parser.py

index eb796ad0bf0b7ca3bafad7b175a8b7b2d5055c1f..a2fe23dfcd7019874e311ed9042ba306eecd04a1 100644 (file)
@@ -157,14 +157,12 @@ class Stack(object):
         Store the stack in the database and return its ID
         If self.id is set, we update the existing stack
         '''
-        new_creds = db_api.user_creds_create(self.context)
 
         s = {
             'name': self.name,
             'raw_template_id': self.t.store(self.context),
             'parameters': self.env.user_env_as_dict(),
             'owner_id': self.owner_id,
-            'user_creds_id': new_creds.id,
             'username': self.context.username,
             'tenant': self.context.tenant_id,
             'action': self.action,
@@ -176,6 +174,8 @@ class Stack(object):
         if self.id:
             db_api.stack_update(self.context, self.id, s)
         else:
+            new_creds = db_api.user_creds_create(self.context)
+            s['user_creds_id'] = new_creds.id
             new_s = db_api.stack_create(self.context, s)
             self.id = new_s.id
 
index 788888f53c3a5ed5b13e4e6336c689b24d162d77..d0419d1d9992fe08eddfd6b39793f1c6ca18b92a 100644 (file)
@@ -1660,6 +1660,24 @@ class StackTest(HeatTestCase):
         db_stack = db_api.stack_get(self.ctx, stack_ownee.id)
         self.assertEqual(db_stack.owner_id, self.stack.id)
 
+    @utils.stack_delete_after
+    def test_store_saves_creds(self):
+        """
+        A user_creds entry is created on first stack store
+        """
+        self.stack = parser.Stack(
+            self.ctx, 'creds_stack', template.Template({}))
+        self.stack.store()
+
+        # The store should've created a user_creds row and set user_creds_id
+        db_stack = db_api.stack_get(self.ctx, self.stack.id)
+        user_creds_id = db_stack.user_creds_id
+        self.assertIsNotNone(user_creds_id)
+
+        # Store again, ID should not change
+        self.stack.store()
+        self.assertEqual(user_creds_id, db_stack.user_creds_id)
+
     @utils.stack_delete_after
     def test_load_honors_owner(self):
         """