summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2017-12-07 05:14:18 +0000
committerGerrit Code Review <review@openstack.org>2017-12-07 05:14:18 +0000
commit8c4db024188f7e70ca70b0effd1584c947ce1825 (patch)
tree7cf897e01caecc9ac4ab92e0c9d51984fe458699
parent336b50b165512a975f7abce6c28e478982ab6a48 (diff)
parentd7e5252d8ca0f97857d24e319fe7f71716323a17 (diff)
Merge "Add backup-show to OSC"
-rw-r--r--releasenotes/notes/add-backup-show-to-osc-022f42ad93136ce6.yaml5
-rw-r--r--setup.cfg1
-rw-r--r--troveclient/osc/v1/database_backups.py30
-rw-r--r--troveclient/tests/osc/v1/test_database_backups.py36
4 files changed, 72 insertions, 0 deletions
diff --git a/releasenotes/notes/add-backup-show-to-osc-022f42ad93136ce6.yaml b/releasenotes/notes/add-backup-show-to-osc-022f42ad93136ce6.yaml
new file mode 100644
index 0000000..277ba01
--- /dev/null
+++ b/releasenotes/notes/add-backup-show-to-osc-022f42ad93136ce6.yaml
@@ -0,0 +1,5 @@
1---
2features:
3 - The command ``trove backup-show`` is now available to use in
4 the python-openstackclient CLI as ``openstack database backup
5 show``
diff --git a/setup.cfg b/setup.cfg
index 9def235..cb80903 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -31,6 +31,7 @@ openstack.cli.extension =
31 31
32openstack.database.v1 = 32openstack.database.v1 =
33 database_backup_list = troveclient.osc.v1.database_backups:ListDatabaseBackups 33 database_backup_list = troveclient.osc.v1.database_backups:ListDatabaseBackups
34 database_backup_show = troveclient.osc.v1.database_backups:ShowDatabaseBackup
34 database_cluster_list = troveclient.osc.v1.database_clusters:ListDatabaseClusters 35 database_cluster_list = troveclient.osc.v1.database_clusters:ListDatabaseClusters
35 database_configuration_list = troveclient.osc.v1.database_configurations:ListDatabaseConfigurations 36 database_configuration_list = troveclient.osc.v1.database_configurations:ListDatabaseConfigurations
36 database_configuration_show = troveclient.osc.v1.database_configurations:ShowDatabaseConfiguration 37 database_configuration_show = troveclient.osc.v1.database_configurations:ShowDatabaseConfiguration
diff --git a/troveclient/osc/v1/database_backups.py b/troveclient/osc/v1/database_backups.py
index a7bd29e..8989596 100644
--- a/troveclient/osc/v1/database_backups.py
+++ b/troveclient/osc/v1/database_backups.py
@@ -14,10 +14,20 @@
14 14
15from osc_lib.command import command 15from osc_lib.command import command
16from osc_lib import utils as osc_utils 16from osc_lib import utils as osc_utils
17import six
17 18
18from troveclient.i18n import _ 19from troveclient.i18n import _
19 20
20 21
22def set_attributes_for_print_detail(backup):
23 info = backup._info.copy()
24 if hasattr(backup, 'datastore'):
25 info['datastore'] = backup.datastore['type']
26 info['datastore_version'] = backup.datastore['version']
27 info['datastore_version_id'] = backup.datastore['version_id']
28 return info
29
30
21class ListDatabaseBackups(command.Lister): 31class ListDatabaseBackups(command.Lister):
22 32
23 _description = _("List database backups") 33 _description = _("List database backups")
@@ -64,3 +74,23 @@ class ListDatabaseBackups(command.Lister):
64 backups = [osc_utils.get_item_properties(b, self.columns) 74 backups = [osc_utils.get_item_properties(b, self.columns)
65 for b in backups] 75 for b in backups]
66 return self.columns, backups 76 return self.columns, backups
77
78
79class ShowDatabaseBackup(command.ShowOne):
80
81 _description = _("Shows details of a database backup")
82
83 def get_parser(self, prog_name):
84 parser = super(ShowDatabaseBackup, self).get_parser(prog_name)
85 parser.add_argument(
86 'backup',
87 metavar='<backup>',
88 help=_('ID or name of the backup'),
89 )
90 return parser
91
92 def take_action(self, parsed_args):
93 database_backups = self.app.client_manager.database.backups
94 backup = osc_utils.find_resource(database_backups, parsed_args.backup)
95 backup = set_attributes_for_print_detail(backup)
96 return zip(*sorted(six.iteritems(backup)))
diff --git a/troveclient/tests/osc/v1/test_database_backups.py b/troveclient/tests/osc/v1/test_database_backups.py
index 05fa18b..a674586 100644
--- a/troveclient/tests/osc/v1/test_database_backups.py
+++ b/troveclient/tests/osc/v1/test_database_backups.py
@@ -48,3 +48,39 @@ class TestBackupList(TestBackups):
48 self.backup_client.list.assert_called_once_with(**self.defaults) 48 self.backup_client.list.assert_called_once_with(**self.defaults)
49 self.assertEqual(self.columns, columns) 49 self.assertEqual(self.columns, columns)
50 self.assertEqual([self.values], data) 50 self.assertEqual([self.values], data)
51
52
53class TestBackupShow(TestBackups):
54
55 values = ('2015-05-16T14:22:28', 'mysql', '5.6', 'v-56', None, 'bk-1234',
56 '1234',
57 'http://backup_srvr/database_backups/bk-1234.xbstream.gz.enc',
58 'bkp_1', None, 0.11, 'COMPLETED', '2015-05-16T14:23:08')
59
60 def setUp(self):
61 super(TestBackupShow, self).setUp()
62 self.cmd = database_backups.ShowDatabaseBackup(self.app, None)
63 self.data = self.fake_backups.get_backup_bk_1234()
64 self.backup_client.get.return_value = self.data
65 self.columns = (
66 'created',
67 'datastore',
68 'datastore_version',
69 'datastore_version_id',
70 'description',
71 'id',
72 'instance_id',
73 'locationRef',
74 'name',
75 'parent_id',
76 'size',
77 'status',
78 'updated',
79 )
80
81 def test_show(self):
82 args = ['bkp_1']
83 parsed_args = self.check_parser(self.cmd, args, [])
84 columns, data = self.cmd.take_action(parsed_args)
85 self.assertEqual(self.columns, columns)
86 self.assertEqual(self.values, data)