diff --git a/tripleoclient/tests/v1/test_container_image.py b/tripleoclient/tests/v1/test_container_image.py index cbc5a0033..f00efb2da 100644 --- a/tripleoclient/tests/v1/test_container_image.py +++ b/tripleoclient/tests/v1/test_container_image.py @@ -927,6 +927,29 @@ class TestTripleoImagePrepareDefault(TestPluginV1): [0]['push_destination'] ) + def test_prepare_default_registyr_login(self): + temp = tempfile.mkdtemp() + self.addCleanup(shutil.rmtree, temp) + env_file = os.path.join(temp, 'containers_env.yaml') + + arglist = ['--enable-registry-login', '--output-env-file', env_file] + verifylist = [] + + self.app.command_options = [ + 'tripleo', 'container', 'image', 'prepare', 'default' + ] + arglist + cmd = container_image.TripleOImagePrepareDefault(self.app, None) + parsed_args = self.check_parser(cmd, arglist, verifylist) + + cmd.take_action(parsed_args) + + with open(env_file) as f: + result = yaml.safe_load(f) + self.assertEqual( + True, + result['parameter_defaults']['ContainerImageRegistryLogin'] + ) + class TestContainerImageBuild(TestPluginV1): diff --git a/tripleoclient/v1/container_image.py b/tripleoclient/v1/container_image.py index 63f02b1c3..30df6175c 100644 --- a/tripleoclient/v1/container_image.py +++ b/tripleoclient/v1/container_image.py @@ -905,6 +905,19 @@ class TripleOImagePrepareDefault(command.Command): help=_('Include a push_destination to trigger upload to a local ' 'registry.') ) + parser.add_argument( + '--enable-registry-login', + dest='registry_login', + action='store_true', + default=False, + help=_('Use this flag to enable the flag to have systems attempt ' + 'to login to a remote registry prior to pulling their ' + 'containers. This flag should be used when ' + '--local-push-destination is *NOT* used and the target ' + 'systems will have network connectivity to the remote ' + 'registries. Do not use this for an overcloud that ' + 'may not have network connectivity to a remote registry.') + ) return parser def take_action(self, parsed_args): @@ -917,6 +930,18 @@ class TripleOImagePrepareDefault(command.Command): params = { 'ContainerImagePrepare': cip } + if parsed_args.registry_login: + if parsed_args.push_destination: + self.log.warning('[WARNING] --local-push-destination was used ' + 'with --enable-registry-login. Please make ' + 'sure you understand the use of these ' + 'parameters together as they can cause ' + 'deployment failures.') + self.log.warning('[NOTE] Make sure to update the paramter_defaults' + ' with ContainerImageRegistryCredentials for the ' + 'registries requiring authentication.') + params['ContainerImageRegistryLogin'] = True + env_data = build_env_file(params, self.app.command_options) self.app.stdout.write(env_data) if parsed_args.output_env_file: