Saggi Mizrahi has uploaded a new change for review. Change subject: Refactor mom init error flow ......................................................................
Refactor mom init error flow Splitting a log to to log invocation is bad because it could potentially separate the 2 log lines. Further more, it usually points out to a bad flow if you only sometimes need to log in the same flow so you resort to such tricks. - Add proper exception when MomThread fails to initialize - Make the two error flows clear and have each logged properly Change-Id: I03ff6057cdbb22b88ed2b5766bda399651c4d058 Signed-off-by: Saggi Mizrahi <[email protected]> --- M vdsm/clientIF.py M vdsm/momIF.py 2 files changed, 25 insertions(+), 10 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/81/9481/1 diff --git a/vdsm/clientIF.py b/vdsm/clientIF.py index 82603af..0bd686f 100644 --- a/vdsm/clientIF.py +++ b/vdsm/clientIF.py @@ -29,7 +29,7 @@ from storage.hsm import HSM from vdsm.config import config import ksm -from momIF import MomThread +from momIF import MomThread, isMomAvailable from vdsm import netinfo from vdsm.define import doneCode, errCode import libvirt @@ -189,14 +189,20 @@ 'Please make sure it is installed.') def _prepareMOM(self): - try: - momconf = config.get("mom", "conf") - self.mom = MomThread(momconf) - except: - self.log.warn("MOM initialization failed and fall " - "back to KsmMonitor") - self.log.debug("Details:", exc_info=True) - self.ksmMonitor = ksm.KsmMonitorThread(self) + momconf = config.get("mom", "conf") + + if isMomAvailable(): + try: + self.mom = MomThread(momconf) + return + except: + self.log.warn("MOM initialization failed and fall " + "back to KsmMonitor", exc_info=True) + + else: + self.log.warn("MOM is not available, fallback to KsmMonitor") + + self.ksmMonitor = ksm.KsmMonitorThread(self) def _syncLibvirtNetworks(self): """ diff --git a/vdsm/momIF.py b/vdsm/momIF.py index 827e9e4..807daef 100644 --- a/vdsm/momIF.py +++ b/vdsm/momIF.py @@ -27,11 +27,20 @@ _momAvailable = False +class MomNotAvailableError(RuntimeError): + pass + + +def isMomAvailable(): + return _momAvailable + + class MomThread(threading.Thread): def __init__(self, momconf): if not _momAvailable: - raise Exception("MOM is not available") + raise MomNotAvailableError() + self.log = logging.getLogger("MOM") self.log.info("Starting up MOM") self._mom = mom.MOM(momconf) -- To view, visit http://gerrit.ovirt.org/9481 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I03ff6057cdbb22b88ed2b5766bda399651c4d058 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Saggi Mizrahi <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
