From c04ec16cf7ad2dbe7bf8edf5f6e7840c54b0efa3 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Tue, 23 Jun 2020 15:45:47 -0500 Subject: Expose flag for forcing use of import for images openstacksdk added support for using image import as a fallback which is transparently supported here, but also provides an override flag to allow a user to force use of import. Expose that here. Depends-On: https://review.opendev.org/737608 Change-Id: Ied938a8f63f305305a20ace42e9f4c84b0a5c00e --- openstackclient/image/v2/image.py | 11 +++++++++++ openstackclient/tests/unit/image/v2/test_image.py | 22 ++++++++++++++++++++++ 2 files changed, 33 insertions(+) (limited to 'openstackclient') diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py index 53ce560d..b068ddaf 100644 --- a/openstackclient/image/v2/image.py +++ b/openstackclient/image/v2/image.py @@ -324,6 +324,14 @@ class CreateImage(command.ShowOne): metavar="", help=_("Set an alternate project on this image (name or ID)"), ) + parser.add_argument( + "--import", + dest="use_import", + action="store_true", + help=_( + "Force the use of glance image import instead of" + " direct upload") + ) common.add_project_domain_option_to_parser(parser) for deadopt in self.deadopts: parser.add_argument( @@ -388,6 +396,9 @@ class CreateImage(command.ShowOne): parsed_args.project_domain, ).id + if parsed_args.use_import: + kwargs['use_import'] = True + # open the file first to ensure any failures are handled before the # image is created. Get the file name (if it is file, and not stdin) # for easier further handling. diff --git a/openstackclient/tests/unit/image/v2/test_image.py b/openstackclient/tests/unit/image/v2/test_image.py index a021cfc7..310f6b76 100644 --- a/openstackclient/tests/unit/image/v2/test_image.py +++ b/openstackclient/tests/unit/image/v2/test_image.py @@ -271,6 +271,28 @@ class TestImageCreate(TestImage): exceptions.CommandError, self.cmd.take_action, parsed_args) + @mock.patch('sys.stdin', side_effect=[None]) + def test_image_create_import(self, raw_input): + + arglist = [ + '--import', + self.new_image.name, + ] + verifylist = [ + ('name', self.new_image.name), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = self.cmd.take_action(parsed_args) + + # ImageManager.create(name=, **) + self.client.create_image.assert_called_with( + name=self.new_image.name, + container_format=image.DEFAULT_CONTAINER_FORMAT, + disk_format=image.DEFAULT_DISK_FORMAT, + use_import=True + ) + class TestAddProjectToImage(TestImage): -- cgit v1.2.1