def test_collect_system_logs_non_journald(self, mock_outputs, mock_journalctl, mock_gzip_b64): mock_journalctl.return_value = False ret = 'SpongeBob SquarePants' mock_gzip_b64.return_value = ret logs_string = utils.collect_system_logs() self.assertEqual(ret, logs_string) calls = [ mock.call(['dmesg']), mock.call(['ps', 'au']), mock.call(['df', '-a']), mock.call(['iptables', '-L']), mock.call(['ip', 'addr']), mock.call(['lshw', '-quiet', '-json']) ] mock_outputs.assert_has_calls(calls, any_order=True) mock_gzip_b64.assert_called_once_with(file_list=['/var/log'], io_dict={ 'iptables': mock.ANY, 'ip_addr': mock.ANY, 'ps': mock.ANY, 'dmesg': mock.ANY, 'df': mock.ANY, 'lshw': mock.ANY })
def test_collect_system_logs_journald(self, mock_logs, mock_outputs, mock_journalctl, mock_gzip_b64): mock_journalctl.return_value = True ret = 'Patrick Star' mock_gzip_b64.return_value = ret logs_string = utils.collect_system_logs() self.assertEqual(ret, logs_string) mock_logs.assert_called_once_with(lines=None) calls = [ mock.call(['ps', 'au']), mock.call(['df', '-a']), mock.call(['iptables', '-L']), mock.call(['ip', 'addr']), mock.call(['lshw', '-quiet', '-json']) ] mock_outputs.assert_has_calls(calls, any_order=True) mock_gzip_b64.assert_called_once_with(file_list=[], io_dict={ 'journal': mock.ANY, 'ip_addr': mock.ANY, 'ps': mock.ANY, 'df': mock.ANY, 'iptables': mock.ANY, 'lshw': mock.ANY })
def collect_system_logs(self): """Collect system logs. Collect and package diagnostic and support data from the ramdisk. :raises: CommandExecutionError if failed to collect the system logs. :returns: A dictionary with the key `system_logs` and the value of a gzipped and base64 encoded string of the file with the logs. """ logs = utils.collect_system_logs() return {'system_logs': logs}
def test_collect_system_logs_non_journald( self, mock_outputs, mock_journalctl, mock_gzip_b64): mock_journalctl.return_value = False ret = 'SpongeBob SquarePants' mock_gzip_b64.return_value = ret logs_string = utils.collect_system_logs() self.assertEqual(ret, logs_string) calls = [mock.call(['dmesg']), mock.call(['ps', 'au']), mock.call(['df', '-a']), mock.call(['iptables', '-L']), mock.call(['ip', 'addr'])] mock_outputs.assert_has_calls(calls, any_order=True) mock_gzip_b64.assert_called_once_with( file_list=['/var/log'], io_dict={'iptables': mock.ANY, 'ip_addr': mock.ANY, 'ps': mock.ANY, 'dmesg': mock.ANY, 'df': mock.ANY})
def test_collect_system_logs_journald( self, mock_logs, mock_outputs, mock_journalctl, mock_gzip_b64): mock_journalctl.return_value = True ret = 'Patrick Star' mock_gzip_b64.return_value = ret logs_string = utils.collect_system_logs() self.assertEqual(ret, logs_string) mock_logs.assert_called_once_with(lines=None) calls = [mock.call(['ps', 'au']), mock.call(['df', '-a']), mock.call(['iptables', '-L']), mock.call(['ip', 'addr'])] mock_outputs.assert_has_calls(calls, any_order=True) mock_gzip_b64.assert_called_once_with( file_list=[], io_dict={'journal': mock.ANY, 'ip_addr': mock.ANY, 'ps': mock.ANY, 'df': mock.ANY, 'iptables': mock.ANY})
def collect_logs(data, failures): """Collect system logs from the ramdisk. As inspection runs before any nodes details are known, it's handy to have logs returned with data. This collector sends logs to inspector in format expected by the 'ramdisk_error' plugin: base64 encoded tar.gz. This collector should be installed last in the collector chain, otherwise it won't collect enough logs. This collector does not report failures. :param data: mutable data that we'll send to inspector :param failures: AccumulatedFailures object """ try: data['logs'] = utils.collect_system_logs(journald_max_lines=10000) except errors.CommandExecutionError: LOG.warning('failed to get system journal') return
def collect_logs(data, failures): """Collect system logs from the ramdisk. As inspection runs before any nodes details are known, it's handy to have logs returned with data. This collector sends logs to inspector in format expected by the 'ramdisk_error' plugin: base64 encoded tar.gz. This collector should be installed last in the collector chain, otherwise it won't collect enough logs. This collector does not report failures. :param data: mutable data that we'll send to inspector :param failures: AccumulatedFailures object """ try: data['logs'] = utils.collect_system_logs(journald_max_lines=10000) except errors.CommandExecutionError: LOG.warning('failed to get system journal') return