Fix filter error in os volume list
This patch fixed a bug of unable to filter volume list by '--project', '--user' in "openstack volume list". Modify uint test for 'volume list' to check parameter of list method. Change-Id: I1fc4296c4c7eca0f7a803dbfd5e15e3bc0d6403f
This commit is contained in:
		@@ -823,6 +823,19 @@ class TestVolumeList(TestVolume):
 | 
			
		||||
 | 
			
		||||
        columns, data = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        search_opts = {
 | 
			
		||||
            'all_tenants': False,
 | 
			
		||||
            'project_id': None,
 | 
			
		||||
            'user_id': None,
 | 
			
		||||
            'display_name': None,
 | 
			
		||||
            'status': None,
 | 
			
		||||
        }
 | 
			
		||||
        self.volumes_mock.list.assert_called_once_with(
 | 
			
		||||
            search_opts=search_opts,
 | 
			
		||||
            marker=None,
 | 
			
		||||
            limit=None,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(self.columns, columns)
 | 
			
		||||
 | 
			
		||||
        server = self.mock_volume.attachments[0]['server_id']
 | 
			
		||||
@@ -853,6 +866,19 @@ class TestVolumeList(TestVolume):
 | 
			
		||||
 | 
			
		||||
        columns, data = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        search_opts = {
 | 
			
		||||
            'all_tenants': True,
 | 
			
		||||
            'project_id': self.project.id,
 | 
			
		||||
            'user_id': None,
 | 
			
		||||
            'display_name': None,
 | 
			
		||||
            'status': None,
 | 
			
		||||
        }
 | 
			
		||||
        self.volumes_mock.list.assert_called_once_with(
 | 
			
		||||
            search_opts=search_opts,
 | 
			
		||||
            marker=None,
 | 
			
		||||
            limit=None,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(self.columns, columns)
 | 
			
		||||
 | 
			
		||||
        server = self.mock_volume.attachments[0]['server_id']
 | 
			
		||||
@@ -885,6 +911,19 @@ class TestVolumeList(TestVolume):
 | 
			
		||||
 | 
			
		||||
        columns, data = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        search_opts = {
 | 
			
		||||
            'all_tenants': True,
 | 
			
		||||
            'project_id': self.project.id,
 | 
			
		||||
            'user_id': None,
 | 
			
		||||
            'display_name': None,
 | 
			
		||||
            'status': None,
 | 
			
		||||
        }
 | 
			
		||||
        self.volumes_mock.list.assert_called_once_with(
 | 
			
		||||
            search_opts=search_opts,
 | 
			
		||||
            marker=None,
 | 
			
		||||
            limit=None,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(self.columns, columns)
 | 
			
		||||
 | 
			
		||||
        server = self.mock_volume.attachments[0]['server_id']
 | 
			
		||||
@@ -915,6 +954,19 @@ class TestVolumeList(TestVolume):
 | 
			
		||||
 | 
			
		||||
        columns, data = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        search_opts = {
 | 
			
		||||
            'all_tenants': False,
 | 
			
		||||
            'project_id': None,
 | 
			
		||||
            'user_id': self.user.id,
 | 
			
		||||
            'display_name': None,
 | 
			
		||||
            'status': None,
 | 
			
		||||
        }
 | 
			
		||||
        self.volumes_mock.list.assert_called_once_with(
 | 
			
		||||
            search_opts=search_opts,
 | 
			
		||||
            marker=None,
 | 
			
		||||
            limit=None,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(self.columns, columns)
 | 
			
		||||
        server = self.mock_volume.attachments[0]['server_id']
 | 
			
		||||
        device = self.mock_volume.attachments[0]['device']
 | 
			
		||||
@@ -946,6 +998,19 @@ class TestVolumeList(TestVolume):
 | 
			
		||||
 | 
			
		||||
        columns, data = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        search_opts = {
 | 
			
		||||
            'all_tenants': False,
 | 
			
		||||
            'project_id': None,
 | 
			
		||||
            'user_id': self.user.id,
 | 
			
		||||
            'display_name': None,
 | 
			
		||||
            'status': None,
 | 
			
		||||
        }
 | 
			
		||||
        self.volumes_mock.list.assert_called_once_with(
 | 
			
		||||
            search_opts=search_opts,
 | 
			
		||||
            marker=None,
 | 
			
		||||
            limit=None,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(self.columns, columns)
 | 
			
		||||
 | 
			
		||||
        server = self.mock_volume.attachments[0]['server_id']
 | 
			
		||||
@@ -976,6 +1041,19 @@ class TestVolumeList(TestVolume):
 | 
			
		||||
 | 
			
		||||
        columns, data = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        search_opts = {
 | 
			
		||||
            'all_tenants': False,
 | 
			
		||||
            'project_id': None,
 | 
			
		||||
            'user_id': None,
 | 
			
		||||
            'display_name': self.mock_volume.name,
 | 
			
		||||
            'status': None,
 | 
			
		||||
        }
 | 
			
		||||
        self.volumes_mock.list.assert_called_once_with(
 | 
			
		||||
            search_opts=search_opts,
 | 
			
		||||
            marker=None,
 | 
			
		||||
            limit=None,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(self.columns, columns)
 | 
			
		||||
 | 
			
		||||
        server = self.mock_volume.attachments[0]['server_id']
 | 
			
		||||
@@ -1006,6 +1084,19 @@ class TestVolumeList(TestVolume):
 | 
			
		||||
 | 
			
		||||
        columns, data = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        search_opts = {
 | 
			
		||||
            'all_tenants': False,
 | 
			
		||||
            'project_id': None,
 | 
			
		||||
            'user_id': None,
 | 
			
		||||
            'display_name': None,
 | 
			
		||||
            'status': self.mock_volume.status,
 | 
			
		||||
        }
 | 
			
		||||
        self.volumes_mock.list.assert_called_once_with(
 | 
			
		||||
            search_opts=search_opts,
 | 
			
		||||
            marker=None,
 | 
			
		||||
            limit=None,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(self.columns, columns)
 | 
			
		||||
 | 
			
		||||
        server = self.mock_volume.attachments[0]['server_id']
 | 
			
		||||
@@ -1036,6 +1127,19 @@ class TestVolumeList(TestVolume):
 | 
			
		||||
 | 
			
		||||
        columns, data = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        search_opts = {
 | 
			
		||||
            'all_tenants': True,
 | 
			
		||||
            'project_id': None,
 | 
			
		||||
            'user_id': None,
 | 
			
		||||
            'display_name': None,
 | 
			
		||||
            'status': None,
 | 
			
		||||
        }
 | 
			
		||||
        self.volumes_mock.list.assert_called_once_with(
 | 
			
		||||
            search_opts=search_opts,
 | 
			
		||||
            marker=None,
 | 
			
		||||
            limit=None,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        self.assertEqual(self.columns, columns)
 | 
			
		||||
 | 
			
		||||
        server = self.mock_volume.attachments[0]['server_id']
 | 
			
		||||
@@ -1067,6 +1171,19 @@ class TestVolumeList(TestVolume):
 | 
			
		||||
 | 
			
		||||
        columns, data = self.cmd.take_action(parsed_args)
 | 
			
		||||
 | 
			
		||||
        search_opts = {
 | 
			
		||||
            'all_tenants': False,
 | 
			
		||||
            'project_id': None,
 | 
			
		||||
            'user_id': None,
 | 
			
		||||
            'display_name': None,
 | 
			
		||||
            'status': None,
 | 
			
		||||
        }
 | 
			
		||||
        self.volumes_mock.list.assert_called_once_with(
 | 
			
		||||
            search_opts=search_opts,
 | 
			
		||||
            marker=None,
 | 
			
		||||
            limit=None,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
        collist = [
 | 
			
		||||
            'ID',
 | 
			
		||||
            'Display Name',
 | 
			
		||||
 
 | 
			
		||||
@@ -417,16 +417,19 @@ class ListVolume(command.Lister):
 | 
			
		||||
            project_id = identity_common.find_project(
 | 
			
		||||
                identity_client,
 | 
			
		||||
                parsed_args.project,
 | 
			
		||||
                parsed_args.project_domain)
 | 
			
		||||
                parsed_args.project_domain).id
 | 
			
		||||
 | 
			
		||||
        user_id = None
 | 
			
		||||
        if parsed_args.user:
 | 
			
		||||
            user_id = identity_common.find_user(identity_client,
 | 
			
		||||
                                                parsed_args.user,
 | 
			
		||||
                                                parsed_args.user_domain)
 | 
			
		||||
                                                parsed_args.user_domain).id
 | 
			
		||||
 | 
			
		||||
        # set value of 'all_tenants' when using project option
 | 
			
		||||
        all_projects = bool(parsed_args.project) or parsed_args.all_projects
 | 
			
		||||
 | 
			
		||||
        search_opts = {
 | 
			
		||||
            'all_tenants': parsed_args.all_projects,
 | 
			
		||||
            'all_tenants': all_projects,
 | 
			
		||||
            'project_id': project_id,
 | 
			
		||||
            'user_id': user_id,
 | 
			
		||||
            'display_name': parsed_args.name,
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,5 @@
 | 
			
		||||
---
 | 
			
		||||
fixes:
 | 
			
		||||
  - |
 | 
			
		||||
    Fix a bug of unable to filter volume list by ``--project``
 | 
			
		||||
    and ``--user`` options in the ``openstack volume list``.
 | 
			
		||||
		Reference in New Issue
	
	Block a user