From 2fe6deee9b2dd0d94d860b1a5fad443d865d1327 Mon Sep 17 00:00:00 2001 From: huangtianhua Date: Thu, 3 Dec 2015 09:45:35 +0800 Subject: [PATCH] Make sure update successful if there is encrypt param Don't append the param in env.encrypted_param_names again when encrypt hidden paramters, otherwise an error will raise when get template from db-object before decrypting. Closes-Bug: #1521925 Change-Id: I4bdaa3391863cd18a451da4eee0cb9314c0057c5 --- heat/objects/raw_template.py | 3 ++- heat/tests/test_stack.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/heat/objects/raw_template.py b/heat/objects/raw_template.py index f517e9aa5e..8e51d48d45 100644 --- a/heat/objects/raw_template.py +++ b/heat/objects/raw_template.py @@ -75,7 +75,8 @@ class RawTemplate( continue clear_text_val = tmpl.env.params.get(param_name) tmpl.env.params[param_name] = crypt.encrypt(clear_text_val) - tmpl.env.encrypted_param_names.append(param_name) + if param_name not in tmpl.env.encrypted_param_names: + tmpl.env.encrypted_param_names.append(param_name) @classmethod def create(cls, context, values): diff --git a/heat/tests/test_stack.py b/heat/tests/test_stack.py index f6345e24f5..d46a65e74a 100644 --- a/heat/tests/test_stack.py +++ b/heat/tests/test_stack.py @@ -2228,6 +2228,27 @@ class StackTest(common.HeatTestCase): self.assertEqual('foo', params.get('param1')) self.assertEqual('bar', params.get('param2')) + # test update the param2 + loaded_stack.state_set(self.stack.CREATE, self.stack.COMPLETE, + 'for_update') + env2 = environment.Environment({'param1': 'foo', 'param2': 'new_bar'}) + new_stack = stack.Stack(self.ctx, 'test_update', + template.Template(tmpl, env=env2)) + + loaded_stack.update(new_stack) + self.assertEqual((loaded_stack.UPDATE, loaded_stack.COMPLETE), + loaded_stack.state) + db_tpl = db_api.raw_template_get(self.ctx, loaded_stack.t.id) + db_params = db_tpl.environment['parameters'] + self.assertEqual('foo', db_params['param1']) + self.assertEqual('cryptography_decrypt_v1', db_params['param2'][0]) + self.assertIsNotNone(db_params['param2'][1]) + + loaded_stack1 = stack.Stack.load(self.ctx, stack_id=self.stack.id) + params = loaded_stack1.t.env.params + self.assertEqual('foo', params.get('param1')) + self.assertEqual('new_bar', params.get('param2')) + def test_parameters_stored_decrypted_successful_load(self): """Test stack loading with disabled parameter value validation.""" tmpl = template_format.parse('''