# ============LICENSE_START=======================================================
# org.onap.vvp/validation-scripts
# ===================================================================
-# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+# Copyright © 2019 AT&T Intellectual Property. All rights reserved.
# ===================================================================
#
# Unless otherwise specified, all software contained herein is licensed
#
# ============LICENSE_END============================================
#
-# ECOMP is a trademark and service mark of AT&T Intellectual Property.
#
import re
+from tests import cached_yaml as yaml
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 "type" not in resource:
- return set()
- if resource["type"] != "OS::Nova::Server":
- return set()
- if "properties" not in resource:
+ if not is_nova_server(resource):
return set()
key_values = ["name", "flavor", "image"]
return set(vm_types)
+def is_nova_server(resource):
+
+ 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):
"""
Get the vm_type for a resource
vm_types.extend(list(get_vm_types_for_resource(v)))
return set(vm_types)
+
+
+def get_all_vm_types(yaml_files):
+ """
+ Get all vm_types for a list of yaml files
+ """
+ vm_types = []
+ for yaml_file in yaml_files:
+ with open(yaml_file, "r") as f:
+ yml = yaml.load(f)
+
+ if "resources" not in yml:
+ continue
+
+ vm_types.extend(get_vm_types(yml["resources"]))
+
+ return set(vm_types)