# ============LICENSE_START=======================================================
# org.onap.vvp/validation-scripts
# ===================================================================
-# Copyright © 2018 AT&T Intellectual Property. All rights reserved.
+# Copyright © 2017 AT&T Intellectual Property. All rights reserved.
# ===================================================================
#
# Unless otherwise specified, all software contained herein is licensed
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
#
-from tests import cached_yaml as yaml
import pytest
+from tests import cached_yaml as yaml
+
+from .helpers import validates
+from .utils.network_roles import property_uses_get_resource
-def test_unique_name_str_replace_use_req_params_in_tmpl(yaml_file):
- '''
- Check that all occurences of str_replace uses either vnf_name or
- vnf_module_id to construct the name
- '''
- with open(yaml_file) as fh:
+@validates("R-18008")
+def test_neutron_port_network_param_is_string(heat_template):
+ """
+ Make sure all network properties use the allowed naming
+ conventions
+ """
+ with open(heat_template) as fh:
yml = yaml.load(fh)
# skip if resources are not defined
if "resources" not in yml:
pytest.skip("No resources specified in the heat template")
- in_template = []
- for v1 in yml["resources"].values():
- if not isinstance(v1, dict):
+ # skip if parameters are not defined
+ if "parameters" not in yml:
+ pytest.skip("No parameters specified in the heat template")
+
+ invalid_ports = []
+ for k, v in yml["resources"].items():
+ if not isinstance(v, dict):
+ continue
+ if "properties" not in v:
continue
- if "properties" not in v1:
+ if property_uses_get_resource(v, "network"):
continue
- if v1["type"] in ["OS::Nova::Server", "OS::Neutron::Port",
- "OS::Heat::ResourceGroup"]:
+ if v.get("type") != "OS::Neutron::Port":
+ continue
+
+ prop = v.get("properties", {}).get("network", {})
+ network_param = prop.get("get_param", "") if isinstance(prop, dict) else ""
+ if not network_param:
+ continue
+
+ param = yml.get("parameters").get(network_param)
+ if not param:
continue
- try:
- v2 = v1["properties"]["name"]
- str_replace = v2["str_replace"]
- params = str_replace["params"]
- template = str_replace["template"]
- in_template.append(all(k3 in template for k3 in params))
- except (TypeError, KeyError):
+ param_type = param.get("type")
+ if not param_type:
continue
- if not in_template:
- pytest.skip("No str_replace instances were detected")
+ if param_type != "string":
+ invalid_ports.append({"port": k, "param": network_param})
- assert all(c for c in in_template)
+ assert not invalid_ports, "network parameter must be defined as string {} ".format(
+ invalid_ports
+ )