[VVP] Support any_of in categories decorator
[vvp/validation-scripts.git] / ice_validator / tests / helpers.py
index 6266f08..424dde1 100644 (file)
@@ -124,16 +124,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
 
 
@@ -415,3 +420,11 @@ 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"
+