From 2c15f8e1b3c0a4d05efa7a37f28ad49db22569d4 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Wed, 27 Jun 2012 11:47:30 +0200 Subject: [PATCH] Don't go fishing in the stack for the KeyName The KeyName should be a property of the Instance, and need not have the same name in the stack parameters. Change-Id: I05dcfd9aa6f92bc7aaa2dbc594062984ac074b7e Signed-off-by: Zane Bitter --- heat/engine/instance.py | 17 ++++++++++------- heat/tests/test_validate.py | 6 +++--- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/heat/engine/instance.py b/heat/engine/instance.py index f49d4a09..39bff989 100644 --- a/heat/engine/instance.py +++ b/heat/engine/instance.py @@ -241,17 +241,20 @@ class Instance(Resource): res = Resource.validate(self) if res: return res + #check validity of key - if self.stack.parms['KeyName']: + try: + key_name = self.properties['KeyName'] + except ValueError: + return + else: keypairs = self.nova().keypairs.list() valid_key = False for k in keypairs: - if k.name == self.stack.parms['KeyName']: - valid_key = True - if not valid_key: - return {'Error': - 'Provided KeyName is not registered with nova'} - return None + if k.name == key_name: + return + return {'Error': + 'Provided KeyName is not registered with nova'} def handle_delete(self): try: diff --git a/heat/tests/test_validate.py b/heat/tests/test_validate.py index 94557017..f5172cb2 100644 --- a/heat/tests/test_validate.py +++ b/heat/tests/test_validate.py @@ -71,7 +71,7 @@ test_template_ref = ''' "Properties": { "ImageId": "image_name", "InstanceType": "m1.large", - "KeyName": "test_KeyName" + "KeyName": { "Ref" : "KeyName" } } }, "DataVolume" : { @@ -112,7 +112,7 @@ test_template_findinmap_valid = ''' "Properties": { "ImageId": "image_name", "InstanceType": "m1.large", - "KeyName": "test_KeyName" + "KeyName": { "Ref" : "KeyName" } } }, "DataVolume" : { @@ -176,7 +176,7 @@ test_template_findinmap_invalid = ''' '"InstanceType" }, "Arch" ] } ] },' + \ ''' "InstanceType": "m1.large", - "KeyName": "test_KeyName" + "KeyName": { "Ref" : "KeyName"} } }, "DataVolume" : { -- 2.45.2