diff --git a/tripleoclient/tests/v1/overcloud_image/test_container_image.py b/tripleoclient/tests/v1/overcloud_image/test_container_image.py index 4ff7864cc..fd9977e1a 100644 --- a/tripleoclient/tests/v1/overcloud_image/test_container_image.py +++ b/tripleoclient/tests/v1/overcloud_image/test_container_image.py @@ -120,6 +120,12 @@ class TestContainerImagePrepare(TestPluginV1): images_file, '--env-file', env_file, + '--set', + 'ceph_namespace=myceph', + '--set', + 'ceph_image=mydaemon', + '--set', + 'ceph_tag=mytag', ] self.cmd.app.command_options = arglist verifylist = [] @@ -144,7 +150,10 @@ class TestContainerImagePrepare(TestPluginV1): name_prefix='os-', name_suffix='foo', namespace='tripleo', - tag='passed-ci' + tag='passed-ci', + ceph_image='mydaemon', + ceph_namespace='myceph', + ceph_tag='mytag' ) ci_data = { 'container_images': [{ diff --git a/tripleoclient/v1/container_image.py b/tripleoclient/v1/container_image.py index 0444d0da9..c74b2b49f 100644 --- a/tripleoclient/v1/container_image.py +++ b/tripleoclient/v1/container_image.py @@ -22,6 +22,7 @@ import sys import tempfile from osc_lib.command import command +from osc_lib import exceptions as oscexc from osc_lib.i18n import _ import yaml @@ -218,6 +219,13 @@ class PrepareImageFiles(command.Command): help=_("Override the default name suffix substitution.\n" "Default is empty."), ) + parser.add_argument( + '--set', + metavar='', + action='append', + help=_('Set the value of a variable in the template, even if it ' + 'has no dedicated argument such as "--suffix".') + ) parser.add_argument( "--exclude", dest="excludes", @@ -244,6 +252,18 @@ class PrepareImageFiles(command.Command): ) return parser + def parse_set_values(self, subs, set_values): + if not set_values: + return + for s in set_values: + try: + (n, v) = s.split(('='), 1) + subs[n] = v + except ValueError: + msg = _('Malformed --set(%s). ' + 'Use the variable=value format.') % s + raise oscexc.CommandError(msg) + def write_env_file(self, params, env_file): with os.fdopen(os.open(env_file, @@ -265,6 +285,7 @@ class PrepareImageFiles(command.Command): 'name_prefix': parsed_args.prefix, 'name_suffix': parsed_args.suffix, } + self.parse_set_values(subs, parsed_args.set) def ffunc(entry): imagename = entry.get('imagename', '')