X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ice_validator%2Ftests%2Ftest_servers_have_required_metadata.py;h=4f76e7badf8519ec5264362c2fed389a141118f1;hb=0c4e64d87728b89aa9cd4d41d738f5bfe64ceee3;hp=82c85e534ff646e215d74bdf78892f5f025c1078;hpb=cc21b8b08b6dbcec577bfb26ff397ac899da8002;p=vvp%2Fvalidation-scripts.git diff --git a/ice_validator/tests/test_servers_have_required_metadata.py b/ice_validator/tests/test_servers_have_required_metadata.py index 82c85e5..4f76e7b 100644 --- a/ice_validator/tests/test_servers_have_required_metadata.py +++ b/ice_validator/tests/test_servers_have_required_metadata.py @@ -2,11 +2,11 @@ # ============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 -# under the Apache License, Version 2.0 (the “License”); +# under the Apache License, Version 2.0 (the "License"); # you may not use this software except in compliance with the License. # You may obtain a copy of the License at # @@ -21,7 +21,7 @@ # # # Unless otherwise specified, all documentation contained herein is licensed -# under the Creative Commons License, Attribution 4.0 Intl. (the “License”); +# under the Creative Commons License, Attribution 4.0 Intl. (the "License"); # you may not use this documentation except in compliance with the License. # You may obtain a copy of the License at # @@ -35,39 +35,43 @@ # # ============LICENSE_END============================================ # -# ECOMP is a trademark and service mark of AT&T Intellectual Property. -# -import yaml import pytest +from tests import cached_yaml as yaml + +from .helpers import validates +@validates("R-37437", "R-71493", "R-72483") def test_servers_have_required_metadata(yaml_file): - ''' + """ Check all defined nova server instances have the required metadata: - vnf_id and vf_module_id - ''' + vnf_id, vf_module_id, and vnf_name + """ with open(yaml_file) as fh: yml = yaml.load(fh) - # Check if the param vm_role is defined if "resources" not in yml: pytest.skip("No resources specified in the heat template") - required_metadata = ["vnf_id", "vf_module_id", "vnf_name"] + required_metadata = {"vnf_id", "vf_module_id", "vnf_name"} - invalid_nova_servers = [] + errors = [] for k, v in yml["resources"].items(): if v.get("type") != "OS::Nova::Server": continue - if 'properties' not in v: + if "properties" not in v: continue - if 'metadata' not in v['properties']: + if "metadata" not in v["properties"]: continue - # do not add the server if it has the required metadata - if set(required_metadata) <= set(v["properties"]["metadata"].keys()): - continue - invalid_nova_servers.append(k) + metadata = set(v.get("properties", {}).get("metadata", {}).keys()) + missing_metadata = required_metadata.difference(metadata) + if missing_metadata: + msg_template = ( + "OS::Nova::Server {} is missing the following " + + "metadata properties: {}" + ) + errors.append(msg_template.format(k, missing_metadata)) - assert not set(invalid_nova_servers) + assert not errors, "\n".join(errors)