summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--releasenotes/notes/add-backup-delete-to-osc-e302b87809cb814c.yaml5
-rw-r--r--setup.cfg1
-rw-r--r--troveclient/osc/v1/database_backups.py26
-rw-r--r--troveclient/tests/osc/v1/test_database_backups.py31
4 files changed, 63 insertions, 0 deletions
diff --git a/releasenotes/notes/add-backup-delete-to-osc-e302b87809cb814c.yaml b/releasenotes/notes/add-backup-delete-to-osc-e302b87809cb814c.yaml
new file mode 100644
index 0000000..b5ac0f8
--- /dev/null
+++ b/releasenotes/notes/add-backup-delete-to-osc-e302b87809cb814c.yaml
@@ -0,0 +1,5 @@
1---
2features:
3 - |
4 The command ``trove backup-delete`` is now available to use in
5 the python-openstackclient CLI as ``openstack database backup delete``
diff --git a/setup.cfg b/setup.cfg
index 00143a0..ad8b366 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -30,6 +30,7 @@ openstack.cli.extension =
30 database = troveclient.osc.plugin 30 database = troveclient.osc.plugin
31 31
32openstack.database.v1 = 32openstack.database.v1 =
33 database_backup_delete = troveclient.osc.v1.database_backups:DeleteDatabaseBackup
33 database_backup_list = troveclient.osc.v1.database_backups:ListDatabaseBackups 34 database_backup_list = troveclient.osc.v1.database_backups:ListDatabaseBackups
34 database_backup_show = troveclient.osc.v1.database_backups:ShowDatabaseBackup 35 database_backup_show = troveclient.osc.v1.database_backups:ShowDatabaseBackup
35 database_cluster_list = troveclient.osc.v1.database_clusters:ListDatabaseClusters 36 database_cluster_list = troveclient.osc.v1.database_clusters:ListDatabaseClusters
diff --git a/troveclient/osc/v1/database_backups.py b/troveclient/osc/v1/database_backups.py
index 8989596..dc12755 100644
--- a/troveclient/osc/v1/database_backups.py
+++ b/troveclient/osc/v1/database_backups.py
@@ -13,6 +13,7 @@
13"""Database v1 Backups action implementations""" 13"""Database v1 Backups action implementations"""
14 14
15from osc_lib.command import command 15from osc_lib.command import command
16from osc_lib import exceptions
16from osc_lib import utils as osc_utils 17from osc_lib import utils as osc_utils
17import six 18import six
18 19
@@ -94,3 +95,28 @@ class ShowDatabaseBackup(command.ShowOne):
94 backup = osc_utils.find_resource(database_backups, parsed_args.backup) 95 backup = osc_utils.find_resource(database_backups, parsed_args.backup)
95 backup = set_attributes_for_print_detail(backup) 96 backup = set_attributes_for_print_detail(backup)
96 return zip(*sorted(six.iteritems(backup))) 97 return zip(*sorted(six.iteritems(backup)))
98
99
100class DeleteDatabaseBackup(command.Command):
101
102 _description = _("Deletes a backup.")
103
104 def get_parser(self, prog_name):
105 parser = super(DeleteDatabaseBackup, self).get_parser(prog_name)
106 parser.add_argument(
107 'backup',
108 metavar='<backup>',
109 help=_('ID or name of the backup.')
110 )
111 return parser
112
113 def take_action(self, parsed_args):
114 database_backups = self.app.client_manager.database.backups
115 try:
116 backup = osc_utils.find_resource(database_backups,
117 parsed_args.backup)
118 database_backups.delete(backup)
119 except Exception as e:
120 msg = (_("Failed to delete backup %(backup)s: %(e)s")
121 % {'backup': parsed_args.backup, 'e': e})
122 raise exceptions.CommandError(msg)
diff --git a/troveclient/tests/osc/v1/test_database_backups.py b/troveclient/tests/osc/v1/test_database_backups.py
index a674586..2355012 100644
--- a/troveclient/tests/osc/v1/test_database_backups.py
+++ b/troveclient/tests/osc/v1/test_database_backups.py
@@ -10,6 +10,11 @@
10# License for the specific language governing permissions and limitations 10# License for the specific language governing permissions and limitations
11# under the License. 11# under the License.
12 12
13import mock
14
15from osc_lib import exceptions
16from osc_lib import utils
17
13from troveclient import common 18from troveclient import common
14from troveclient.osc.v1 import database_backups 19from troveclient.osc.v1 import database_backups
15from troveclient.tests.osc.v1 import fakes 20from troveclient.tests.osc.v1 import fakes
@@ -84,3 +89,29 @@ class TestBackupShow(TestBackups):
84 columns, data = self.cmd.take_action(parsed_args) 89 columns, data = self.cmd.take_action(parsed_args)
85 self.assertEqual(self.columns, columns) 90 self.assertEqual(self.columns, columns)
86 self.assertEqual(self.values, data) 91 self.assertEqual(self.values, data)
92
93
94class TestDatabaseBackupDelete(TestBackups):
95
96 def setUp(self):
97 super(TestDatabaseBackupDelete, self).setUp()
98 self.cmd = database_backups.DeleteDatabaseBackup(self.app, None)
99
100 @mock.patch.object(utils, 'find_resource')
101 def test_backup_delete(self, mock_find):
102 args = ['backup1']
103 mock_find.return_value = args[0]
104 parsed_args = self.check_parser(self.cmd, args, [])
105 result = self.cmd.take_action(parsed_args)
106 self.backup_client.delete.assert_called_with('backup1')
107 self.assertIsNone(result)
108
109 @mock.patch.object(utils, 'find_resource')
110 def test_backup_delete_with_exception(self, mock_find):
111 args = ['fakebackup']
112 parsed_args = self.check_parser(self.cmd, args, [])
113
114 mock_find.side_effect = exceptions.CommandError
115 self.assertRaises(exceptions.CommandError,
116 self.cmd.take_action,
117 parsed_args)