Merge "[VVP] Fix redundant errors: missing base module or nested dirs"
[vvp/validation-scripts.git] / ice_validator / tests / utils / ports.py
index afce592..d65202c 100644 (file)
@@ -2,7 +2,7 @@
 # ============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
@@ -41,13 +41,37 @@ from tests.helpers import parameter_type_to_heat_type, prop_iterator
 from . import nested_dict
 
 
-def check_parameter_format(yaml_file, regx, intext, resource_processor, *properties):
+AAP_EXEMPT_CAVEAT = (
+    "If this VNF is not able to adhere to this requirement, please consult the Heat "
+    "Orchestration Template guidelines for more information. If you are knowingly "
+    "violating this requirement after reading the guidelines, then add the parameter "
+    "to the aap_exempt list under this resources metadata to suppress this warning."
+)
+
+
+def get_aap_exemptions(resource_props):
+    """
+    Gets the list of parameters that the Heat author has exempted from following
+    the naming conventions associated with AAP.
+
+    :param resource_props: dict of properties under the resource ID
+    :return: list of all parameters to exempt or an empty list
+    """
+    metadata = resource_props.get("metadata") or {}
+    return metadata.get("aap_exempt") or []
+
+
+def check_parameter_format(
+    yaml_file, regx, intext, resource_processor, *properties, exemptions_allowed=False
+):
     """
     yaml_file: input file to check
     regx: dictionary containing the regex to use to validate parameter
     intext: internal or external
     resource_processor: resource type specific helper, defined in structures.py
     properties: arg list of property that is being checked
+    exemptions_allowed: If True, then parameters in the aap_exempt list are allowed to
+                        not follow the rules
     """
 
     invalid_parameters = []
@@ -72,47 +96,57 @@ def check_parameter_format(yaml_file, regx, intext, resource_processor, *propert
                 and "get_resource" not in param
                 and "get_attr" not in param
             ):
-
                 # checking parameter uses get_param
                 parameter = param.get("get_param")
                 if not parameter:
                     msg = (
                         "Unexpected parameter format for {} {} property {}: {}. "
-                        "Please consult the heat guidelines documentation for details."
+                        "Please consult the heat guidelines documentation for details."
                     ).format(resource_type, rid, properties, param)
                     invalid_parameters.append(msg)  # should this be a failure?
                     continue
 
-                # getting parameter if the get_param uses list, and getting official HEAT parameter type
+                # getting parameter if the get_param uses list, and getting official
+                # HEAT parameter type
                 parameter_type = parameter_type_to_heat_type(parameter)
                 if parameter_type == "comma_delimited_list":
                     parameter = parameter[0]
                 elif parameter_type != "string":
                     continue
 
-                # checking parameter format = parameter type defined in parameters section
-                heat_parameter_type = nested_dict.get(heat_parameters, parameter, "type")
+                # checking parameter format = parameter type defined in parameters
+                # section
+                heat_parameter_type = nested_dict.get(
+                    heat_parameters, parameter, "type"
+                )
                 if not heat_parameter_type or heat_parameter_type != parameter_type:
                     msg = (
                         "{} {} parameter {} defined as type {} "
                         + "is being used as type {} in the heat template"
                     ).format(
-                        resource_type, properties, parameter, heat_parameter_type, parameter_type
+                        resource_type,
+                        properties,
+                        parameter,
+                        heat_parameter_type,
+                        parameter_type,
                     )
                     invalid_parameters.append(msg)  # should this actually be an error?
                     continue
 
-                # if parameter type is not in regx dict, then it is not supported by automation
+                if exemptions_allowed and parameter in get_aap_exemptions(resource):
+                    continue
+
+                # if parameter type is not in regx dict, then it is not supported
+                # by automation
                 regx_dict = regx[resource_intext].get(parameter_type)
                 if not regx_dict:
                     msg = (
-                        "WARNING: {} {} parameter {} defined as type {} "
-                        "is not supported by platform automation. If this VNF is not able "
-                        "to adhere to this requirement, please consult the Heat Orchestration "
-                        "Template guidelines for alternative solutions. If already adhering to "
-                        "an alternative provided by the heat guidelines, please disregard this "
-                        "message."
-                    ).format(resource_type, properties, parameter, parameter_type)
+                        "{} {} {} parameter {} defined as type {} "
+                        "which is required by platform data model for proper "
+                        "assignment and inventory."
+                    ).format(resource_type, rid, properties, parameter, parameter_type)
+                    if exemptions_allowed:
+                        msg = "WARNING: {} {}".format(msg, AAP_EXEMPT_CAVEAT)
                     invalid_parameters.append(msg)
                     continue
 
@@ -121,9 +155,20 @@ def check_parameter_format(yaml_file, regx, intext, resource_processor, *propert
                 readable_format = regx[resource_intext][parameter_type]["readable"]
                 match = regexp.match(parameter)
                 if not match:
-                    msg = "{} {} property {} parameter {} does not follow {} format {}".format(
-                        resource_type, rid, properties, parameter, resource_intext, readable_format
+                    msg = (
+                        "{} {} property {} parameter {} does not follow {} "
+                        "format {} which is required by platform data model for proper "
+                        "assignment and inventory."
+                    ).format(
+                        resource_type,
+                        rid,
+                        properties,
+                        parameter,
+                        resource_intext,
+                        readable_format,
                     )
+                    if exemptions_allowed:
+                        msg = "WARNING: {} {}".format(msg, AAP_EXEMPT_CAVEAT)
                     invalid_parameters.append(msg)
                     continue
 
@@ -139,7 +184,14 @@ def check_parameter_format(yaml_file, regx, intext, resource_processor, *propert
                         msg = (
                             "{0} {1} property {2} parameter "
                             "{3} {4} does match resource {4} {5}"
-                        ).format(resource_type, rid, properties, parameter, check, resource_match)
+                        ).format(
+                            resource_type,
+                            rid,
+                            properties,
+                            parameter,
+                            check,
+                            resource_match,
+                        )
                         invalid_parameters.append(msg)
                         continue