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
This commit is contained in:
Steven Hardy 2014-07-16 17:59:09 +01:00
parent 5387ab44dc
commit 523e517fa7
2 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -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.