diff --git a/doc/source/command-objects/backup.rst b/doc/source/command-objects/backup.rst index 9fff393d0c..d7d96c289c 100644 --- a/doc/source/command-objects/backup.rst +++ b/doc/source/command-objects/backup.rst @@ -2,7 +2,7 @@ backup ====== -Block Storage v1 +Block Storage v1, v2 backup create ------------- @@ -53,8 +53,15 @@ Delete backup(s) .. code:: bash os backup delete + [--force] [ ...] +.. option:: --force + + Allow delete in state other than error or available + + *Volume version 2 only* + .. _backup_delete-backup: .. describe:: diff --git a/openstackclient/tests/volume/v2/test_backup.py b/openstackclient/tests/volume/v2/test_backup.py index b1e6594cb3..ce26a2d6f0 100644 --- a/openstackclient/tests/volume/v2/test_backup.py +++ b/openstackclient/tests/volume/v2/test_backup.py @@ -156,7 +156,23 @@ class TestBackupDelete(TestBackup): result = self.cmd.take_action(parsed_args) - self.backups_mock.delete.assert_called_with(self.backup.id) + self.backups_mock.delete.assert_called_with(self.backup.id, False) + self.assertIsNone(result) + + def test_backup_delete_with_force(self): + arglist = [ + '--force', + self.backup.id, + ] + verifylist = [ + ('force', True), + ("backups", [self.backup.id]) + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + result = self.cmd.take_action(parsed_args) + + self.backups_mock.delete.assert_called_with(self.backup.id, True) self.assertIsNone(result) diff --git a/openstackclient/volume/v2/backup.py b/openstackclient/volume/v2/backup.py index a8da40800d..fed5f09e2d 100644 --- a/openstackclient/volume/v2/backup.py +++ b/openstackclient/volume/v2/backup.py @@ -92,6 +92,12 @@ class DeleteBackup(command.Command): nargs="+", help=_("Backup(s) to delete (name or ID)") ) + parser.add_argument( + '--force', + action='store_true', + default=False, + help=_("Allow delete in state other than error or available") + ) return parser def take_action(self, parsed_args): @@ -99,7 +105,7 @@ class DeleteBackup(command.Command): for backup in parsed_args.backups: backup_id = utils.find_resource( volume_client.backups, backup).id - volume_client.backups.delete(backup_id) + volume_client.backups.delete(backup_id, parsed_args.force) class ListBackup(command.Lister): diff --git a/releasenotes/notes/bug-1597188-a2ff62b809865365.yaml b/releasenotes/notes/bug-1597188-a2ff62b809865365.yaml new file mode 100644 index 0000000000..d1f23c416b --- /dev/null +++ b/releasenotes/notes/bug-1597188-a2ff62b809865365.yaml @@ -0,0 +1,6 @@ +--- +features: + - | + Add ``--force`` option to ``backup delete`` command to allow delete + in state other than error or available. + [Bug `1597188 `_]