diff options
Diffstat (limited to 'ice_validator/tests')
-rw-r--r-- | ice_validator/tests/test_network_format.py | 23 | ||||
-rw-r--r-- | ice_validator/tests/test_nova_servers_vm_types_use_get_param.py | 10 | ||||
-rw-r--r-- | ice_validator/tests/utils/vm_types.py | 8 |
3 files changed, 13 insertions, 28 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 diff --git a/ice_validator/tests/test_nova_servers_vm_types_use_get_param.py b/ice_validator/tests/test_nova_servers_vm_types_use_get_param.py index 63698f1..ce653f6 100644 --- a/ice_validator/tests/test_nova_servers_vm_types_use_get_param.py +++ b/ice_validator/tests/test_nova_servers_vm_types_use_get_param.py @@ -40,7 +40,7 @@ import pytest from tests import cached_yaml as yaml -from .helpers import validates +from .helpers import validates, is_nova_server @validates("R-901331", "R-481670", "R-663631") @@ -59,13 +59,7 @@ def test_vm_type_assignments_on_nova_servers_only_use_get_param(yaml_file): invalid_nova_servers = set() for k, v in yml["resources"].items(): - if not isinstance(v, dict): - continue - if "properties" not in v: - continue - if "type" not in v: - continue - if v["type"] != "OS::Nova::Server": + if not is_nova_server(v): continue for k2, v2 in v["properties"].items(): diff --git a/ice_validator/tests/utils/vm_types.py b/ice_validator/tests/utils/vm_types.py index ae6d7ff..7570581 100644 --- a/ice_validator/tests/utils/vm_types.py +++ b/ice_validator/tests/utils/vm_types.py @@ -50,8 +50,6 @@ def get_vm_types_for_resource(resource): - If more than one vm_type is detected all vm_types will be returned """ - if not isinstance(resource, dict): - return set() if not is_nova_server(resource): return set() @@ -83,11 +81,7 @@ def get_vm_types_for_resource(resource): def is_nova_server(resource): - return ( - "type" in resource - and "properties" in resource - and resource.get("type") == "OS::Nova::Server" - ) + return isinstance(resource, dict) and "type" in resource and "properties" in resource and resource.get("type") == "OS::Nova::Server" def get_vm_type_for_nova_server(resource): |