From 59662a150028718b1657f69eebc5dc10d849ef75 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Sun, 5 Mar 2023 10:04:00 -0800 Subject: [PATCH] fix for lines that start with tab --- jc/parsers/zpool_status.py | 4 ++-- tests/fixtures/generic/zpool-status-v4.json | 1 + tests/fixtures/generic/zpool-status-v4.out | 21 +++++++++++++++++++++ tests/test_zpool_status.py | 14 +++++++++++++- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/generic/zpool-status-v4.json create mode 100644 tests/fixtures/generic/zpool-status-v4.out diff --git a/jc/parsers/zpool_status.py b/jc/parsers/zpool_status.py index 27c831b1..bce6c001 100644 --- a/jc/parsers/zpool_status.py +++ b/jc/parsers/zpool_status.py @@ -138,7 +138,7 @@ from jc.parsers.kv import parse as kv_parse class info(): """Provides parser metadata (version, author, etc.)""" - version = '1.0' + version = '1.1' description = '`zpool status` command parser' author = 'Kelly Brazil' author_email = 'kellyjonbrazil@gmail.com' @@ -233,7 +233,7 @@ def parse( continue # preserve indentation in continuation lines - if line.startswith(' '): + if line.startswith(' ') or line.startswith('\t'): pool_str += line + '\n' continue diff --git a/tests/fixtures/generic/zpool-status-v4.json b/tests/fixtures/generic/zpool-status-v4.json new file mode 100644 index 00000000..69635305 --- /dev/null +++ b/tests/fixtures/generic/zpool-status-v4.json @@ -0,0 +1 @@ +[{"pool":"pool1","state":"ONLINE","status":"Some supported and requested features are not enabled on the pool.\nThe pool can still be used, but some features are unavailable.","action":"Enable all features using 'zpool upgrade'. Once this is done,\nthe pool may no longer be accessible by software that does not support\nthe features. See zpool-features(7) for details.","scan":"scrub repaired 0B in 11:16:03 with 0 errors on Sun Feb 12 11:40:04 2023","config":[{"name":"pool1","state":"ONLINE","read":0,"write":0,"checksum":0},{"name":"mirror-0","state":"ONLINE","read":0,"write":0,"checksum":0},{"name":"wwn-0x5000c500c65ac66f","state":"ONLINE","read":0,"write":0,"checksum":0},{"name":"wwn-0x5000c500c5eee542","state":"ONLINE","read":0,"write":0,"checksum":0},{"name":"mirror-1","state":"ONLINE","read":0,"write":0,"checksum":0},{"name":"wwn-0x5000c500e39e8af6","state":"ONLINE","read":0,"write":0,"checksum":0},{"name":"wwn-0x5000c500e3b3a41e","state":"ONLINE","read":0,"write":0,"checksum":0}],"errors":"No known data errors"}] diff --git a/tests/fixtures/generic/zpool-status-v4.out b/tests/fixtures/generic/zpool-status-v4.out new file mode 100644 index 00000000..01a2f807 --- /dev/null +++ b/tests/fixtures/generic/zpool-status-v4.out @@ -0,0 +1,21 @@ + pool: pool1 + state: ONLINE +status: Some supported and requested features are not enabled on the pool. + The pool can still be used, but some features are unavailable. +action: Enable all features using 'zpool upgrade'. Once this is done, + the pool may no longer be accessible by software that does not support + the features. See zpool-features(7) for details. + scan: scrub repaired 0B in 11:16:03 with 0 errors on Sun Feb 12 11:40:04 2023 +config: + + NAME STATE READ WRITE CKSUM + pool1 ONLINE 0 0 0 + mirror-0 ONLINE 0 0 0 + wwn-0x5000c500c65ac66f ONLINE 0 0 0 + wwn-0x5000c500c5eee542 ONLINE 0 0 0 + mirror-1 ONLINE 0 0 0 + wwn-0x5000c500e39e8af6 ONLINE 0 0 0 + wwn-0x5000c500e3b3a41e ONLINE 0 0 0 + +errors: No known data errors + diff --git a/tests/test_zpool_status.py b/tests/test_zpool_status.py index e31c4c4c..122ac3ef 100644 --- a/tests/test_zpool_status.py +++ b/tests/test_zpool_status.py @@ -22,7 +22,10 @@ class MyTests(unittest.TestCase): 'fixtures/generic/zpool-status-v2.json'), 'zpool_status3': ( 'fixtures/generic/zpool-status-v3.out', - 'fixtures/generic/zpool-status-v3.json') + 'fixtures/generic/zpool-status-v3.json'), + 'zpool_status4': ( + 'fixtures/generic/zpool-status-v4.out', + 'fixtures/generic/zpool-status-v4.json') } for file, filepaths in fixtures.items(): @@ -66,6 +69,15 @@ class MyTests(unittest.TestCase): self.f_json['zpool_status3'] ) + def test_zpool_status_v_with_tabs(self): + """ + Test 'zpool status -v' with tabs instead of spaces + """ + self.assertEqual( + parse(self.f_in['zpool_status4'], quiet=True), + self.f_json['zpool_status4'] + ) + if __name__ == '__main__': unittest.main()