Drop multiprocessing for do_transaction (#1208296)
When running the transaction in a separate process it crashes if you use a https repo source. There's really no need for threads or processes in lorax so drop it. Also switched to using the DNF TransactionProgress API for progress reporting.
This commit is contained in:
parent
dc663cd9bf
commit
b3bf61bfdd
@ -85,23 +85,23 @@ class LoraxDownloadCallback(dnf.callback.DownloadProgress):
|
|||||||
self.total_size = total_size
|
self.total_size = total_size
|
||||||
|
|
||||||
|
|
||||||
class LoraxRpmCallback(dnf.callback.LoggingTransactionDisplay):
|
class LoraxRpmCallback(dnf.callback.TransactionProgress):
|
||||||
def __init__(self, queue):
|
def __init__(self):
|
||||||
super(LoraxRpmCallback, self).__init__()
|
super(LoraxRpmCallback, self).__init__()
|
||||||
self._queue = queue
|
|
||||||
self._last_ts = None
|
self._last_ts = None
|
||||||
self.cnt = 0
|
|
||||||
|
|
||||||
def event(self, package, action, te_current, te_total, ts_current, ts_total):
|
def progress(self, package, action, ti_done, ti_total, ts_done, ts_total):
|
||||||
if action == self.PKG_INSTALL and te_current == 0:
|
if action == self.PKG_INSTALL:
|
||||||
# do not report same package twice
|
# do not report same package twice
|
||||||
if self._last_ts == ts_current:
|
if self._last_ts == ts_done:
|
||||||
return
|
return
|
||||||
self._last_ts = ts_current
|
self._last_ts = ts_done
|
||||||
|
|
||||||
msg = '(%d/%d) %s.%s' % \
|
msg = '(%d/%d) %s.%s' % (ts_done, ts_total, package.name, package.arch)
|
||||||
(ts_current, ts_total, package.name, package.arch)
|
logger.info(msg)
|
||||||
self.cnt += 1
|
|
||||||
self._queue.put(('install', msg))
|
|
||||||
elif action == self.TRANS_POST:
|
elif action == self.TRANS_POST:
|
||||||
self._queue.put(('post', None))
|
msg = "Performing post-installation setup tasks"
|
||||||
|
logger.info(msg)
|
||||||
|
|
||||||
|
def error(self, err_msg):
|
||||||
|
logger.warning(err_msg)
|
||||||
|
@ -32,15 +32,12 @@ from pylorax.dnfhelper import LoraxDownloadCallback, LoraxRpmCallback
|
|||||||
from pylorax.base import DataHolder
|
from pylorax.base import DataHolder
|
||||||
from pylorax.executils import runcmd, runcmd_output
|
from pylorax.executils import runcmd, runcmd_output
|
||||||
from pylorax.imgutils import mkcpio
|
from pylorax.imgutils import mkcpio
|
||||||
import pylorax.output as output
|
|
||||||
|
|
||||||
from mako.lookup import TemplateLookup
|
from mako.lookup import TemplateLookup
|
||||||
from mako.exceptions import text_error_template
|
from mako.exceptions import text_error_template
|
||||||
import sys, traceback
|
import sys, traceback
|
||||||
import struct
|
import struct
|
||||||
import dnf
|
import dnf
|
||||||
import multiprocessing
|
|
||||||
import queue
|
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
class LoraxTemplate(object):
|
class LoraxTemplate(object):
|
||||||
@ -501,40 +498,12 @@ class LoraxTemplateRunner(object):
|
|||||||
else:
|
else:
|
||||||
logger.debug("removepkg %s: no files to remove!", p)
|
logger.debug("removepkg %s: no files to remove!", p)
|
||||||
|
|
||||||
def get_token_checked(self, process, token_queue):
|
|
||||||
"""Try to get token from queue checking that process is still alive"""
|
|
||||||
|
|
||||||
try:
|
|
||||||
# wait at most a minute for the token
|
|
||||||
(token, msg) = token_queue.get(timeout=60)
|
|
||||||
except queue.Empty:
|
|
||||||
if process.is_alive():
|
|
||||||
try:
|
|
||||||
# process still alive, give it 2 minutes more
|
|
||||||
(token, msg) = token_queue.get(timeout=120)
|
|
||||||
except queue.Empty:
|
|
||||||
# waited for 3 minutes and got nothing
|
|
||||||
raise Exception("The transaction process got stuck somewhere (no message from it in 3 minutes)")
|
|
||||||
else:
|
|
||||||
raise Exception("The transaction process has ended abruptly")
|
|
||||||
|
|
||||||
return (token, msg)
|
|
||||||
|
|
||||||
def run_pkg_transaction(self):
|
def run_pkg_transaction(self):
|
||||||
'''
|
'''
|
||||||
run_pkg_transaction
|
run_pkg_transaction
|
||||||
Actually install all the packages requested by previous 'installpkg'
|
Actually install all the packages requested by previous 'installpkg'
|
||||||
commands.
|
commands.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def do_transaction(base, token_queue):
|
|
||||||
try:
|
|
||||||
display = LoraxRpmCallback(token_queue)
|
|
||||||
base.do_transaction(display=display)
|
|
||||||
except BaseException as e:
|
|
||||||
logger.error("The transaction process has ended abruptly: %s", e)
|
|
||||||
token_queue.put(('quit', str(e)))
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logger.info("Checking dependencies")
|
logger.info("Checking dependencies")
|
||||||
self.dbo.resolve()
|
self.dbo.resolve()
|
||||||
@ -555,24 +524,12 @@ class LoraxTemplateRunner(object):
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
logger.info("Preparing transaction from installation source")
|
logger.info("Preparing transaction from installation source")
|
||||||
token_queue = multiprocessing.Queue()
|
try:
|
||||||
msgout = output.LoraxOutput()
|
display = LoraxRpmCallback()
|
||||||
process = multiprocessing.Process(target=do_transaction, args=(self.dbo, token_queue))
|
self.dbo.do_transaction(display=display)
|
||||||
process.start()
|
except BaseException as e:
|
||||||
(token, msg) = self.get_token_checked(process, token_queue)
|
logger.error("The transaction process has ended abruptly: %s", e)
|
||||||
|
raise
|
||||||
while token not in ('post', 'quit'):
|
|
||||||
if token == 'install':
|
|
||||||
logging.info("%s", msg)
|
|
||||||
msgout.writeline(msg)
|
|
||||||
(token, msg) = self.get_token_checked(process, token_queue)
|
|
||||||
|
|
||||||
if token == 'quit':
|
|
||||||
logger.error("Transaction failed.")
|
|
||||||
raise Exception("Transaction failed")
|
|
||||||
|
|
||||||
logger.info("Performing post-installation setup tasks")
|
|
||||||
process.join()
|
|
||||||
|
|
||||||
# Reset the package sack to pick up the installed packages
|
# Reset the package sack to pick up the installed packages
|
||||||
self.dbo.reset(repos=False)
|
self.dbo.reset(repos=False)
|
||||||
|
Loading…
Reference in New Issue
Block a user