From: Aline Manera <alinefm(a)br.ibm.com>
Add new tests to verify the URI /host/stats/history
Signed-off-by: Aline Manera <alinefm(a)br.ibm.com>
---
tests/test_model.py | 12 +++++++-----
tests/test_rest.py | 12 +++++++-----
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/tests/test_model.py b/tests/test_model.py
index 2fb4446..4ff0813 100644
--- a/tests/test_model.py
+++ b/tests/test_model.py
@@ -986,6 +986,9 @@ class ModelTests(unittest.TestCase):
objstore_loc=self.tmp_store)
time.sleep(1.5)
stats = inst.hoststats_lookup()
+ stats_keys = ['cpu_utilization', 'memory',
'disk_read_rate',
+ 'disk_write_rate', 'net_recv_rate',
'net_sent_rate']
+ self.assertEquals(sorted(stats_keys), sorted(stats.keys()))
cpu_utilization = stats['cpu_utilization']
# cpu_utilization is set int 0, after first stats sample
# the cpu_utilization is float in range [0.0, 100.0]
@@ -1000,11 +1003,10 @@ class ModelTests(unittest.TestCase):
self.assertIn('buffers', memory_stats)
self.assertIn('avail', memory_stats)
- self.assertIn('disk_read_rate', stats)
- self.assertIn('disk_write_rate', stats)
-
- self.assertIn('net_recv_rate', stats)
- self.assertIn('net_sent_rate', stats)
+ history = inst.hoststatshistory_lookup()
+ self.assertEquals(sorted(stats_keys), sorted(history.keys()))
+ for key, value in history.iteritems():
+ self.assertEquals(type(value), list)
@unittest.skipUnless(utils.running_as_root(), 'Must be run as root')
def test_deep_scan(self):
diff --git a/tests/test_rest.py b/tests/test_rest.py
index 06396db..76e5e13 100644
--- a/tests/test_rest.py
+++ b/tests/test_rest.py
@@ -1555,8 +1555,12 @@ class RestTests(unittest.TestCase):
self.assertEquals(6114058240, info['memory'])
def test_hoststats(self):
+ stats_keys = ['cpu_utilization', 'memory',
'disk_read_rate',
+ 'disk_write_rate', 'net_recv_rate',
'net_sent_rate']
resp = self.request('/host/stats').read()
stats = json.loads(resp)
+ self.assertEquals(sorted(stats_keys), sorted(stats.keys()))
+
cpu_utilization = stats['cpu_utilization']
self.assertIsInstance(cpu_utilization, float)
self.assertGreaterEqual(cpu_utilization, 0.0)
@@ -1569,11 +1573,9 @@ class RestTests(unittest.TestCase):
self.assertIn('buffers', memory_stats)
self.assertIn('avail', memory_stats)
- self.assertIn('disk_read_rate', stats)
- self.assertIn('disk_write_rate', stats)
-
- self.assertIn('net_recv_rate', stats)
- self.assertIn('net_sent_rate', stats)
+ resp = self.request('/host/stats/history').read()
+ history = json.loads(resp)
+ self.assertEquals(sorted(stats_keys), sorted(history.keys()))
def test_packages_update(self):
resp = self.request('/host/packagesupdate', None, 'GET')
--
1.7.10.4