Deprecate cinder-manage logs commands

These commands search Cinder log files and
/var/log/messages to look for log messages related
to Cinder.

This is hacky and bound to be unreliable in
deployments which now may have log files configured
in different ways.

They also read entire log files into memory as
lists and reverse them, which is bound to be slow
on large deployments.

Deprecate these commands and leave log analysis
as a job for another tool.

Change-Id: I5672904383d41949b86cfdff41cfa0f0ae79b5ba
This commit is contained in:
Eric Harney 2017-12-10 11:18:10 -05:00
parent b6c5f82b7f
commit 7c00d9b966
3 changed files with 28 additions and 4 deletions

View File

@ -411,8 +411,15 @@ class ConfigCommands(object):
class GetLogCommands(object):
"""Get logging information."""
deprecation_msg = ('DEPRECATED: The log commands are deprecated '
'since Queens and are not maintained. They will be '
'removed in an upcoming release.')
def errors(self):
"""Get all of the errors from the log files."""
print(self.deprecation_msg)
error_found = 0
if CONF.log_dir:
logs = [x for x in os.listdir(CONF.log_dir) if x.endswith('.log')]
@ -436,6 +443,9 @@ class GetLogCommands(object):
help='Number of entries to list (default: %(default)d)')
def syslog(self, num_entries=10):
"""Get <num_entries> of the cinder syslog events."""
print(self.deprecation_msg)
entries = int(num_entries)
count = 0
log_file = ''

View File

@ -494,7 +494,10 @@ class TestCinderManageCmd(test.TestCase):
get_log_cmds = cinder_manage.GetLogCommands()
get_log_cmds.errors()
self.assertEqual(expected_out, fake_out.getvalue())
out_lines = fake_out.getvalue().splitlines(True)
self.assertTrue(out_lines[0].startswith('DEPRECATED'))
self.assertEqual(expected_out, out_lines[1])
@mock.patch('six.moves.builtins.open')
@mock.patch('os.listdir')
@ -505,13 +508,18 @@ class TestCinderManageCmd(test.TestCase):
with mock.patch('sys.stdout', new=six.StringIO()) as fake_out:
open.return_value = six.StringIO(
'[ ERROR ] fake-error-message')
expected_out = ('fake-dir/fake-error.log:-\n'
'Line 1 : [ ERROR ] fake-error-message\n')
expected_out = ['fake-dir/fake-error.log:-\n',
'Line 1 : [ ERROR ] fake-error-message\n']
get_log_cmds = cinder_manage.GetLogCommands()
get_log_cmds.errors()
self.assertEqual(expected_out, fake_out.getvalue())
out_lines = fake_out.getvalue().splitlines(True)
self.assertTrue(out_lines[0].startswith('DEPRECATED'))
self.assertEqual(expected_out[0], out_lines[1])
self.assertEqual(expected_out[1], out_lines[2])
open.assert_called_once_with('fake-dir/fake-error.log', 'r')
listdir.assert_called_once_with(CONF.log_dir)

View File

@ -0,0 +1,6 @@
---
deprecations:
- |
Deprecate the "cinder-manage logs" commands. These will be removed
in a later release.