Merge "Fix the project option to user list so it filters"
This commit is contained in:
		@@ -156,6 +156,7 @@ class ListUser(lister.Lister):
 | 
			
		||||
 | 
			
		||||
    def take_action(self, parsed_args):
 | 
			
		||||
        self.log.debug('take_action(%s)' % parsed_args)
 | 
			
		||||
        identity_client = self.app.client_manager.identity
 | 
			
		||||
 | 
			
		||||
        def _format_project(project):
 | 
			
		||||
            if not project:
 | 
			
		||||
@@ -165,6 +166,14 @@ class ListUser(lister.Lister):
 | 
			
		||||
            else:
 | 
			
		||||
                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:
 | 
			
		||||
            columns = (
 | 
			
		||||
                'ID',
 | 
			
		||||
@@ -183,14 +192,20 @@ class ListUser(lister.Lister):
 | 
			
		||||
            # Cache the project list
 | 
			
		||||
            project_cache = {}
 | 
			
		||||
            try:
 | 
			
		||||
                for p in self.app.client_manager.identity.tenants.list():
 | 
			
		||||
                for p in identity_client.tenants.list():
 | 
			
		||||
                    project_cache[p.id] = p
 | 
			
		||||
            except Exception:
 | 
			
		||||
                # Just forget it if there's any trouble
 | 
			
		||||
                pass
 | 
			
		||||
        else:
 | 
			
		||||
            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:
 | 
			
		||||
            # FIXME(dtroyer): Sometimes user objects have 'tenant_id' instead
 | 
			
		||||
 
 | 
			
		||||
@@ -381,6 +381,11 @@ class TestUserList(TestUser):
 | 
			
		||||
    def setUp(self):
 | 
			
		||||
        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 = [
 | 
			
		||||
            fakes.FakeResource(
 | 
			
		||||
                None,
 | 
			
		||||
@@ -408,7 +413,7 @@ class TestUserList(TestUser):
 | 
			
		||||
        # DisplayCommandBase.take_action() returns two tuples
 | 
			
		||||
        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')
 | 
			
		||||
        self.assertEqual(columns, collist)
 | 
			
		||||
@@ -426,11 +431,12 @@ class TestUserList(TestUser):
 | 
			
		||||
            ('project', identity_fakes.project_id),
 | 
			
		||||
        ]
 | 
			
		||||
        parsed_args = self.check_parser(self.cmd, arglist, verifylist)
 | 
			
		||||
        project_id = identity_fakes.PROJECT_2['id']
 | 
			
		||||
 | 
			
		||||
        # DisplayCommandBase.take_action() returns two tuples
 | 
			
		||||
        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')
 | 
			
		||||
        self.assertEqual(columns, collist)
 | 
			
		||||
@@ -452,7 +458,7 @@ class TestUserList(TestUser):
 | 
			
		||||
        # DisplayCommandBase.take_action() returns two tuples
 | 
			
		||||
        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')
 | 
			
		||||
        self.assertEqual(columns, collist)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user