[VVP] Handle intrinsic functions in prop_iterator
[vvp/validation-scripts.git] / ice_validator / tests / helpers.py
index fefa8de..f4a368c 100644 (file)
@@ -53,6 +53,23 @@ __path__ = [os.path.dirname(os.path.abspath(__file__))]
 DEFAULT_OUTPUT_DIR = "{}/../output".format(__path__[0])
 RE_BASE = re.compile(r"(^base$)|(^base_)|(_base_)|(_base$)")
 
+INTRINSIC_FUNCTIONS = [
+    "get_resource",
+    "get_attr",
+    "str_replace",
+    "get_param",
+    "list_join",
+    "get_file",
+    "resource_facade",
+    "Fn::Select",
+    "repeat",
+    "digest",
+    "str_split",
+    "yaql",
+    "map_replace",
+    "map_merge",
+]
+
 
 def is_base_module(template_path):
     basename = os.path.basename(template_path).lower()
@@ -124,16 +141,21 @@ def validates(*requirement_ids):
     return decorator
 
 
-def categories(*categories):
+def categories(*all_of, any_of=None):
+    any_of = set(any_of) if any_of else set()
+    all_of = set(all_of) if all_of else set()
+
     def decorator(func):
         @funcutils.wraps(func)
         def wrapper(*args, **kw):
             return func(*args, **kw)
 
-        wrapper.categories = categories
+        wrapper.all_categories = all_of
+        wrapper.any_categories = any_of
         return wrapper
 
-    decorator.categories = categories
+    decorator.all_categories = all_of
+    decorator.any_categories = any_of
     return decorator
 
 
@@ -316,12 +338,13 @@ def parameter_type_to_heat_type(parameter):
 
 
 def prop_iterator(resource, *props):
-    terminators = ["get_resource", "get_attr", "str_replace", "get_param"]
     if "properties" in resource:
         resource = resource.get("properties")
     props = list(props)
 
-    if isinstance(resource, dict) and any(x for x in terminators if x in resource):
+    if isinstance(resource, dict) and any(
+        x for x in INTRINSIC_FUNCTIONS if x in resource
+    ):
         yield resource
     else:
         prop = resource.get(props.pop(0))
@@ -393,7 +416,10 @@ def unzip(zip_path, target_dir):
     :param zip_path:    path to valid zip file
     :param target_dir:  directory to unzip zip_path
     """
-    check(zipfile.is_zipfile(zip_path), "{} is not a valid zipfile or does not exist".format(zip_path))
+    check(
+        zipfile.is_zipfile(zip_path),
+        "{} is not a valid zipfile or does not exist".format(zip_path),
+    )
     archive = zipfile.ZipFile(zip_path)
     if not os.path.exists(target_dir):
         os.makedirs(target_dir, exist_ok=True)
@@ -412,3 +438,15 @@ def remove(sequence, exclude, key=None):
     key_func = key if key else lambda x: x
     result = (s for s in sequence if key_func(s) not in exclude)
     return set(result) if isinstance(sequence, Set) else list(result)
+
+
+def is_nova_server(resource):
+    """
+    checks resource is a nova server
+    """
+    return (
+        isinstance(resource, dict)
+        and "type" in resource
+        and "properties" in resource
+        and resource.get("type") == "OS::Nova::Server"
+    )