Browse Source

Fix service-get-log to respect server filters

The service-get-log command returns always the same output ignoring
the 'server' filters.

This fix avoid returning all the results when using the 'server' filter.

How to reproduce:
'cinder  --os-volume-api-version 3.52 service-get-log
--server localhost.localdomain@cep'
return the same output than
'cinder  --os-volume-api-version 3.52 service-get-log'

Change-Id: Iecb3faad9270f969185089cc291127b340483a46
(cherry picked from commit e793c5e249)
changes/22/737322/1
Sofia Enriquez 2 years ago
parent
commit
0f6b4cdcd4
  1. 13
      cinder/api/contrib/services.py
  2. 27
      cinder/tests/unit/api/contrib/test_services.py

13
cinder/api/contrib/services.py

@ -202,11 +202,14 @@ class ServiceController(wsgi.Controller):
log_req = objects.LogLevel(context, prefix=prefix)
if constants.API_BINARY in binaries:
levels = utils.get_log_levels(prefix)
result.append({'host': CONF.host,
'binary': constants.API_BINARY,
'levels': levels})
# Avoid showing constants if 'server' is set.
server_filter = body.get('server')
if not server_filter or server_filter == CONF.host:
if constants.API_BINARY in binaries:
levels = utils.get_log_levels(prefix)
result.append({'host': CONF.host,
'binary': constants.API_BINARY,
'levels': levels})
for service in services:
levels = self.rpc_apis[service.binary].get_log_levels(context,
service,

27
cinder/tests/unit/api/contrib/test_services.py

@ -824,6 +824,33 @@ class ServicesTest(test.TestCase):
self.controller._get_log, req, self.context,
body=body)
@mock.patch('cinder.api.contrib.services.ServiceController._get_log')
def test_get_log_w_server_filter(self, get_log_mock):
server_filter = 'controller-0'
body = {'host': CONF.host, 'server': server_filter}
req = FakeRequest(version=mv.LOG_LEVEL)
log_levels = self.controller._get_log(req, mock.sentinel.context, body)
self.assertEqual(get_log_mock.return_value, log_levels)
get_log_mock.assert_called_once_with(req, mock.sentinel.context, body)
self.assertNotEqual(log_levels['binary'], constants.API_BINARY)
self.assertIsNot(log_levels, constants.API_BINARY)
@mock.patch('cinder.api.contrib.services.ServiceController._get_log')
def test_get_log_w_server_equals_to_host(self, get_log_mock):
server_filter = 'server-0'
body = {'host': CONF.host, 'server': server_filter}
req = FakeRequest(version=mv.LOG_LEVEL)
log_levels = self.controller._get_log(req, mock.sentinel.context, body)
self.assertEqual(get_log_mock.return_value, log_levels)
self.assertNotEqual(log_levels['binary'], constants.API_BINARY)
self.assertIsNot(log_levels, constants.API_BINARY)
@ddt.data(None, '', '*')
@mock.patch('cinder.objects.ServiceList.get_all')
def test__log_params_binaries_service_all(self, binary, service_list_mock):

Loading…
Cancel
Save