aboutsummaryrefslogtreecommitdiffstats
path: root/ice_validator/tests/utils
diff options
context:
space:
mode:
authorLovett, Trevor <trevor.lovett@att.com>2019-10-08 13:32:34 -0500
committerLovett, Trevor (tl2972) <tl2972@att.com>2019-10-08 13:37:18 -0500
commit842888dc28ebccab45e627669f7ee23f04920dc7 (patch)
treef3cbc0bdc74dddd63ca9ce6f2bd8d6503f62def9 /ice_validator/tests/utils
parentd78c645df31a19567667d3e6d3acdf0474f39bf1 (diff)
[VVP] Flag duplicate parameters in .env files
Also some minor tweaks to preload generation so it doesn't fail on partial heat templates Change-Id: If39288dde645b0b53a338e7672336807ffa1b6d7 Issue-ID: VVP-284 Signed-off-by: Lovett, Trevor <trevor.lovett@att.com>
Diffstat (limited to 'ice_validator/tests/utils')
-rw-r--r--ice_validator/tests/utils/vm_types.py2
-rw-r--r--ice_validator/tests/utils/yaml_custom_utils.py47
2 files changed, 35 insertions, 14 deletions
diff --git a/ice_validator/tests/utils/vm_types.py b/ice_validator/tests/utils/vm_types.py
index e0ea7e7..12fc5a2 100644
--- a/ice_validator/tests/utils/vm_types.py
+++ b/ice_validator/tests/utils/vm_types.py
@@ -99,7 +99,7 @@ def get_vm_type_for_nova_server(resource):
vm_types = get_vm_types_for_resource(resource)
# if more than one vm_type was identified, return None
- if len(vm_types) > 1:
+ if not vm_types or len(vm_types) > 1:
return None
return vm_types.pop()
diff --git a/ice_validator/tests/utils/yaml_custom_utils.py b/ice_validator/tests/utils/yaml_custom_utils.py
index 6b99dea..597352a 100644
--- a/ice_validator/tests/utils/yaml_custom_utils.py
+++ b/ice_validator/tests/utils/yaml_custom_utils.py
@@ -38,22 +38,43 @@
#
from yaml.constructor import ConstructorError
+from yaml.nodes import MappingNode
+try:
+ from yaml import CLoader as SafeLoader
+except ImportError:
+ from yaml import SafeLoader
-def raise_duplicates_keys(loader, node, deep=False):
- """Raise error when duplicate keys found in yaml file."""
- mapping = {}
- for key_node, value_node in node.value:
- key = loader.construct_object(key_node, deep=deep)
- value = loader.construct_object(value_node, deep=deep)
- if key in mapping:
+class UniqueKeyLoader(SafeLoader):
+ def construct_mapping(self, node, deep=False):
+ if not isinstance(node, MappingNode):
raise ConstructorError(
- "while constructing a mapping",
+ None,
+ None,
+ "expected a mapping node, but found %s" % node.id,
node.start_mark,
- "found duplicate key (%s)" % key,
- key_node.start_mark,
)
- mapping[key] = value
-
- return loader.construct_mapping(node, deep)
+ mapping = {}
+ for key_node, value_node in node.value:
+ key = self.construct_object(key_node, deep=deep)
+ try:
+ hash(key)
+ except TypeError as exc:
+ raise ConstructorError(
+ "while constructing a mapping",
+ node.start_mark,
+ "found unacceptable key (%s)" % exc,
+ key_node.start_mark,
+ )
+ # check for duplicate keys
+ if key in mapping:
+ raise ConstructorError(
+ "while constructing a mapping",
+ node.start_mark,
+ "found duplicate key",
+ key_node.start_mark,
+ )
+ value = self.construct_object(value_node, deep=deep)
+ mapping[key] = value
+ return mapping