Skip to content

Commit 0f74e80

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Follow-on for volume list - add tests, clean help"
2 parents d3e2e35 + 195a0ed commit 0f74e80

6 files changed

Lines changed: 365 additions & 26 deletions

File tree

doc/source/command-objects/volume.rst

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,34 +109,44 @@ List volumes
109109
[--status <status>]
110110
[--long]
111111
112-
.. option:: --all-projects
113-
114112
.. option:: --project <project>
115113
116114
Filter results by project (name or ID) (admin only)
117115
116+
*Volume version 2 only*
117+
118118
.. option:: --project-domain <project-domain>
119119
120120
Domain the project belongs to (name or ID).
121121
This can be used in case collisions between project names exist.
122122
123+
*Volume version 2 only*
124+
123125
.. option:: --user <user>
124126
125127
Filter results by user (name or ID) (admin only)
126128
129+
*Volume version 2 only*
130+
127131
.. option:: --user-domain <user-domain>
128132
129133
Domain the user belongs to (name or ID).
130134
This can be used in case collisions between user names exist.
131135
136+
*Volume version 2 only*
137+
132138
.. option:: --name <name>
133139
134-
Filter results by name
140+
Filter results by volume name
135141
136142
.. option:: --status <status>
137143
138144
Filter results by status
139145
146+
.. option:: --all-projects
147+
148+
Include all projects (admin only)
149+
140150
.. option:: --long
141151
142152
List additional fields in output

openstackclient/tests/volume/v1/test_volume.py

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,188 @@ def test_volume_create_image_name(self):
527527
self.assertEqual(datalist, data)
528528

529529

530+
class TestVolumeList(TestVolume):
531+
532+
def setUp(self):
533+
super(TestVolumeList, self).setUp()
534+
535+
self.volumes_mock.list.return_value = [
536+
fakes.FakeResource(
537+
None,
538+
copy.deepcopy(volume_fakes.VOLUME),
539+
loaded=True,
540+
),
541+
]
542+
543+
# Get the command object to test
544+
self.cmd = volume.ListVolume(self.app, None)
545+
546+
def test_volume_list_no_options(self):
547+
arglist = []
548+
verifylist = [
549+
('long', False),
550+
('all_projects', False),
551+
('name', None),
552+
('status', None),
553+
]
554+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
555+
556+
columns, data = self.cmd.take_action(parsed_args)
557+
558+
collist = (
559+
'ID',
560+
'Display Name',
561+
'Status',
562+
'Size',
563+
'Attached to',
564+
)
565+
self.assertEqual(collist, columns)
566+
567+
datalist = ((
568+
volume_fakes.volume_id,
569+
volume_fakes.volume_name,
570+
volume_fakes.volume_status,
571+
volume_fakes.volume_size,
572+
'',
573+
), )
574+
self.assertEqual(datalist, tuple(data))
575+
576+
def test_volume_list_name(self):
577+
arglist = [
578+
'--name', volume_fakes.volume_name,
579+
]
580+
verifylist = [
581+
('long', False),
582+
('all_projects', False),
583+
('name', volume_fakes.volume_name),
584+
('status', None),
585+
]
586+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
587+
588+
columns, data = self.cmd.take_action(parsed_args)
589+
590+
collist = (
591+
'ID',
592+
'Display Name',
593+
'Status',
594+
'Size',
595+
'Attached to',
596+
)
597+
self.assertEqual(collist, tuple(columns))
598+
599+
datalist = ((
600+
volume_fakes.volume_id,
601+
volume_fakes.volume_name,
602+
volume_fakes.volume_status,
603+
volume_fakes.volume_size,
604+
'',
605+
), )
606+
self.assertEqual(datalist, tuple(data))
607+
608+
def test_volume_list_status(self):
609+
arglist = [
610+
'--status', volume_fakes.volume_status,
611+
]
612+
verifylist = [
613+
('long', False),
614+
('all_projects', False),
615+
('name', None),
616+
('status', volume_fakes.volume_status),
617+
]
618+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
619+
620+
columns, data = self.cmd.take_action(parsed_args)
621+
622+
collist = (
623+
'ID',
624+
'Display Name',
625+
'Status',
626+
'Size',
627+
'Attached to',
628+
)
629+
self.assertEqual(collist, tuple(columns))
630+
631+
datalist = ((
632+
volume_fakes.volume_id,
633+
volume_fakes.volume_name,
634+
volume_fakes.volume_status,
635+
volume_fakes.volume_size,
636+
'',
637+
), )
638+
self.assertEqual(datalist, tuple(data))
639+
640+
def test_volume_list_all_projects(self):
641+
arglist = [
642+
'--all-projects',
643+
]
644+
verifylist = [
645+
('long', False),
646+
('all_projects', True),
647+
('name', None),
648+
('status', None),
649+
]
650+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
651+
652+
columns, data = self.cmd.take_action(parsed_args)
653+
654+
collist = (
655+
'ID',
656+
'Display Name',
657+
'Status',
658+
'Size',
659+
'Attached to',
660+
)
661+
self.assertEqual(collist, columns)
662+
663+
datalist = ((
664+
volume_fakes.volume_id,
665+
volume_fakes.volume_name,
666+
volume_fakes.volume_status,
667+
volume_fakes.volume_size,
668+
'',
669+
), )
670+
self.assertEqual(datalist, tuple(data))
671+
672+
def test_volume_list_long(self):
673+
arglist = [
674+
'--long',
675+
]
676+
verifylist = [
677+
('long', True),
678+
('all_projects', False),
679+
('name', None),
680+
('status', None),
681+
]
682+
683+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
684+
685+
columns, data = self.cmd.take_action(parsed_args)
686+
687+
collist = (
688+
'ID',
689+
'Display Name',
690+
'Status',
691+
'Size',
692+
'Type',
693+
'Bootable',
694+
'Attached to',
695+
'Properties',
696+
)
697+
self.assertEqual(collist, columns)
698+
699+
datalist = ((
700+
volume_fakes.volume_id,
701+
volume_fakes.volume_name,
702+
volume_fakes.volume_status,
703+
volume_fakes.volume_size,
704+
volume_fakes.volume_type,
705+
'',
706+
'',
707+
"Alpha='a', Beta='b', Gamma='g'",
708+
), )
709+
self.assertEqual(datalist, tuple(data))
710+
711+
530712
class TestVolumeSet(TestVolume):
531713

532714
def setUp(self):

openstackclient/tests/volume/v2/fakes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import mock
1717

1818
from openstackclient.tests import fakes
19-
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
19+
from openstackclient.tests.identity.v3 import fakes as identity_fakes
2020
from openstackclient.tests.image.v2 import fakes as image_fakes
2121
from openstackclient.tests import utils
2222

@@ -212,7 +212,7 @@ def setUp(self):
212212
endpoint=fakes.AUTH_URL,
213213
token=fakes.AUTH_TOKEN
214214
)
215-
self.app.client_manager.identity = identity_fakes.FakeIdentityv2Client(
215+
self.app.client_manager.identity = identity_fakes.FakeIdentityv3Client(
216216
endpoint=fakes.AUTH_URL,
217217
token=fakes.AUTH_TOKEN
218218
)

0 commit comments

Comments
 (0)