]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Fix the way self.properties is checked for a value.
authorAngus Salkeld <asalkeld@redhat.com>
Mon, 27 Aug 2012 04:02:26 +0000 (14:02 +1000)
committerAngus Salkeld <asalkeld@redhat.com>
Mon, 27 Aug 2012 04:02:26 +0000 (14:02 +1000)
The following only checks if the key is in the properties, and
all schema keys are, so it is not the way to check if a value
has been set.

if 'DesiredCapacity' in self.properties:
change to:
if self.properties:

Fixes: #199
Change-Id: I6bcb3e74420031532dc249aafe85d5a428d0a80e
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
heat/engine/autoscaling.py
heat/engine/eip.py
heat/engine/security_group.py
heat/engine/user.py

index e599a7f7b7bb2a7de5b71896ae8c738824ab45d1..4fe4ee2ef000a8a871c2e0f7179b9022ea851114 100644 (file)
@@ -59,7 +59,7 @@ class AutoScalingGroup(Resource):
 
     def handle_create(self):
 
-        if 'DesiredCapacity' in self.properties:
+        if self.properties['DesiredCapacity']:
             num_to_create = int(self.properties['DesiredCapacity'])
         else:
             num_to_create = int(self.properties['MinSize'])
index 854db76fba0cdde3a53417721d5d41c9758ecaf2..4b9e59d4c9a51fe357e0dc3d910cb574f3ddbad9 100644 (file)
@@ -85,10 +85,7 @@ class ElasticIpAssociation(Resource):
         super(ElasticIpAssociation, self).__init__(name, json_snippet, stack)
 
     def FnGetRefId(self):
-        if not 'EIP' in self.properties:
-            return unicode('0.0.0.0')
-        else:
-            return unicode(self.properties['EIP'])
+        return unicode(self.properties.get('EIP', '0.0.0.0'))
 
     def validate(self):
         '''
index dcebff9d518c0d652ecb6b9f703caf9c237fac74..91301a6379db8f61c0330c96c24628caed77cac2 100644 (file)
@@ -49,7 +49,7 @@ class SecurityGroup(Resource):
                                           self.properties['GroupDescription'])
 
         self.instance_id_set(sec.id)
-        if 'SecurityGroupIngress' in self.properties:
+        if self.properties['SecurityGroupIngress']:
             rules_client = self.nova().security_group_rules
             for i in self.properties['SecurityGroupIngress']:
                 try:
index d5a1e83e6410bc2bf874a50c9469c4b930eaa6d5..e735fbe9f636c29f16e25d5d4c4bd60d472db2c4 100644 (file)
@@ -44,10 +44,9 @@ class User(Resource):
 
     def handle_create(self):
         passwd = ''
-        if 'LoginProfile' in self.properties:
-            if self.properties['LoginProfile'] and \
-                'Password' in self.properties['LoginProfile']:
-                passwd = self.properties['LoginProfile']['Password']
+        if self.properties['LoginProfile'] and \
+            'Password' in self.properties['LoginProfile']:
+            passwd = self.properties['LoginProfile']['Password']
 
         tenant_id = self.context.tenant_id
         user = self.keystone().users.create(self.name, passwd,