From 1eb2d6c9f6840e59880b771953020f5a2e5d8967 Mon Sep 17 00:00:00 2001 From: wanghao Date: Wed, 27 Dec 2017 15:10:06 +0800 Subject: [PATCH] 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 --- cinderclient/api_versions.py | 2 +- cinderclient/tests/unit/v3/fakes.py | 7 +++++++ cinderclient/tests/unit/v3/test_services.py | 14 ++++++++++++++ cinderclient/v3/shell.py | 2 ++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cinderclient/api_versions.py b/cinderclient/api_versions.py index a622d9c05..796e069e2 100644 --- a/cinderclient/api_versions.py +++ b/cinderclient/api_versions.py @@ -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 = {} diff --git a/cinderclient/tests/unit/v3/fakes.py b/cinderclient/tests/unit/v3/fakes.py index 910633ef3..48e97f492 100644 --- a/cinderclient/tests/unit/v3/fakes.py +++ b/cinderclient/tests/unit/v3/fakes.py @@ -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}) # diff --git a/cinderclient/tests/unit/v3/test_services.py b/cinderclient/tests/unit/v3/test_services.py index 5bb3140e6..0715cd378 100644 --- a/cinderclient/tests/unit/v3/test_services.py +++ b/cinderclient/tests/unit/v3/test_services.py @@ -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) diff --git a/cinderclient/v3/shell.py b/cinderclient/v3/shell.py index 644cc054b..839be19c3 100644 --- a/cinderclient/v3/shell.py +++ b/cinderclient/v3/shell.py @@ -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)