]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Report versions in cinder-manager service list
authorLisaLi <xiaoyan.li@intel.com>
Fri, 4 Mar 2016 07:02:30 +0000 (15:02 +0800)
committerLisaLi <xiaoyan.li@intel.com>
Wed, 9 Mar 2016 01:02:40 +0000 (09:02 +0800)
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
cinder/tests/unit/test_cmd.py

index 5f1157da40cd79ee696289473e3402ad3e35fbb7..758c8d1b647fedb8f30f9dc622a62fdb20aa1aa8 100644 (file)
@@ -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.')
index 895e84bebef94fd31de9545b29ce970dbc61ed31..cbcccb849734ae151c921479be9c79b9cf613601 100644 (file)
@@ -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"