Francesco Romani has uploaded a new change for review.
Change subject: tests: add HostStatsThread._getCpuCoreStats test
......................................................................
tests: add HostStatsThread._getCpuCoreStats test
Next patch wants to refactor
HostStatsThread._getCpuCoreStats into a free function,
so this patch adds very basic test coverage.
This test needs to be refactored as well, and will
be done alongside the method refactoring.
Change-Id: I6c6a82c77054e76d7d08322ad83d086302c2bbad
Signed-off-by: Francesco Romani <fromani(a)redhat.com>
---
M tests/samplingTests.py
M tests/vmfakelib.py
2 files changed, 49 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/72/41372/1
diff --git a/tests/samplingTests.py b/tests/samplingTests.py
index 9e3c3c3..74218e7 100644
--- a/tests/samplingTests.py
+++ b/tests/samplingTests.py
@@ -30,11 +30,14 @@
from vdsm.password import ProtectedPassword
import virt.sampling as sampling
+import caps
+
from testValidation import brokentest, ValidateRunningAsRoot
from testlib import permutations, expandPermutations
from testlib import VdsmTestCase as TestCaseBase
from monkeypatch import MonkeyPatchScope
from functional import dummy
+import vmfakelib as fake
class SamplingTests(TestCaseBase):
@@ -269,6 +272,36 @@
}
self.assertEquals(self._hs.get(), expected)
+ def testCpuCoreStats(self):
+ node_id, cpu_id = 0, 0
+ self._hs = sampling.HostStatsThread(self.log)
+ cpu_sample = {'user': 1.0, 'sys': 2.0}
+
+ for fake_ts in xrange(5): # FIXME
+ self._hs._samples.append(
+ fake.HostSample(fake_ts, {cpu_id: cpu_sample}))
+
+ def fakeNumaTopology():
+ return {
+ node_id: {
+ 'cpus': [cpu_id]
+ }
+ }
+
+ expected = {
+ '0': {
+ 'cpuIdle': '100.00',
+ 'cpuSys': '0.00',
+ 'cpuUser': '0.00',
+ 'nodeIndex': 0
+ }
+ }
+
+ with MonkeyPatchScope([(caps, 'getNumaTopology',
+ fakeNumaTopology)]):
+ self.assertEqual(self._hs._getCpuCoresStats(),
+ expected)
+
class StatsCacheTests(TestCaseBase):
diff --git a/tests/vmfakelib.py b/tests/vmfakelib.py
index 995508c..61ac448 100644
--- a/tests/vmfakelib.py
+++ b/tests/vmfakelib.py
@@ -240,3 +240,19 @@
def last(self):
return self._samples
+
+
+class CpuCoreSample(object):
+
+ def __init__(self, samples):
+ self._samples = samples
+
+ def getCoreSample(self, key):
+ return self._samples[key]
+
+
+class HostSample(object):
+
+ def __init__(self, timestamp, samples):
+ self.timestamp = timestamp
+ self.cpuCores = CpuCoreSample(samples)
--
To view, visit
https://gerrit.ovirt.org/41372
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I6c6a82c77054e76d7d08322ad83d086302c2bbad
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani(a)redhat.com>