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
This commit is contained in:
melanie witt 2021-08-12 22:06:36 +00:00
parent ed87f7949e
commit 12c93c6d5f
4 changed files with 43 additions and 0 deletions

View File

@ -103,6 +103,10 @@ class ListService(command.Lister):
"Updated At", "Updated At",
"Disabled Reason" "Disabled Reason"
) )
has_forced_down = (
compute_client.api_version >= api_versions.APIVersion('2.11'))
if has_forced_down:
columns += ("Forced Down",)
else: else:
columns = ( columns = (
"ID", "ID",

View File

@ -722,6 +722,8 @@ class FakeService(object):
'state': 'state-' + uuid.uuid4().hex, 'state': 'state-' + uuid.uuid4().hex,
'updated_at': 'time-' + uuid.uuid4().hex, 'updated_at': 'time-' + uuid.uuid4().hex,
'disabled_reason': 'earthquake', 'disabled_reason': 'earthquake',
# Introduced in API microversion 2.11
'forced_down': False,
} }
# Overwrite default attributes. # Overwrite default attributes.

View File

@ -190,6 +190,38 @@ class TestServiceList(TestService):
self.assertEqual(self.columns_long, columns) self.assertEqual(self.columns_long, columns)
self.assertEqual(self.data_long, list(data)) self.assertEqual(self.data_long, list(data))
def test_service_list_with_long_option_2_11(self):
arglist = [
'--host', self.service.host,
'--service', self.service.binary,
'--long'
]
verifylist = [
('host', self.service.host),
('service', self.service.binary),
('long', True)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.app.client_manager.compute.api_version = api_versions.APIVersion(
'2.11')
# In base command class Lister in cliff, abstract method take_action()
# returns a tuple containing the column names and an iterable
# containing the data to be listed.
columns, data = self.cmd.take_action(parsed_args)
self.service_mock.list.assert_called_with(
self.service.host,
self.service.binary,
)
# In 2.11 there is also a forced_down column.
columns_long = self.columns_long + ('Forced Down',)
data_long = [self.data_long[0] + (self.service.forced_down,)]
self.assertEqual(columns_long, columns)
self.assertEqual(data_long, list(data))
class TestServiceSet(TestService): class TestServiceSet(TestService):

View File

@ -0,0 +1,5 @@
---
features:
- |
Add column ``Forced Down`` to the output of ``compute service list
--long``. Only available starting with ``--os-compute-api-version 2.11``.