Use container_images_file for all image prepare

The recently merged change Ie8543bed3363aac539cfd35e04e8dfaaa166ebc3
added five new options to undercloud.conf to drive the container
prepare during undercloud install. However this is not nearly as
flexible as the prepare workflow for overcloud deploy, which can have
multiple entries in the ContainerImagePrepare parameter list.

This change removes those new options, and uses the specified
container_images_file file as the source for the ContainerImagePrepare
parameter *or* the container image parameters.

If no file is specified, the environment has a default
ContainerImagePrepare parameter set which will result in a working
undercloud based on the defaults in kolla_builder.

Change-Id: Ic1e6eb5ff0aaeaded279c97139adc9fdebb12857
Blueprint: containerized-undercloud
This commit is contained in:
Steve Baker 2018-03-20 16:28:18 +13:00
parent e3695e44b5
commit 5741603308
3 changed files with 52 additions and 89 deletions

View File

@ -1,16 +1,8 @@
---
features:
- |
Parameters for undercloud container images can now be populated during the
run of `openstack undercloud install --use-heat`. This is controlled by the
new `undercloud.conf` options:
* container_image_namespace
* container_image_name_prefix
* container_image_name_suffix
* container_image_tag
* container_image_tag_from_label
If the option `container_images_file` is set then the above options are
ignored. Generally default values will be sufficient, resulting in the
undercloud being deployed with the recommended images using versioned tags.
If no undercloud.conf `container_images_file` is set then `openstack
undercloud install --use-heat` will deploy an undercloud with the latest
containers as specified by the defaults. This allows the
`container_images_file` option to be not mandatory.

View File

@ -25,6 +25,8 @@ import os
import tempfile
import yaml
from tripleo_common.image import kolla_builder
from tripleoclient.tests import base
from tripleoclient.v1 import undercloud_config
@ -248,39 +250,43 @@ class TestContainerImageConfig(base.TestCase):
super(TestContainerImageConfig, self).setUp()
conf_keys = (
'container_images_file',
'container_image_namespace',
'container_image_name_prefix',
'container_image_name_suffix',
'container_image_tag',
'container_image_tag_from_label'
)
self.conf = mock.Mock(**{key: getattr(undercloud_config.CONF, key)
for key in conf_keys})
def test_mandatory_conf(self):
self.assertRaises(RuntimeError,
undercloud_config._container_images_config,
self.conf, [], {})
def test_defaults(self):
env = {}
deploy_args = []
self.conf.container_image_namespace = 'foo'
cip_default = getattr(kolla_builder,
'CONTAINER_IMAGE_PREPARE_PARAM', None)
self.addCleanup(setattr, kolla_builder,
'CONTAINER_IMAGE_PREPARE_PARAM', cip_default)
setattr(kolla_builder, 'CONTAINER_IMAGE_PREPARE_PARAM', [{
'set': {
'namespace': 'one',
'name_prefix': 'two',
'name_suffix': 'three',
'tag': 'four',
},
'tag_from_label': 'five',
}])
undercloud_config._container_images_config(self.conf, deploy_args, env)
self.assertEqual([], deploy_args)
cip = env['ContainerImagePrepare'][0]
set = cip['set']
self.assertEqual(
'foo', cip['namespace'])
'one', set['namespace'])
self.assertEqual(
self.conf.container_image_name_prefix, cip['name_prefix'])
'two', set['name_prefix'])
self.assertEqual(
self.conf.container_image_name_suffix, cip['name_suffix'])
'three', set['name_suffix'])
self.assertEqual(
self.conf.container_image_tag, cip['tag'])
'four', set['tag'])
self.assertEqual(
self.conf.container_image_tag_from_label,
cip.get('tag_from_label'))
'five', cip['tag_from_label'])
def test_container_images_file(self):
env = {}
@ -294,23 +300,21 @@ class TestContainerImageConfig(base.TestCase):
def test_custom(self):
env = {}
deploy_args = []
self.conf.container_image_namespace = 'one'
self.conf.container_image_name_prefix = 'two'
self.conf.container_image_name_suffix = 'three'
self.conf.container_image_tag = 'four'
self.conf.container_image_tag_from_label = 'five'
with tempfile.NamedTemporaryFile(mode='w') as f:
yaml.dump({
'parameter_defaults': {'ContainerImagePrepare': [{
'set': {
'namespace': 'one',
'name_prefix': 'two',
'name_suffix': 'three',
'tag': 'four',
},
'tag_from_label': 'five',
}]}
}, f)
self.conf.container_images_file = f.name
cif_name = f.name
undercloud_config._container_images_config(self.conf, deploy_args, env)
self.assertEqual([], deploy_args)
cip = env['ContainerImagePrepare'][0]
self.assertEqual(
'one', cip['namespace'])
self.assertEqual(
'two', cip['name_prefix'])
self.assertEqual(
'three', cip['name_suffix'])
self.assertEqual(
'four', cip['tag'])
self.assertEqual(
'five', cip['tag_from_label'])
undercloud_config._container_images_config(
self.conf, deploy_args, env)
self.assertEqual(['-e', cif_name], deploy_args)

View File

@ -357,32 +357,10 @@ _opts = [
),
cfg.StrOpt('container_images_file',
default='',
help=('Container yaml file with all available images in the '
'registry. When not specified, the values provided by '
'this file will be generated using the '
'container_image_* options.')
),
cfg.StrOpt('container_image_namespace',
default='',
help=('Namespace portion of image path, for example: %s' %
ci_defaults.get('namespace'))
),
cfg.StrOpt('container_image_name_prefix',
default=ci_defaults.get('name_prefix'),
help=('Name prefix of container image names')
),
cfg.StrOpt('container_image_name_suffix',
default=ci_defaults.get('name_suffix'),
help=('Name suffix of container image names')
),
cfg.StrOpt('container_image_tag',
default=ci_defaults.get('tag'),
help=('Tag of undercloud images to deploy')
),
cfg.StrOpt('container_image_tag_from_label',
default=ci_defaults.get('tag_from_label'),
help=('Image label to use to discover versioned tag')
),
help=('Heat environment file with parameters for all required '
'container images. Or alternatively, parameter '
'"ContainerImagePrepare" to drive the required image '
'preparation.')),
cfg.BoolOpt('enable_ironic',
default=True,
help=('Whether to enable the ironic service.')),
@ -750,19 +728,8 @@ def _write_env_file(env_data,
def _container_images_config(conf, deploy_args, env_data):
if conf.container_images_file:
deploy_args += ['-e', conf.container_images_file]
elif conf.container_image_namespace:
pd = kolla_builder.container_images_prepare_defaults()
if conf.container_image_namespace:
pd['namespace'] = conf.container_image_namespace
if conf.container_image_name_prefix:
pd['name_prefix'] = conf.container_image_name_prefix
if conf.container_image_name_suffix:
pd['name_suffix'] = conf.container_image_name_suffix
if conf.container_image_tag:
pd['tag'] = conf.container_image_tag
if conf.container_image_tag_from_label:
pd['tag_from_label'] = conf.container_image_tag_from_label
env_data['ContainerImagePrepare'] = [pd]
else:
raise RuntimeError('Either "container_images_file" or '
'"container_image_namespace" must be specified.')
# no images file was provided. Set a default ContainerImagePrepare
# parameter to trigger the preparation of the required container list
cip = kolla_builder.CONTAINER_IMAGE_PREPARE_PARAM
env_data['ContainerImagePrepare'] = cip