From a9fcc75f60719ae06b8efa7f7d1a0fbd9ea2236e Mon Sep 17 00:00:00 2001 From: Douglas Raillard Date: Wed, 18 May 2022 14:46:41 +0100 Subject: [PATCH] collector/dmesg: Fix dmesg_out property When no entry has been recorded by the collector, return an empty string rather than returning the full dmesg log. Also fix get_data() that would fail try to add None + '\n' if dmesg_out property returns None. --- devlib/collector/dmesg.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/devlib/collector/dmesg.py b/devlib/collector/dmesg.py index e6eb9fe..b5ba616 100644 --- a/devlib/collector/dmesg.py +++ b/devlib/collector/dmesg.py @@ -202,10 +202,10 @@ class DmesgCollector(CollectorBase): try: entry = self.entries[0] except IndexError: - i = 0 + return '' else: i = entry.line_nr - return '\n'.join(out.splitlines()[i:]) + return '\n'.join(out.splitlines()[i:]) @property def entries(self): @@ -278,5 +278,5 @@ class DmesgCollector(CollectorBase): if self.output_path is None: raise RuntimeError("Output path was not set.") with open(self.output_path, 'wt') as f: - f.write(self.dmesg_out + '\n') + f.write((self.dmesg_out or '') + '\n') return CollectorOutput([CollectorOutputEntry(self.output_path, 'file')])