Fix the project option to user list so it filters
The --project option to the user list command was not implemented * Allow users to be filted by project * Support id or name of project with the find_resource command * Make sure the report does not contain duplicates Change-Id: Ic0e10cccd7749d38a7d4b80bbdc68e61a660084b Closes-Bug: #1177255
This commit is contained in:
parent
ee22070473
commit
e72072adc3
openstackclient
@ -156,6 +156,7 @@ class ListUser(lister.Lister):
|
|||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
self.log.debug('take_action(%s)' % parsed_args)
|
self.log.debug('take_action(%s)' % parsed_args)
|
||||||
|
identity_client = self.app.client_manager.identity
|
||||||
|
|
||||||
def _format_project(project):
|
def _format_project(project):
|
||||||
if not project:
|
if not project:
|
||||||
@ -165,6 +166,14 @@ class ListUser(lister.Lister):
|
|||||||
else:
|
else:
|
||||||
return project
|
return project
|
||||||
|
|
||||||
|
project = None
|
||||||
|
if parsed_args.project:
|
||||||
|
project = utils.find_resource(
|
||||||
|
identity_client.tenants,
|
||||||
|
parsed_args.project,
|
||||||
|
)
|
||||||
|
project = project.id
|
||||||
|
|
||||||
if parsed_args.long:
|
if parsed_args.long:
|
||||||
columns = (
|
columns = (
|
||||||
'ID',
|
'ID',
|
||||||
@ -183,14 +192,20 @@ class ListUser(lister.Lister):
|
|||||||
# Cache the project list
|
# Cache the project list
|
||||||
project_cache = {}
|
project_cache = {}
|
||||||
try:
|
try:
|
||||||
for p in self.app.client_manager.identity.tenants.list():
|
for p in identity_client.tenants.list():
|
||||||
project_cache[p.id] = p
|
project_cache[p.id] = p
|
||||||
except Exception:
|
except Exception:
|
||||||
# Just forget it if there's any trouble
|
# Just forget it if there's any trouble
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
columns = column_headers = ('ID', 'Name')
|
columns = column_headers = ('ID', 'Name')
|
||||||
data = self.app.client_manager.identity.users.list()
|
data = identity_client.users.list(tenant_id=project)
|
||||||
|
|
||||||
|
if parsed_args.project:
|
||||||
|
d = {}
|
||||||
|
for s in data:
|
||||||
|
d[s.id] = s
|
||||||
|
data = d.values()
|
||||||
|
|
||||||
if parsed_args.long:
|
if parsed_args.long:
|
||||||
# FIXME(dtroyer): Sometimes user objects have 'tenant_id' instead
|
# FIXME(dtroyer): Sometimes user objects have 'tenant_id' instead
|
||||||
|
@ -381,6 +381,11 @@ class TestUserList(TestUser):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestUserList, self).setUp()
|
super(TestUserList, self).setUp()
|
||||||
|
|
||||||
|
self.projects_mock.get.return_value = fakes.FakeResource(
|
||||||
|
None,
|
||||||
|
copy.deepcopy(identity_fakes.PROJECT_2),
|
||||||
|
loaded=True,
|
||||||
|
)
|
||||||
self.projects_mock.list.return_value = [
|
self.projects_mock.list.return_value = [
|
||||||
fakes.FakeResource(
|
fakes.FakeResource(
|
||||||
None,
|
None,
|
||||||
@ -408,7 +413,7 @@ class TestUserList(TestUser):
|
|||||||
# DisplayCommandBase.take_action() returns two tuples
|
# DisplayCommandBase.take_action() returns two tuples
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.users_mock.list.assert_called_with()
|
self.users_mock.list.assert_called_with(tenant_id=None)
|
||||||
|
|
||||||
collist = ('ID', 'Name')
|
collist = ('ID', 'Name')
|
||||||
self.assertEqual(columns, collist)
|
self.assertEqual(columns, collist)
|
||||||
@ -426,11 +431,12 @@ class TestUserList(TestUser):
|
|||||||
('project', identity_fakes.project_id),
|
('project', identity_fakes.project_id),
|
||||||
]
|
]
|
||||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
project_id = identity_fakes.PROJECT_2['id']
|
||||||
|
|
||||||
# DisplayCommandBase.take_action() returns two tuples
|
# DisplayCommandBase.take_action() returns two tuples
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.users_mock.list.assert_called_with()
|
self.users_mock.list.assert_called_with(tenant_id=project_id)
|
||||||
|
|
||||||
collist = ('ID', 'Name')
|
collist = ('ID', 'Name')
|
||||||
self.assertEqual(columns, collist)
|
self.assertEqual(columns, collist)
|
||||||
@ -452,7 +458,7 @@ class TestUserList(TestUser):
|
|||||||
# DisplayCommandBase.take_action() returns two tuples
|
# DisplayCommandBase.take_action() returns two tuples
|
||||||
columns, data = self.cmd.take_action(parsed_args)
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
self.users_mock.list.assert_called_with()
|
self.users_mock.list.assert_called_with(tenant_id=None)
|
||||||
|
|
||||||
collist = ('ID', 'Name', 'Project', 'Email', 'Enabled')
|
collist = ('ID', 'Name', 'Project', 'Email', 'Enabled')
|
||||||
self.assertEqual(columns, collist)
|
self.assertEqual(columns, collist)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user