2016-03-23 09:38:34 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import os
|
|
|
|
from kobo.threads import ThreadPool, WorkerThread
|
2016-04-07 12:33:37 +00:00
|
|
|
import re
|
2016-03-23 09:38:34 +00:00
|
|
|
|
|
|
|
from .base import ConfigGuardedPhase
|
|
|
|
from .. import util
|
|
|
|
from ..paths import translate_path
|
2016-04-07 12:33:37 +00:00
|
|
|
from ..wrappers import kojiwrapper, scm
|
2016-03-23 09:38:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OSTreePhase(ConfigGuardedPhase):
|
|
|
|
name = 'ostree'
|
|
|
|
|
2016-04-01 05:28:59 +00:00
|
|
|
config_options = [
|
2016-03-23 09:38:34 +00:00
|
|
|
{
|
|
|
|
"name": "ostree",
|
2016-04-01 05:28:59 +00:00
|
|
|
"expected_types": [list],
|
2016-03-23 09:38:34 +00:00
|
|
|
"optional": True,
|
|
|
|
}
|
2016-04-01 05:28:59 +00:00
|
|
|
]
|
2016-03-23 09:38:34 +00:00
|
|
|
|
|
|
|
def __init__(self, compose):
|
|
|
|
super(OSTreePhase, self).__init__(compose)
|
|
|
|
self.pool = ThreadPool(logger=self.compose._logger)
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
for variant in self.compose.get_variants():
|
|
|
|
for arch in variant.arches:
|
|
|
|
for conf in util.get_arch_variant_data(self.compose.conf, self.name, arch, variant):
|
|
|
|
self.pool.add(OSTreeThread(self.pool))
|
|
|
|
self.pool.queue_put((self.compose, variant, arch, conf))
|
|
|
|
|
|
|
|
self.pool.start()
|
|
|
|
|
|
|
|
|
|
|
|
class OSTreeThread(WorkerThread):
|
|
|
|
def process(self, item, num):
|
|
|
|
compose, variant, arch, config = item
|
|
|
|
self.num = num
|
2016-04-06 12:57:12 +00:00
|
|
|
with util.failable(compose, variant, arch, 'ostree'):
|
|
|
|
self.worker(compose, variant, arch, config)
|
2016-03-23 09:38:34 +00:00
|
|
|
|
2016-04-06 12:57:12 +00:00
|
|
|
def worker(self, compose, variant, arch, config):
|
2016-03-23 09:38:34 +00:00
|
|
|
msg = 'OSTree phase for variant %s, arch %s' % (variant.uid, arch)
|
|
|
|
self.pool.log_info('[BEGIN] %s' % msg)
|
2016-05-18 06:03:31 +00:00
|
|
|
workdir = compose.paths.work.topdir('ostree-%d' % self.num)
|
|
|
|
self.logdir = compose.paths.log.topdir('%s/%s/ostree-%d' %
|
|
|
|
(arch, variant.uid, self.num))
|
2016-04-07 12:33:37 +00:00
|
|
|
repodir = os.path.join(workdir, 'config_repo')
|
2016-03-23 09:38:34 +00:00
|
|
|
|
|
|
|
source_variant = compose.variants[config['source_repo_from']]
|
|
|
|
source_repo = translate_path(compose, compose.paths.compose.repository(arch, source_variant))
|
|
|
|
|
2016-04-07 12:33:37 +00:00
|
|
|
self._clone_repo(repodir, config['config_url'], config.get('config_branch', 'master'))
|
|
|
|
self._tweak_mirrorlist(repodir, source_repo)
|
|
|
|
|
2016-05-09 13:59:02 +00:00
|
|
|
# Ensure target directory exists, otherwise Koji task will fail to
|
|
|
|
# mount it.
|
|
|
|
util.makedirs(config['ostree_repo'])
|
|
|
|
|
2016-04-07 12:33:37 +00:00
|
|
|
self._run_ostree_cmd(compose, variant, arch, config, repodir)
|
2016-03-23 09:38:34 +00:00
|
|
|
|
|
|
|
self.pool.log_info('[DONE ] %s' % msg)
|
|
|
|
|
2016-04-07 12:33:37 +00:00
|
|
|
def _run_ostree_cmd(self, compose, variant, arch, config, config_repo):
|
2016-03-23 09:38:34 +00:00
|
|
|
cmd = [
|
|
|
|
'pungi-make-ostree',
|
2016-05-25 11:37:39 +00:00
|
|
|
'--log-dir=%s' % os.path.join(self.logdir),
|
|
|
|
'--treefile=%s' % os.path.join(config_repo, config['treefile']),
|
2016-04-05 07:13:01 +00:00
|
|
|
config['ostree_repo']
|
2016-03-23 09:38:34 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
runroot_channel = compose.conf.get("runroot_channel", None)
|
|
|
|
runroot_tag = compose.conf["runroot_tag"]
|
|
|
|
|
|
|
|
packages = ['pungi', 'ostree', 'rpm-ostree']
|
|
|
|
log_file = os.path.join(self.logdir, 'runroot.log')
|
2016-04-07 12:04:50 +00:00
|
|
|
mounts = [compose.topdir, config['ostree_repo']]
|
2016-03-23 09:38:34 +00:00
|
|
|
koji = kojiwrapper.KojiWrapper(compose.conf["koji_profile"])
|
|
|
|
koji_cmd = koji.get_runroot_cmd(runroot_tag, arch, cmd,
|
|
|
|
channel=runroot_channel,
|
|
|
|
use_shell=True, task_id=True,
|
2016-04-07 12:04:50 +00:00
|
|
|
packages=packages, mounts=mounts)
|
2016-03-23 09:38:34 +00:00
|
|
|
output = koji.run_runroot_cmd(koji_cmd, log_file=log_file)
|
|
|
|
if output["retcode"] != 0:
|
|
|
|
raise RuntimeError("Runroot task failed: %s. See %s for more details."
|
|
|
|
% (output["task_id"], log_file))
|
2016-04-07 12:33:37 +00:00
|
|
|
|
|
|
|
def _clone_repo(self, repodir, url, branch):
|
|
|
|
scm.get_dir_from_scm({'scm': 'git', 'repo': url, 'branch': branch, 'dir': '.'},
|
|
|
|
repodir, logger=self.pool._logger)
|
|
|
|
|
|
|
|
def _tweak_mirrorlist(self, repodir, source_repo):
|
|
|
|
for file in os.listdir(repodir):
|
|
|
|
if file.endswith('.repo'):
|
|
|
|
tweak_file(os.path.join(repodir, file), source_repo)
|
|
|
|
|
|
|
|
|
|
|
|
def tweak_file(path, source_repo):
|
2016-04-15 06:17:40 +00:00
|
|
|
"""
|
|
|
|
Ensure a given .repo file points to `source_repo`.
|
|
|
|
|
|
|
|
This function replaces all lines starting with `mirrorlist`, `metalink` or
|
|
|
|
`baseurl` with `baseurl` set to requested repository.
|
|
|
|
"""
|
2016-04-07 12:33:37 +00:00
|
|
|
with open(path, 'r') as f:
|
|
|
|
contents = f.read()
|
2016-05-25 11:37:39 +00:00
|
|
|
replacement = 'baseurl=%s' % source_repo
|
|
|
|
exp = re.compile(r'^(mirrorlist|metalink|baseurl)=.*$', re.MULTILINE)
|
|
|
|
contents = exp.sub(replacement, contents)
|
2016-04-07 12:33:37 +00:00
|
|
|
with open(path, 'w') as f:
|
|
|
|
f.write(contents)
|