Ensure all image parameters have a default set
Now that the PrepareContainerImageParameters action is part of the deploy workflow, environments/containers-default-parameters.yaml is overwritten with a dry-run prepare. The output of this prepare is filtered to *only* those images required for deployment. However heat requires all image parameters to be populated, regardless of whether they're required, so this change will ensure that a value is set for all image parameters by sharing the logic from the PrepareContainerImageEnv image (which runs during the plan creation workflow). Change-Id: Ia2f013714dafac91075456576ec421fbddd822ae Closes-Bug: #1787268
This commit is contained in:
parent
c7233c6fdb
commit
8b557554a4
@ -32,6 +32,26 @@ from tripleo_common.utils import plan as plan_utils
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def default_image_params():
|
||||
def ffunc(entry):
|
||||
return entry
|
||||
|
||||
template_file = os.path.join(sys.prefix, 'share', 'tripleo-common',
|
||||
'container-images',
|
||||
'overcloud_containers.yaml.j2')
|
||||
|
||||
builder = kolla_builder.KollaImageBuilder([template_file])
|
||||
result = builder.container_images_from_template(filter=ffunc)
|
||||
|
||||
params = {}
|
||||
for entry in result:
|
||||
imagename = entry.get('imagename', '')
|
||||
if 'params' in entry:
|
||||
for p in entry.pop('params'):
|
||||
params[p] = imagename
|
||||
return params
|
||||
|
||||
|
||||
class PrepareContainerImageEnv(base.TripleOAction):
|
||||
"""Populates env parameters with results from container image prepare
|
||||
|
||||
@ -44,22 +64,7 @@ class PrepareContainerImageEnv(base.TripleOAction):
|
||||
|
||||
def run(self, context):
|
||||
|
||||
def ffunc(entry):
|
||||
return entry
|
||||
|
||||
template_file = os.path.join(sys.prefix, 'share', 'tripleo-common',
|
||||
'container-images',
|
||||
'overcloud_containers.yaml.j2')
|
||||
|
||||
builder = kolla_builder.KollaImageBuilder([template_file])
|
||||
result = builder.container_images_from_template(filter=ffunc)
|
||||
|
||||
params = {}
|
||||
for entry in result:
|
||||
imagename = entry.get('imagename', '')
|
||||
if 'params' in entry:
|
||||
for p in entry.pop('params'):
|
||||
params[p] = imagename
|
||||
params = default_image_params()
|
||||
swift = self.get_object_client(context)
|
||||
try:
|
||||
swift.put_object(
|
||||
@ -122,9 +127,16 @@ class PrepareContainerImageParameters(base.TripleOAction):
|
||||
env_files, env = plan_utils.process_environments_and_files(
|
||||
swift, env_paths)
|
||||
|
||||
# ensure every image parameter has a default value, even if prepare
|
||||
# didn't return it
|
||||
params = default_image_params()
|
||||
|
||||
role_data = self._get_role_data(swift)
|
||||
image_params = kolla_builder.container_images_prepare_multi(
|
||||
env, role_data, dry_run=True)
|
||||
if image_params:
|
||||
params.update(image_params)
|
||||
|
||||
except Exception as err:
|
||||
LOG.exception("Error occurred while processing plan files.")
|
||||
return actions.Result(error=six.text_type(err))
|
||||
@ -138,7 +150,7 @@ class PrepareContainerImageParameters(base.TripleOAction):
|
||||
self.container,
|
||||
constants.CONTAINER_DEFAULTS_ENVIRONMENT,
|
||||
yaml.safe_dump(
|
||||
{'parameter_defaults': image_params},
|
||||
{'parameter_defaults': params},
|
||||
default_flow_style=False
|
||||
)
|
||||
)
|
||||
|
@ -133,7 +133,10 @@ class PrepareContainerImageParametersTest(base.TestCase):
|
||||
@mock.patch("tripleo_common.utils.plan.get_env", autospec=True)
|
||||
@mock.patch("tripleo_common.image.kolla_builder."
|
||||
"container_images_prepare_multi")
|
||||
def test_run(self, prepare, get_env, update_action, goc, grd):
|
||||
@mock.patch("tripleo_common.image.kolla_builder.KollaImageBuilder")
|
||||
def test_run(self, kib, prepare, get_env, update_action, goc, grd):
|
||||
builder = kib.return_value
|
||||
builder.container_images_from_template.return_value = image_entries
|
||||
plan = {
|
||||
'version': '1.0',
|
||||
'environments': [],
|
||||
@ -145,7 +148,12 @@ class PrepareContainerImageParametersTest(base.TestCase):
|
||||
{'path': 'environments/containers-default-parameters.yaml'},
|
||||
{'path': 'user-environment.yaml'}
|
||||
]}
|
||||
image_params = {'FooContainerImage': '192.0.2.1/foo/image'}
|
||||
image_params = {
|
||||
'FooContainerImage': '192.0.2.1/foo/image',
|
||||
'DockerNovaComputeImage': 't/cb-nova-compute:liberty',
|
||||
'DockerNovaLibvirtConfigImage': 't/cb-nova-compute:liberty',
|
||||
'DockerNovaLibvirtImage': 't/cb-nova-libvirt:liberty',
|
||||
}
|
||||
image_env_contents = yaml.safe_dump(
|
||||
{'parameter_defaults': image_params},
|
||||
default_flow_style=False
|
||||
|
Loading…
Reference in New Issue
Block a user