From 870b20b34ff86c89a9bc25c30b044da023b7fccd Mon Sep 17 00:00:00 2001 From: "Le'Sage, Oded (ol7435)" Date: Tue, 27 Apr 2021 16:21:30 -0500 Subject: [PATCH] implement support for heat's get_file function Enhances Shaker's heat client to support templates which use Heat's get_file function to pass locally available files to the heat engine via the API request Change-Id: I51d3bf3ebcfe09833bbe15f96d36fc8ee5926bf5 --- shaker/openstack/clients/heat.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/shaker/openstack/clients/heat.py b/shaker/openstack/clients/heat.py index cb09d43..35eca66 100755 --- a/shaker/openstack/clients/heat.py +++ b/shaker/openstack/clients/heat.py @@ -14,23 +14,33 @@ # limitations under the License. import sys +import tempfile import time from heatclient import exc +from heatclient.common import template_utils from oslo_log import log as logging -from timeout_decorator import timeout -from timeout_decorator import TimeoutError +from timeout_decorator import TimeoutError, timeout LOG = logging.getLogger(__name__) def create_stack(heat_client, stack_name, template, parameters, environment=None): + # process_template_path expects a path to a file object, create + # a temporary named file and write the contents of template to it + with tempfile.NamedTemporaryFile(mode='w+t') as fd: + fd.write(template) + fd.seek(0) + files, processed_template = template_utils.process_template_path( + fd.name) + stack_params = { 'stack_name': stack_name, - 'template': template, + 'template': processed_template, 'parameters': parameters, 'environment': environment, + 'files': files, } stack = heat_client.stacks.create(**stack_params)['stack']