From f13d36ae0114e159663ea2a3fa07260df9d9407d Mon Sep 17 00:00:00 2001 From: Steven Hardy Date: Mon, 21 Mar 2016 17:03:43 +0000 Subject: [PATCH] Fix regression handling relative paths in environment 7627e1bae53747e1471caf632dfc1b6edf2e26cf introduced new code to add the environment to the files mapping, so server side resolution of multiple environments is possible. However, the environment added is wrong when you're handling those with relative paths inside, we must add the resolved version or the keys don't map to keys in the files map, an you get an error when we try to locate the file on the server. Evidently we lack adequate functional test coverage of this, which can be addressed via a heat patch, but I added a unit test illustrating the problem. Change-Id: I3bd2cd48623e4ad1b4067f4cefc7ddff30b9e88d Closes-Bug: #1560106 --- heatclient/common/template_utils.py | 6 +-- heatclient/tests/unit/test_template_utils.py | 42 ++++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/heatclient/common/template_utils.py b/heatclient/common/template_utils.py index fae54efe..a1b176c3 100644 --- a/heatclient/common/template_utils.py +++ b/heatclient/common/template_utils.py @@ -289,9 +289,6 @@ def process_environment_and_files(env_path=None, env_base_url = utils.base_url_for_url(env_url) raw_env = request.urlopen(env_url).read() - if include_env_in_files: - files[env_url] = raw_env - env = environment_format.parse(raw_env) resolve_environment_urls( @@ -299,6 +296,9 @@ def process_environment_and_files(env_path=None, files, env_base_url) + if include_env_in_files: + files[env_url] = jsonutils.dumps(env) + return files, env diff --git a/heatclient/tests/unit/test_template_utils.py b/heatclient/tests/unit/test_template_utils.py index 920573d6..551f4636 100644 --- a/heatclient/tests/unit/test_template_utils.py +++ b/heatclient/tests/unit/test_template_utils.py @@ -409,6 +409,48 @@ class ShellEnvironmentTest(testtools.TestCase): files['file:///home/b/a.yaml']) self.assertEqual(['file:///home/my/dir/env1.yaml'], env_file_list) + self.assertEqual(json.dumps(expected_env), + files['file:///home/my/dir/env1.yaml']) + + def test_process_environment_relative_file_tracker(self): + + self.m.StubOutWithMock(request, 'urlopen') + env_file = '/home/my/dir/env.yaml' + env_url = 'file:///home/my/dir/env.yaml' + env = b''' + resource_registry: + "OS::Thingy": a.yaml + ''' + + request.urlopen(env_url).AndReturn( + six.BytesIO(env)) + request.urlopen('file:///home/my/dir/a.yaml').AndReturn( + six.BytesIO(self.template_a)) + request.urlopen('file:///home/my/dir/a.yaml').AndReturn( + six.BytesIO(self.template_a)) + self.m.ReplayAll() + + self.assertEqual( + env_url, + utils.normalise_file_path_to_url(env_file)) + self.assertEqual( + 'file:///home/my/dir', + utils.base_url_for_url(env_url)) + + env_file_list = [] + files, env = template_utils.process_multiple_environments_and_files( + [env_file], env_list_tracker=env_file_list) + + # Verify + expected_env = {'resource_registry': + {'OS::Thingy': 'file:///home/my/dir/a.yaml'}} + self.assertEqual(expected_env, env) + + self.assertEqual(self.template_a.decode('utf-8'), + files['file:///home/my/dir/a.yaml']) + self.assertEqual(['file:///home/my/dir/env.yaml'], env_file_list) + self.assertEqual(json.dumps(expected_env), + files['file:///home/my/dir/env.yaml']) def test_global_files(self): url = 'file:///home/b/a.yaml'