Browse Source

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 <zbitter@redhat.com>
changes/64/264/1
Zane Bitter 10 years ago
parent
commit
2c15f8e1b3
  1. 17
      heat/engine/instance.py
  2. 6
      heat/tests/test_validate.py

17
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:

6
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" : {

Loading…
Cancel
Save