Skip to content

Commit

Permalink
Handle security_group_entries = None when retrieving policy_rules
Browse files Browse the repository at this point in the history
Closes-Bug: 1786500

'security_group_entries' can be set to None. Retrieve policy_rule
as an empty list in that case.

Change-Id: I9ad7d3f297dfe2ed84ce7ec543c6480d4da82dfc
  • Loading branch information
npchandran committed Aug 14, 2018
1 parent c7bfee9 commit 52342fd
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/config/api-server/vnc_cfg_api_server/vnc_cfg_types.py
Expand Up @@ -4525,6 +4525,10 @@ def _check_policy_rules(entries, network_policy_rule=False):
# end _check_policy_rules

class SecurityGroupServer(Resource, SecurityGroup):
get_nested_key_as_list = classmethod(lambda cls, x, y, z: (x.get(y).get(z)
if (type(x) is dict and
x.get(y) and x.get(y).get(z)) else []))

@classmethod
def _set_configured_security_group_id(cls, obj_dict):
fq_name_str = ':'.join(obj_dict['fq_name'])
Expand Down Expand Up @@ -4604,9 +4608,8 @@ def pre_dbe_create(cls, tenant_name, obj_dict, db_conn):
return False, result
proj_dict = result

rule_count = len(
obj_dict.get('security_group_entries',
{}).get('policy_rule', []))
rule_count = len(cls.get_nested_key_as_list(obj_dict,
'security_group_entries', 'policy_rule'))
ok, result = cls.check_security_group_rule_quota(
proj_dict, db_conn, rule_count)
if not ok:
Expand Down Expand Up @@ -4654,12 +4657,10 @@ def pre_dbe_update(cls, id, fq_name, obj_dict, db_conn, **kwargs):
if not ok:
return False, result
proj_dict = result
new_rule_count = len(
obj_dict.get('security_group_entries',
{}).get('policy_rule', []))
existing_rule_count = len(
sg_dict.get('security_group_entries',
{}).get('policy_rule', []))
new_rule_count = len(cls.get_nested_key_as_list(obj_dict,
'security_group_entries', 'policy_rule'))
existing_rule_count = len(cls.get_nested_key_as_list(sg_dict,
'security_group_entries', 'policy_rule'))
rule_count = (new_rule_count - existing_rule_count)
ok, result = cls.check_security_group_rule_quota(
proj_dict, db_conn, rule_count)
Expand Down

0 comments on commit 52342fd

Please sign in to comment.