From 4ca172ae78bc606b02150b07776b695f1b3a6678 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Tue, 30 Jan 2018 10:45:01 -0500 Subject: [PATCH] Include file content in scenario tests Use the heatclient utilities for loading referenced files and passing them in the files dict when running scenario tests. This allows testing nested stack scenarios in a way that is representative of how users would encounter them. Change-Id: I6693a0a9e0e1af42b69ade12c8da6f12d370eb49 Story: #1739447 Task: 22218 --- heat_tempest_plugin/common/test.py | 8 -------- .../tests/scenario/scenario_base.py | 18 ++++++++++++++++-- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/heat_tempest_plugin/common/test.py b/heat_tempest_plugin/common/test.py index 429d4ae..aacd019 100644 --- a/heat_tempest_plugin/common/test.py +++ b/heat_tempest_plugin/common/test.py @@ -10,7 +10,6 @@ # License for the specific language governing permissions and limitations # under the License. -import os import random import re import subprocess @@ -206,13 +205,6 @@ class HeatIntegrationTest(testtools.testcase.WithAttributes, LOG.info('Console output for %s', server.id) LOG.info(server.get_console_output()) - def _load_template(self, base_file, file_name, sub_dir=None): - sub_dir = sub_dir or '' - filepath = os.path.join(os.path.dirname(os.path.realpath(base_file)), - sub_dir, file_name) - with open(filepath) as f: - return f.read() - def create_keypair(self, client=None, name=None): if client is None: client = self.compute_client diff --git a/heat_tempest_plugin/tests/scenario/scenario_base.py b/heat_tempest_plugin/tests/scenario/scenario_base.py index 5cfb5d1..db38c4e 100644 --- a/heat_tempest_plugin/tests/scenario/scenario_base.py +++ b/heat_tempest_plugin/tests/scenario/scenario_base.py @@ -10,6 +10,10 @@ # License for the specific language governing permissions and limitations # under the License. +import os +import yaml + +from heatclient.common import template_utils from oslo_utils import reflection from heat_tempest_plugin.common import test @@ -33,9 +37,19 @@ class ScenarioTestsBase(test.HeatIntegrationTest): if not self.conf.minimal_instance_type: raise self.skipException("No minimal flavor configured to test") + def _load_template(self, base_file, file_name, sub_dir=None, files=None): + sub_dir = sub_dir or '' + filepath = os.path.join(os.path.dirname(os.path.realpath(base_file)), + sub_dir, file_name) + _files, template = template_utils.get_template_contents(filepath, + files=files) + return yaml.safe_dump(template) + def launch_stack(self, template_name, expected_status='CREATE_COMPLETE', parameters=None, **kwargs): - template = self._load_template(__file__, template_name, self.sub_dir) + files = kwargs.get('files', {}) + template = self._load_template(__file__, template_name, self.sub_dir, + files) parameters = parameters or {} @@ -45,7 +59,7 @@ class ScenarioTestsBase(test.HeatIntegrationTest): stack_id = self.stack_create( stack_name=kwargs.get('stack_name'), template=template, - files=kwargs.get('files'), + files=files, parameters=parameters, environment=kwargs.get('environment'), expected_status=expected_status