#
# ============LICENSE_END============================================
#
-# ECOMP is a trademark and service mark of AT&T Intellectual Property.
#
"""test
"""
import re
import pytest
-import yaml
+from tests import cached_yaml as yaml
+from tests.utils import nested_files
-from .helpers import validates
+from .helpers import validates, is_nova_server
VERSION = "1.1.0"
@validates("R-98450")
-def test_availability_zone_naming(heat_template):
+def test_availability_zone_naming(yaml_file):
"""
Make sure all availability zones are properly formatted
"""
- with open(heat_template) as fh:
+ if nested_files.file_is_a_nested_template(yaml_file):
+ pytest.skip("test does not apply to nested files")
+
+ with open(yaml_file) as fh:
yml = yaml.load(fh)
# skip if resources are not defined
invalid_availability_zones = set()
- for v1 in yml["resources"].values():
- if not isinstance(v1, dict):
- continue
- if "properties" not in v1:
- continue
- if "type" not in v1:
+ for k1, v1 in yml["resources"].items():
+ if not is_nova_server(v1):
continue
- if v1["type"] == "OS::Nova::Server":
- for k2, v2 in v1["properties"].items():
- if k2 != "availability_zone":
- continue
- if "str_replace" in v2:
- continue
- if not re.match(r"availability_zone_\d+", v2["get_param"]):
- invalid_availability_zones.add(v2["get_param"])
+ for k2, v2 in v1["properties"].items():
+ if k2 != "availability_zone" or "str_replace" in v2:
+ continue
+ if "get_param" not in v2:
+ invalid_availability_zones.add(k1)
+ continue
+ if not isinstance(v2["get_param"], str):
+ continue
+ if not re.match(r"availability_zone_\d+", v2["get_param"]):
+ invalid_availability_zones.add(v2["get_param"])
assert not invalid_availability_zones, "invalid availability zones %s" % list(
invalid_availability_zones