summaryrefslogtreecommitdiffstats
path: root/src/software
diff options
context:
space:
mode:
authorMichal Minar <miminar@redhat.com>2013-11-08 16:28:20 +0100
committerMichal Minar <miminar@redhat.com>2013-11-08 16:46:30 +0100
commita1720b88b0047dbdfaff33c485dc88379b2ee67e (patch)
tree5f9f609e3586d7e573576ee59d233105b49fa64e /src/software
parentb9cdba8739dfdbebe5cd65202e7ae642783b183c (diff)
downloadopenlmi-providers-a1720b88b0047dbdfaff33c485dc88379b2ee67e.tar.gz
openlmi-providers-a1720b88b0047dbdfaff33c485dc88379b2ee67e.tar.xz
openlmi-providers-a1720b88b0047dbdfaff33c485dc88379b2ee67e.zip
software: better cope with termination request
When cimom is terminated or killed and the provider is requested to clean up, let's stop waiting for separated process to complete its jobs and raise an error instead.
Diffstat (limited to 'src/software')
-rw-r--r--src/software/lmi/software/yumdb/__init__.py22
-rw-r--r--src/software/lmi/software/yumdb/errors.py4
2 files changed, 22 insertions, 4 deletions
diff --git a/src/software/lmi/software/yumdb/__init__.py b/src/software/lmi/software/yumdb/__init__.py
index 85f809e..54013f1 100644
--- a/src/software/lmi/software/yumdb/__init__.py
+++ b/src/software/lmi/software/yumdb/__init__.py
@@ -55,6 +55,7 @@ from lmi.software.yumdb.packagecheck import PackageFile
from lmi.software.yumdb.packageinfo import PackageInfo
from lmi.software.yumdb.process import YumWorker
from lmi.software.yumdb.repository import Repository
+from lmi.software.yumdb import errors
LOG = cmpi_logging.get_logger(__name__)
@@ -180,6 +181,10 @@ class YumDB(singletonmixin.Singleton):
"""
All arguments are passed to yum.YumBase constructor.
"""
+ #: Separated process accessing yum's api and handling jobs. Initialized
+ #: when first needed. If this is ``False``, clean up request has been
+ #: received. If ``None``, process has not been started yet or it was
+ #: killed.
self._process = None
if kwargs is None:
kwargs = {}
@@ -254,7 +259,7 @@ class YumDB(singletonmixin.Singleton):
"""
timeout = Configuration.get_instance().get_safe(
'Jobs', 'WaitCompleteTimeout', float)
- while True:
+ while self._process is not False: # process terminated
LOG().debug("[jobid=%d] blocking on downlink queue", job.jobid)
try:
jobout = self._worker.downlink.get(block=True, timeout=timeout)
@@ -274,6 +279,8 @@ class YumDB(singletonmixin.Singleton):
LOG().warn("[jobid=%d] wait for job reply timeout"
"(%d seconds) occured", job.jobid, timeout)
self._handle_reply_timeout(job)
+ raise errors.TerminatingError("can not complete job %s,"
+ " terminating ..." % job)
@cmpi_logging.trace_method
def _send_and_receive(self, job):
@@ -306,6 +313,9 @@ class YumDB(singletonmixin.Singleton):
job.jobid)
self._reply_cond.notifyAll()
return self._replies.pop(job.jobid)
+ if self._process is False:
+ raise errors.TerminatingError("can not complete job %s,"
+ " terminating ..." % job)
elif job.jobid not in self._expected:
# process terminated, resending job
LOG().warn("[jobid=%d] job removed from expected list,"
@@ -319,7 +329,7 @@ class YumDB(singletonmixin.Singleton):
LOG().debug("[jobid=%d] another %d threads expecting reply,"
" suspending...", job.jobid, len(self._expected) - 1)
self._reply_cond.wait()
- LOG().debug("[jobid=%d] received reply, waking up",
+ LOG().debug("[jobid=%d] received reply or terminating; waking up",
job.jobid)
return self._receive_reply(job)
@@ -342,6 +352,8 @@ class YumDB(singletonmixin.Singleton):
"""
YumWorker process accessor. It's created upon first need.
"""
+ if self._process is False:
+ raise errors.TerminatingError("provider is terminating")
if self._process is None:
LOG().trace_info("starting YumWorker")
uplink = Queue()
@@ -385,12 +397,14 @@ class YumDB(singletonmixin.Singleton):
Shut down the YumWorker process.
"""
with self._reply_lock:
- if self._process is not None:
+ if self._process:
LOG().info('terminating YumWorker')
self._process.uplink.put(None) # terminating command
self._process.join()
LOG().info('YumWorker terminated')
- self._process = None
+ # prohibit next instantiation
+ self._process = False
+ self._reply_cond.notifyAll()
else:
LOG().warn("clean_up called, when process not initialized!")
diff --git a/src/software/lmi/software/yumdb/errors.py b/src/software/lmi/software/yumdb/errors.py
index 44eb1c7..39238d1 100644
--- a/src/software/lmi/software/yumdb/errors.py
+++ b/src/software/lmi/software/yumdb/errors.py
@@ -50,6 +50,10 @@ class TransactionExecutionFailed(TransactionError):
"""Raised, when YumBase.doTransaction() method fails."""
pass
+class TerminatingError(TransactionError):
+ """Raised when job can not be completed due to provider's termination."""
+ pass
+
class PackageError(YumDBError):
"""Generic exception for error concerning package handling."""
pass