diff --git a/releasenotes/notes/container-image-commands-49eaa9c338085844.yaml b/releasenotes/notes/container-image-commands-49eaa9c338085844.yaml new file mode 100644 index 000000000..a408abe69 --- /dev/null +++ b/releasenotes/notes/container-image-commands-49eaa9c338085844.yaml @@ -0,0 +1,9 @@ +--- +features: + - | + New command ``overcloud container image upload``. This is the container + image equivalent to the ``overcloud image upload`` command. + - | + New command ``overcloud container image build``. This command receives the + same ``--config-file`` argument as ``overcloud container image upload`` and + invokes kolla-build to build the images specified in that file. diff --git a/setup.cfg b/setup.cfg index af2d7784c..f2eb39b4f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -63,6 +63,7 @@ openstack.tripleoclient.v1 = baremetal_configure_boot = tripleoclient.v1.baremetal:ConfigureBaremetalBoot overcloud_netenv_validate = tripleoclient.v1.overcloud_netenv_validate:ValidateOvercloudNetenv overcloud_container_image_upload = tripleoclient.v1.container_image:UploadImage + overcloud_container_image_build = tripleoclient.v1.container_image:BuildImage overcloud_delete = tripleoclient.v1.overcloud_delete:DeleteOvercloud overcloud_credentials = tripleoclient.v1.overcloud_credentials:OvercloudCredentials overcloud_deploy = tripleoclient.v1.overcloud_deploy:DeployOvercloud diff --git a/tripleoclient/tests/v1/overcloud_image/test_container_image.py b/tripleoclient/tests/v1/overcloud_image/test_container_image.py index 40aeb9b5c..d1f03a7d9 100644 --- a/tripleoclient/tests/v1/overcloud_image/test_container_image.py +++ b/tripleoclient/tests/v1/overcloud_image/test_container_image.py @@ -58,3 +58,48 @@ class TestContainerImageUpload(TestPluginV1): mock_manager.assert_called_once_with( ['/tmp/foo.yaml', '/tmp/bar.yaml']) mock_manager.return_value.upload.assert_called_once_with() + + +class TestContainerImageBuild(TestPluginV1): + + def setUp(self): + super(TestContainerImageBuild, self).setUp() + + # Get the command object to test + self.cmd = container_image.BuildImage(self.app, None) + + @mock.patch('tripleo_common.image.kolla_builder.KollaImageBuilder', + autospec=True) + def test_container_image_build_noargs(self, mock_builder): + arglist = [] + verifylist = [] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + + mock_builder.assert_called_once_with([]) + mock_builder.return_value.build_images.assert_called_once_with([]) + + @mock.patch('tripleo_common.image.kolla_builder.KollaImageBuilder', + autospec=True) + def test_container_image_build(self, mock_builder): + arglist = [ + '--config-file', + '/tmp/foo.yaml', + '--config-file', + '/tmp/bar.yaml', + '--kolla-config-file', + '/tmp/kolla.conf' + ] + verifylist = [] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + + mock_builder.assert_called_once_with([ + '/tmp/foo.yaml', '/tmp/bar.yaml']) + mock_builder.return_value.build_images.assert_called_once_with([ + '/tmp/kolla.conf' + ]) diff --git a/tripleoclient/v1/container_image.py b/tripleoclient/v1/container_image.py index 5299cbdfa..b7a327191 100644 --- a/tripleoclient/v1/container_image.py +++ b/tripleoclient/v1/container_image.py @@ -19,6 +19,7 @@ from osc_lib.command import command from osc_lib.i18n import _ from tripleo_common.image import image_uploader +from tripleo_common.image import kolla_builder class UploadImage(command.Command): @@ -45,3 +46,40 @@ class UploadImage(command.Command): uploader = image_uploader.ImageUploadManager( parsed_args.config_files) uploader.upload() + + +class BuildImage(command.Command): + """Build overcloud container images with kolla-build.""" + + auth_required = False + log = logging.getLogger(__name__ + ".BuildImage") + + def get_parser(self, prog_name): + parser = super(BuildImage, self).get_parser(prog_name) + parser.add_argument( + "--config-file", + dest="config_files", + metavar='', + default=[], + action="append", + help=_("YAML config file specifying the images to build. May be " + "specified multiple times. Order is preserved, and later " + "files will override some options in previous files. " + "Other options will append."), + ) + parser.add_argument( + "--kolla-config-file", + dest="kolla_config_files", + metavar='', + default=[], + action="append", + help=_("Path to a Kolla config file to use. Multiple config files " + "can be specified, with values in later files taking " + "precedence."), + ) + return parser + + def take_action(self, parsed_args): + self.log.debug("take_action(%s)" % parsed_args) + builder = kolla_builder.KollaImageBuilder(parsed_args.config_files) + builder.build_images(parsed_args.kolla_config_files)