aboutsummaryrefslogtreecommitdiffstats
path: root/ice_validator/tests/utils/nested_files.py
diff options
context:
space:
mode:
authorstark, steven <ss820f@att.com>2018-09-13 16:49:43 -0700
committerstark, steven <ss820f@att.com>2018-09-13 17:21:45 -0700
commit31d5da59b39d38760cc519a2c5e5b70357b539e8 (patch)
tree7298d118aefb1e7494afa5cbedaa5e499b78373d /ice_validator/tests/utils/nested_files.py
parent8de26dd1cc9ed33c3ab85a5014ac949f174db932 (diff)
[VVP] udpating scripts for casablanca
adding new "infrastructure" scripts addresses bugs VVP-100, VVP-101, VVP-102 adding base tests updating tests where arguments have changed Adds traceability for task VVP-92 Change-Id: I067d8e80934403039e66fbc9fc93766587f67b4e Issue-ID: VVP-80 Signed-off-by: stark, steven <ss820f@att.com>
Diffstat (limited to 'ice_validator/tests/utils/nested_files.py')
-rw-r--r--ice_validator/tests/utils/nested_files.py69
1 files changed, 42 insertions, 27 deletions
diff --git a/ice_validator/tests/utils/nested_files.py b/ice_validator/tests/utils/nested_files.py
index 02f733d..c551646 100644
--- a/ice_validator/tests/utils/nested_files.py
+++ b/ice_validator/tests/utils/nested_files.py
@@ -43,17 +43,17 @@
from os import path
import re
-import yaml
+from tests import cached_yaml as yaml
-VERSION = "1.0.2"
+VERSION = '1.0.2'
def get_list_of_nested_files(yml, dirpath):
- """
+ '''
return a list of all nested files
- """
+ '''
- if not hasattr(yml, "items"):
+ if not hasattr(yml, 'items'):
return []
nested_files = []
@@ -63,34 +63,41 @@ def get_list_of_nested_files(yml, dirpath):
t = v["type"]
if t.endswith(".yml") or t.endswith(".yaml"):
filepath = path.join(dirpath, t)
- with open(filepath) as fh:
- t_yml = yaml.load(fh)
- nested_files.append(filepath)
- nested_files.extend(get_list_of_nested_files(t_yml, dirpath))
+ if path.exists(filepath):
+ with open(filepath) as fh:
+ t_yml = yaml.load(fh)
+ nested_files.append(filepath)
+ nested_files.extend(get_list_of_nested_files(t_yml, dirpath))
elif t == "OS::Heat::ResourceGroup":
- rdt = v.get("properties", {}).get("resource_def", {}).get("type", None)
+ rdt = (v.get("properties", {})
+ .get("resource_def", {})
+ .get("type", None))
if rdt and (rdt.endswith(".yml") or rdt.endswith(".yaml")):
filepath = path.join(dirpath, rdt)
- with open(filepath) as fh:
- rdt_yml = yaml.load(fh)
- nested_files.append(filepath)
- nested_files.extend(get_list_of_nested_files(rdt_yml, dirpath))
+ if path.exists(filepath):
+ with open(filepath) as fh:
+ rdt_yml = yaml.load(fh)
+ nested_files.append(filepath)
+ nested_files.extend(
+ get_list_of_nested_files(rdt_yml, dirpath))
if isinstance(v, dict):
- nested_files.extend(get_list_of_nested_files(v, dirpath))
+ nested_files.extend(
+ get_list_of_nested_files(v, dirpath))
elif isinstance(v, list):
for d in v:
- nested_files.extend(get_list_of_nested_files(d, dirpath))
+ nested_files.extend(
+ get_list_of_nested_files(d, dirpath))
return nested_files
def check_for_invalid_nesting(yml, yaml_file, dirpath):
- """
+ '''
return a list of all nested files
- """
- if not hasattr(yml, "items"):
+ '''
+ if not hasattr(yml, 'items'):
return []
invalid_nesting = []
- p = re.compile("^[A-z]*::[A-z]*::[A-z]*$")
+ p = re.compile('^[A-z]*::[A-z]*::[A-z]*$')
for v in yml.values():
if isinstance(v, dict) and "type" in v:
@@ -102,9 +109,7 @@ def check_for_invalid_nesting(yml, yaml_file, dirpath):
if not isinstance(rd, dict) or "type" not in rd:
invalid_nesting.append(yaml_file)
continue
- elif not p.match(rd["type"]) and not (
- rd["type"].endswith(".yml") or rd["type"].endswith(".yaml")
- ):
+ elif not p.match(rd["type"]):
filepath = path.join(dirpath, rd["type"])
else:
continue
@@ -115,11 +120,21 @@ def check_for_invalid_nesting(yml, yaml_file, dirpath):
yml = yaml.load(fh)
except yaml.YAMLError as e:
invalid_nesting.append(filepath)
- print(e) # pylint: disable=superfluous-parens
- invalid_nesting.extend(check_for_invalid_nesting(yml, filepath, dirpath))
+ print(e) # pylint: disable=superfluous-parens
+ invalid_nesting.extend(check_for_invalid_nesting(
+ yml,
+ filepath,
+ dirpath))
if isinstance(v, dict):
- invalid_nesting.extend(check_for_invalid_nesting(v, yaml_file, dirpath))
+ invalid_nesting.extend(check_for_invalid_nesting(
+ v,
+ yaml_file,
+ dirpath))
elif isinstance(v, list):
for d in v:
- invalid_nesting.extend(check_for_invalid_nesting(d, yaml_file, dirpath))
+ invalid_nesting.extend(check_for_invalid_nesting(
+ d,
+ yaml_file,
+ dirpath))
return invalid_nesting
+