Skip to content

Commit 8664a2f

Browse files
committed
Support "--long" option in ListService
Add "--long" option in ListService so that compute service disabled reason can be showed. Change-Id: I1ace8f1c4e4efe0a1a8f6710425d73eb5db9e5e1 Closes-Bug: #1556815
1 parent 7608123 commit 8664a2f

4 files changed

Lines changed: 59 additions & 10 deletions

File tree

doc/source/command-objects/compute-service.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ List service command
3131
os compute service list
3232
[--host <host>]
3333
[--service <service>]
34+
[--long]
3435
3536
.. _compute-service-list:
3637
.. describe:: --host <host>
@@ -41,6 +42,10 @@ List service command
4142

4243
Name of service
4344

45+
.. describe:: --long
46+
47+
List additional fields in output
48+
4449

4550
compute service set
4651
-------------------

openstackclient/compute/v2/service.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,37 @@ def get_parser(self, prog_name):
4949
"--service",
5050
metavar="<service>",
5151
help="Name of service")
52+
parser.add_argument(
53+
"--long",
54+
action="store_true",
55+
default=False,
56+
help="List additional fields in output"
57+
)
5258
return parser
5359

5460
def take_action(self, parsed_args):
5561
compute_client = self.app.client_manager.compute
56-
columns = (
57-
"Id",
58-
"Binary",
59-
"Host",
60-
"Zone",
61-
"Status",
62-
"State",
63-
"Updated At"
64-
)
62+
if parsed_args.long:
63+
columns = (
64+
"Id",
65+
"Binary",
66+
"Host",
67+
"Zone",
68+
"Status",
69+
"State",
70+
"Updated At",
71+
"Disabled Reason"
72+
)
73+
else:
74+
columns = (
75+
"Id",
76+
"Binary",
77+
"Host",
78+
"Zone",
79+
"Status",
80+
"State",
81+
"Updated At"
82+
)
6583
data = compute_client.services.list(parsed_args.host,
6684
parsed_args.service)
6785
return (columns,

openstackclient/tests/compute/v2/fakes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@
7979
service_host = 'host_test'
8080
service_binary = 'compute_test'
8181
service_status = 'enabled'
82+
service_disabled_reason = 'earthquake'
8283
SERVICE = {
8384
'host': service_host,
8485
'binary': service_binary,
8586
'status': service_status,
87+
'disabled_reason': service_disabled_reason,
8688
}
8789

8890

openstackclient/tests/compute/v2/test_service.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,37 @@ def test_service_list(self):
8585
# In base command class Lister in cliff, abstract method take_action()
8686
# returns a tuple containing the column names and an iterable
8787
# containing the data to be listed.
88-
self.cmd.take_action(parsed_args)
88+
columns, data = self.cmd.take_action(parsed_args)
8989

9090
self.service_mock.list.assert_called_with(
9191
compute_fakes.service_host,
9292
compute_fakes.service_binary,
9393
)
9494

95+
self.assertNotIn("Disabled Reason", columns)
96+
self.assertNotIn(compute_fakes.service_disabled_reason, list(data)[0])
97+
98+
def test_service_list_with_long_option(self):
99+
arglist = [
100+
'--host', compute_fakes.service_host,
101+
'--service', compute_fakes.service_binary,
102+
'--long'
103+
]
104+
verifylist = [
105+
('host', compute_fakes.service_host),
106+
('service', compute_fakes.service_binary),
107+
('long', True)
108+
]
109+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
110+
111+
# In base command class Lister in cliff, abstract method take_action()
112+
# returns a tuple containing the column names and an iterable
113+
# containing the data to be listed.
114+
columns, data = self.cmd.take_action(parsed_args)
115+
116+
self.assertIn("Disabled Reason", columns)
117+
self.assertIn(compute_fakes.service_disabled_reason, list(data)[0])
118+
95119

96120
class TestServiceSet(TestService):
97121

0 commit comments

Comments
 (0)