diff --git a/pungi/checks.py b/pungi/checks.py index 50f1acab..775aaf1e 100644 --- a/pungi/checks.py +++ b/pungi/checks.py @@ -45,6 +45,7 @@ import jsonschema import six from kobo.shortcuts import force_list from pungi.phases import PHASES_NAMES +from pungi.runroot import RUNROOT_TYPES from productmd.common import RELEASE_TYPES from productmd.composeinfo import COMPOSE_TYPES @@ -586,9 +587,39 @@ def make_schema(): "runroot": { "deprecated": "remove it. Please specify 'runroot_method' if you want to enable runroot, otherwise run things locally", }, - "runroot_method": { + "global_runroot_method": { "type": "string", - "enum": ["local", "koji", "openssh"], + "enum": RUNROOT_TYPES, + }, + "runroot_method": { + "oneOf": [ + { + "type": "string", + "enum": RUNROOT_TYPES, + }, + { + "type": "object", + "properties": { + "buildinstall": { + "type": "string", + "enum": RUNROOT_TYPES, + }, + "ostree_installer": { + "type": "string", + "enum": RUNROOT_TYPES, + }, + "ostree": { + "type": "string", + "enum": RUNROOT_TYPES, + }, + "createiso": { + "type": "string", + "enum": RUNROOT_TYPES, + }, + }, + "additionalProperties": False, + } + ] }, "runroot_ssh_username": { "type": "string", diff --git a/pungi/phases/buildinstall.py b/pungi/phases/buildinstall.py index 6485a82b..7ad825be 100644 --- a/pungi/phases/buildinstall.py +++ b/pungi/phases/buildinstall.py @@ -455,7 +455,7 @@ class BuildinstallThread(WorkerThread): time.sleep(num * 3) # Start the runroot task. - runroot = Runroot(compose) + runroot = Runroot(compose, phase="buildinstall") runroot.run( cmd, log_file=log_file, arch=arch, packages=packages, mounts=[compose.topdir], diff --git a/pungi/phases/createiso.py b/pungi/phases/createiso.py index 1445667f..135de4f8 100644 --- a/pungi/phases/createiso.py +++ b/pungi/phases/createiso.py @@ -278,7 +278,7 @@ def run_createiso_command(num, compose, bootable, arch, cmd, mounts, } packages.extend(extra_packages[compose.conf["buildinstall_method"]]) - runroot = Runroot(compose) + runroot = Runroot(compose, phase="createiso") build_arch = arch if runroot.runroot_method == "koji" and not bootable: diff --git a/pungi/phases/ostree.py b/pungi/phases/ostree.py index 9761d98d..d1ccf7a1 100644 --- a/pungi/phases/ostree.py +++ b/pungi/phases/ostree.py @@ -162,7 +162,7 @@ class OSTreeThread(WorkerThread): log_file = os.path.join(self.logdir, 'runroot.log') mounts = [compose.topdir, config['ostree_repo']] - runroot = Runroot(compose) + runroot = Runroot(compose, phase="ostree") runroot.run( cmd, log_file=log_file, arch=arch, packages=packages, mounts=mounts, new_chroot=True, diff --git a/pungi/phases/ostree_installer.py b/pungi/phases/ostree_installer.py index c69b60a9..e080065a 100644 --- a/pungi/phases/ostree_installer.py +++ b/pungi/phases/ostree_installer.py @@ -199,7 +199,7 @@ class OstreeInstallerThread(WorkerThread): log_file = os.path.join(self.logdir, 'runroot.log') - runroot = Runroot(compose) + runroot = Runroot(compose, phase="ostree_installer") runroot.run( cmd, log_file=log_file, arch=arch, packages=packages, mounts=[compose.topdir], chown_paths=[output_dir], diff --git a/pungi/runroot.py b/pungi/runroot.py index f830bb76..b9b1618e 100644 --- a/pungi/runroot.py +++ b/pungi/runroot.py @@ -21,25 +21,31 @@ from kobo.shortcuts import run from pungi.wrappers import kojiwrapper +RUNROOT_TYPES = ["local", "koji", "openssh"] + + class Runroot(kobo.log.LoggingBase): - def __init__(self, compose, logger=None): + def __init__(self, compose, logger=None, phase=None): """ Creates new Runroot instance. :param Compose compose: Compose instance. :param Logger logger: Logger instance to log message to. + :param str phase: Pungi phase the runroot task is run as part of. """ kobo.log.LoggingBase.__init__(self, logger=logger) self.compose = compose - self.runroot_method = self.get_runroot_method() + self.runroot_method = self.get_runroot_method(phase) # Holds the result of last `run()` call. self._result = None - def get_runroot_method(self): + def get_runroot_method(self, phase=None): """ Returns the runroot method by checking the `runroot_tag` and `runroot_method` options in configuration. + :param str phase: Pungi phase to get the runroot method for. + :return: The configured method """ runroot_tag = self.compose.conf.get("runroot_tag") @@ -48,6 +54,15 @@ class Runroot(kobo.log.LoggingBase): # If we have runroot tag and no method, let's assume koji method # for backwards compatibility. return "koji" + + if isinstance(runroot_method, dict): + # If runroot_method is set to dict, check if there is runroot_method + # override for the current phase. + if phase in runroot_method: + return runroot_method[phase] + global_runroot_method = self.compose.conf.get("global_runroot_method") + return global_runroot_method or "local" + # Otherwise use the configured method or default to local if nothing is # given. return runroot_method or "local" diff --git a/tests/test_runroot.py b/tests/test_runroot.py index bde46e28..ab8942ba 100644 --- a/tests/test_runroot.py +++ b/tests/test_runroot.py @@ -27,6 +27,25 @@ class TestRunrootOpenSSH(helpers.PungiTestCase): method = self.runroot.get_runroot_method() self.assertEqual(method, "openssh") + def test_get_runroot_method_phase(self): + self.compose.conf["runroot_method"] = {"ostree": "openssh"} + method = self.runroot.get_runroot_method(phase="ostree") + self.assertEqual(method, "openssh") + + # Test fallback to local + method = self.runroot.get_runroot_method(phase="createiso") + self.assertEqual(method, "local") + + def test_get_runroot_method_global_runroot_method(self): + self.compose.conf["runroot_method"] = {"ostree": "openssh"} + self.compose.conf["global_runroot_method"] = "koji" + method = self.runroot.get_runroot_method(phase="ostree") + self.assertEqual(method, "openssh") + + # Test global_runroot_method + method = self.runroot.get_runroot_method(phase="createiso") + self.assertEqual(method, "koji") + def _ssh_call(self, cmd, suffix=None): """ Helper method returning default SSH mock.call with given command `cmd`.