From 523e517fa7bf17d4a211413f62abbd07a594a4d7 Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Wed, 16 Jul 2014 17:59:09 +0100 Subject: [PATCH] Pass user_creds_id when creating backup stack When creating a backup stack on update, we don't want to create a new user_creds record, or update won't work with a trust-scoped token. So instead pass the existing stack user_creds_id in to the constructor when creating the backup stack. The current behavior is actually doubly wrong, since we don't delete user_creds records when deleting the backup stack, so the stale creds records are probably left behind in the DB. Change-Id: I6bd0568fdf5301b876c40acddc73542bcfc224e3 Partial-Bug: #1342593 --- heat/engine/parser.py | 3 ++- heat/tests/test_parser.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/heat/engine/parser.py b/heat/engine/parser.py index 2c9c1e129a..6e1d8e4253 100644 --- a/heat/engine/parser.py +++ b/heat/engine/parser.py @@ -566,7 +566,8 @@ class Stack(collections.Mapping): return self.load(self.context, stack=s) elif create_if_missing: prev = type(self)(self.context, self.name, copy.deepcopy(self.t), - self.env, owner_id=self.id) + self.env, owner_id=self.id, + user_creds_id=self.user_creds_id) prev.store(backup=True) LOG.debug('Created new backup stack') return prev diff --git a/heat/tests/test_parser.py b/heat/tests/test_parser.py index 76f0d7d59c..b22c936910 100644 --- a/heat/tests/test_parser.py +++ b/heat/tests/test_parser.py @@ -3064,6 +3064,18 @@ class StackTest(HeatTestCase): self.stack.store() self.assertEqual(user_creds_id, db_stack.user_creds_id) + def test_backup_copies_user_creds_id(self): + ctx_init = utils.dummy_context(user='my_user', + password='my_pass') + ctx_init.request_id = self.ctx.request_id + creds = db_api.user_creds_create(ctx_init) + self.stack = parser.Stack(self.ctx, 'creds_init', self.tmpl, + user_creds_id=creds.id) + self.stack.store() + self.assertEqual(creds.id, self.stack.user_creds_id) + backup = self.stack._backup_stack() + self.assertEqual(creds.id, backup.user_creds_id) + def test_stored_context_err(self): """ Test stored_context error path.