Francesco Romani has uploaded a new change for review. Change subject: virt: sampling: add empty() method to StatsSample ......................................................................
virt: sampling: add empty() method to StatsSample kill the EMPTY_SAMPLE constant. we always need to fill the 'stats_age' field with meaningful value, None is not good. Replace it with a proper method. Change-Id: I7bc3712d36c46ade9a779411028817c197ec34b3 Backport-To: 4.0 Backport-To: 3.6 Bug-Url: https://bugzilla.redhat.com/1357798 Signed-off-by: Francesco Romani <from...@redhat.com> --- M lib/vdsm/virt/sampling.py M tests/samplingTests.py 2 files changed, 12 insertions(+), 6 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/20/61420/1 diff --git a/lib/vdsm/virt/sampling.py b/lib/vdsm/virt/sampling.py index 4cfd3b1..9cb3f2f 100644 --- a/lib/vdsm/virt/sampling.py +++ b/lib/vdsm/virt/sampling.py @@ -346,12 +346,18 @@ return sample -StatsSample = namedtuple('StatsSample', - ['first_value', 'last_value', - 'interval', 'stats_age']) +_StatsSample = namedtuple('StatsSample', + ['first_value', 'last_value', + 'interval', 'stats_age']) -EMPTY_SAMPLE = StatsSample(None, None, None, None) +class StatsSample(_StatsSample): + def empty(self): + return ( + self.first_value is None and + self.last_value is None and + self.interval is None + ) class StatsCache(object): diff --git a/tests/samplingTests.py b/tests/samplingTests.py index ee8be7f..2dc9bd9 100644 --- a/tests/samplingTests.py +++ b/tests/samplingTests.py @@ -256,14 +256,14 @@ def test_empty(self): res = self.cache.get('x') # vmid not relevant - self.assertEqual(res, sampling.EMPTY_SAMPLE) + self.assertTrue(res.empty()) def test_not_enough_samples(self): self._feed_cache(( ({'a': 42}, 1), )) res = self.cache.get('a') - self.assertEqual(res, sampling.EMPTY_SAMPLE) + self.assertTrue(res.empty()) def test_get(self): self._feed_cache(( -- To view, visit https://gerrit.ovirt.org/61420 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7bc3712d36c46ade9a779411028817c197ec34b3 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Francesco Romani <from...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/admin/lists/vdsm-patches@lists.fedorahosted.org