Yaniv Bronhaim has uploaded a new change for review. Change subject: Moving panic function to utils and set panic mock for tests ......................................................................
Moving panic function to utils and set panic mock for tests The patch moves panic function to vdsm utils for general use. During tests panic call will raise assertionError. Signed-off-by: Yaniv Bronhaim <ybron...@redhat.com> Change-Id: Ia2ae7ba76d6a935c0f8c8854bedce985376ed219 --- M lib/vdsm/utils.py M tests/testrunner.py M tests/utilsTests.py M vdsm/storage/misc.py M vdsm/storage/sp.py M vdsm/supervdsm.py 6 files changed, 25 insertions(+), 10 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/27/14427/1 diff --git a/lib/vdsm/utils.py b/lib/vdsm/utils.py index cfec8cc..f1a31b6 100644 --- a/lib/vdsm/utils.py +++ b/lib/vdsm/utils.py @@ -36,6 +36,7 @@ import glob import io import logging +import sys import os import pwd import select @@ -813,3 +814,9 @@ raise time.sleep(sleep) + + +def panic(msg): + logging.error("Panic: %s", msg, exc_info=True) + os.killpg(0, 9) + sys.exit(-3) diff --git a/tests/testrunner.py b/tests/testrunner.py index bbbb127..012dbe7 100644 --- a/tests/testrunner.py +++ b/tests/testrunner.py @@ -38,6 +38,15 @@ from testValidation import SlowTestsPlugin, StressTestsPlugin + +# Mock panic() for tests. Instead of exit, raising AssertionError for tests +def panicMock(msg): + msg = "Panic: %s" % (msg) + raise AssertionError(msg) + +from vdsm import utils +utils.panic = panicMock + import zombieReaper zombieReaper.registerSignalHandler() diff --git a/tests/utilsTests.py b/tests/utilsTests.py index dcc78ed..758bc8a 100644 --- a/tests/utilsTests.py +++ b/tests/utilsTests.py @@ -75,3 +75,8 @@ self.assertEquals(e.errno, errno.ENOENT) self.assertTrue(NAME in e.strerror, msg='%s not in %s' % (NAME, e.strerror)) + + +class GeneralUtilsTests(TestCaseBase): + def testPanic(self): + self.assertRaises(AssertionError, utils.panic, "panic test") diff --git a/vdsm/storage/misc.py b/vdsm/storage/misc.py index b500f25..7c735b6 100644 --- a/vdsm/storage/misc.py +++ b/vdsm/storage/misc.py @@ -159,12 +159,6 @@ return result -def panic(msg): - log.error("Panic: %s", msg, exc_info=True) - os.killpg(0, 9) - sys.exit(-3) - - execCmdLogger = enableLogSkip(logging.getLogger('Storage.Misc.excCmd'), ignoreSourceFiles=[__file__], logSkipName="Storage.Misc.excCmd") diff --git a/vdsm/storage/sp.py b/vdsm/storage/sp.py index 39ea182..ed79808 100644 --- a/vdsm/storage/sp.py +++ b/vdsm/storage/sp.py @@ -32,7 +32,7 @@ from imageRepository.formatConverter import DefaultFormatConverter -from vdsm import constants +from vdsm import constants, utils import storage_mailbox import blockSD import fileSD @@ -388,7 +388,7 @@ try: blockSD.BlockStorageDomain.doUnmountMaster(master) except se.StorageDomainMasterUnmountError as e: - misc.panic("unmount %s failed - %s" % (master, e)) + utils.panic("unmount %s failed - %s" % (master, e)) else: cls.log.debug("master `%s` is not mounted, skipping", master) @@ -429,7 +429,7 @@ stopFailed = True if stopFailed: - misc.panic("Unrecoverable errors during SPM stop process.") + utils.panic("Unrecoverable errors during SPM stop process.") self.spmRole = SPM_FREE diff --git a/vdsm/supervdsm.py b/vdsm/supervdsm.py index 720be05..b69d6ea 100644 --- a/vdsm/supervdsm.py +++ b/vdsm/supervdsm.py @@ -201,7 +201,7 @@ # more time than expected. utils.retry(self._connect, Exception, timeout=60, tries=3) except: - misc.panic("Couldn't connect to supervdsm") + utils.panic("Couldn't connect to supervdsm") def __getattr__(self, name): return ProxyCaller(self, name) -- To view, visit http://gerrit.ovirt.org/14427 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia2ae7ba76d6a935c0f8c8854bedce985376ed219 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Yaniv Bronhaim <ybron...@redhat.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches