diff --git a/openstackclient/image/v2/image.py b/openstackclient/image/v2/image.py index fe237e4e1a..95c56f23f2 100644 --- a/openstackclient/image/v2/image.py +++ b/openstackclient/image/v2/image.py @@ -1689,7 +1689,8 @@ class ImportImage(command.ShowOne): "'copy-image' import method)" ), ) - parser.add_argument( + allow_failure_group = parser.add_mutually_exclusive_group() + allow_failure_group.add_argument( '--allow-failure', action='store_true', dest='allow_failure', @@ -1700,9 +1701,9 @@ class ImportImage(command.ShowOne): 'Only usable with --stores or --all-stores' ), ) - parser.add_argument( + allow_failure_group.add_argument( '--disallow-failure', - action='store_true', + action='store_false', dest='allow_failure', default=True, help=_( diff --git a/openstackclient/tests/unit/image/v2/test_image.py b/openstackclient/tests/unit/image/v2/test_image.py index 69a65a59cb..f563828cb6 100644 --- a/openstackclient/tests/unit/image/v2/test_image.py +++ b/openstackclient/tests/unit/image/v2/test_image.py @@ -2092,6 +2092,38 @@ class TestImageImport(TestImage): all_stores_must_succeed=False, ) + def test_import_image__copy_image_disallow_failure(self): + self.image.status = 'active' + arglist = [ + self.image.name, + '--method', + 'copy-image', + '--store', + 'fast', + '--disallow-failure', + ] + verifylist = [ + ('image', self.image.name), + ('import_method', 'copy-image'), + ('stores', ['fast']), + ('allow_failure', False), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + self.cmd.take_action(parsed_args) + + self.image_client.import_image.assert_called_once_with( + self.image, + method='copy-image', + uri=None, + remote_region=None, + remote_image_id=None, + remote_service_interface=None, + stores=['fast'], + all_stores=None, + all_stores_must_succeed=True, + ) + def test_import_image__glance_download(self): arglist = [ self.image.name,