Ignore missing rendered heat envs in prepare

Since we use j2 templates for some of the heat environments, and at the
moment they are rendered when uploading them to swift at the beginning
of the deployment workflow, it is possible that one of the heat
environment file passed to the prepare command is, or references a file
that is, not yet rendered.

This commit implements a custom object_request() function that makes
process_multiple_environments_and_files() ignore the missing files.

Change-Id: I6f31898ca3db9563d3d8e8e6e0a9f0cdaebf24ca
Co-Authored-By: Thomas Hervé <therve@redhat.com>
Closes-Bug: #1730650
(cherry picked from commit a68cbfd515)
This commit is contained in:
Martin André 2017-11-09 09:50:46 +01:00
parent 4198fe6dc0
commit d43034f29d
2 changed files with 16 additions and 3 deletions

View File

@ -205,7 +205,9 @@ class TestContainerImagePrepare(TestPluginV1):
self.cmd.take_action(parsed_args)
mock_builder.assert_called_once_with([tmpl_file])
pmef.assert_called_once_with(['environment/docker.yaml'])
pmef.assert_called_once_with(['environment/docker.yaml'],
env_path_is_object=mock.ANY,
object_request=mock.ANY)
cift.assert_called_once_with(
filter=mock.ANY,
name_prefix='os-',
@ -295,7 +297,9 @@ class TestContainerImagePrepare(TestPluginV1):
self.cmd.take_action(parsed_args)
mock_builder.assert_called_once_with([tmpl_file])
pmef.assert_called_once_with(pmef_call_args)
pmef.assert_called_once_with(pmef_call_args,
env_path_is_object=mock.ANY,
object_request=mock.ANY)
cift.assert_called_once_with(
filter=mock.ANY,
name_prefix='os-',

View File

@ -22,10 +22,12 @@ import sys
import tempfile
from heatclient.common import template_utils
from heatclient.common import utils as heat_utils
from osc_lib.command import command
from osc_lib import exceptions as oscexc
from osc_lib.i18n import _
import requests
from six.moves.urllib import request
import yaml
from tripleo_common.image import image_uploader
@ -378,9 +380,16 @@ class PrepareImageFiles(command.Command):
if not environment_files:
return None
def get_env_file(method, path):
if not os.path.exists(path):
return '{}'
env_url = heat_utils.normalise_file_path_to_url(path)
return request.urlopen(env_url).read()
env_files, env = (
template_utils.process_multiple_environments_and_files(
environment_files))
environment_files, env_path_is_object=lambda path: True,
object_request=get_env_file))
enabled_services = self.get_enabled_services(env, roles_file)
containerized_services = set()
for service, env_path in env.get('resource_registry', {}).items():