diff --git a/bin/pungi-koji b/bin/pungi-koji index 1b149225..5f9a09d9 100755 --- a/bin/pungi-koji +++ b/bin/pungi-koji @@ -181,7 +181,8 @@ def main(): from pungi.compose import Compose - logger = logging.Logger("Pungi") + logger = logging.getLogger("Pungi") + logger.setLevel(logging.DEBUG) kobo.log.add_stderr_logger(logger) conf = kobo.conf.PyConfigParser() diff --git a/pungi/media_split.py b/pungi/media_split.py index a1e3f479..61d104b8 100644 --- a/pungi/media_split.py +++ b/pungi/media_split.py @@ -61,12 +61,15 @@ class MediaSplitter(object): are added; there is no re-ordering. The number of disk is thus not the possible minimum. """ - def __init__(self, media_size, compose=None): + def __init__(self, media_size, compose=None, logger=None): self.media_size = media_size self.files = [] # to preserve order self.file_sizes = {} self.sticky_files = set() self.compose = compose + self.logger = logger + if not self.logger and self.compose: + self.logger = self.compose._logger def add_file(self, name, size, sticky=False): name = os.path.normpath(name) @@ -120,9 +123,9 @@ class MediaSplitter(object): total_size_single += size if self.compose: if self.media_size: - self.compose.log_debug("MediaSplitter: free space on single media would be %s. " - "Total size of single medium: %s." - % (self.media_size - total_size_single, total_size_single)) + self.logger.debug("MediaSplitter: free space on single media would be %s. " + "Total size of single medium: %s." + % (self.media_size - total_size_single, total_size_single)) else: - self.compose.log_debug("MediaSplitter: Total size of single medium: %s." % total_size_single) + self.logger.debug("MediaSplitter: Total size of single medium: %s." % total_size_single) return disks diff --git a/pungi/phases/base.py b/pungi/phases/base.py index 3e0ce447..f4b62ff1 100644 --- a/pungi/phases/base.py +++ b/pungi/phases/base.py @@ -13,6 +13,8 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, see . +import logging + from pungi import util @@ -151,3 +153,21 @@ class ImageConfigMixin(object): ksurl = self.compose.conf.get('global_ksurl') self.compose.conf['private_global_ksurl'] = util.resolve_git_url(ksurl) return self.compose.conf['private_global_ksurl'] + + +class PhaseLoggerMixin(object): + """ + A mixin that can extend a phase with a new logging logger that copy + handlers from compose, but with different formatter that includes phase name. + """ + def __init__(self, *args, **kwargs): + super(PhaseLoggerMixin, self).__init__(*args, **kwargs) + self.logger = logging.getLogger(self.name.upper()) + self.logger.setLevel(logging.DEBUG) + format = "%(asctime)s [%(name)-16s] [%(levelname)-8s] %(message)s" + import copy + for handler in self.compose._logger.handlers: + hl = copy.copy(handler) + hl.setFormatter(logging.Formatter(format, datefmt="%Y-%m-%d %H:%M:%S")) + hl.setLevel(logging.DEBUG) + self.logger.addHandler(hl) diff --git a/pungi/phases/buildinstall.py b/pungi/phases/buildinstall.py index 6ed2a847..a1b2bde7 100644 --- a/pungi/phases/buildinstall.py +++ b/pungi/phases/buildinstall.py @@ -175,7 +175,7 @@ def get_kickstart_file(compose): msg = "Getting ks.cfg" kickstart_path = os.path.join(compose.paths.work.topdir(arch="global"), "ks.cfg") if os.path.exists(kickstart_path): - compose.log_warn("[SKIP ] %s" % msg) + compose.log_warning("[SKIP ] %s" % msg) return kickstart_path compose.log_info("[BEGIN] %s" % msg) diff --git a/pungi/phases/createiso.py b/pungi/phases/createiso.py index 0a7f0ff1..ce6044f5 100644 --- a/pungi/phases/createiso.py +++ b/pungi/phases/createiso.py @@ -28,7 +28,7 @@ from kobo.shortcuts import run, relative_path from pungi.wrappers import iso from pungi.wrappers.createrepo import CreaterepoWrapper from pungi.wrappers.kojiwrapper import KojiWrapper -from pungi.phases.base import PhaseBase +from pungi.phases.base import PhaseBase, PhaseLoggerMixin from pungi.util import (makedirs, get_volid, get_arch_variant_data, failable, get_file_size, get_mtime) from pungi.media_split import MediaSplitter, convert_media_size @@ -37,12 +37,12 @@ from pungi.compose_metadata.discinfo import read_discinfo, write_discinfo from .. import createiso -class CreateisoPhase(PhaseBase): +class CreateisoPhase(PhaseLoggerMixin, PhaseBase): name = "createiso" def __init__(self, compose): - PhaseBase.__init__(self, compose) - self.pool = ThreadPool(logger=self.compose._logger) + super(CreateisoPhase, self).__init__(compose) + self.pool = ThreadPool(logger=self.logger) def _find_rpms(self, path): """Check if there are some RPMs in the path.""" @@ -69,7 +69,7 @@ class CreateisoPhase(PhaseBase): for arch in variant.arches + ["src"]: skip_iso = get_arch_variant_data(self.compose.conf, "createiso_skip", arch, variant) if skip_iso == [True]: - self.compose.log_info("Skipping createiso for %s.%s due to config option" % (variant, arch)) + self.logger.info("Skipping createiso for %s.%s due to config option" % (variant, arch)) continue volid = get_volid(self.compose, arch, variant, disc_type=disc_type) @@ -80,13 +80,14 @@ class CreateisoPhase(PhaseBase): continue if not self._find_rpms(os_tree): - self.compose.log_warning("No RPMs found for %s.%s, skipping ISO" - % (variant.uid, arch)) + self.logger.warn("No RPMs found for %s.%s, skipping ISO" + % (variant.uid, arch)) continue bootable = self._is_bootable(variant, arch) - split_iso_data = split_iso(self.compose, arch, variant, no_split=bootable) + split_iso_data = split_iso(self.compose, arch, variant, no_split=bootable, + logger=self.logger) disc_count = len(split_iso_data) for disc_num, iso_data in enumerate(split_iso_data): @@ -97,7 +98,7 @@ class CreateisoPhase(PhaseBase): iso_path = self.compose.paths.compose.iso_path( arch, variant, filename, symlink_to=symlink_isos_to) if os.path.isfile(iso_path): - self.compose.log_warning("Skipping mkisofs, image already exists: %s" % iso_path) + self.logger.warn("Skipping mkisofs, image already exists: %s" % iso_path) continue deliverables.append(iso_path) @@ -158,7 +159,7 @@ class CreateisoPhase(PhaseBase): class CreateIsoThread(WorkerThread): def fail(self, compose, cmd, variant, arch): - compose.log_error("CreateISO failed, removing ISO: %s" % cmd["iso_path"]) + self.pool.log_error("CreateISO failed, removing ISO: %s" % cmd["iso_path"]) try: # remove incomplete ISO os.unlink(cmd["iso_path"]) @@ -174,7 +175,7 @@ class CreateIsoThread(WorkerThread): def process(self, item, num): compose, cmd, variant, arch = item can_fail = compose.can_fail(variant, arch, 'iso') - with failable(compose, can_fail, variant, arch, 'iso'): + with failable(compose, can_fail, variant, arch, 'iso', logger=self.pool._logger): self.worker(compose, cmd, variant, arch, num) def worker(self, compose, cmd, variant, arch, num): @@ -281,7 +282,7 @@ class CreateIsoThread(WorkerThread): variant=str(variant)) -def split_iso(compose, arch, variant, no_split=False): +def split_iso(compose, arch, variant, no_split=False, logger=None): """ Split contents of the os/ directory for given tree into chunks fitting on ISO. @@ -292,12 +293,14 @@ def split_iso(compose, arch, variant, no_split=False): infinite so that everything goes on single disc. A warning is printed if the size is bigger than configured. """ + if not logger: + logger = compose._logger media_size = compose.conf['iso_size'] media_reserve = compose.conf['split_iso_reserve'] split_size = convert_media_size(media_size) - convert_media_size(media_reserve) real_size = 10**20 if no_split else split_size - ms = MediaSplitter(real_size, compose) + ms = MediaSplitter(real_size, compose, logger=logger) os_tree = compose.paths.compose.os_tree(arch, variant) extra_files_dir = compose.paths.work.extra_files_dir(arch, variant) @@ -319,7 +322,7 @@ def split_iso(compose, arch, variant, no_split=False): boot_iso_rpath = ti.images.images.get(arch, {}).get("boot.iso", None) if boot_iso_rpath: all_files_ignore.append(boot_iso_rpath) - compose.log_debug("split_iso all_files_ignore = %s" % ", ".join(all_files_ignore)) + logger.debug("split_iso all_files_ignore = %s" % ", ".join(all_files_ignore)) for root, dirs, files in os.walk(os_tree): for dn in dirs[:]: @@ -332,7 +335,7 @@ def split_iso(compose, arch, variant, no_split=False): rel_path = relative_path(path, os_tree.rstrip("/") + "/") sticky = rel_path in extra_files if rel_path in all_files_ignore: - compose.log_info("split_iso: Skipping %s" % rel_path) + logger.info("split_iso: Skipping %s" % rel_path) continue if root.startswith(compose.paths.compose.packages(arch, variant)): packages.append((path, os.path.getsize(path), sticky)) @@ -344,11 +347,11 @@ def split_iso(compose, arch, variant, no_split=False): result = ms.split() if no_split and result[0]['size'] > split_size: - compose.log_warning('ISO for %s.%s does not fit on single media! ' - 'It is %s bytes too big. (Total size: %s B)' - % (variant.uid, arch, - result[0]['size'] - split_size, - result[0]['size'])) + logger.warn('ISO for %s.%s does not fit on single media! ' + 'It is %s bytes too big. (Total size: %s B)' + % (variant.uid, arch, + result[0]['size'] - split_size, + result[0]['size'])) return result diff --git a/pungi/phases/image_build.py b/pungi/phases/image_build.py index 0f8f1604..07605e57 100644 --- a/pungi/phases/image_build.py +++ b/pungi/phases/image_build.py @@ -14,13 +14,13 @@ from kobo.threads import ThreadPool, WorkerThread from productmd.images import Image -class ImageBuildPhase(base.ImageConfigMixin, base.ConfigGuardedPhase): +class ImageBuildPhase(base.PhaseLoggerMixin, base.ImageConfigMixin, base.ConfigGuardedPhase): """class for wrapping up koji image-build""" name = "image_build" def __init__(self, compose): super(ImageBuildPhase, self).__init__(compose) - self.pool = ThreadPool(logger=self.compose._logger) + self.pool = ThreadPool(logger=self.logger) def _get_install_tree(self, image_conf, variant): """ @@ -139,7 +139,7 @@ class ImageBuildPhase(base.ImageConfigMixin, base.ConfigGuardedPhase): class CreateImageBuildThread(WorkerThread): def fail(self, compose, cmd): - compose.log_error("CreateImageBuild failed.") + self.pool.log_error("CreateImageBuild failed.") def process(self, item, num): compose, cmd = item @@ -148,7 +148,8 @@ class CreateImageBuildThread(WorkerThread): failable_arches = cmd.get('failable_arches', []) self.can_fail = bool(failable_arches) # TODO handle failure per architecture; currently not possible in single task - with failable(compose, self.can_fail, variant, '*', 'image-build', subvariant): + with failable(compose, self.can_fail, variant, '*', 'image-build', subvariant, + logger=self.pool._logger): self.worker(num, compose, variant, subvariant, cmd) def worker(self, num, compose, variant, subvariant, cmd): @@ -207,7 +208,7 @@ class CreateImageBuildThread(WorkerThread): # The usecase here is that you can run koji image-build with multiple --format # It's ok to do it serialized since we're talking about max 2 images per single # image_build record - linker = Linker(logger=compose._logger) + linker = Linker(logger=self.pool._logger) for image_info in image_infos: image_dir = cmd["image_dir"] % {"arch": image_info['arch']} makedirs(image_dir) diff --git a/pungi/phases/live_images.py b/pungi/phases/live_images.py index 6ae4fd1f..3d3a1605 100644 --- a/pungi/phases/live_images.py +++ b/pungi/phases/live_images.py @@ -37,12 +37,12 @@ if sys.version_info[0] == 3: return (a > b) - (a < b) -class LiveImagesPhase(base.ImageConfigMixin, base.ConfigGuardedPhase): +class LiveImagesPhase(base.PhaseLoggerMixin, base.ImageConfigMixin, base.ConfigGuardedPhase): name = "live_images" def __init__(self, compose): super(LiveImagesPhase, self).__init__(compose) - self.pool = ThreadPool(logger=self.compose._logger) + self.pool = ThreadPool(logger=self.logger) def _get_extra_repos(self, arch, variant, extras): repo = [] @@ -154,7 +154,8 @@ class CreateLiveImageThread(WorkerThread): self.failable_arches = cmd.get('failable_arches', []) # TODO handle failure per architecture; currently not possible in single task self.can_fail = bool(self.failable_arches) - with failable(compose, self.can_fail, variant, arch, 'live', cmd.get('subvariant')): + with failable(compose, self.can_fail, variant, arch, 'live', cmd.get('subvariant'), + logger=self.pool._logger): self.worker(compose, cmd, variant, arch, num) def worker(self, compose, cmd, variant, arch, num): @@ -215,8 +216,8 @@ class CreateLiveImageThread(WorkerThread): if cmd["sign"]: # Sign the rpm wrapped images and get their paths - compose.log_info("Signing rpm wrapped images in task_id: %s (expected key ID: %s)" - % (output["task_id"], compose.conf.get("signing_key_id"))) + self.pool.log_info("Signing rpm wrapped images in task_id: %s (expected key ID: %s)" + % (output["task_id"], compose.conf.get("signing_key_id"))) signed_rpm_paths = self._sign_image(koji_wrapper, compose, cmd, output["task_id"]) if signed_rpm_paths: rpm_paths = signed_rpm_paths @@ -275,12 +276,12 @@ class CreateLiveImageThread(WorkerThread): signing_command = compose.conf.get("signing_command") if not signing_key_id: - compose.log_warning("Signing is enabled but signing_key_id is not specified") - compose.log_warning("Signing skipped") + self.pool.log_warning("Signing is enabled but signing_key_id is not specified") + self.pool.log_warning("Signing skipped") return None if not signing_command: - compose.log_warning("Signing is enabled but signing_command is not specified") - compose.log_warning("Signing skipped") + self.pool.log_warning("Signing is enabled but signing_command is not specified") + self.pool.log_warning("Signing skipped") return None # Prepare signing log file @@ -293,7 +294,7 @@ class CreateLiveImageThread(WorkerThread): log_file=signing_log_file, signing_key_password=compose.conf.get("signing_key_password")) except RuntimeError: - compose.log_error("Error while signing rpm wrapped images. See log: %s" % signing_log_file) + self.pool.log_error("Error while signing rpm wrapped images. See log: %s" % signing_log_file) raise # Get pats to the signed rpms @@ -306,8 +307,8 @@ class CreateLiveImageThread(WorkerThread): return rpm_paths # Signed RPMs are not available - compose.log_warning("Signed files are not available: %s" % rpm_paths) - compose.log_warning("Unsigned files will be used") + self.pool.log_warning("Signed files are not available: %s" % rpm_paths) + self.pool.log_warning("Unsigned files will be used") return None diff --git a/pungi/phases/livemedia_phase.py b/pungi/phases/livemedia_phase.py index 0d98dadd..aa0f400b 100644 --- a/pungi/phases/livemedia_phase.py +++ b/pungi/phases/livemedia_phase.py @@ -5,7 +5,7 @@ import time from kobo import shortcuts from pungi.util import get_variant_data, makedirs, get_mtime, get_file_size, failable -from pungi.phases.base import ConfigGuardedPhase, ImageConfigMixin +from pungi.phases.base import ConfigGuardedPhase, ImageConfigMixin, PhaseLoggerMixin from pungi.linker import Linker from pungi.paths import translate_path from pungi.wrappers.kojiwrapper import KojiWrapper @@ -13,13 +13,13 @@ from kobo.threads import ThreadPool, WorkerThread from productmd.images import Image -class LiveMediaPhase(ImageConfigMixin, ConfigGuardedPhase): +class LiveMediaPhase(PhaseLoggerMixin, ImageConfigMixin, ConfigGuardedPhase): """class for wrapping up koji spin-livemedia""" name = 'live_media' def __init__(self, compose): super(LiveMediaPhase, self).__init__(compose) - self.pool = ThreadPool(logger=self.compose._logger) + self.pool = ThreadPool(logger=self.logger) def _get_repos(self, image_conf, variant): """ @@ -103,7 +103,8 @@ class LiveMediaThread(WorkerThread): self.failable_arches = config.pop('failable_arches') self.num = num # TODO handle failure per architecture; currently not possible in single task - with failable(compose, bool(self.failable_arches), variant, '*', 'live-media', subvariant): + with failable(compose, bool(self.failable_arches), variant, '*', 'live-media', subvariant, + logger=self.pool._logger): self.worker(compose, variant, subvariant, config) def _get_log_file(self, compose, variant, subvariant, config): @@ -116,7 +117,7 @@ class LiveMediaThread(WorkerThread): output = koji_wrapper.run_blocking_cmd(cmd, log_file=log_file) self.pool.log_debug('live media outputs: %s' % (output)) if output['retcode'] != 0: - compose.log_error('Live media task failed.') + self.pool.log_error('Live media task failed.') raise RuntimeError('Live media task failed: %s. See %s for more details.' % (output['task_id'], log_file)) return output @@ -154,7 +155,7 @@ class LiveMediaThread(WorkerThread): % (output['task_id'], len(config['arches']), len(image_infos))) raise RuntimeError('Image count mismatch in task %s.' % output['task_id']) - linker = Linker(logger=compose._logger) + linker = Linker(logger=self.pool._logger) link_type = compose.conf["link_type"] for image_info in image_infos: image_dir = compose.paths.compose.iso_dir(image_info['arch'], variant) diff --git a/pungi/phases/osbs.py b/pungi/phases/osbs.py index 0a37b818..6b38a54d 100644 --- a/pungi/phases/osbs.py +++ b/pungi/phases/osbs.py @@ -4,18 +4,18 @@ import json import os from kobo.threads import ThreadPool, WorkerThread -from .base import ConfigGuardedPhase +from .base import ConfigGuardedPhase, PhaseLoggerMixin from .. import util from ..wrappers import kojiwrapper from ..paths import translate_path -class OSBSPhase(ConfigGuardedPhase): +class OSBSPhase(PhaseLoggerMixin, ConfigGuardedPhase): name = 'osbs' def __init__(self, compose): super(OSBSPhase, self).__init__(compose) - self.pool = ThreadPool(logger=self.compose._logger) + self.pool = ThreadPool(logger=self.logger) self.pool.metadata = {} def run(self): @@ -39,7 +39,8 @@ class OSBSThread(WorkerThread): def process(self, item, num): compose, variant, config = item self.num = num - with util.failable(compose, bool(config.pop('failable', None)), variant, '*', 'osbs'): + with util.failable(compose, bool(config.pop('failable', None)), variant, '*', 'osbs', + logger=self.pool._logger): self.worker(compose, variant, config) def worker(self, compose, variant, config): diff --git a/pungi/phases/ostree_installer.py b/pungi/phases/ostree_installer.py index b07d7a40..5c559452 100644 --- a/pungi/phases/ostree_installer.py +++ b/pungi/phases/ostree_installer.py @@ -7,19 +7,19 @@ from productmd import images import pipes from kobo import shortcuts -from .base import ConfigGuardedPhase +from .base import ConfigGuardedPhase, PhaseLoggerMixin from .. import util from ..paths import translate_path from ..util import get_volid from ..wrappers import kojiwrapper, iso, lorax, scm -class OstreeInstallerPhase(ConfigGuardedPhase): +class OstreeInstallerPhase(PhaseLoggerMixin, ConfigGuardedPhase): name = 'ostree_installer' def __init__(self, compose): super(OstreeInstallerPhase, self).__init__(compose) - self.pool = ThreadPool(logger=self.compose._logger) + self.pool = ThreadPool(logger=self.logger) def run(self): for variant in self.compose.get_variants(): @@ -37,7 +37,8 @@ class OstreeInstallerThread(WorkerThread): self.num = num failable_arches = config.get('failable', []) self.can_fail = util.can_arch_fail(failable_arches, arch) - with util.failable(compose, self.can_fail, variant, arch, 'ostree-installer'): + with util.failable(compose, self.can_fail, variant, arch, 'ostree-installer', + logger=self.pool._logger): self.worker(compose, variant, arch, config) def worker(self, compose, variant, arch, config): diff --git a/pungi/util.py b/pungi/util.py index a65fb992..2b785e03 100644 --- a/pungi/util.py +++ b/pungi/util.py @@ -451,8 +451,10 @@ def process_args(fmt, args): @contextlib.contextmanager -def failable(compose, can_fail, variant, arch, deliverable, subvariant=None): +def failable(compose, can_fail, variant, arch, deliverable, subvariant=None, logger=None): """If a deliverable can fail, log a message and go on as if it succeeded.""" + if not logger: + logger = compose._logger msg = deliverable.replace('-', ' ').capitalize() if can_fail: compose.attempt_deliverable(variant, arch, deliverable, subvariant) @@ -468,11 +470,11 @@ def failable(compose, can_fail, variant, arch, deliverable, subvariant=None): ident = 'variant %s, arch %s' % (variant.uid if variant else 'None', arch) if subvariant: ident += ', subvariant %s' % subvariant - compose.log_info('[FAIL] %s (%s) failed, but going on anyway.' - % (msg, ident)) - compose.log_info(str(exc)) + logger.info('[FAIL] %s (%s) failed, but going on anyway.' + % (msg, ident)) + logger.info(str(exc)) tb = traceback.format_exc() - compose.log_debug(tb) + logger.debug(tb) def can_arch_fail(failable_arches, arch): diff --git a/tests/helpers.py b/tests/helpers.py index 53828a7f..216289b1 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -60,6 +60,11 @@ class DummyCompose(object): type='variant', is_empty=False), } self.all_variants = self.variants.copy() + + # for PhaseLoggerMixin + self._logger = mock.Mock() + self._logger.handlers = [mock.Mock()] + self.log_info = mock.Mock() self.log_error = mock.Mock() self.log_debug = mock.Mock() diff --git a/tests/test_buildinstall.py b/tests/test_buildinstall.py index ea976067..bea5616c 100644 --- a/tests/test_buildinstall.py +++ b/tests/test_buildinstall.py @@ -563,7 +563,7 @@ class BuildinstallThreadTestCase(PungiTestCase): with mock.patch('time.sleep'): t.process((compose, 'x86_64', None, cmd), 0) - compose.log_info.assert_has_calls([ + compose._logger.info.assert_has_calls([ mock.call('[FAIL] Buildinstall (variant None, arch x86_64) failed, but going on anyway.'), mock.call('Runroot task failed: 1234. See %s/logs/x86_64/buildinstall.x86_64.log for more details.' % self.topdir) @@ -599,7 +599,7 @@ class BuildinstallThreadTestCase(PungiTestCase): with mock.patch('time.sleep'): t.process((compose, 'x86_64', compose.variants['Server'], cmd), 0) - compose.log_info.assert_has_calls([ + compose._logger.info.assert_has_calls([ mock.call('[FAIL] Buildinstall (variant Server, arch x86_64) failed, but going on anyway.'), mock.call('Runroot task failed: 1234. See %s/logs/x86_64/buildinstall-Server.x86_64.log for more details.' % self.topdir) ]) diff --git a/tests/test_createiso_phase.py b/tests/test_createiso_phase.py index 5702415e..c977c3b8 100644 --- a/tests/test_createiso_phase.py +++ b/tests/test_createiso_phase.py @@ -49,12 +49,13 @@ class CreateisoPhaseTest(helpers.PungiTestCase): pool = ThreadPool.return_value phase = createiso.CreateisoPhase(compose) + phase.logger = mock.Mock() phase.run() self.assertEqual(len(pool.add.call_args_list), 0) self.assertEqual(pool.queue_put.call_args_list, []) self.assertItemsEqual( - compose.log_warning.call_args_list, + phase.logger.warn.call_args_list, [mock.call('No RPMs found for Everything.x86_64, skipping ISO'), mock.call('No RPMs found for Everything.amd64, skipping ISO'), mock.call('No RPMs found for Everything.src, skipping ISO'), @@ -93,7 +94,7 @@ class CreateisoPhaseTest(helpers.PungiTestCase): [mock.call(compose, 'x86_64', compose.variants['Server'], disc_count=1, disc_num=1, split_iso_data=disc_data)]) self.assertEqual(split_iso.call_args_list, - [mock.call(compose, 'x86_64', compose.variants['Server'], no_split=False)]) + [mock.call(compose, 'x86_64', compose.variants['Server'], no_split=False, logger=phase.logger)]) self.assertEqual(len(pool.add.call_args_list), 1) self.maxDiff = None self.assertItemsEqual( @@ -160,8 +161,8 @@ class CreateisoPhaseTest(helpers.PungiTestCase): disc_count=1, disc_num=1, split_iso_data=disc_data)]) self.assertItemsEqual( split_iso.call_args_list, - [mock.call(compose, 'x86_64', compose.variants['Server'], no_split=True), - mock.call(compose, 'src', compose.variants['Server'], no_split=False)]) + [mock.call(compose, 'x86_64', compose.variants['Server'], no_split=True, logger=phase.logger), + mock.call(compose, 'src', compose.variants['Server'], no_split=False, logger=phase.logger)]) self.assertEqual(len(pool.add.call_args_list), 2) self.maxDiff = None self.assertItemsEqual( @@ -463,11 +464,12 @@ class CreateisoThreadTest(helpers.PungiTestCase): run_runroot = KojiWrapper.return_value.run_runroot_cmd run_runroot.side_effect = helpers.boom - t = createiso.CreateIsoThread(mock.Mock()) + pool = mock.Mock() + t = createiso.CreateIsoThread(pool) with mock.patch('time.sleep'): t.process((compose, cmd, compose.variants['Server'], 'x86_64'), 1) - compose.log_info.assert_has_calls([ + pool._logger.info.assert_has_calls([ mock.call('[FAIL] Iso (variant Server, arch x86_64) failed, but going on anyway.'), mock.call('BOOM') ]) @@ -505,11 +507,12 @@ class CreateisoThreadTest(helpers.PungiTestCase): 'task_id': '1234', } - t = createiso.CreateIsoThread(mock.Mock()) + pool = mock.Mock() + t = createiso.CreateIsoThread(pool) with mock.patch('time.sleep'): t.process((compose, cmd, compose.variants['Server'], 'x86_64'), 1) - compose.log_info.assert_has_calls([ + pool._logger.info.assert_has_calls([ mock.call('[FAIL] Iso (variant Server, arch x86_64) failed, but going on anyway.'), mock.call('Runroot task failed: 1234. See %s for more details.' % (self.topdir + '/logs/x86_64/createiso-image-name.x86_64.log')) @@ -585,11 +588,12 @@ class CreateisoThreadTest(helpers.PungiTestCase): } run.side_effect = helpers.boom - t = createiso.CreateIsoThread(mock.Mock()) + pool = mock.Mock() + t = createiso.CreateIsoThread(pool) with mock.patch('time.sleep'): t.process((compose, cmd, compose.variants['Server'], 'x86_64'), 1) - compose.log_info.assert_has_calls([ + pool._logger.info.assert_has_calls([ mock.call('[FAIL] Iso (variant Server, arch x86_64) failed, but going on anyway.'), mock.call('BOOM') ]) @@ -718,7 +722,7 @@ class SplitIsoTest(helpers.PungiTestCase): os.path.join(base_path, 'Packages/b/bash.rpm')], 'size': 5400166400}]) self.assertEqual( - compose.log_warning.call_args_list, + compose._logger.warn.call_args_list, [mock.call('ISO for Server.x86_64 does not fit on single media! ' 'It is 710652160 bytes too big. (Total size: 5400166400 B)')] ) diff --git a/tests/test_imagebuildphase.py b/tests/test_imagebuildphase.py index 2fad381f..d1d07036 100644 --- a/tests/test_imagebuildphase.py +++ b/tests/test_imagebuildphase.py @@ -747,7 +747,7 @@ class TestCreateImageBuildThread(PungiTestCase): with mock.patch('time.sleep'): t.process((compose, cmd), 1) - compose.log_info.assert_has_calls([ + pool._logger.info.assert_has_calls([ mock.call('[FAIL] Image build (variant Client, arch *, subvariant Client) failed, but going on anyway.'), mock.call('ImageBuild task failed: 1234. See %s for more details.' % (os.path.join(self.topdir, @@ -792,7 +792,7 @@ class TestCreateImageBuildThread(PungiTestCase): with mock.patch('time.sleep'): t.process((compose, cmd), 1) - compose.log_info.assert_has_calls([ + pool._logger.info.assert_has_calls([ mock.call('[FAIL] Image build (variant Client, arch *, subvariant Client) failed, but going on anyway.'), mock.call('BOOM'), ]) diff --git a/tests/test_liveimagesphase.py b/tests/test_liveimagesphase.py index 6f383164..e3be6902 100644 --- a/tests/test_liveimagesphase.py +++ b/tests/test_liveimagesphase.py @@ -727,7 +727,7 @@ class TestCreateLiveImageThread(PungiTestCase): with mock.patch('time.sleep'): t.process((compose, cmd, compose.variants['Client'], 'amd64'), 1) - compose.log_info.assert_has_calls([ + pool._logger.info.assert_has_calls([ mock.call('[FAIL] Live (variant Client, arch amd64, subvariant Client) failed, but going on anyway.'), mock.call('LiveImage task failed: 123. See %s/logs/amd64/liveimage-None-None-xyz.amd64.log for more details.' % self.topdir) @@ -766,7 +766,7 @@ class TestCreateLiveImageThread(PungiTestCase): with mock.patch('time.sleep'): t.process((compose, cmd, compose.variants['Client'], 'amd64'), 1) - compose.log_info.assert_has_calls([ + pool._logger.info.assert_has_calls([ mock.call('[FAIL] Live (variant Client, arch amd64, subvariant Client) failed, but going on anyway.'), mock.call('BOOM') ]) diff --git a/tests/test_livemediaphase.py b/tests/test_livemediaphase.py index 6d577de0..7e4bc266 100644 --- a/tests/test_livemediaphase.py +++ b/tests/test_livemediaphase.py @@ -516,7 +516,7 @@ class TestLiveMediaThread(PungiTestCase): with mock.patch('time.sleep'): t.process((compose, compose.variants['Server'], config), 1) - compose.log_info.assert_has_calls([ + pool._logger.info.assert_has_calls([ mock.call('[FAIL] Live media (variant Server, arch *, subvariant KDE) failed, but going on anyway.'), mock.call('Live media task failed: 1234. See %s for more details.' % (os.path.join(self.topdir, 'logs/amd64-x86_64/livemedia-Server-KDE.amd64-x86_64.log'))) @@ -559,7 +559,7 @@ class TestLiveMediaThread(PungiTestCase): with mock.patch('time.sleep'): t.process((compose, compose.variants['Server'], config), 1) - compose.log_info.assert_has_calls([ + pool._logger.info.assert_has_calls([ mock.call('[FAIL] Live media (variant Server, arch *, subvariant KDE) failed, but going on anyway.'), mock.call('BOOM') ]) diff --git a/tests/test_media_split.py b/tests/test_media_split.py index dec35a66..fa6e7dbc 100644 --- a/tests/test_media_split.py +++ b/tests/test_media_split.py @@ -65,14 +65,14 @@ class MediaSplitterTestCase(unittest.TestCase): def assertFreeSpace(self, free, total): self.assertEqual( - self.compose.mock_calls, - [mock.call.log_debug('MediaSplitter: free space on single media would be %s. ' - 'Total size of single medium: %s.' % (free, total))]) + self.compose._logger.debug.mock_calls, + [mock.call('MediaSplitter: free space on single media would be %s. ' + 'Total size of single medium: %s.' % (free, total))]) def assertUnlimited(self, total): self.assertEqual( - self.compose.mock_calls, - [mock.call.log_debug('MediaSplitter: Total size of single medium: %s.' % total)]) + self.compose._logger.debug.mock_calls, + [mock.call('MediaSplitter: Total size of single medium: %s.' % total)]) def test_sum_size(self): ms = media_split.MediaSplitter(bl(100)) diff --git a/tests/test_ostree_installer_phase.py b/tests/test_ostree_installer_phase.py index ad7ee2fc..e06e6c58 100644 --- a/tests/test_ostree_installer_phase.py +++ b/tests/test_ostree_installer_phase.py @@ -340,7 +340,7 @@ class OstreeThreadTest(helpers.PungiTestCase): t = ostree.OstreeInstallerThread(pool) t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1) - self.compose.log_info.assert_has_calls([ + pool._logger.info.assert_has_calls([ mock.call('[FAIL] Ostree installer (variant Everything, arch x86_64) failed, but going on anyway.'), mock.call('BOOM') ]) @@ -370,7 +370,7 @@ class OstreeThreadTest(helpers.PungiTestCase): t = ostree.OstreeInstallerThread(pool) t.process((self.compose, self.compose.variants['Everything'], 'x86_64', cfg), 1) - self.compose.log_info.assert_has_calls([ + pool._logger.info.assert_has_calls([ mock.call('[FAIL] Ostree installer (variant Everything, arch x86_64) failed, but going on anyway.'), mock.call('Runroot task failed: 1234. See %s/logs/x86_64/ostree_installer/runroot.log for more details.' % self.topdir) diff --git a/tests/test_ostree_phase.py b/tests/test_ostree_phase.py index 0ef10194..bf01f6c1 100644 --- a/tests/test_ostree_phase.py +++ b/tests/test_ostree_phase.py @@ -147,7 +147,7 @@ class OSTreeThreadTest(helpers.PungiTestCase): t.process((self.compose, self.compose.variants['Everything'], 'x86_64', self.cfg), 1) - self.compose.log_info.assert_has_calls([ + self.compose._logger.info.assert_has_calls([ mock.call('[FAIL] Ostree (variant Everything, arch x86_64) failed, but going on anyway.'), mock.call('Runroot task failed: 1234. See %s for more details.' % (self.topdir + '/logs/x86_64/Everything/ostree-1/runroot.log')) @@ -166,7 +166,7 @@ class OSTreeThreadTest(helpers.PungiTestCase): t.process((self.compose, self.compose.variants['Everything'], 'x86_64', self.cfg), 1) - self.compose.log_info.assert_has_calls([ + self.compose._logger.info.assert_has_calls([ mock.call('[FAIL] Ostree (variant Everything, arch x86_64) failed, but going on anyway.'), mock.call('BOOM') ])