Skip to content

Commit 12c93c6

Browse files
committed
Show "Forced Down" compute service status with --long
Currently, the unified client does not have the ability to show the "Forced Down" field of a GET /os-services response in microversion 2.11 even though the legacy client can. This adds a "Forced Down" column to the 'openstack compute service list --long' command output when microversion 2.11 is used. Story: 2009115 Task: 43011 Change-Id: I10bc2fedbf0e867a990227962b2b6e60f5681f69
1 parent ed87f79 commit 12c93c6

4 files changed

Lines changed: 43 additions & 0 deletions

File tree

openstackclient/compute/v2/service.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ def take_action(self, parsed_args):
103103
"Updated At",
104104
"Disabled Reason"
105105
)
106+
has_forced_down = (
107+
compute_client.api_version >= api_versions.APIVersion('2.11'))
108+
if has_forced_down:
109+
columns += ("Forced Down",)
106110
else:
107111
columns = (
108112
"ID",

openstackclient/tests/unit/compute/v2/fakes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,8 @@ def create_one_service(attrs=None):
722722
'state': 'state-' + uuid.uuid4().hex,
723723
'updated_at': 'time-' + uuid.uuid4().hex,
724724
'disabled_reason': 'earthquake',
725+
# Introduced in API microversion 2.11
726+
'forced_down': False,
725727
}
726728

727729
# Overwrite default attributes.

openstackclient/tests/unit/compute/v2/test_service.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,38 @@ def test_service_list_with_long_option(self):
190190
self.assertEqual(self.columns_long, columns)
191191
self.assertEqual(self.data_long, list(data))
192192

193+
def test_service_list_with_long_option_2_11(self):
194+
arglist = [
195+
'--host', self.service.host,
196+
'--service', self.service.binary,
197+
'--long'
198+
]
199+
verifylist = [
200+
('host', self.service.host),
201+
('service', self.service.binary),
202+
('long', True)
203+
]
204+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
205+
self.app.client_manager.compute.api_version = api_versions.APIVersion(
206+
'2.11')
207+
208+
# In base command class Lister in cliff, abstract method take_action()
209+
# returns a tuple containing the column names and an iterable
210+
# containing the data to be listed.
211+
columns, data = self.cmd.take_action(parsed_args)
212+
213+
self.service_mock.list.assert_called_with(
214+
self.service.host,
215+
self.service.binary,
216+
)
217+
218+
# In 2.11 there is also a forced_down column.
219+
columns_long = self.columns_long + ('Forced Down',)
220+
data_long = [self.data_long[0] + (self.service.forced_down,)]
221+
222+
self.assertEqual(columns_long, columns)
223+
self.assertEqual(data_long, list(data))
224+
193225

194226
class TestServiceSet(TestService):
195227

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Add column ``Forced Down`` to the output of ``compute service list
5+
--long``. Only available starting with ``--os-compute-api-version 2.11``.

0 commit comments

Comments
 (0)