X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ice_validator%2Ftests%2Ftest_non_server_name.py;h=7a5c11f385d9c3aa46f828e5ffbdbb6f0f1a6f92;hb=0c4e64d87728b89aa9cd4d41d738f5bfe64ceee3;hp=7d881550e9c8c0f07761bcb21b5306f8e60d8027;hpb=1f4df7c7ad27b23773ad9cdbe4db1632ce388cf1;p=vvp%2Fvalidation-scripts.git diff --git a/ice_validator/tests/test_non_server_name.py b/ice_validator/tests/test_non_server_name.py index 7d88155..7a5c11f 100644 --- a/ice_validator/tests/test_non_server_name.py +++ b/ice_validator/tests/test_non_server_name.py @@ -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 @@ -35,19 +35,20 @@ # # ============LICENSE_END============================================ # -# ECOMP is a trademark and service mark of AT&T Intellectual Property. # """ resource property name """ - -import pytest +import os +import collections from .structures import Heat +from .structures import HeatProcessor from .helpers import validates +from tests.utils import nested_files -VERSION = "1.1.0" +VERSION = "1.2.0" def get_non_servers(heat): @@ -63,21 +64,16 @@ def get_non_servers(heat): @validates("R-85734") -def test_non_server_name(heat_template): +def test_non_server_name(yaml_file): """ If a VNF's Heat Orchestration Template contains the property ``name`` for a non ``OS::Nova::Server`` resource, the intrinsic function - ``str_replace`` **MUST** be used in conjunction with the ECOMP + ``str_replace`` **MUST** be used in conjunction with the ONAP supplied metadata parameter ``vnf_name`` to generate a unique value. """ - h = Heat(filepath=heat_template) - if not h.resources: - pytest.skip("No resources in this template") - + h = Heat(filepath=yaml_file) non_servers = get_non_servers(h) - if not non_servers: - pytest.skip("No non-server resources in this template") bad = [] for rid, resource in non_servers.items(): @@ -138,6 +134,33 @@ def test_non_server_name(heat_template): + "template ({})" ).format(rid, vnf_name_param, template) ) - msg = "Improper name property for non-OS::Nova::Server resources. " + ". ".join(bad) + msg = ( + "Improper name property for" " non-OS::Nova::Server resources. " + ) + ". ".join(bad) assert not bad, msg + + +@validates("R-85734") +def test_non_server_name_unique(heat_template): + """Test name has unique value + """ + list_nest = nested_files.get_list_of_nested_files( + heat_template, os.path.dirname(heat_template) + ) + list_nest.append(heat_template) + non_servers = {} + for yaml_file in list_nest: + h = Heat(filepath=yaml_file) + non_servers.update(get_non_servers(h)) + names = collections.defaultdict(set) + for rid, resource in non_servers.items(): + name = HeatProcessor.get_str_replace_name(resource) + if name: + names[name].add(rid) + bad = {key: value for key, value in names.items() if len(value) > 1} + delim = "\n" + 4 * " " + assert not bad, "Names must be unique," " not shared across resource ids.%s%s" % ( + delim, + delim.join("%s: %s" % (name, list(value)) for name, value in bad.items()), + )