From b35245b6cd506b69ae6e2ff9aec1f3fe7c0dc4ef Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Fri, 23 Aug 2013 13:26:35 +0100 Subject: [PATCH] Only create user_creds row on initial stack store 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 | 4 ++-- heat/tests/test_parser.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/heat/engine/parser.py b/heat/engine/parser.py index eb796ad0..a2fe23df 100644 --- a/heat/engine/parser.py +++ b/heat/engine/parser.py @@ -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 diff --git a/heat/tests/test_parser.py b/heat/tests/test_parser.py index 788888f5..d0419d1d 100644 --- a/heat/tests/test_parser.py +++ b/heat/tests/test_parser.py @@ -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): """ -- 2.45.2