diff --git a/cinder/cmd/manage.py b/cinder/cmd/manage.py index 27fc64e5054..fab416a7e0e 100644 --- a/cinder/cmd/manage.py +++ b/cinder/cmd/manage.py @@ -56,7 +56,6 @@ from __future__ import print_function import logging as python_logging -import os import prettytable import sys import time @@ -459,68 +458,6 @@ class ConfigCommands(object): print('%s = %s' % (key, value)) -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')] - for file in logs: - log_file = os.path.join(CONF.log_dir, file) - lines = [line.strip() for line in open(log_file, "r")] - lines.reverse() - print_name = 0 - for index, line in enumerate(lines): - if line.find(" ERROR ") > 0: - error_found += 1 - if print_name == 0: - print(log_file + ":-") - print_name = 1 - print(_("Line %(dis)d : %(line)s") % - {'dis': len(lines) - index, 'line': line}) - if error_found == 0: - print(_("No errors in logfiles!")) - - @args('num_entries', nargs='?', type=int, default=10, - help='Number of entries to list (default: %(default)d)') - def syslog(self, num_entries=10): - """Get of the cinder syslog events.""" - - print(self.deprecation_msg) - - entries = int(num_entries) - count = 0 - log_file = '' - if os.path.exists('/var/log/syslog'): - log_file = '/var/log/syslog' - elif os.path.exists('/var/log/messages'): - log_file = '/var/log/messages' - else: - print(_("Unable to find system log file!")) - sys.exit(1) - lines = [line.strip() for line in open(log_file, "r")] - lines.reverse() - print(_("Last %s cinder syslog entries:-") % (entries)) - for line in lines: - if line.find("cinder") > 0: - count += 1 - print(_("%s") % (line)) - if count == entries: - break - - if count == 0: - print(_("No cinder entries in syslog!")) - - class BackupCommands(object): """Methods for managing backups.""" @@ -759,7 +696,6 @@ CATEGORIES = { 'cg': ConsistencyGroupCommands, 'db': DbCommands, 'host': HostCommands, - 'logs': GetLogCommands, 'service': ServiceCommands, 'shell': ShellCommands, 'version': VersionCommands, diff --git a/cinder/tests/unit/test_cmd.py b/cinder/tests/unit/test_cmd.py index be62dacd48d..38ed8376e4b 100644 --- a/cinder/tests/unit/test_cmd.py +++ b/cinder/tests/unit/test_cmd.py @@ -615,56 +615,6 @@ class TestCinderManageCmd(test.TestCase): self.assertEqual(expected_out, fake_out.getvalue()) - def test_get_log_commands_no_errors(self): - with mock.patch('sys.stdout', new=six.StringIO()) as fake_out: - CONF.set_override('log_dir', None) - expected_out = 'No errors in logfiles!\n' - - get_log_cmds = cinder_manage.GetLogCommands() - get_log_cmds.errors() - - 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') - def test_get_log_commands_errors(self, listdir, open): - CONF.set_override('log_dir', 'fake-dir') - listdir.return_value = ['fake-error.log'] - - 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'] - - get_log_cmds = cinder_manage.GetLogCommands() - get_log_cmds.errors() - - 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) - - @mock.patch('six.moves.builtins.open') - @mock.patch('os.path.exists') - def test_get_log_commands_syslog_no_log_file(self, path_exists, open): - path_exists.return_value = False - - get_log_cmds = cinder_manage.GetLogCommands() - with mock.patch('sys.stdout', new=six.StringIO()): - exit = self.assertRaises(SystemExit, get_log_cmds.syslog) - self.assertEqual(1, exit.code) - - path_exists.assert_any_call('/var/log/syslog') - path_exists.assert_any_call('/var/log/messages') - @mock.patch('cinder.db.backup_get_all') @mock.patch('cinder.context.get_admin_context') def test_backup_commands_list(self, get_admin_context, backup_get_all): diff --git a/releasenotes/notes/remove-cinder-manage-logs-cmds-40fb8f475b37fb2f.yaml b/releasenotes/notes/remove-cinder-manage-logs-cmds-40fb8f475b37fb2f.yaml new file mode 100644 index 00000000000..8ef07985333 --- /dev/null +++ b/releasenotes/notes/remove-cinder-manage-logs-cmds-40fb8f475b37fb2f.yaml @@ -0,0 +1,7 @@ +--- +other: + - | + The "cinder-manage logs" commands have been removed. Information + previously gathered by these commands may be found in cinder service and + syslog logs. +