Francesco Romani has uploaded a new change for review.
Change subject: tests: sampling: add initial HostStatsThread tests ......................................................................
tests: sampling: add initial HostStatsThread tests
This patch adds a unit test to HostStatsThread.
Change-Id: Ic4e5765364cf46e1ebfaac72aa5f75c80e83779e Relates-To: https://bugzilla.redhat.com/1113948 Signed-off-by: Francesco Romani fromani@redhat.com --- M tests/samplingTests.py M vdsm/virt/sampling.py 2 files changed, 37 insertions(+), 1 deletion(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/66/29566/1
diff --git a/tests/samplingTests.py b/tests/samplingTests.py index 2ff703e..5126f69 100644 --- a/tests/samplingTests.py +++ b/tests/samplingTests.py @@ -21,6 +21,8 @@ import os import tempfile import shutil +import threading +import time
from vdsm import ipwrapper import virt.sampling as sampling @@ -111,3 +113,37 @@ s1 = sampling.InterfaceSample(lo) s1.operstate = 'x' self.assertEquals('operstate:x', s1.connlog_diff(s0)) + + +class HostStatsThread(TestCaseBase): + FAILED_SAMPLE = 3 # random 'small' value + STOP_SAMPLE = 6 # ditto + + def setUp(self): + self._hs = None + self._sampleCount = 0 + self._samplingDone = threading.Event() + + def testContinueWithErrors(self): + """ + bz1113948: do not give up on errors != TimeoutError + """ + def WrapHostSample(pid): + self._sampleCount += 1 + if self._sampleCount == self.FAILED_SAMPLE: + raise ValueError + if self._sampleCount == self.STOP_SAMPLE: + self._hs.stop() + self._samplingDone.set() + return None # sampling.HostSample(pid) + + def nosleep(seconds): + pass + + with MonkeyPatchScope([(sampling, 'HostSample', WrapHostSample), + (time, 'sleep', nosleep)]): + self._hs = sampling.HostStatsThread(self.log) + self._hs.start() + self._samplingDone.wait() + self._hs.stop() + self.assertTrue(self._sampleCount >= self.STOP_SAMPLE) diff --git a/vdsm/virt/sampling.py b/vdsm/virt/sampling.py index 5f04f27..ccb0672 100644 --- a/vdsm/virt/sampling.py +++ b/vdsm/virt/sampling.py @@ -507,7 +507,7 @@ exc_info=True) except Exception: self._log.exception("Error while sampling stats") - self._stopEvent.wait(self.SAMPLE_INTERVAL_SEC) + time.sleep(self.SAMPLE_INTERVAL_SEC)
@utils.memoized def _boot_time(self):
Francesco Romani has posted comments on this change.
Change subject: tests: sampling: add initial HostStatsThread tests ......................................................................
Patch Set 1: Verified+1
Verified: it works and do not waste time
Ran 8 tests in 0.165s
oVirt Jenkins CI Server has posted comments on this change.
Change subject: tests: sampling: add initial HostStatsThread tests ......................................................................
Patch Set 1:
Build Failed
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/9957/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/10742/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_virt_functional_tests_gerrit/1157/ : There was an infra issue, please contact infra@ovirt.org
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/10899/ : SUCCESS
Vinzenz Feenstra has posted comments on this change.
Change subject: tests: sampling: add initial HostStatsThread tests ......................................................................
Patch Set 1: Code-Review-1
(1 comment)
http://gerrit.ovirt.org/#/c/29566/1/vdsm/virt/sampling.py File vdsm/virt/sampling.py:
Line 506: self._log.error("Timeout while sampling stats", Line 507: exc_info=True) Line 508: except Exception: Line 509: self._log.exception("Error while sampling stats") Line 510: time.sleep(self.SAMPLE_INTERVAL_SEC) Well I don't see why you would sleep here? This is not a good idea. If the stop event is set you should come out of there ASAP Line 511: Line 512: @utils.memoized Line 513: def _boot_time(self): Line 514: # Try to get boot time only once, if N/A just log the error and never
Francesco Romani has posted comments on this change.
Change subject: tests: sampling: add initial HostStatsThread tests ......................................................................
Patch Set 2:
fixed wasteful wait.
oVirt Jenkins CI Server has posted comments on this change.
Change subject: tests: sampling: add initial HostStatsThread tests ......................................................................
Patch Set 2:
Build Failed
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/10365/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/11150/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_virt_functional_tests_gerrit/1348/ : There was an infra issue, please contact infra@ovirt.org
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/11307/ : FAILURE
Francesco Romani has posted comments on this change.
Change subject: tests: sampling: add initial HostStatsThread tests ......................................................................
Patch Set 2: Verified+1
verified running the new test.
Francesco Romani has posted comments on this change.
Change subject: tests: sampling: add initial HostStatsThread tests ......................................................................
Patch Set 2: -Verified
Francesco Romani has posted comments on this change.
Change subject: tests: sampling: add initial HostStatsThread tests ......................................................................
Patch Set 3: Verified+1
veridied running the new test fixed to make pyflakes happy as well.
oVirt Jenkins CI Server has posted comments on this change.
Change subject: tests: sampling: add initial HostStatsThread tests ......................................................................
Patch Set 3:
Build Failed
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/13088/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/12930/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/12140/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_virt_functional_tests_gerrit/1803/ : There was an infra issue, please contact infra@ovirt.org
Dan Kenigsberg has posted comments on this change.
Change subject: tests: sampling: add initial HostStatsThread tests ......................................................................
Patch Set 3:
(1 comment)
http://gerrit.ovirt.org/#/c/29566/3/vdsm/virt/sampling.py File vdsm/virt/sampling.py:
Line 481: """ Line 482: A thread that periodically samples host statistics. Line 483: """ Line 484: AVERAGING_WINDOW = 5 Line 485: SAMPLE_INTERVAL_SEC = 2 can we monkey-patch the class member, instead of adding a test-only arg? Line 486: _CONNLOG = logging.getLogger('connectivity') Line 487: Line 488: def __init__(self, log, sampleInterval=None): Line 489: self.startTime = time.time()
Francesco Romani has posted comments on this change.
Change subject: tests: sampling: add initial HostStatsThread tests ......................................................................
Patch Set 3:
(1 comment)
http://gerrit.ovirt.org/#/c/29566/3/vdsm/virt/sampling.py File vdsm/virt/sampling.py:
Line 481: """ Line 482: A thread that periodically samples host statistics. Line 483: """ Line 484: AVERAGING_WINDOW = 5 Line 485: SAMPLE_INTERVAL_SEC = 2
can we monkey-patch the class member, instead of adding a test-only arg?
Good point. Done. Line 486: _CONNLOG = logging.getLogger('connectivity') Line 487: Line 488: def __init__(self, log, sampleInterval=None): Line 489: self.startTime = time.time()
Francesco Romani has posted comments on this change.
Change subject: tests: sampling: add initial HostStatsThread tests ......................................................................
Patch Set 4: Verified+1
version 4 uses monkey patch to avoid a test-only argument, as Dan suggested.
Dan Kenigsberg has posted comments on this change.
Change subject: tests: sampling: add initial HostStatsThread tests ......................................................................
Patch Set 4: Code-Review+2
Dan Kenigsberg has submitted this change and it was merged.
Change subject: tests: sampling: add initial HostStatsThread tests ......................................................................
tests: sampling: add initial HostStatsThread tests
This patch adds a unit test to HostStatsThread.
Change-Id: Ic4e5765364cf46e1ebfaac72aa5f75c80e83779e Relates-To: https://bugzilla.redhat.com/1113948 Signed-off-by: Francesco Romani fromani@redhat.com Reviewed-on: http://gerrit.ovirt.org/29566 Reviewed-by: Dan Kenigsberg danken@redhat.com --- M tests/samplingTests.py 1 file changed, 32 insertions(+), 0 deletions(-)
Approvals: Dan Kenigsberg: Looks good to me, approved Francesco Romani: Verified
oVirt Jenkins CI Server has posted comments on this change.
Change subject: tests: sampling: add initial HostStatsThread tests ......................................................................
Patch Set 4:
Build Failed
http://jenkins.ovirt.org/job/vdsm_master_pep8_gerrit/13801/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit_tests_gerrit_el/13012/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_created/13964/ : SUCCESS
oVirt Jenkins CI Server has posted comments on this change.
Change subject: tests: sampling: add initial HostStatsThread tests ......................................................................
Patch Set 5:
Build Failed
http://jenkins.ovirt.org/job/vdsm_master-libfapi_create-rpms-el6-x86_64_merg... : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_create-rpms-fc21-x86_64_merged/247/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master-libfapi_create-rpms-fc20-x86_64_mer... : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_create-rpms_merged_test_debug/464/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master-libfapi_create-rpms-el7-x86_64_merg... : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_create-rpms-fc20-x86_64_merged/262/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_unit-tests_merged/4256/ : FAILURE
http://jenkins.ovirt.org/job/vdsm_master_create-rpms-el6-x86_64_merged/269/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_create-rpms-el7-x86_64_merged/271/ : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master-libfapi_create-rpms-fc21-x86_64_mer... : SUCCESS
http://jenkins.ovirt.org/job/vdsm_master_verify-error-codes_merged/6094/ : SUCCESS
vdsm-patches@lists.fedorahosted.org