Nir Soffer has uploaded a new change for review.
Change subject: clientIF: Decouple HSM and clientIF
......................................................................
clientIF: Decouple HSM and clientIF
clientIF.irs is currently created in clientIF.__init__, coupling
clientIF and HSM and creating confusion about irs availability during
initialization. There is a small window where irs is constructed but
not set yet. This state is invalid; we have only two states, irs
enabled or not, and we don't support moving from one state to the other.
This patch separates irs creation from clientIF creation. clientIF is
created now with either a fully constructed irs object or None,
eliminating the confusing unwanted state.
This change also makes it easier to test clientIF, allowing creating of
clientIF with fake irs instance.
Change-Id: I09aba3638d0dcf5aef73864dd0fe8eae1ced70b2
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
M vdsm/clientIF.py
M vdsm/vdsm
2 files changed, 22 insertions(+), 20 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/77/21877/1
diff --git a/vdsm/clientIF.py b/vdsm/clientIF.py
index 0b67e45..4ff570c 100644
--- a/vdsm/clientIF.py
+++ b/vdsm/clientIF.py
@@ -25,8 +25,6 @@
from xml.dom import minidom
import uuid
-from storage.dispatcher import Dispatcher
-from storage.hsm import HSM
import alignmentScan
from vdsm.config import config
import ksm
@@ -61,21 +59,25 @@
_instance = None
_instanceLock = threading.Lock()
- def __init__(self, log):
+ def __init__(self, irs, log):
"""
Initialize the (single) clientIF instance
+ :param irs: a Dispatcher object to be used as this object's irs.
+ :type irs: :class:`storage.dispatcher.Dispatcher`
:param log: a log object to be used for this object's logging.
:type log: :class:`logging.Logger`
"""
self.vmContainerLock = threading.Lock()
self._networkSemaphore = threading.Semaphore()
self._shutdownSemaphore = threading.Semaphore()
+ self.irs = irs
+ if self.irs:
+ self.irs.registerDomainStateChangeCallback(self.contEIOVms)
self.log = log
self._recovery = True
self.channelListener = Listener(self.log)
self._generationID = str(uuid.uuid4())
- self._initIRS()
self.mom = None
if _glusterEnabled:
self.gluster = gapi.GlusterApi(self, log)
@@ -130,14 +132,14 @@
vmObj.cont()
@classmethod
- def getInstance(cls, log=None):
+ def getInstance(cls, irs=None, log=None):
with cls._instanceLock:
if cls._instance is None:
if log is None:
raise Exception("Logging facility is required to create "
"the single clientIF instance")
else:
- cls._instance = clientIF(log)
+ cls._instance = clientIF(irs, log)
return cls._instance
def _loadBindingXMLRPC(self):
@@ -246,16 +248,6 @@
binding.start()
while self._enabled:
time.sleep(3)
-
- def _initIRS(self):
- self.irs = None
- if config.getboolean('irs', 'irs_enable'):
- try:
- self.irs = Dispatcher(HSM())
- except:
- self.log.error("Error initializing IRS", exc_info=True)
- else:
- self.irs.registerDomainStateChangeCallback(self.contEIOVms)
def _getUUIDSpecPath(self, uuid):
try:
diff --git a/vdsm/vdsm b/vdsm/vdsm
index 4ef9370..51e6aaa 100755
--- a/vdsm/vdsm
+++ b/vdsm/vdsm
@@ -24,6 +24,9 @@
from vdsm import constants
from vdsm.config import config
+from storage.dispatcher import Dispatcher
+from storage.hsm import HSM
+
import zombiereaper
import dsaversion
if sys.version_info[0] == 2:
@@ -42,6 +45,7 @@
def serve_clients(log):
cif = None
+ irs = None
def sigtermHandler(signum, frame):
if cif:
@@ -49,17 +53,23 @@
cif.prepareForShutdown()
def sigusr1Handler(signum, frame):
- if cif and cif.irs:
+ if irs:
log.debug("Received signal %s" % signum)
- cif.irs.spmStop(
- cif.irs.getConnectedStoragePoolsList()['poollist'][0])
+ irs.spmStop(
+ irs.getConnectedStoragePoolsList()['poollist'][0])
signal.signal(signal.SIGTERM, sigtermHandler)
signal.signal(signal.SIGUSR1, sigusr1Handler)
zombiereaper.registerSignalHandler()
+ if config.getboolean('irs', 'irs_enable'):
+ try:
+ irs = Dispatcher(HSM())
+ except:
+ log.error("Error initializing IRS", exc_info=True)
+
from clientIF import clientIF # must import after config is read
- cif = clientIF.getInstance(log)
+ cif = clientIF.getInstance(irs, log)
cif.serve()
--
To view, visit
http://gerrit.ovirt.org/21877
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I09aba3638d0dcf5aef73864dd0fe8eae1ced70b2
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer(a)redhat.com>