Skip to content

Commit afba783

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Fix filter error in os volume list"
2 parents 89b7488 + 51ea68a commit afba783

3 files changed

Lines changed: 128 additions & 3 deletions

File tree

openstackclient/tests/unit/volume/v2/test_volume.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,19 @@ def test_volume_list_no_options(self):
823823

824824
columns, data = self.cmd.take_action(parsed_args)
825825

826+
search_opts = {
827+
'all_tenants': False,
828+
'project_id': None,
829+
'user_id': None,
830+
'display_name': None,
831+
'status': None,
832+
}
833+
self.volumes_mock.list.assert_called_once_with(
834+
search_opts=search_opts,
835+
marker=None,
836+
limit=None,
837+
)
838+
826839
self.assertEqual(self.columns, columns)
827840

828841
server = self.mock_volume.attachments[0]['server_id']
@@ -853,6 +866,19 @@ def test_volume_list_project(self):
853866

854867
columns, data = self.cmd.take_action(parsed_args)
855868

869+
search_opts = {
870+
'all_tenants': True,
871+
'project_id': self.project.id,
872+
'user_id': None,
873+
'display_name': None,
874+
'status': None,
875+
}
876+
self.volumes_mock.list.assert_called_once_with(
877+
search_opts=search_opts,
878+
marker=None,
879+
limit=None,
880+
)
881+
856882
self.assertEqual(self.columns, columns)
857883

858884
server = self.mock_volume.attachments[0]['server_id']
@@ -885,6 +911,19 @@ def test_volume_list_project_domain(self):
885911

886912
columns, data = self.cmd.take_action(parsed_args)
887913

914+
search_opts = {
915+
'all_tenants': True,
916+
'project_id': self.project.id,
917+
'user_id': None,
918+
'display_name': None,
919+
'status': None,
920+
}
921+
self.volumes_mock.list.assert_called_once_with(
922+
search_opts=search_opts,
923+
marker=None,
924+
limit=None,
925+
)
926+
888927
self.assertEqual(self.columns, columns)
889928

890929
server = self.mock_volume.attachments[0]['server_id']
@@ -915,6 +954,19 @@ def test_volume_list_user(self):
915954

916955
columns, data = self.cmd.take_action(parsed_args)
917956

957+
search_opts = {
958+
'all_tenants': False,
959+
'project_id': None,
960+
'user_id': self.user.id,
961+
'display_name': None,
962+
'status': None,
963+
}
964+
self.volumes_mock.list.assert_called_once_with(
965+
search_opts=search_opts,
966+
marker=None,
967+
limit=None,
968+
)
969+
918970
self.assertEqual(self.columns, columns)
919971
server = self.mock_volume.attachments[0]['server_id']
920972
device = self.mock_volume.attachments[0]['device']
@@ -946,6 +998,19 @@ def test_volume_list_user_domain(self):
946998

947999
columns, data = self.cmd.take_action(parsed_args)
9481000

1001+
search_opts = {
1002+
'all_tenants': False,
1003+
'project_id': None,
1004+
'user_id': self.user.id,
1005+
'display_name': None,
1006+
'status': None,
1007+
}
1008+
self.volumes_mock.list.assert_called_once_with(
1009+
search_opts=search_opts,
1010+
marker=None,
1011+
limit=None,
1012+
)
1013+
9491014
self.assertEqual(self.columns, columns)
9501015

9511016
server = self.mock_volume.attachments[0]['server_id']
@@ -976,6 +1041,19 @@ def test_volume_list_name(self):
9761041

9771042
columns, data = self.cmd.take_action(parsed_args)
9781043

1044+
search_opts = {
1045+
'all_tenants': False,
1046+
'project_id': None,
1047+
'user_id': None,
1048+
'display_name': self.mock_volume.name,
1049+
'status': None,
1050+
}
1051+
self.volumes_mock.list.assert_called_once_with(
1052+
search_opts=search_opts,
1053+
marker=None,
1054+
limit=None,
1055+
)
1056+
9791057
self.assertEqual(self.columns, columns)
9801058

9811059
server = self.mock_volume.attachments[0]['server_id']
@@ -1006,6 +1084,19 @@ def test_volume_list_status(self):
10061084

10071085
columns, data = self.cmd.take_action(parsed_args)
10081086

1087+
search_opts = {
1088+
'all_tenants': False,
1089+
'project_id': None,
1090+
'user_id': None,
1091+
'display_name': None,
1092+
'status': self.mock_volume.status,
1093+
}
1094+
self.volumes_mock.list.assert_called_once_with(
1095+
search_opts=search_opts,
1096+
marker=None,
1097+
limit=None,
1098+
)
1099+
10091100
self.assertEqual(self.columns, columns)
10101101

10111102
server = self.mock_volume.attachments[0]['server_id']
@@ -1036,6 +1127,19 @@ def test_volume_list_all_projects(self):
10361127

10371128
columns, data = self.cmd.take_action(parsed_args)
10381129

1130+
search_opts = {
1131+
'all_tenants': True,
1132+
'project_id': None,
1133+
'user_id': None,
1134+
'display_name': None,
1135+
'status': None,
1136+
}
1137+
self.volumes_mock.list.assert_called_once_with(
1138+
search_opts=search_opts,
1139+
marker=None,
1140+
limit=None,
1141+
)
1142+
10391143
self.assertEqual(self.columns, columns)
10401144

10411145
server = self.mock_volume.attachments[0]['server_id']
@@ -1067,6 +1171,19 @@ def test_volume_list_long(self):
10671171

10681172
columns, data = self.cmd.take_action(parsed_args)
10691173

1174+
search_opts = {
1175+
'all_tenants': False,
1176+
'project_id': None,
1177+
'user_id': None,
1178+
'display_name': None,
1179+
'status': None,
1180+
}
1181+
self.volumes_mock.list.assert_called_once_with(
1182+
search_opts=search_opts,
1183+
marker=None,
1184+
limit=None,
1185+
)
1186+
10701187
collist = [
10711188
'ID',
10721189
'Display Name',

openstackclient/volume/v2/volume.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,16 +417,19 @@ def _format_attach(attachments):
417417
project_id = identity_common.find_project(
418418
identity_client,
419419
parsed_args.project,
420-
parsed_args.project_domain)
420+
parsed_args.project_domain).id
421421

422422
user_id = None
423423
if parsed_args.user:
424424
user_id = identity_common.find_user(identity_client,
425425
parsed_args.user,
426-
parsed_args.user_domain)
426+
parsed_args.user_domain).id
427+
428+
# set value of 'all_tenants' when using project option
429+
all_projects = bool(parsed_args.project) or parsed_args.all_projects
427430

428431
search_opts = {
429-
'all_tenants': parsed_args.all_projects,
432+
'all_tenants': all_projects,
430433
'project_id': project_id,
431434
'user_id': user_id,
432435
'display_name': parsed_args.name,
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
Fix a bug of unable to filter volume list by ``--project``
5+
and ``--user`` options in the ``openstack volume list``.

0 commit comments

Comments
 (0)