Add block storage log level {list, set} commands
This patch adds the ``block storage log level list`` and ``block storage log level set`` commands that allow operators to list the current log levels of cinder services and also enables them to set a particular log level. Change-Id: I16cd8084fb505a9e68a35a936ef3b8b1f3cdc712
This commit is contained in:
parent
e7ebf7544b
commit
a9e3049e9c
@ -0,0 +1,8 @@
|
||||
=======================
|
||||
Block Storage Log Level
|
||||
=======================
|
||||
|
||||
Block Storage v3
|
||||
|
||||
.. autoprogram-cliff:: openstack.volume.v3
|
||||
:command: block storage log level *
|
@ -103,9 +103,9 @@ retype,volume type set --type,Changes the volume type for a volume.
|
||||
revert-to-snapshot,volume revert,Revert a volume to the specified snapshot. (Supported by API versions 3.40 - 3.latest)
|
||||
service-disable,volume service set --disable,Disables the service.
|
||||
service-enable,volume service set --enable,Enables the service.
|
||||
service-get-log,,(Supported by API versions 3.32 - 3.latest)
|
||||
service-get-log,block storage log level list,(Supported by API versions 3.32 - 3.latest)
|
||||
service-list,volume service list,Lists all services. Filter by host and service binary.
|
||||
service-set-log,,(Supported by API versions 3.32 - 3.latest)
|
||||
service-set-log,block storage log level set,(Supported by API versions 3.32 - 3.latest)
|
||||
set-bootable,volume set --bootable / --not-bootable,Update bootable status of a volume.
|
||||
show,volume show,Shows volume details.
|
||||
snapshot-create,snapshot create,Creates a snapshot.
|
||||
|
|
@ -47,6 +47,8 @@ class FakeVolumeClient:
|
||||
self.volumes.resource_class = fakes.FakeResource(None, {})
|
||||
self.volume_types = mock.Mock()
|
||||
self.volume_types.resource_class = fakes.FakeResource(None, {})
|
||||
self.services = mock.Mock()
|
||||
self.services.resource_class = fakes.FakeResource(None, {})
|
||||
|
||||
|
||||
class TestVolume(utils.TestCommand):
|
||||
@ -436,3 +438,20 @@ def get_volume_attachments(attachments=None, count=2):
|
||||
attachments = create_volume_attachments(count)
|
||||
|
||||
return mock.Mock(side_effect=attachments)
|
||||
|
||||
|
||||
def create_service_log_level_entry(attrs=None):
|
||||
service_log_level_info = {
|
||||
'host': 'host_test',
|
||||
'binary': 'cinder-api',
|
||||
'prefix': 'cinder.api.common',
|
||||
'level': 'DEBUG',
|
||||
}
|
||||
# Overwrite default attributes if there are some attributes set
|
||||
attrs = attrs or {}
|
||||
|
||||
service_log_level_info.update(attrs)
|
||||
|
||||
service_log_level = fakes.FakeResource(
|
||||
None, service_log_level_info, loaded=True)
|
||||
return service_log_level
|
||||
|
@ -0,0 +1,233 @@
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
from cinderclient import api_versions
|
||||
import ddt
|
||||
from osc_lib import exceptions
|
||||
|
||||
from openstackclient.tests.unit import utils as tests_utils
|
||||
from openstackclient.tests.unit.volume.v3 import fakes as volume_fakes
|
||||
from openstackclient.volume.v3 import block_storage_log_level as service
|
||||
|
||||
|
||||
class TestService(volume_fakes.TestVolume):
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
# Get a shortcut to the ServiceManager Mock
|
||||
self.service_mock = self.app.client_manager.volume.services
|
||||
self.service_mock.reset_mock()
|
||||
|
||||
|
||||
class TestBlockStorageLogLevelList(TestService):
|
||||
|
||||
service_log = volume_fakes.create_service_log_level_entry()
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
self.service_mock.get_log_levels.return_value = [self.service_log]
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = service.BlockStorageLogLevelList(self.app, None)
|
||||
|
||||
def test_block_storage_log_level_list(self):
|
||||
self.app.client_manager.volume.api_version = \
|
||||
api_versions.APIVersion('3.32')
|
||||
arglist = [
|
||||
'--host', self.service_log.host,
|
||||
'--service', self.service_log.binary,
|
||||
'--log-prefix', self.service_log.prefix,
|
||||
]
|
||||
verifylist = [
|
||||
('host', self.service_log.host),
|
||||
('service', self.service_log.binary),
|
||||
('log_prefix', self.service_log.prefix),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
expected_columns = [
|
||||
'Binary',
|
||||
'Host',
|
||||
'Prefix',
|
||||
'Level',
|
||||
]
|
||||
|
||||
# confirming if all expected columns are present in the result.
|
||||
self.assertEqual(expected_columns, columns)
|
||||
|
||||
datalist = ((
|
||||
self.service_log.binary,
|
||||
self.service_log.host,
|
||||
self.service_log.prefix,
|
||||
self.service_log.level,
|
||||
), )
|
||||
|
||||
# confirming if all expected values are present in the result.
|
||||
self.assertEqual(datalist, tuple(data))
|
||||
|
||||
# checking if proper call was made to get log level of services
|
||||
self.service_mock.get_log_levels.assert_called_with(
|
||||
server=self.service_log.host,
|
||||
binary=self.service_log.binary,
|
||||
prefix=self.service_log.prefix,
|
||||
)
|
||||
|
||||
def test_block_storage_log_level_list_pre_332(self):
|
||||
arglist = [
|
||||
'--host', self.service_log.host,
|
||||
'--service', 'cinder-api',
|
||||
'--log-prefix', 'cinder_test.api.common',
|
||||
]
|
||||
verifylist = [
|
||||
('host', self.service_log.host),
|
||||
('service', 'cinder-api'),
|
||||
('log_prefix', 'cinder_test.api.common'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
exc = self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
||||
parsed_args)
|
||||
self.assertIn(
|
||||
'--os-volume-api-version 3.32 or greater is required', str(exc))
|
||||
|
||||
def test_block_storage_log_level_list_invalid_service_name(self):
|
||||
self.app.client_manager.volume.api_version = \
|
||||
api_versions.APIVersion('3.32')
|
||||
arglist = [
|
||||
'--host', self.service_log.host,
|
||||
'--service', 'nova-api',
|
||||
'--log-prefix', 'cinder_test.api.common',
|
||||
]
|
||||
verifylist = [
|
||||
('host', self.service_log.host),
|
||||
('service', 'nova-api'),
|
||||
('log_prefix', 'cinder_test.api.common'),
|
||||
]
|
||||
|
||||
self.assertRaises(tests_utils.ParserException, self.check_parser,
|
||||
self.cmd, arglist, verifylist)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class TestBlockStorageLogLevelSet(TestService):
|
||||
|
||||
service_log = volume_fakes.create_service_log_level_entry()
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
# Get the command object to test
|
||||
self.cmd = service.BlockStorageLogLevelSet(self.app, None)
|
||||
|
||||
def test_block_storage_log_level_set(self):
|
||||
self.app.client_manager.volume.api_version = \
|
||||
api_versions.APIVersion('3.32')
|
||||
arglist = [
|
||||
'ERROR',
|
||||
'--host', self.service_log.host,
|
||||
'--service', self.service_log.binary,
|
||||
'--log-prefix', self.service_log.prefix,
|
||||
]
|
||||
verifylist = [
|
||||
('level', 'ERROR'),
|
||||
('host', self.service_log.host),
|
||||
('service', self.service_log.binary),
|
||||
('log_prefix', self.service_log.prefix),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
# checking if proper call was made to set log level of services
|
||||
self.service_mock.set_log_levels.assert_called_with(
|
||||
level='ERROR',
|
||||
server=self.service_log.host,
|
||||
binary=self.service_log.binary,
|
||||
prefix=self.service_log.prefix,
|
||||
)
|
||||
|
||||
def test_block_storage_log_level_set_pre_332(self):
|
||||
arglist = [
|
||||
'ERROR',
|
||||
'--host', self.service_log.host,
|
||||
'--service', 'cinder-api',
|
||||
'--log-prefix', 'cinder_test.api.common',
|
||||
]
|
||||
verifylist = [
|
||||
('level', 'ERROR'),
|
||||
('host', self.service_log.host),
|
||||
('service', 'cinder-api'),
|
||||
('log_prefix', 'cinder_test.api.common'),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
exc = self.assertRaises(exceptions.CommandError, self.cmd.take_action,
|
||||
parsed_args)
|
||||
self.assertIn(
|
||||
'--os-volume-api-version 3.32 or greater is required', str(exc))
|
||||
|
||||
def test_block_storage_log_level_set_invalid_service_name(self):
|
||||
self.app.client_manager.volume.api_version = \
|
||||
api_versions.APIVersion('3.32')
|
||||
arglist = [
|
||||
'ERROR',
|
||||
'--host', self.service_log.host,
|
||||
'--service', 'nova-api',
|
||||
'--log-prefix', 'cinder.api.common',
|
||||
]
|
||||
verifylist = [
|
||||
('level', 'ERROR'),
|
||||
('host', self.service_log.host),
|
||||
('service', 'nova-api'),
|
||||
('log_prefix', 'cinder.api.common'),
|
||||
]
|
||||
|
||||
self.assertRaises(tests_utils.ParserException, self.check_parser,
|
||||
self.cmd, arglist, verifylist)
|
||||
|
||||
@ddt.data('WARNING', 'info', 'Error', 'debuG', 'fake-log-level')
|
||||
def test_block_storage_log_level_set_log_level(self, log_level):
|
||||
self.app.client_manager.volume.api_version = \
|
||||
api_versions.APIVersion('3.32')
|
||||
arglist = [
|
||||
log_level,
|
||||
'--host', self.service_log.host,
|
||||
'--service', 'cinder-api',
|
||||
'--log-prefix', 'cinder.api.common',
|
||||
]
|
||||
verifylist = [
|
||||
('level', log_level.upper()),
|
||||
('host', self.service_log.host),
|
||||
('service', 'cinder-api'),
|
||||
('log_prefix', 'cinder.api.common'),
|
||||
]
|
||||
|
||||
if log_level == 'fake-log-level':
|
||||
self.assertRaises(tests_utils.ParserException, self.check_parser,
|
||||
self.cmd, arglist, verifylist)
|
||||
else:
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
# checking if proper call was made to set log level of services
|
||||
self.service_mock.set_log_levels.assert_called_with(
|
||||
level=log_level.upper(),
|
||||
server=self.service_log.host,
|
||||
binary=self.service_log.binary,
|
||||
prefix=self.service_log.prefix)
|
147
openstackclient/volume/v3/block_storage_log_level.py
Normal file
147
openstackclient/volume/v3/block_storage_log_level.py
Normal file
@ -0,0 +1,147 @@
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
"""Block Storage Service action implementations"""
|
||||
|
||||
from cinderclient import api_versions
|
||||
from osc_lib.command import command
|
||||
from osc_lib import exceptions
|
||||
from osc_lib import utils
|
||||
|
||||
from openstackclient.i18n import _
|
||||
|
||||
|
||||
class BlockStorageLogLevelList(command.Lister):
|
||||
"""List log levels of block storage service.
|
||||
|
||||
Supported by --os-volume-api-version 3.32 or greater.
|
||||
"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super().get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"--host",
|
||||
metavar="<host>",
|
||||
default="",
|
||||
help=_("List block storage service log level of specified host "
|
||||
"(name only)")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--service",
|
||||
metavar="<service>",
|
||||
default="",
|
||||
choices=(
|
||||
'',
|
||||
'*',
|
||||
'cinder-api',
|
||||
'cinder-volume',
|
||||
'cinder-scheduler',
|
||||
'cinder-backup'),
|
||||
help=_("List block storage service log level of the specified "
|
||||
"service (name only)")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--log-prefix",
|
||||
metavar="<log-prefix>",
|
||||
default="",
|
||||
help="Prefix for the log, e.g. 'sqlalchemy'"
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
service_client = self.app.client_manager.volume
|
||||
columns = [
|
||||
"Binary",
|
||||
"Host",
|
||||
"Prefix",
|
||||
"Level",
|
||||
]
|
||||
|
||||
if service_client.api_version < api_versions.APIVersion('3.32'):
|
||||
msg = _(
|
||||
"--os-volume-api-version 3.32 or greater is required to "
|
||||
"support the 'block storage log level list' command"
|
||||
)
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
data = service_client.services.get_log_levels(
|
||||
binary=parsed_args.service,
|
||||
server=parsed_args.host,
|
||||
prefix=parsed_args.log_prefix)
|
||||
|
||||
return (columns,
|
||||
(utils.get_item_properties(
|
||||
s, columns,
|
||||
) for s in data))
|
||||
|
||||
|
||||
class BlockStorageLogLevelSet(command.Command):
|
||||
"""Set log level of block storage service
|
||||
|
||||
Supported by --os-volume-api-version 3.32 or greater.
|
||||
"""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super().get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"level",
|
||||
metavar="<log-level>",
|
||||
choices=('INFO', 'WARNING', 'ERROR', 'DEBUG'),
|
||||
type=str.upper,
|
||||
help=_("Desired log level.")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--host",
|
||||
metavar="<host>",
|
||||
default="",
|
||||
help=_("Set block storage service log level of specified host "
|
||||
"(name only)")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--service",
|
||||
metavar="<service>",
|
||||
default="",
|
||||
choices=(
|
||||
'',
|
||||
'*',
|
||||
'cinder-api',
|
||||
'cinder-volume',
|
||||
'cinder-scheduler',
|
||||
'cinder-backup'),
|
||||
help=_("Set block storage service log level of specified service "
|
||||
"(name only)")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--log-prefix",
|
||||
metavar="<log-prefix>",
|
||||
default="",
|
||||
help="Prefix for the log, e.g. 'sqlalchemy'"
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
service_client = self.app.client_manager.volume
|
||||
|
||||
if service_client.api_version < api_versions.APIVersion('3.32'):
|
||||
msg = _(
|
||||
"--os-volume-api-version 3.32 or greater is required to "
|
||||
"support the 'block storage log level set' command"
|
||||
)
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
service_client.services.set_log_levels(
|
||||
level=parsed_args.level,
|
||||
binary=parsed_args.service,
|
||||
server=parsed_args.host,
|
||||
prefix=parsed_args.log_prefix)
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Added ``block storage log level list`` and ``block storage log level set``
|
||||
commands that allows operators to list and set log levels for cinder
|
||||
services.
|
@ -822,3 +822,5 @@ openstack.volume.v3 =
|
||||
|
||||
volume_summary = openstackclient.volume.v3.volume:VolumeSummary
|
||||
volume_revert = openstackclient.volume.v3.volume:VolumeRevertToSnapshot
|
||||
block_storage_log_level_list = openstackclient.volume.v3.block_storage_log_level:BlockStorageLogLevelList
|
||||
block_storage_log_level_set = openstackclient.volume.v3.block_storage_log_level:BlockStorageLogLevelSet
|
||||
|
Loading…
Reference in New Issue
Block a user