From 7c00d9b966abac50ad5ad8664fbe327ba2aca10e Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Sun, 10 Dec 2017 11:18:10 -0500 Subject: [PATCH] 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 --- cinder/cmd/manage.py | 10 ++++++++++ cinder/tests/unit/test_cmd.py | 16 ++++++++++++---- ...deprecate_logs_commands-a0d59cb7535a2138.yaml | 6 ++++++ 3 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 releasenotes/notes/deprecate_logs_commands-a0d59cb7535a2138.yaml diff --git a/cinder/cmd/manage.py b/cinder/cmd/manage.py index 6a832e06b13..9abda4b33ff 100644 --- a/cinder/cmd/manage.py +++ b/cinder/cmd/manage.py @@ -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 of the cinder syslog events.""" + + print(self.deprecation_msg) + entries = int(num_entries) count = 0 log_file = '' diff --git a/cinder/tests/unit/test_cmd.py b/cinder/tests/unit/test_cmd.py index 4276bada0ea..05b80b61e98 100644 --- a/cinder/tests/unit/test_cmd.py +++ b/cinder/tests/unit/test_cmd.py @@ -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) diff --git a/releasenotes/notes/deprecate_logs_commands-a0d59cb7535a2138.yaml b/releasenotes/notes/deprecate_logs_commands-a0d59cb7535a2138.yaml new file mode 100644 index 00000000000..85d6ba17541 --- /dev/null +++ b/releasenotes/notes/deprecate_logs_commands-a0d59cb7535a2138.yaml @@ -0,0 +1,6 @@ +--- + +deprecations: + - | + Deprecate the "cinder-manage logs" commands. These will be removed + in a later release.