Add unit test to check YAML syntax in templates

Change-Id: I10bc9621f068815126d00e59a2db83101febe201
diff --git a/tcp_tests/helpers/env_config.py b/tcp_tests/helpers/env_config.py
index 81e6764..5dbc87d 100644
--- a/tcp_tests/helpers/env_config.py
+++ b/tcp_tests/helpers/env_config.py
@@ -322,7 +322,7 @@
                       "from template aborted.")
 
 
-def yaml_template_load(config_file, options=None):
+def yaml_template_load(config_file, options=None, log_env_vars=True):
     """Temporary moved from fuel_devops to use jinja2"""
     dirname = os.path.dirname(config_file)
 
@@ -376,5 +376,5 @@
     TemplateLoader.add_constructor(
         yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG, construct_mapping)
 
-    f = utils.render_template(config_file, options)
+    f = utils.render_template(config_file, options, log_env_vars=log_env_vars)
     return yaml.load(f, TemplateLoader)
diff --git a/tcp_tests/helpers/utils.py b/tcp_tests/helpers/utils.py
index e24c18b..8cfa67a 100644
--- a/tcp_tests/helpers/utils.py
+++ b/tcp_tests/helpers/utils.py
@@ -332,7 +332,7 @@
         self.write_content()
 
 
-def render_template(file_path, options=None):
+def render_template(file_path, options=None, log_env_vars=True):
     required_env_vars = set()
     optional_env_vars = dict()
 
@@ -362,11 +362,11 @@
                                        followlinks=True))
     template = environment.get_template(filename).render(options)
 
-    if required_env_vars:
+    if required_env_vars and log_env_vars:
         LOG.info("Required environment variables:")
         for var in required_env_vars:
             LOG.info("    {0}".format(var))
-    if optional_env_vars:
+    if optional_env_vars and log_env_vars:
         LOG.info("Optional environment variables:")
         for var, default in sorted(optional_env_vars.iteritems()):
             LOG.info("    {0} , value = {1}".format(var, default))
diff --git a/tcp_tests/tests/unit/test_yaml_templates.py b/tcp_tests/tests/unit/test_yaml_templates.py
new file mode 100644
index 0000000..54eb5b3
--- /dev/null
+++ b/tcp_tests/tests/unit/test_yaml_templates.py
@@ -0,0 +1,62 @@
+import pytest
+import mock
+import os
+
+from tcp_tests.helpers import env_config
+from tcp_tests import settings_oslo
+
+config = settings_oslo.load_config(config_files=[])
+config.underlay.ssh = [
+    {"node_name": "cfg01.cookied-dop-sl2.local", "host": "10.70.0.15"},
+    {"node_name": "cid01.cookied-dop-sl2.local", "host": "10.70.0.91"},
+    {"node_name": "cid02.cookied-dop-sl2.local", "host": "10.70.0.92"},
+    {"node_name": "cid03.cookied-dop-sl2.local", "host": "10.70.0.93"},
+    {"node_name": "ctl01.cookied-dop-sl2.local", "host": "10.70.0.11"},
+    {"node_name": "ctl02.cookied-dop-sl2.local", "host": "10.70.0.12"},
+    {"node_name": "ctl03.cookied-dop-sl2.local", "host": "10.70.0.13"},
+    {"node_name": "mon01.cookied-dop-sl2.local", "host": "10.70.0.71"},
+    {"node_name": "mon02.cookied-dop-sl2.local", "host": "10.70.0.72"},
+    {"node_name": "mon03.cookied-dop-sl2.local", "host": "10.70.0.73"},
+    {"node_name": "prx01.cookied-dop-sl2.local", "host": "10.70.0.81"},
+    {"node_name": "cmp001.cookied-dop-sl2.local", "host": "10.70.0.101"},
+    {"node_name": "cmp002.cookied-dop-sl2.local", "host": "10.70.0.102"},
+    {"node_name": "gtw01.cookied-dop-sl2.local", "host": "10.70.0.224"}
+]
+
+config.underlay.address_pools = {
+    "admin-pool01": "10.70.0.0/24",
+    "private-pool01": "10.60.0.0/24",
+    "tenant-pool01": "10.80.0.0/24",
+    "external-pool01": "10.90.0.0/24"
+}
+config.underlay.ssh_keys = [
+    {"public": "AAAARRRGGHHHhh", "private": "--- BLABLA-KEY ---"}
+]
+
+
+def find_yaml_paths():
+    exts = ['.yml', '.yaml']
+    for root, subFolder, files in os.walk('./tcp_tests/templates/'):
+        for filename in files:
+            if any([filename.endswith(ext) for ext in exts]):
+                yield str(os.path.join(root, filename))
+
+
+@pytest.mark.parametrize("yaml_path", find_yaml_paths())
+@pytest.mark.unit_tests
+@mock.patch('os.environ', autospec=True)
+def test_jinja_render_yaml_file(mock_os_environ, yaml_path):
+    def os_environ_getitem(name):
+        return "=< Mock value >="
+
+    def os_environ_get(name, default_value):
+        return default_value or "=< Mock value >="
+
+    mock_os_environ.__getitem__ = mock.Mock(side_effect=os_environ_getitem)
+    mock_os_environ.get = mock.Mock(side_effect=os_environ_get)
+
+    options = {
+        'config': config,
+    }
+    env_config.yaml_template_load(yaml_path, options=options,
+                                  log_env_vars=False)
diff --git a/tox.ini b/tox.ini
index 9014d59..99a92f2 100644
--- a/tox.ini
+++ b/tox.ini
@@ -13,6 +13,7 @@
 install_command = pip install -U {opts} {packages}
 deps =
     -r{toxinidir}/tcp_tests/requirements.txt
+    mock>=1.2
 usedevelop = False
 commands = py.test -s -vvv tcp_tests/tests/unit