summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwangyao <wangyao@cmss.chinamobile.com>2017-12-07 18:53:12 +0800
committerwangyao <wangyao@cmss.chinamobile.com>2017-12-07 21:36:24 +0800
commit854d3e2a3186bc64a2148a68570176eedf5fb5b6 (patch)
tree2105a2def58ee89e35077e84b16aab463e9c44e3
parent22ae4cf93788c73ccdd639423989f70be339dbac (diff)
Add user-show to OSC
This change adds database support to the python-openstackclient project for the user-show command. The trove command user-show is now: openstack database user show Change-Id: I92455f1606c8a20b477fdbe66daf98e59cc19fd7 Partially-Implements: trove-support-in-python-openstackclient
Notes
Notes (review): Code-Review+2: Manoj Kumar <manoj@linux.vnet.ibm.com> Workflow+1: Manoj Kumar <manoj@linux.vnet.ibm.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Fri, 08 Dec 2017 00:56:43 +0000 Reviewed-on: https://review.openstack.org/526338 Project: openstack/python-troveclient Branch: refs/heads/master
-rw-r--r--releasenotes/notes/add-user-show-to-osc-6ef3db10a82f1f46.yaml5
-rw-r--r--setup.cfg1
-rw-r--r--troveclient/osc/v1/database_users.py31
-rw-r--r--troveclient/tests/osc/v1/test_database_users.py22
4 files changed, 59 insertions, 0 deletions
diff --git a/releasenotes/notes/add-user-show-to-osc-6ef3db10a82f1f46.yaml b/releasenotes/notes/add-user-show-to-osc-6ef3db10a82f1f46.yaml
new file mode 100644
index 0000000..459d191
--- /dev/null
+++ b/releasenotes/notes/add-user-show-to-osc-6ef3db10a82f1f46.yaml
@@ -0,0 +1,5 @@
1---
2features:
3 - The command ``trove user-show`` is now available to use in
4 the python-openstackclient CLI as ``openstack database user
5 show``
diff --git a/setup.cfg b/setup.cfg
index d8aba3e..032800a 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -43,6 +43,7 @@ openstack.database.v1 =
43 database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits 43 database_limit_list = troveclient.osc.v1.database_limits:ListDatabaseLimits
44 database_list = troveclient.osc.v1.databases:ListDatabases 44 database_list = troveclient.osc.v1.databases:ListDatabases
45 database_user_list = troveclient.osc.v1.database_users:ListDatabaseUsers 45 database_user_list = troveclient.osc.v1.database_users:ListDatabaseUsers
46 database_user_show = troveclient.osc.v1.database_users:ShowDatabaseUser
46 datastore_list = troveclient.osc.v1.datastores:ListDatastores 47 datastore_list = troveclient.osc.v1.datastores:ListDatastores
47 datastore_show = troveclient.osc.v1.datastores:ShowDatastore 48 datastore_show = troveclient.osc.v1.datastores:ShowDatastore
48 49
diff --git a/troveclient/osc/v1/database_users.py b/troveclient/osc/v1/database_users.py
index 3cf6ffe..5a22133 100644
--- a/troveclient/osc/v1/database_users.py
+++ b/troveclient/osc/v1/database_users.py
@@ -14,6 +14,7 @@
14 14
15from osc_lib.command import command 15from osc_lib.command import command
16from osc_lib import utils 16from osc_lib import utils
17import six
17 18
18from troveclient.i18n import _ 19from troveclient.i18n import _
19 20
@@ -44,3 +45,33 @@ class ListDatabaseUsers(command.Lister):
44 user.databases = ', '.join(db_names) 45 user.databases = ', '.join(db_names)
45 users = [utils.get_item_properties(u, self.columns) for u in users] 46 users = [utils.get_item_properties(u, self.columns) for u in users]
46 return self.columns, users 47 return self.columns, users
48
49
50class ShowDatabaseUser(command.ShowOne):
51
52 _description = _("Shows details of a database user of an instance.")
53
54 def get_parser(self, prog_name):
55 parser = super(ShowDatabaseUser, self).get_parser(prog_name)
56 parser.add_argument(
57 'instance',
58 metavar='<instance>',
59 help=_('ID of the instance.'),
60 )
61 parser.add_argument(
62 'name',
63 metavar='<name>',
64 help=_('Name of user.'),
65 )
66 parser.add_argument(
67 "--host",
68 metavar="<host>",
69 help=_("Optional host of user."),
70 )
71 return parser
72
73 def take_action(self, parsed_args):
74 db_users = self.app.client_manager.database.users
75 user = db_users.get(parsed_args.instance, parsed_args.name,
76 hostname=parsed_args.host)
77 return zip(*sorted(six.iteritems(user._info)))
diff --git a/troveclient/tests/osc/v1/test_database_users.py b/troveclient/tests/osc/v1/test_database_users.py
index ecef4d8..fe5a19c 100644
--- a/troveclient/tests/osc/v1/test_database_users.py
+++ b/troveclient/tests/osc/v1/test_database_users.py
@@ -40,3 +40,25 @@ class TestUserList(TestUsers):
40 self.user_client.list.assert_called_once_with(*args) 40 self.user_client.list.assert_called_once_with(*args)
41 self.assertEqual(self.columns, columns) 41 self.assertEqual(self.columns, columns)
42 self.assertEqual([self.values], data) 42 self.assertEqual([self.values], data)
43
44
45class TestUserShow(TestUsers):
46 values = ([{'name': 'db1'}], '%', 'harry')
47
48 def setUp(self):
49 super(TestUserShow, self).setUp()
50 self.cmd = database_users.ShowDatabaseUser(self.app, None)
51 self.data = self.fake_users.get_instances_1234_users_harry()
52 self.user_client.get.return_value = self.data
53 self.columns = (
54 'databases',
55 'host',
56 'name',
57 )
58
59 def test_user_show_defaults(self):
60 args = ['my_instance', 'harry']
61 parsed_args = self.check_parser(self.cmd, args, [])
62 columns, data = self.cmd.take_action(parsed_args)
63 self.assertEqual(self.columns, columns)
64 self.assertEqual(self.values, data)