Change in vdsm[master]: tests: add tests for vmstats.cpu()

fromani at redhat.com fromani at redhat.com
Sun Feb 21 18:12:01 UTC 2016


Francesco Romani has uploaded a new change for review.

Change subject: tests: add tests for vmstats.cpu()
......................................................................

tests: add tests for vmstats.cpu()

Add tests for vmstats.cpu()

Change-Id: I8d8fe466a351335922f31b7ae264d2a870a30edb
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M tests/vmStatsTests.py
M vdsm/virt/vmstats.py
2 files changed, 51 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/77/53777/1

diff --git a/tests/vmStatsTests.py b/tests/vmStatsTests.py
index 26b29e8..6012a7d 100644
--- a/tests/vmStatsTests.py
+++ b/tests/vmStatsTests.py
@@ -461,6 +461,56 @@
         return partial_stats
 
 
+ at expandPermutations
+class CpuStatsTests(VmStatsTestCase):
+    # all data stolen from Vdsm and/or virsh -r domstats
+
+    # [first, last]
+    @permutations([[{}, {}],
+                   [{}, {'cpu.user': 4740000000, 'cpu.system': 6490000000}],
+                   [{'cpu.user': 4740000000, 'cpu.system': 6490000000}, {}]])
+    def test_empty_samples(self, first, last):
+        stats = {}
+        res = vmstats.cpu(stats, {}, {}, 15.)
+        self.assertEqual(stats,
+                         {'cpuUser': 0.0, 'cpuSys': 0.0})
+        self.assertFalse(res)
+
+    def test_only_cpu_user_system(self):
+        stats = {}
+        res = vmstats.cpu(stats,
+                          {'cpu.user': 4740000000, 'cpu.system': 6490000000},
+                          {'cpu.user': 4760000000, 'cpu.system': 6500000000},
+                          15.)
+        self.assertEqual(stats, {
+                         'cpuUser': 0.0,
+                         'cpuSys': 0.2,
+                         'cpuUsage': '11260000000',
+                         })
+        self.assertFalse(res)
+
+    def test_update_all_keys(self):
+        stats = {}
+        res = vmstats.cpu(stats,
+                    {
+                        'cpu.user': 4740000000,
+                        'cpu.system': 6490000000,
+                        'cpu.time': 24345584838,
+                    },
+                    {
+                        'cpu.user': 4760000000,
+                        'cpu.system': 6500000000,
+                        'cpu.time': 24478198023,
+                    },
+                    15.)
+        self.assertEqual(stats, {
+                         'cpuUser':  0.6840879,
+                         'cpuSys': 0.2,
+                         'cpuUsage': '11260000000',
+                         })
+        self.assertTrue(res)
+
+
 # helpers
 
 def _ensure_delta(stats_before, stats_after, key, delta):
diff --git a/vdsm/virt/vmstats.py b/vdsm/virt/vmstats.py
index 7855b4b..e77bf31 100644
--- a/vdsm/virt/vmstats.py
+++ b/vdsm/virt/vmstats.py
@@ -125,6 +125,7 @@
 
     except KeyError as e:
         logging.exception("CPU stats not available: %s", e)
+        return {}
 
     return stats
 


-- 
To view, visit https://gerrit.ovirt.org/53777
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8d8fe466a351335922f31b7ae264d2a870a30edb
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>


More information about the vdsm-patches mailing list