Correct the usage of properties.get() with default value
Class Properties overwrites the __getitem__ method, 1. to raise KeyError if the key is an invalid property, then the default value is return in supper.get() method 2. if the key is a valid property, the default value won't be returned by using the format: self.properties.get(key, default_value) This patch changes to the format as following for case2: self.properties.get(key) or default_value Also, if the property is required or has default value in schema, let's use self.properties[key] instead. Change-Id: I2f546c69aa128c9aa6240ebd065df18a799b754d
This commit is contained in:
parent
56ab930f7b
commit
ce78ba1462
|
@ -1150,7 +1150,7 @@ class CloudLoadBalancer(resource.Resource):
|
|||
self._validate_https_redirect()
|
||||
# if a vip specifies and id, it can't specify version or type;
|
||||
# otherwise version and type are required
|
||||
for vip in self.properties.get(self.VIRTUAL_IPS, []):
|
||||
for vip in self.properties[self.VIRTUAL_IPS]:
|
||||
has_id = vip.get(self.VIRTUAL_IP_ID) is not None
|
||||
has_version = vip.get(self.VIRTUAL_IP_IP_VERSION) is not None
|
||||
has_type = vip.get(self.VIRTUAL_IP_TYPE) is not None
|
||||
|
|
|
@ -119,7 +119,7 @@ class CloudServer(server.Server):
|
|||
self._rack_connect_started_event_sent = False
|
||||
|
||||
def _config_drive(self):
|
||||
user_data_format = self.properties.get(self.USER_DATA_FORMAT, "")
|
||||
user_data_format = self.properties[self.USER_DATA_FORMAT]
|
||||
is_sw_config = user_data_format == self.SOFTWARE_CONFIG
|
||||
user_data = self.properties.get(self.USER_DATA)
|
||||
config_drive = self.properties.get(self.CONFIG_DRIVE)
|
||||
|
|
|
@ -362,7 +362,7 @@ class InstanceGroup(stack_resource.StackResource):
|
|||
self._lb_reload()
|
||||
|
||||
def _lb_reload(self, exclude=None):
|
||||
lb_names = self.properties.get(self.LOAD_BALANCER_NAMES, None)
|
||||
lb_names = self.properties.get(self.LOAD_BALANCER_NAMES) or []
|
||||
if lb_names:
|
||||
lb_dict = dict((name, self.stack[name]) for name in lb_names)
|
||||
lbutils.reload_loadbalancers(self, lb_dict, exclude)
|
||||
|
|
|
@ -142,7 +142,7 @@ class SoftwareComponent(sc.SoftwareConfig):
|
|||
|
||||
# One lifecycle action (e.g. CREATE) can only be associated with one
|
||||
# config; otherwise a way to define ordering would be required.
|
||||
configs = self.properties.get(self.CONFIGS, [])
|
||||
configs = self.properties[self.CONFIGS]
|
||||
config_actions = set()
|
||||
for config in configs:
|
||||
actions = config.get(self.CONFIG_ACTIONS)
|
||||
|
|
|
@ -614,10 +614,10 @@ class SoftwareDeploymentGroup(resource_group.ResourceGroup):
|
|||
update_policy_schema = {}
|
||||
|
||||
def get_size(self):
|
||||
return len(self.properties.get(self.SERVERS, {}))
|
||||
return len(self.properties[self.SERVERS])
|
||||
|
||||
def _resource_names(self):
|
||||
return iter(self.properties.get(self.SERVERS, {}))
|
||||
return iter(self.properties[self.SERVERS])
|
||||
|
||||
def get_resource_def(self, include_all=False):
|
||||
return dict(self.properties)
|
||||
|
|
Loading…
Reference in New Issue