diff options
author | wanghao <sxmatch1986@gmail.com> | 2017-12-27 15:10:06 +0800 |
---|---|---|
committer | wanghao <sxmatch1986@gmail.com> | 2018-01-09 09:04:00 +0800 |
commit | 1eb2d6c9f6840e59880b771953020f5a2e5d8967 (patch) | |
tree | 66c4d129016d22e4fd9f280a2e91d2ce3fbec298 | |
parent | 36a2f4b4ebe8c46df2b7786ad9402ac7b12e700a (diff) | |
download | python-cinderclient-1eb2d6c9f6840e59880b771953020f5a2e5d8967.tar.gz |
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
-rw-r--r-- | cinderclient/api_versions.py | 2 | ||||
-rw-r--r-- | cinderclient/tests/unit/v3/fakes.py | 7 | ||||
-rw-r--r-- | cinderclient/tests/unit/v3/test_services.py | 14 | ||||
-rw-r--r-- | cinderclient/v3/shell.py | 2 |
4 files changed, 24 insertions, 1 deletions
diff --git a/cinderclient/api_versions.py b/cinderclient/api_versions.py index a622d9c..796e069 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 910633e..48e97f4 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 5bb3140..0715cd3 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 644cc05..839be19 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) |