Support for reporting backend state in service list

This patch will support the feature: report backend state in service list
in client side.

Depends-On: I561dca3ef7c1901401621bc112389dbd178a907e

Change-Id: If15e1fa50b5feecd74c7394c918f4fc9d87bcf3e
Implements: blueprint report-backend-state-in-service-list
This commit is contained in:
wanghao 2017-12-27 15:10:06 +08:00
parent 36a2f4b4eb
commit 1eb2d6c9f6
4 changed files with 24 additions and 1 deletions

View File

@ -29,7 +29,7 @@ LOG = logging.getLogger(__name__)
# key is a deprecated version and value is an alternative version.
DEPRECATED_VERSIONS = {"1": "2"}
DEPRECATED_VERSION = "2.0"
MAX_VERSION = "3.48"
MAX_VERSION = "3.49"
MIN_VERSION = "3.0"
_SUBSTITUTIONS = {}

View File

@ -145,6 +145,7 @@ class FakeHTTPClient(fake_v2.FakeHTTPClient):
'state': 'up',
'updated_at': datetime(2012, 10, 29, 13, 42, 2),
'cluster': 'cluster1',
'backend_state': 'up',
},
{
'id': 2,
@ -155,6 +156,7 @@ class FakeHTTPClient(fake_v2.FakeHTTPClient):
'state': 'down',
'updated_at': datetime(2012, 9, 18, 8, 3, 38),
'cluster': 'cluster1',
'backend_state': 'down',
},
{
'id': 3,
@ -174,6 +176,11 @@ class FakeHTTPClient(fake_v2.FakeHTTPClient):
if not self.api_version.matches('3.7'):
for svc in services:
del svc['cluster']
if not self.api_version.matches('3.49'):
for svc in services:
if svc['binary'] == 'cinder-volume':
del svc['backend_state']
return (200, {}, {'services': services})
#

View File

@ -79,3 +79,17 @@ class ServicesTest(utils.TestCase):
loaded=True)]
# Since it will be sorted by the prefix we can compare them directly
self.assertListEqual(expected, result)
def test_list_services_with_backend_state(self):
cs = fakes.FakeClient(api_version=api_versions.APIVersion('3.49'))
services_list = cs.services.list()
cs.assert_called('GET', '/os-services')
self.assertEqual(3, len(services_list))
for service in services_list:
self.assertIsInstance(service, services.Service)
# Make sure backend_state fields from v3.49 is present and not
# None
if service.binary == 'cinder-volume':
self.assertIsNotNone(getattr(service, 'backend_state',
None))
self._assert_request_id(services_list)

View File

@ -1597,6 +1597,8 @@ def do_service_list(cs, args):
# so as not to add the column when the extended ext is not enabled.
if result and hasattr(result[0], 'disabled_reason'):
columns.append("Disabled Reason")
if cs.api_version.matches('3.49'):
columns.extend(["Backend State"])
utils.print_list(result, columns)