Populate ContainerImagePrepare variable

If the user does not specify an explicit container_images_file in the
undercloud.conf, the variable ContainerImagePrepare will be set with
the values required to run the image prepare during the undercloud
deploy run.

This uses the same ContainerImagePrepare variable interface proposed
for the overcloud mistral-driven container prepare
I1b485ff9491fe2b1cf850116f9133de8d05f3d40.

The actual image preparation will be added to undercloud_deploy.py in
a following change in this series.

Change-Id: Ie8543bed3363aac539cfd35e04e8dfaaa166ebc3
Blueprint: #containerized-undercloud
This commit is contained in:
Steve Baker 2018-02-16 12:11:04 +13:00
parent cc24b1af9c
commit 67d40fcb9e
3 changed files with 139 additions and 6 deletions

View File

@ -0,0 +1,16 @@
---
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.

View File

@ -241,3 +241,76 @@ class TestTLSSettings(base.TestCase):
IOError,
undercloud_config._get_public_tls_resource_registry_overwrites,
'/tmp/unexistent-file-12345.yaml')
class TestContainerImageConfig(base.TestCase):
def setUp(self):
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'
undercloud_config._container_images_config(self.conf, deploy_args, env)
self.assertEqual([], deploy_args)
cip = env['ContainerImagePrepare'][0]
self.assertEqual(
'foo', cip['namespace'])
self.assertEqual(
self.conf.container_image_name_prefix, cip['name_prefix'])
self.assertEqual(
self.conf.container_image_name_suffix, cip['name_suffix'])
self.assertEqual(
self.conf.container_image_tag, cip['tag'])
self.assertEqual(
self.conf.container_image_tag_from_label,
cip.get('tag_from_label'))
def test_container_images_file(self):
env = {}
deploy_args = []
self.conf.container_images_file = '/tmp/container_images_file.yaml'
undercloud_config._container_images_config(self.conf, deploy_args, env)
self.assertEqual(['-e', '/tmp/container_images_file.yaml'],
deploy_args)
self.assertEqual({}, env)
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'
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'])

View File

@ -23,6 +23,7 @@ import logging
import netaddr
import os
from oslo_config import cfg
from tripleo_common.image import kolla_builder
from tripleoclient import utils
from tripleoclient.v1 import undercloud_preflight
import yaml
@ -67,6 +68,7 @@ PATHS = Paths()
# When adding new options to the lists below, make sure to regenerate the
# sample config by running "tox -e genconfig" in the project root.
ci_defaults = kolla_builder.container_images_prepare_defaults()
_opts = [
cfg.StrOpt('deployment_user',
help=('User used to run openstack undercloud install command '
@ -344,11 +346,33 @@ _opts = [
default='',
help=('URL for the heat container image to use.')
),
# NOTE(aschultz): LP#1754067 - required until we can do this automatically
cfg.StrOpt('container_images_file',
required=True,
help=('Container yaml file with all available images in the'
'registry')
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')
),
cfg.BoolOpt('enable_ironic',
default=True,
@ -520,8 +544,7 @@ def prepare_undercloud_deploy(upgrade=False, no_validations=False):
deploy_args.append('--heat-container-image=%s'
% CONF['heat_container_image'])
if CONF.get('container_images_file'):
deploy_args += ['-e', CONF['container_images_file']]
_container_images_config(CONF, deploy_args, env_data)
if CONF.get('enable_ironic'):
deploy_args += ['-e', os.path.join(
@ -698,3 +721,24 @@ def _write_env_file(env_data,
except yaml.YAMLError as exc:
raise exc
return env_file
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.')