X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ice_validator%2Ftests%2Fhelpers.py;h=f4a368ce86f991050a16637ffb99338b41917a00;hb=ed4e48f967b1fccdd3fb142c0a166ee04ad6c2b0;hp=94effed587784725aee5c84971010d509d307999;hpb=84db7f8f65cd0ec77f09cfde365599df9890ce6c;p=vvp%2Fvalidation-scripts.git diff --git a/ice_validator/tests/helpers.py b/ice_validator/tests/helpers.py index 94effed..f4a368c 100644 --- a/ice_validator/tests/helpers.py +++ b/ice_validator/tests/helpers.py @@ -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 @@ -305,9 +327,7 @@ def parameter_type_to_heat_type(parameter): parameter_type = "string" elif isinstance(parameter, dict): parameter_type = "json" - elif isinstance(parameter, int): - parameter_type = "number" - elif isinstance(parameter, float): + elif isinstance(parameter, int) or isinstance(parameter, float): parameter_type = "number" elif isinstance(parameter, bool): parameter_type = "boolean" @@ -318,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)) @@ -395,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) @@ -414,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" + )