From b257ce8c2fe6825fe435b4d04b4184091030db10 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Sun, 13 Mar 2022 12:25:50 -0700 Subject: [PATCH] add mpstat_s tests --- .../centos-7.7/mpstat-A-2-5-streaming.json | 1 + .../centos-7.7/mpstat-A-streaming.json | 1 + .../fixtures/centos-7.7/mpstat-streaming.json | 1 + tests/test_mpstat_s.py | 62 +++++++++++++++++++ 4 files changed, 65 insertions(+) create mode 100644 tests/fixtures/centos-7.7/mpstat-A-2-5-streaming.json create mode 100644 tests/fixtures/centos-7.7/mpstat-A-streaming.json create mode 100644 tests/fixtures/centos-7.7/mpstat-streaming.json create mode 100644 tests/test_mpstat_s.py diff --git a/tests/fixtures/centos-7.7/mpstat-A-2-5-streaming.json b/tests/fixtures/centos-7.7/mpstat-A-2-5-streaming.json new file mode 100644 index 00000000..4fb6a882 --- /dev/null +++ b/tests/fixtures/centos-7.7/mpstat-A-2-5-streaming.json @@ -0,0 +1 @@ +[{"cpu":"all","percent_usr":0.0,"percent_nice":0.0,"percent_sys":0.5,"percent_iowait":0.0,"percent_irq":0.0,"percent_soft":0.0,"percent_steal":0.0,"percent_guest":0.0,"percent_gnice":0.0,"percent_idle":99.5,"type":"cpu","time":"03:16:17 PM"},{"cpu":"0","percent_usr":0.0,"percent_nice":0.0,"percent_sys":0.5,"percent_iowait":0.0,"percent_irq":0.0,"percent_soft":0.0,"percent_steal":0.0,"percent_guest":0.0,"percent_gnice":0.0,"percent_idle":99.5,"type":"cpu","time":"03:16:17 PM"},{"cpu":"all","intr_s":55.5,"type":"interrupts","time":"03:16:17 PM"},{"cpu":"0","intr_s":54.0,"type":"interrupts","time":"03:16:17 PM"},{"cpu":"0","0_s":0.0,"1_s":0.0,"4_s":0.0,"8_s":0.0,"9_s":0.0,"12_s":0.0,"14_s":0.0,"15_s":1.0,"16_s":4.5,"17_s":0.0,"18_s":0.0,"19_s":1.5,"24_s":0.0,"25_s":0.0,"26_s":0.0,"27_s":0.0,"28_s":0.0,"29_s":0.0,"30_s":0.0,"31_s":0.0,"32_s":0.0,"33_s":0.0,"34_s":0.0,"35_s":0.0,"36_s":0.0,"37_s":0.0,"38_s":0.0,"39_s":0.0,"40_s":0.0,"41_s":0.0,"42_s":0.0,"43_s":0.0,"44_s":0.0,"45_s":0.0,"46_s":0.0,"47_s":0.0,"48_s":0.0,"49_s":0.0,"50_s":0.0,"51_s":0.0,"52_s":0.0,"53_s":0.0,"54_s":0.0,"55_s":0.0,"56_s":0.0,"57_s":0.0,"nmi_s":0.0,"loc_s":44.0,"spu_s":0.0,"pmi_s":0.0,"iwi_s":4.5,"rtr_s":0.0,"res_s":0.0,"cal_s":0.0,"tlb_s":0.0,"trm_s":0.0,"thr_s":0.0,"dfr_s":0.0,"mce_s":0.0,"mcp_s":0.0,"err_s":0.0,"mis_s":0.0,"pin_s":0.0,"npi_s":0.0,"piw_s":0.0,"type":"interrupts","time":"03:16:17 PM"},{"cpu":"0","hi_s":0.0,"timer_s":35.0,"net_tx_s":0.5,"net_rx_s":1.5,"block_s":0.5,"block_iopoll_s":0.0,"tasklet_s":0.0,"sched_s":0.0,"hrtimer_s":0.0,"rcu_s":16.5,"type":"interrupts","time":"03:16:17 PM"},{"cpu":"all","percent_usr":0.5,"percent_nice":0.0,"percent_sys":0.0,"percent_iowait":0.0,"percent_irq":0.0,"percent_soft":0.0,"percent_steal":0.0,"percent_guest":0.0,"percent_gnice":0.0,"percent_idle":99.5,"type":"cpu","time":"03:16:19 PM"},{"cpu":"0","percent_usr":0.5,"percent_nice":0.0,"percent_sys":0.0,"percent_iowait":0.0,"percent_irq":0.0,"percent_soft":0.0,"percent_steal":0.0,"percent_guest":0.0,"percent_gnice":0.0,"percent_idle":99.5,"type":"cpu","time":"03:16:19 PM"},{"cpu":"all","intr_s":56.5,"type":"interrupts","time":"03:16:19 PM"},{"cpu":"0","intr_s":51.5,"type":"interrupts","time":"03:16:19 PM"},{"cpu":"0","0_s":0.0,"1_s":0.0,"4_s":0.0,"8_s":0.0,"9_s":0.0,"12_s":0.0,"14_s":0.0,"15_s":1.0,"16_s":5.0,"17_s":0.0,"18_s":0.0,"19_s":1.5,"24_s":0.0,"25_s":0.0,"26_s":0.0,"27_s":0.0,"28_s":0.0,"29_s":0.0,"30_s":0.0,"31_s":0.0,"32_s":0.0,"33_s":0.0,"34_s":0.0,"35_s":0.0,"36_s":0.0,"37_s":0.0,"38_s":0.0,"39_s":0.0,"40_s":0.0,"41_s":0.0,"42_s":0.0,"43_s":0.0,"44_s":0.0,"45_s":0.0,"46_s":0.0,"47_s":0.0,"48_s":0.0,"49_s":0.0,"50_s":0.0,"51_s":0.0,"52_s":0.0,"53_s":0.0,"54_s":0.0,"55_s":0.0,"56_s":0.0,"57_s":0.0,"nmi_s":0.0,"loc_s":43.5,"spu_s":0.0,"pmi_s":0.0,"iwi_s":5.5,"rtr_s":0.0,"res_s":0.0,"cal_s":0.0,"tlb_s":0.0,"trm_s":0.0,"thr_s":0.0,"dfr_s":0.0,"mce_s":0.0,"mcp_s":0.0,"err_s":0.0,"mis_s":0.0,"pin_s":0.0,"npi_s":0.0,"piw_s":0.0,"type":"interrupts","time":"03:16:19 PM"},{"cpu":"0","hi_s":0.0,"timer_s":33.5,"net_tx_s":0.0,"net_rx_s":1.5,"block_s":0.5,"block_iopoll_s":0.0,"tasklet_s":0.0,"sched_s":0.0,"hrtimer_s":0.0,"rcu_s":16.0,"type":"interrupts","time":"03:16:19 PM"},{"cpu":"all","percent_usr":0.0,"percent_nice":0.0,"percent_sys":0.5,"percent_iowait":0.0,"percent_irq":0.0,"percent_soft":0.0,"percent_steal":0.0,"percent_guest":0.0,"percent_gnice":0.0,"percent_idle":99.5,"type":"cpu","time":"03:16:21 PM"},{"cpu":"0","percent_usr":0.0,"percent_nice":0.0,"percent_sys":0.5,"percent_iowait":0.0,"percent_irq":0.0,"percent_soft":0.0,"percent_steal":0.0,"percent_guest":0.0,"percent_gnice":0.0,"percent_idle":99.5,"type":"cpu","time":"03:16:21 PM"},{"cpu":"all","intr_s":59.0,"type":"interrupts","time":"03:16:21 PM"},{"cpu":"0","intr_s":55.0,"type":"interrupts","time":"03:16:21 PM"},{"cpu":"0","0_s":0.0,"1_s":0.0,"4_s":0.0,"8_s":0.0,"9_s":0.0,"12_s":0.0,"14_s":0.0,"15_s":0.0,"16_s":5.0,"17_s":0.0,"18_s":0.0,"19_s":1.5,"24_s":0.0,"25_s":0.0,"26_s":0.0,"27_s":0.0,"28_s":0.0,"29_s":0.0,"30_s":0.0,"31_s":0.0,"32_s":0.0,"33_s":0.0,"34_s":0.0,"35_s":0.0,"36_s":0.0,"37_s":0.0,"38_s":0.0,"39_s":0.0,"40_s":0.0,"41_s":0.0,"42_s":0.0,"43_s":0.0,"44_s":0.0,"45_s":0.0,"46_s":0.0,"47_s":0.0,"48_s":0.0,"49_s":0.0,"50_s":0.0,"51_s":0.0,"52_s":0.0,"53_s":0.0,"54_s":0.0,"55_s":0.0,"56_s":0.0,"57_s":0.0,"nmi_s":0.0,"loc_s":47.0,"spu_s":0.0,"pmi_s":0.0,"iwi_s":6.5,"rtr_s":0.0,"res_s":0.0,"cal_s":0.0,"tlb_s":0.0,"trm_s":0.0,"thr_s":0.0,"dfr_s":0.0,"mce_s":0.0,"mcp_s":0.0,"err_s":0.0,"mis_s":0.0,"pin_s":0.0,"npi_s":0.0,"piw_s":0.0,"type":"interrupts","time":"03:16:21 PM"},{"cpu":"0","hi_s":0.0,"timer_s":35.5,"net_tx_s":0.5,"net_rx_s":1.5,"block_s":0.0,"block_iopoll_s":0.0,"tasklet_s":0.0,"sched_s":0.0,"hrtimer_s":0.0,"rcu_s":17.5,"type":"interrupts","time":"03:16:21 PM"},{"cpu":"all","percent_usr":0.0,"percent_nice":0.0,"percent_sys":0.5,"percent_iowait":0.0,"percent_irq":0.0,"percent_soft":0.0,"percent_steal":0.0,"percent_guest":0.0,"percent_gnice":0.0,"percent_idle":99.5,"type":"cpu","time":"03:16:23 PM"},{"cpu":"0","percent_usr":0.0,"percent_nice":0.0,"percent_sys":0.5,"percent_iowait":0.0,"percent_irq":0.0,"percent_soft":0.0,"percent_steal":0.0,"percent_guest":0.0,"percent_gnice":0.0,"percent_idle":99.5,"type":"cpu","time":"03:16:23 PM"},{"cpu":"all","intr_s":56.5,"type":"interrupts","time":"03:16:23 PM"},{"cpu":"0","intr_s":53.5,"type":"interrupts","time":"03:16:23 PM"},{"cpu":"0","0_s":0.0,"1_s":0.0,"4_s":0.0,"8_s":0.0,"9_s":0.0,"12_s":0.0,"14_s":0.0,"15_s":1.0,"16_s":5.0,"17_s":0.0,"18_s":0.0,"19_s":1.0,"24_s":0.0,"25_s":0.0,"26_s":0.0,"27_s":0.0,"28_s":0.0,"29_s":0.0,"30_s":0.0,"31_s":0.0,"32_s":0.0,"33_s":0.0,"34_s":0.0,"35_s":0.0,"36_s":0.0,"37_s":0.0,"38_s":0.0,"39_s":0.0,"40_s":0.0,"41_s":0.0,"42_s":0.0,"43_s":0.0,"44_s":0.0,"45_s":0.0,"46_s":0.0,"47_s":0.0,"48_s":0.0,"49_s":0.0,"50_s":0.0,"51_s":0.0,"52_s":0.0,"53_s":0.0,"54_s":0.0,"55_s":0.0,"56_s":0.0,"57_s":0.0,"nmi_s":0.0,"loc_s":43.5,"spu_s":0.0,"pmi_s":0.0,"iwi_s":6.0,"rtr_s":0.0,"res_s":0.0,"cal_s":0.0,"tlb_s":0.0,"trm_s":0.0,"thr_s":0.0,"dfr_s":0.0,"mce_s":0.0,"mcp_s":0.0,"err_s":0.0,"mis_s":0.0,"pin_s":0.0,"npi_s":0.0,"piw_s":0.0,"type":"interrupts","time":"03:16:23 PM"},{"cpu":"0","hi_s":0.0,"timer_s":34.5,"net_tx_s":0.0,"net_rx_s":1.0,"block_s":0.5,"block_iopoll_s":0.0,"tasklet_s":0.0,"sched_s":0.0,"hrtimer_s":0.0,"rcu_s":17.5,"type":"interrupts","time":"03:16:23 PM"},{"cpu":"all","percent_usr":0.0,"percent_nice":0.0,"percent_sys":0.0,"percent_iowait":0.0,"percent_irq":0.0,"percent_soft":0.0,"percent_steal":0.0,"percent_guest":0.0,"percent_gnice":0.0,"percent_idle":100.0,"type":"cpu","time":"03:16:25 PM"},{"cpu":"0","percent_usr":0.0,"percent_nice":0.0,"percent_sys":0.0,"percent_iowait":0.0,"percent_irq":0.0,"percent_soft":0.0,"percent_steal":0.0,"percent_guest":0.0,"percent_gnice":0.0,"percent_idle":100.0,"type":"cpu","time":"03:16:25 PM"},{"cpu":"all","intr_s":56.28,"type":"interrupts","time":"03:16:25 PM"},{"cpu":"0","intr_s":50.75,"type":"interrupts","time":"03:16:25 PM"},{"cpu":"0","0_s":0.0,"1_s":0.0,"4_s":0.0,"8_s":0.0,"9_s":0.0,"12_s":0.0,"14_s":0.0,"15_s":1.01,"16_s":4.52,"17_s":1.01,"18_s":0.0,"19_s":1.51,"24_s":0.0,"25_s":0.0,"26_s":0.0,"27_s":0.0,"28_s":0.0,"29_s":0.0,"30_s":0.0,"31_s":0.0,"32_s":0.0,"33_s":0.0,"34_s":0.0,"35_s":0.0,"36_s":0.0,"37_s":0.0,"38_s":0.0,"39_s":0.0,"40_s":0.0,"41_s":0.0,"42_s":0.0,"43_s":0.0,"44_s":0.0,"45_s":0.0,"46_s":0.0,"47_s":0.0,"48_s":0.0,"49_s":0.0,"50_s":0.0,"51_s":0.0,"52_s":0.0,"53_s":0.0,"54_s":0.0,"55_s":0.0,"56_s":0.0,"57_s":0.0,"nmi_s":0.0,"loc_s":43.22,"spu_s":0.0,"pmi_s":0.0,"iwi_s":5.03,"rtr_s":0.0,"res_s":0.0,"cal_s":0.0,"tlb_s":0.0,"trm_s":0.0,"thr_s":0.0,"dfr_s":0.0,"mce_s":0.0,"mcp_s":0.0,"err_s":0.0,"mis_s":0.0,"pin_s":0.0,"npi_s":0.0,"piw_s":0.0,"type":"interrupts","time":"03:16:25 PM"},{"cpu":"0","hi_s":0.0,"timer_s":32.16,"net_tx_s":0.0,"net_rx_s":1.51,"block_s":1.51,"block_iopoll_s":0.0,"tasklet_s":0.0,"sched_s":0.0,"hrtimer_s":0.0,"rcu_s":15.58,"type":"interrupts","time":"03:16:25 PM"},{"cpu":"all","percent_usr":0.1,"percent_nice":0.0,"percent_sys":0.3,"percent_iowait":0.0,"percent_irq":0.0,"percent_soft":0.0,"percent_steal":0.0,"percent_guest":0.0,"percent_gnice":0.0,"percent_idle":99.6,"type":"cpu","average":true},{"cpu":"0","percent_usr":0.1,"percent_nice":0.0,"percent_sys":0.3,"percent_iowait":0.0,"percent_irq":0.0,"percent_soft":0.0,"percent_steal":0.0,"percent_guest":0.0,"percent_gnice":0.0,"percent_idle":99.6,"type":"cpu","average":true},{"cpu":"all","intr_s":56.76,"type":"interrupts","average":true},{"cpu":"0","intr_s":52.95,"type":"interrupts","average":true},{"cpu":"0","0_s":0.0,"1_s":0.0,"4_s":0.0,"8_s":0.0,"9_s":0.0,"12_s":0.0,"14_s":0.0,"15_s":0.8,"16_s":4.8,"17_s":0.2,"18_s":0.0,"19_s":1.4,"24_s":0.0,"25_s":0.0,"26_s":0.0,"27_s":0.0,"28_s":0.0,"29_s":0.0,"30_s":0.0,"31_s":0.0,"32_s":0.0,"33_s":0.0,"34_s":0.0,"35_s":0.0,"36_s":0.0,"37_s":0.0,"38_s":0.0,"39_s":0.0,"40_s":0.0,"41_s":0.0,"42_s":0.0,"43_s":0.0,"44_s":0.0,"45_s":0.0,"46_s":0.0,"47_s":0.0,"48_s":0.0,"49_s":0.0,"50_s":0.0,"51_s":0.0,"52_s":0.0,"53_s":0.0,"54_s":0.0,"55_s":0.0,"56_s":0.0,"57_s":0.0,"nmi_s":0.0,"loc_s":44.24,"spu_s":0.0,"pmi_s":0.0,"iwi_s":5.51,"rtr_s":0.0,"res_s":0.0,"cal_s":0.0,"tlb_s":0.0,"trm_s":0.0,"thr_s":0.0,"dfr_s":0.0,"mce_s":0.0,"mcp_s":0.0,"err_s":0.0,"mis_s":0.0,"pin_s":0.0,"npi_s":0.0,"piw_s":0.0,"type":"interrupts","average":true},{"cpu":"0","hi_s":0.0,"timer_s":34.13,"net_tx_s":0.2,"net_rx_s":1.4,"block_s":0.6,"block_iopoll_s":0.0,"tasklet_s":0.0,"sched_s":0.0,"hrtimer_s":0.0,"rcu_s":16.62,"type":"interrupts","average":true}] diff --git a/tests/fixtures/centos-7.7/mpstat-A-streaming.json b/tests/fixtures/centos-7.7/mpstat-A-streaming.json new file mode 100644 index 00000000..c685ff0f --- /dev/null +++ b/tests/fixtures/centos-7.7/mpstat-A-streaming.json @@ -0,0 +1 @@ +[{"cpu":"all","percent_usr":0.22,"percent_nice":0.0,"percent_sys":0.37,"percent_iowait":0.01,"percent_irq":0.0,"percent_soft":0.0,"percent_steal":0.0,"percent_guest":0.0,"percent_gnice":0.0,"percent_idle":99.4,"type":"cpu","time":"03:15:06 PM"},{"cpu":"0","percent_usr":0.22,"percent_nice":0.0,"percent_sys":0.37,"percent_iowait":0.01,"percent_irq":0.0,"percent_soft":0.0,"percent_steal":0.0,"percent_guest":0.0,"percent_gnice":0.0,"percent_idle":99.4,"type":"cpu","time":"03:15:06 PM"},{"cpu":"all","intr_s":37.61,"type":"interrupts","time":"03:15:06 PM"},{"cpu":"0","intr_s":33.15,"type":"interrupts","time":"03:15:06 PM"},{"cpu":"0","0_s":0.02,"1_s":0.02,"4_s":0.01,"8_s":0.0,"9_s":0.0,"12_s":0.01,"14_s":0.0,"15_s":1.0,"16_s":0.75,"17_s":1.14,"18_s":0.03,"19_s":0.69,"24_s":0.0,"25_s":0.0,"26_s":0.0,"27_s":0.0,"28_s":0.0,"29_s":0.0,"30_s":0.0,"31_s":0.0,"32_s":0.0,"33_s":0.0,"34_s":0.0,"35_s":0.0,"36_s":0.0,"37_s":0.0,"38_s":0.0,"39_s":0.0,"40_s":0.0,"41_s":0.0,"42_s":0.0,"43_s":0.0,"44_s":0.0,"45_s":0.0,"46_s":0.0,"47_s":0.0,"48_s":0.0,"49_s":0.0,"50_s":0.0,"51_s":0.0,"52_s":0.0,"53_s":0.0,"54_s":0.0,"55_s":0.0,"56_s":0.0,"57_s":0.0,"nmi_s":0.0,"loc_s":32.69,"spu_s":0.0,"pmi_s":0.0,"iwi_s":1.24,"rtr_s":0.0,"res_s":0.0,"cal_s":0.0,"tlb_s":0.0,"trm_s":0.0,"thr_s":0.0,"dfr_s":0.0,"mce_s":0.0,"mcp_s":0.0,"err_s":0.0,"mis_s":0.0,"pin_s":0.0,"npi_s":0.0,"piw_s":0.0,"type":"interrupts","time":"03:15:06 PM"},{"cpu":"0","hi_s":0.0,"timer_s":21.26,"net_tx_s":0.2,"net_rx_s":0.69,"block_s":1.58,"block_iopoll_s":0.0,"tasklet_s":0.03,"sched_s":0.0,"hrtimer_s":0.0,"rcu_s":9.39,"type":"interrupts","time":"03:15:06 PM"}] diff --git a/tests/fixtures/centos-7.7/mpstat-streaming.json b/tests/fixtures/centos-7.7/mpstat-streaming.json new file mode 100644 index 00000000..f89c71d3 --- /dev/null +++ b/tests/fixtures/centos-7.7/mpstat-streaming.json @@ -0,0 +1 @@ +[{"cpu":"all","percent_usr":0.23,"percent_nice":0.0,"percent_sys":0.37,"percent_iowait":0.01,"percent_irq":0.0,"percent_soft":0.0,"percent_steal":0.0,"percent_guest":0.0,"percent_gnice":0.0,"percent_idle":99.39,"type":"cpu","time":"03:14:20 PM"}] diff --git a/tests/test_mpstat_s.py b/tests/test_mpstat_s.py new file mode 100644 index 00000000..39de208d --- /dev/null +++ b/tests/test_mpstat_s.py @@ -0,0 +1,62 @@ +import os +import json +import unittest +import jc.parsers.mpstat_s + +THIS_DIR = os.path.dirname(os.path.abspath(__file__)) + +# To create streaming output use: +# $ cat mpstat.out | jc --mpstat-s | jello -c > mpstat-streaming.json + + +class MyTests(unittest.TestCase): + + def setUp(self): + pass + # input + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/mpstat.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_mpstat = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/mpstat-A.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_mpstat_A = f.read() + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/mpstat-A-2-5.out'), 'r', encoding='utf-8') as f: + self.centos_7_7_mpstat_A_2_5 = f.read() + + # output + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/mpstat-streaming.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_mpstat_streaming_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/mpstat-A-streaming.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_mpstat_A_streaming_json = json.loads(f.read()) + + with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/mpstat-A-2-5-streaming.json'), 'r', encoding='utf-8') as f: + self.centos_7_7_mpstat_A_2_5_streaming_json = json.loads(f.read()) + + def test_mpstat_s_nodata(self): + """ + Test 'mpstat' with no data + """ + self.assertEqual(list(jc.parsers.mpstat_s.parse([], quiet=True)), []) + + def test_mpstat_s_centos_7_7(self): + """ + Test 'mpstat' on Centos 7.7 + """ + self.assertEqual(list(jc.parsers.mpstat_s.parse(self.centos_7_7_mpstat.splitlines(), quiet=True)), self.centos_7_7_mpstat_streaming_json) + + def test_mpstat_s_A_centos_7_7(self): + """ + Test 'mpstat -A' on Centos 7.7 + """ + self.assertEqual(list(jc.parsers.mpstat_s.parse(self.centos_7_7_mpstat_A.splitlines(), quiet=True)), self.centos_7_7_mpstat_A_streaming_json) + + def test_mpstat_s_A_2_5_centos_7_7(self): + """ + Test 'mpstat -A 2 5' on Centos 7.7 + """ + self.assertEqual(list(jc.parsers.mpstat_s.parse(self.centos_7_7_mpstat_A_2_5.splitlines(), quiet=True)), self.centos_7_7_mpstat_A_2_5_streaming_json) + + +if __name__ == '__main__': + unittest.main()