From 5620901ba3be32d2e96d75bee4765b6aa03a1d58 Mon Sep 17 00:00:00 2001 From: LisaLi Date: Fri, 4 Mar 2016 15:02:30 +0800 Subject: [PATCH] Report versions in cinder-manager service list We set rpc_current_version and object_current_version in Mitaka. This patch is to show these two fields in command 'cinder-manage service list' to help admin know the versions of each service. It helps during upgrade. Change-Id: Idb17bd0aafaf1cb44b6291ff74b234e83be96461 Closes-bug: #1548152 --- cinder/cmd/manage.py | 12 +++++++++--- cinder/tests/unit/test_cmd.py | 33 ++++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/cinder/cmd/manage.py b/cinder/cmd/manage.py index 5f1157da4..758c8d1b6 100644 --- a/cinder/cmd/manage.py +++ b/cinder/cmd/manage.py @@ -421,13 +421,15 @@ class ServiceCommands(object): """Show a list of all cinder services.""" ctxt = context.get_admin_context() services = objects.ServiceList.get_all(ctxt) - print_format = "%-16s %-36s %-16s %-10s %-5s %-10s" + print_format = "%-16s %-36s %-16s %-10s %-5s %-20s %-12s %-15s" print(print_format % (_('Binary'), _('Host'), _('Zone'), _('Status'), _('State'), - _('Updated At'))) + _('Updated At'), + _('RPC Version'), + _('Object Version'))) for svc in services: alive = utils.service_is_up(svc) art = ":-)" if alive else "XXX" @@ -437,9 +439,13 @@ class ServiceCommands(object): updated_at = svc.updated_at if updated_at: updated_at = timeutils.normalize_time(updated_at) + rpc_version = (svc.rpc_current_version or + rpc.LIBERTY_RPC_VERSIONS.get(svc.binary, '')) + object_version = (svc.object_current_version or 'liberty') print(print_format % (svc.binary, svc.host.partition('.')[0], svc.availability_zone, status, art, - updated_at)) + updated_at, rpc_version, + object_version)) @args('binary', type=str, help='Service to delete from the host.') diff --git a/cinder/tests/unit/test_cmd.py b/cinder/tests/unit/test_cmd.py index 895e84beb..cbcccb849 100644 --- a/cinder/tests/unit/test_cmd.py +++ b/cinder/tests/unit/test_cmd.py @@ -14,6 +14,7 @@ import datetime import six import sys +from cinder import rpc try: from unittest import mock except ImportError: @@ -674,19 +675,29 @@ class TestCinderManageCmd(test.TestCase): service_get_all.return_value = [service] service_is_up.return_value = True with mock.patch('sys.stdout', new=six.StringIO()) as fake_out: - format = "%-16s %-36s %-16s %-10s %-5s %-10s" + format = "%-16s %-36s %-16s %-10s %-5s %-20s %-12s %-15s" print_format = format % ('Binary', 'Host', 'Zone', 'Status', 'State', - 'Updated At') + 'Updated At', + 'RPC Version', + 'Object Version') + rpc_version = service['rpc_current_version'] + if not rpc_version: + rpc_version = rpc.LIBERTY_RPC_VERSIONS[service['binary']] + object_version = service['object_current_version'] + if not object_version: + object_version = 'liberty' service_format = format % (service['binary'], service['host'].partition('.')[0], service['availability_zone'], 'enabled', ':-)', - service['updated_at']) + service['updated_at'], + rpc_version, + object_version) expected_out = print_format + '\n' + service_format + '\n' service_cmds = cinder_manage.ServiceCommands() @@ -701,16 +712,24 @@ class TestCinderManageCmd(test.TestCase): 'host': 'fake-host.fake-domain', 'availability_zone': 'fake-zone', 'updated_at': '2014-06-30 11:22:33', - 'disabled': False} - self._test_service_commands_list(service) + 'disabled': False, + 'rpc_current_version': '1.1', + 'object_current_version': '1.1'} + for binary in ('volume', 'scheduler', 'backup'): + service['binary'] = 'cinder-%s' % binary + self._test_service_commands_list(service) def test_service_commands_list_no_updated_at(self): service = {'binary': 'cinder-binary', 'host': 'fake-host.fake-domain', 'availability_zone': 'fake-zone', 'updated_at': None, - 'disabled': False} - self._test_service_commands_list(service) + 'disabled': False, + 'rpc_current_version': None, + 'object_current_version': None} + for binary in ('volume', 'scheduler', 'backup'): + service['binary'] = 'cinder-%s' % binary + self._test_service_commands_list(service) def test_get_arg_string(self): args1 = "foobar" -- 2.45.2