mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-08-08 22:36:48 +02:00
add vmstat tests
This commit is contained in:
1
tests/fixtures/centos-7.7/vmstat-a.json
vendored
Normal file
1
tests/fixtures/centos-7.7/vmstat-a.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"runnable_procs":2,"uninterruptible_sleeping_procs":0,"virtual_mem_used":0,"free_mem":2794696,"buffer_mem":null,"cache_mem":null,"inactive_mem":295968,"active_mem":312736,"swap_in":0,"swap_out":0,"blocks_in":1,"blocks_out":3,"interrupts":29,"context_switches":57,"user_time":0,"system_time":0,"idle_time":99,"io_wait_time":0,"stolen_time":0,"timestamp":null,"timezone":null}]
|
1
tests/fixtures/centos-7.7/vmstat-at-5-10.json
vendored
Normal file
1
tests/fixtures/centos-7.7/vmstat-at-5-10.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"runnable_procs":2,"uninterruptible_sleeping_procs":0,"virtual_mem_used":0,"free_mem":2794716,"buffer_mem":null,"cache_mem":null,"inactive_mem":295968,"active_mem":312724,"swap_in":0,"swap_out":0,"blocks_in":1,"blocks_out":3,"interrupts":29,"context_switches":57,"user_time":0,"system_time":0,"idle_time":99,"io_wait_time":0,"stolen_time":0,"timestamp":"2021-09-16 20:33:13","timezone":"PDT","epoch":1631849593,"epoch_utc":null},{"runnable_procs":0,"uninterruptible_sleeping_procs":0,"virtual_mem_used":0,"free_mem":2794716,"buffer_mem":null,"cache_mem":null,"inactive_mem":295968,"active_mem":312744,"swap_in":0,"swap_out":0,"blocks_in":0,"blocks_out":0,"interrupts":41,"context_switches":84,"user_time":0,"system_time":0,"idle_time":100,"io_wait_time":0,"stolen_time":0,"timestamp":"2021-09-16 20:33:18","timezone":"PDT","epoch":1631849598,"epoch_utc":null},{"runnable_procs":0,"uninterruptible_sleeping_procs":0,"virtual_mem_used":0,"free_mem":2794716,"buffer_mem":null,"cache_mem":null,"inactive_mem":295968,"active_mem":312752,"swap_in":0,"swap_out":0,"blocks_in":0,"blocks_out":0,"interrupts":41,"context_switches":84,"user_time":0,"system_time":0,"idle_time":100,"io_wait_time":0,"stolen_time":0,"timestamp":"2021-09-16 20:33:23","timezone":"PDT","epoch":1631849603,"epoch_utc":null},{"runnable_procs":0,"uninterruptible_sleeping_procs":0,"virtual_mem_used":0,"free_mem":2794716,"buffer_mem":null,"cache_mem":null,"inactive_mem":295968,"active_mem":312752,"swap_in":0,"swap_out":0,"blocks_in":0,"blocks_out":0,"interrupts":44,"context_switches":87,"user_time":0,"system_time":0,"idle_time":100,"io_wait_time":0,"stolen_time":0,"timestamp":"2021-09-16 20:33:28","timezone":"PDT","epoch":1631849608,"epoch_utc":null}]
|
1
tests/fixtures/centos-7.7/vmstat-awt.json
vendored
Normal file
1
tests/fixtures/centos-7.7/vmstat-awt.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"runnable_procs":2,"uninterruptible_sleeping_procs":0,"virtual_mem_used":0,"free_mem":2794864,"buffer_mem":null,"cache_mem":null,"inactive_mem":295968,"active_mem":312724,"swap_in":0,"swap_out":0,"blocks_in":1,"blocks_out":3,"interrupts":29,"context_switches":57,"user_time":0,"system_time":0,"idle_time":99,"io_wait_time":0,"stolen_time":0,"timestamp":"2021-09-16 20:31:30","timezone":"PDT","epoch":1631849490,"epoch_utc":null}]
|
1
tests/fixtures/centos-7.7/vmstat-d.json
vendored
Normal file
1
tests/fixtures/centos-7.7/vmstat-d.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"disk":"sda","total_reads":15257,"merged_reads":100,"sectors_read":841035,"reading_ms":8395,"total_writes":50851,"merged_writes":5502,"sectors_written":1648657,"writing_ms":146540,"current_io":0,"io_seconds":44,"timestamp":null,"timezone":null},{"disk":"sr0","total_reads":0,"merged_reads":0,"sectors_read":0,"reading_ms":0,"total_writes":0,"merged_writes":0,"sectors_written":0,"writing_ms":0,"current_io":0,"io_seconds":0,"timestamp":null,"timezone":null},{"disk":"dm-0","total_reads":14910,"merged_reads":0,"sectors_read":775075,"reading_ms":8350,"total_writes":56343,"merged_writes":0,"sectors_written":1644520,"writing_ms":180880,"current_io":0,"io_seconds":44,"timestamp":null,"timezone":null},{"disk":"dm-1","total_reads":88,"merged_reads":0,"sectors_read":4408,"reading_ms":13,"total_writes":0,"merged_writes":0,"sectors_written":0,"writing_ms":0,"current_io":0,"io_seconds":0,"timestamp":null,"timezone":null}]
|
1
tests/fixtures/centos-7.7/vmstat-dt.json
vendored
Normal file
1
tests/fixtures/centos-7.7/vmstat-dt.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"disk":"sda","total_reads":15257,"merged_reads":100,"sectors_read":841035,"reading_ms":8395,"total_writes":50851,"merged_writes":5502,"sectors_written":1648657,"writing_ms":146540,"current_io":0,"io_seconds":44,"timestamp":"2021-09-16 20:32:28","timezone":"UTC","epoch":1631849548,"epoch_utc":1631824348},{"disk":"sr0","total_reads":0,"merged_reads":0,"sectors_read":0,"reading_ms":0,"total_writes":0,"merged_writes":0,"sectors_written":0,"writing_ms":0,"current_io":0,"io_seconds":0,"timestamp":"2021-09-16 20:32:28","timezone":"UTC","epoch":1631849548,"epoch_utc":1631824348},{"disk":"dm-0","total_reads":14910,"merged_reads":0,"sectors_read":775075,"reading_ms":8350,"total_writes":56343,"merged_writes":0,"sectors_written":1644520,"writing_ms":180880,"current_io":0,"io_seconds":44,"timestamp":"2021-09-16 20:32:28","timezone":"UTC","epoch":1631849548,"epoch_utc":1631824348},{"disk":"dm-1","total_reads":88,"merged_reads":0,"sectors_read":4408,"reading_ms":13,"total_writes":0,"merged_writes":0,"sectors_written":0,"writing_ms":0,"current_io":0,"io_seconds":0,"timestamp":"2021-09-16 20:32:28","timezone":"UTC","epoch":1631849548,"epoch_utc":1631824348}]
|
1
tests/fixtures/centos-7.7/vmstat-w.json
vendored
Normal file
1
tests/fixtures/centos-7.7/vmstat-w.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"runnable_procs":2,"uninterruptible_sleeping_procs":0,"virtual_mem_used":0,"free_mem":2794484,"buffer_mem":2108,"cache_mem":741208,"inactive_mem":null,"active_mem":null,"swap_in":0,"swap_out":0,"blocks_in":1,"blocks_out":3,"interrupts":29,"context_switches":57,"user_time":0,"system_time":0,"idle_time":99,"io_wait_time":0,"stolen_time":0,"timestamp":null,"timezone":null}]
|
1
tests/fixtures/centos-7.7/vmstat.json
vendored
Normal file
1
tests/fixtures/centos-7.7/vmstat.json
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
[{"runnable_procs":2,"uninterruptible_sleeping_procs":0,"virtual_mem_used":0,"free_mem":2794468,"buffer_mem":2108,"cache_mem":741208,"inactive_mem":null,"active_mem":null,"swap_in":0,"swap_out":0,"blocks_in":1,"blocks_out":3,"interrupts":29,"context_switches":57,"user_time":0,"system_time":0,"idle_time":99,"io_wait_time":0,"stolen_time":0,"timestamp":null,"timezone":null}]
|
113
tests/test_vmstat.py
Normal file
113
tests/test_vmstat.py
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import json
|
||||||
|
import unittest
|
||||||
|
import jc.parsers.vmstat
|
||||||
|
|
||||||
|
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
# Set the timezone on POSIX systems. Need to manually set for Windows tests
|
||||||
|
if not sys.platform.startswith('win32'):
|
||||||
|
os.environ['TZ'] = 'America/Los_Angeles'
|
||||||
|
time.tzset()
|
||||||
|
|
||||||
|
|
||||||
|
class MyTests(unittest.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
# input
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/vmstat.out'), 'r', encoding='utf-8') as f:
|
||||||
|
self.centos_7_7_vmstat = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/vmstat-a.out'), 'r', encoding='utf-8') as f:
|
||||||
|
self.centos_7_7_vmstat_a = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/vmstat-at-5-10.out'), 'r', encoding='utf-8') as f:
|
||||||
|
self.centos_7_7_vmstat_at_5_10 = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/vmstat-awt.out'), 'r', encoding='utf-8') as f:
|
||||||
|
self.centos_7_7_vmstat_awt = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/vmstat-d.out'), 'r', encoding='utf-8') as f:
|
||||||
|
self.centos_7_7_vmstat_d = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/vmstat-dt.out'), 'r', encoding='utf-8') as f:
|
||||||
|
self.centos_7_7_vmstat_dt = f.read()
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/vmstat-w.out'), 'r', encoding='utf-8') as f:
|
||||||
|
self.centos_7_7_vmstat_w = f.read()
|
||||||
|
|
||||||
|
# output
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/vmstat.json'), 'r', encoding='utf-8') as f:
|
||||||
|
self.centos_7_7_vmstat_json = json.loads(f.read())
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/vmstat-a.json'), 'r', encoding='utf-8') as f:
|
||||||
|
self.centos_7_7_vmstat_a_json = json.loads(f.read())
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/vmstat-at-5-10.json'), 'r', encoding='utf-8') as f:
|
||||||
|
self.centos_7_7_vmstat_at_5_10_json = json.loads(f.read())
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/vmstat-awt.json'), 'r', encoding='utf-8') as f:
|
||||||
|
self.centos_7_7_vmstat_awt_json = json.loads(f.read())
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/vmstat-d.json'), 'r', encoding='utf-8') as f:
|
||||||
|
self.centos_7_7_vmstat_d_json = json.loads(f.read())
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/vmstat-dt.json'), 'r', encoding='utf-8') as f:
|
||||||
|
self.centos_7_7_vmstat_dt_json = json.loads(f.read())
|
||||||
|
|
||||||
|
with open(os.path.join(THIS_DIR, os.pardir, 'tests/fixtures/centos-7.7/vmstat-w.json'), 'r', encoding='utf-8') as f:
|
||||||
|
self.centos_7_7_vmstat_w_json = json.loads(f.read())
|
||||||
|
|
||||||
|
def test_vmstat_nodata(self):
|
||||||
|
"""
|
||||||
|
Test 'vmstat' with no data
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.vmstat.parse('', quiet=True), [])
|
||||||
|
|
||||||
|
def test_vmstat(self):
|
||||||
|
"""
|
||||||
|
Test 'vmstat'
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.vmstat.parse(self.centos_7_7_vmstat, quiet=True), self.centos_7_7_vmstat_json)
|
||||||
|
|
||||||
|
def test_vmstat_a(self):
|
||||||
|
"""
|
||||||
|
Test 'vmstat -a'
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.vmstat.parse(self.centos_7_7_vmstat_a, quiet=True), self.centos_7_7_vmstat_a_json)
|
||||||
|
|
||||||
|
def test_vmstat_at_5_10(self):
|
||||||
|
"""
|
||||||
|
Test 'vmstat -at 5 10'
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.vmstat.parse(self.centos_7_7_vmstat_at_5_10, quiet=True), self.centos_7_7_vmstat_at_5_10_json)
|
||||||
|
|
||||||
|
def test_vmstat_awt(self):
|
||||||
|
"""
|
||||||
|
Test 'vmstat -awt'
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.vmstat.parse(self.centos_7_7_vmstat_awt, quiet=True), self.centos_7_7_vmstat_awt_json)
|
||||||
|
|
||||||
|
def test_vmstat_d(self):
|
||||||
|
"""
|
||||||
|
Test 'vmstat -d'
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.vmstat.parse(self.centos_7_7_vmstat_d, quiet=True), self.centos_7_7_vmstat_d_json)
|
||||||
|
|
||||||
|
def test_vmstat_dt(self):
|
||||||
|
"""
|
||||||
|
Test 'vmstat -dt'
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.vmstat.parse(self.centos_7_7_vmstat_dt, quiet=True), self.centos_7_7_vmstat_dt_json)
|
||||||
|
|
||||||
|
def test_vmstat_w(self):
|
||||||
|
"""
|
||||||
|
Test 'vmstat -w'
|
||||||
|
"""
|
||||||
|
self.assertEqual(jc.parsers.vmstat.parse(self.centos_7_7_vmstat_w, quiet=True), self.centos_7_7_vmstat_w_json)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Reference in New Issue
Block a user