diff options
author | Ezhilarasi <ezhrajam@in.ibm.com> | 2019-10-01 15:21:51 +0530 |
---|---|---|
committer | Ezhilarasi R <ezhrajam@in.ibm.com> | 2019-10-01 13:51:24 +0000 |
commit | 0c8c078d41b364602ed967a1bdffdb06c6b53ea7 (patch) | |
tree | 78c8bbf8453c4913882a88569ffabb835e4df37a /ice_validator/tests | |
parent | 9a4d57bc88ea61d9dbe70b2f550a7f54a9a8eab5 (diff) |
reduce cognitive complexity
Reduce cognitive complexity in test_network_format.py
Change-Id: I6f42192988f7b3361479b66740e287b8f9e6d887
Issue-ID: VVP-313
Signed-off-by: Ezhilarasi <ezhrajam@in.ibm.com>
Diffstat (limited to 'ice_validator/tests')
-rw-r--r-- | ice_validator/tests/test_network_format.py | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/ice_validator/tests/test_network_format.py b/ice_validator/tests/test_network_format.py index f146f75..e360795 100644 --- a/ice_validator/tests/test_network_format.py +++ b/ice_validator/tests/test_network_format.py @@ -70,9 +70,7 @@ def test_network_resource_id_format(yaml_file): invalid_networks = [] for k, v in yml["resources"].items(): - if not isinstance(v, dict): - continue - if "properties" not in v: + if not has_properties(v): continue if property_uses_get_resource(v, "network"): continue @@ -106,23 +104,15 @@ def test_network_has_subnet(yaml_file): networks = [] for k, v in yml["resources"].items(): - if not isinstance(v, dict): - continue - if "properties" not in v: + if not has_properties(v) or v.get("type") not in ["OS::Neutron::Net"]: continue # need to check if contrail networks also require subnet # and it is defined the same as neutron networks # if v.get("type") not in NETWORK_RESOURCE_TYPES: - if v.get("type") not in ["OS::Neutron::Net"]: - continue networks.append(k) for k, v in yml["resources"].items(): - if not isinstance(v, dict): - continue - if "properties" not in v: - continue - if v.get("type") != "OS::Neutron::Subnet": + if not has_properties(v) and v.get("type") != "OS::Neutron::Subnet": continue network_prop = v.get("properties", {}).get("network", {}).get("get_resource") @@ -136,3 +126,10 @@ def test_network_has_subnet(yaml_file): x += 1 assert not networks, "Networks detected without subnet {}".format(networks) + + +def has_properties(resource): + """ + checks resource is a Neutron Subnet + """ + return isinstance(resource, dict) and "properties" in resource |