From f5aef9ac36257cfd9808c0dbdb80c5adc412876b Mon Sep 17 00:00:00 2001 From: Huanxuan Ao Date: Wed, 6 Jul 2016 11:11:56 +0800 Subject: [PATCH] Add '--force' option to 'backup delete' command in volumev2 Add '--force' option to 'backup delete' command in volumev2 (v2 only) to allow delete in state other than error or available. Change-Id: I661ea0d465db227e374cbacdde0206fa1a6dd3d5 Closes-Bug: #1597188 --- doc/source/command-objects/backup.rst | 9 ++++++++- openstackclient/tests/volume/v2/test_backup.py | 18 +++++++++++++++++- openstackclient/volume/v2/backup.py | 8 +++++++- .../notes/bug-1597188-a2ff62b809865365.yaml | 6 ++++++ 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 releasenotes/notes/bug-1597188-a2ff62b809865365.yaml 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 `_]