2015-02-10 13:19:34 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; version 2 of the License.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Library General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2016-09-21 12:49:13 +00:00
|
|
|
# along with this program; if not, see <https://gnu.org/licenses/>.
|
2015-02-10 13:19:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
import errno
|
|
|
|
import os
|
|
|
|
import time
|
|
|
|
import shutil
|
|
|
|
import re
|
|
|
|
|
|
|
|
from kobo.threads import ThreadPool, WorkerThread
|
2016-02-26 09:31:43 +00:00
|
|
|
from kobo.shortcuts import run
|
2015-06-02 22:32:21 +00:00
|
|
|
from productmd.images import Image
|
2017-09-21 07:29:53 +00:00
|
|
|
from six.moves import shlex_quote
|
2015-02-10 13:19:34 +00:00
|
|
|
|
2015-07-22 17:00:36 +00:00
|
|
|
from pungi.arch import get_valid_arches
|
2017-04-25 13:22:09 +00:00
|
|
|
from pungi.util import get_volid, get_arch_variant_data
|
2017-02-20 09:34:55 +00:00
|
|
|
from pungi.util import get_file_size, get_mtime, failable, makedirs
|
2017-11-22 09:50:14 +00:00
|
|
|
from pungi.util import copy_all, translate_path
|
2015-03-12 21:12:38 +00:00
|
|
|
from pungi.wrappers.lorax import LoraxWrapper
|
2016-10-12 11:56:19 +00:00
|
|
|
from pungi.wrappers import iso
|
2015-03-12 21:12:38 +00:00
|
|
|
from pungi.wrappers.scm import get_file_from_scm
|
|
|
|
from pungi.phases.base import PhaseBase
|
2019-03-21 09:58:13 +00:00
|
|
|
from pungi.runroot import Runroot
|
2015-02-10 13:19:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
class BuildinstallPhase(PhaseBase):
|
|
|
|
name = "buildinstall"
|
|
|
|
|
|
|
|
def __init__(self, compose):
|
|
|
|
PhaseBase.__init__(self, compose)
|
|
|
|
self.pool = ThreadPool(logger=self.compose._logger)
|
2017-08-25 10:08:22 +00:00
|
|
|
# A set of (variant_uid, arch) pairs that completed successfully. This
|
|
|
|
# is needed to skip copying files for failed tasks.
|
|
|
|
self.pool.finished_tasks = set()
|
2017-11-08 13:24:01 +00:00
|
|
|
self.buildinstall_method = self.compose.conf.get("buildinstall_method")
|
|
|
|
self.used_lorax = self.buildinstall_method == 'lorax'
|
2015-02-10 13:19:34 +00:00
|
|
|
|
2018-05-24 11:18:57 +00:00
|
|
|
self.warned_skipped = False
|
|
|
|
|
2015-02-10 13:19:34 +00:00
|
|
|
def skip(self):
|
|
|
|
if PhaseBase.skip(self):
|
|
|
|
return True
|
2019-07-22 07:29:47 +00:00
|
|
|
if not self.compose.conf.get("buildinstall_method"):
|
2018-05-24 11:18:57 +00:00
|
|
|
if not self.warned_skipped:
|
|
|
|
msg = "Not a bootable product. Skipping buildinstall."
|
|
|
|
self.compose.log_debug(msg)
|
|
|
|
self.warned_skipped = True
|
2015-02-10 13:19:34 +00:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2018-04-09 13:32:33 +00:00
|
|
|
def _get_lorax_cmd(self, repo_baseurl, output_dir, variant, arch, buildarch, volid, final_output_dir):
|
2015-12-08 08:29:24 +00:00
|
|
|
noupgrade = True
|
|
|
|
bugurl = None
|
|
|
|
nomacboot = True
|
2017-10-23 14:05:54 +00:00
|
|
|
add_template = []
|
|
|
|
add_arch_template = []
|
|
|
|
add_template_var = []
|
|
|
|
add_arch_template_var = []
|
2019-01-07 09:48:28 +00:00
|
|
|
rootfs_size = None
|
2019-03-22 11:47:16 +00:00
|
|
|
version = self.compose.conf["release_version"]
|
2015-12-08 08:29:24 +00:00
|
|
|
for data in get_arch_variant_data(self.compose.conf, 'lorax_options', arch, variant):
|
|
|
|
if not data.get('noupgrade', True):
|
|
|
|
noupgrade = False
|
|
|
|
if data.get('bugurl'):
|
|
|
|
bugurl = data.get('bugurl')
|
|
|
|
if not data.get('nomacboot', True):
|
|
|
|
nomacboot = False
|
2019-02-01 13:24:20 +00:00
|
|
|
if "rootfs_size" in data:
|
|
|
|
rootfs_size = data.get("rootfs_size")
|
2017-10-23 14:05:54 +00:00
|
|
|
add_template.extend(data.get('add_template', []))
|
|
|
|
add_arch_template.extend(data.get('add_arch_template', []))
|
|
|
|
add_template_var.extend(data.get('add_template_var', []))
|
|
|
|
add_arch_template_var.extend(data.get('add_arch_template_var', []))
|
2019-03-22 11:47:16 +00:00
|
|
|
if "version" in data:
|
|
|
|
version = data["version"]
|
2016-08-17 10:30:42 +00:00
|
|
|
output_dir = os.path.join(output_dir, variant.uid)
|
2017-11-22 09:50:14 +00:00
|
|
|
output_topdir = output_dir
|
2016-11-09 07:50:37 +00:00
|
|
|
|
|
|
|
# The paths module will modify the filename (by inserting arch). But we
|
|
|
|
# only care about the directory anyway.
|
2019-05-16 09:02:04 +00:00
|
|
|
log_dir = _get_log_dir(self.compose, variant, arch)
|
2016-11-09 07:50:37 +00:00
|
|
|
|
2017-11-22 09:50:14 +00:00
|
|
|
# If the buildinstall_topdir is set, it means Koji is used for
|
|
|
|
# buildinstall phase and the filesystem with Koji is read-only.
|
|
|
|
# In that case, we have to write logs to buildinstall_topdir and
|
|
|
|
# later copy them back to our local log directory.
|
|
|
|
if self.compose.conf.get("buildinstall_topdir", None):
|
|
|
|
output_dir = os.path.join(output_dir, "results")
|
|
|
|
|
2018-04-04 13:22:28 +00:00
|
|
|
repos = [repo_baseurl] + get_arch_variant_data(self.compose.conf,
|
|
|
|
'lorax_extra_sources', arch, variant)
|
2018-04-09 13:32:33 +00:00
|
|
|
if self.compose.has_comps:
|
|
|
|
comps_repo = self.compose.paths.work.comps_repo(arch, variant)
|
|
|
|
if final_output_dir != output_dir:
|
|
|
|
comps_repo = translate_path(self.compose, comps_repo)
|
|
|
|
repos.append(comps_repo)
|
2018-04-04 13:22:28 +00:00
|
|
|
|
2015-12-08 08:29:24 +00:00
|
|
|
lorax = LoraxWrapper()
|
2016-08-17 10:30:42 +00:00
|
|
|
lorax_cmd = lorax.get_lorax_cmd(self.compose.conf["release_name"],
|
2019-03-22 11:47:16 +00:00
|
|
|
version,
|
|
|
|
version,
|
2018-04-04 13:22:28 +00:00
|
|
|
repos,
|
2016-08-17 10:30:42 +00:00
|
|
|
output_dir,
|
|
|
|
variant=variant.uid,
|
|
|
|
buildinstallpackages=variant.buildinstallpackages,
|
|
|
|
is_final=self.compose.supported,
|
|
|
|
buildarch=buildarch,
|
|
|
|
volid=volid,
|
|
|
|
nomacboot=nomacboot,
|
|
|
|
bugurl=bugurl,
|
2017-10-23 14:05:54 +00:00
|
|
|
add_template=add_template,
|
|
|
|
add_arch_template=add_arch_template,
|
|
|
|
add_template_var=add_template_var,
|
|
|
|
add_arch_template_var=add_arch_template_var,
|
2016-11-09 07:50:37 +00:00
|
|
|
noupgrade=noupgrade,
|
2019-01-07 09:48:28 +00:00
|
|
|
rootfs_size=rootfs_size,
|
2016-11-09 07:50:37 +00:00
|
|
|
log_dir=log_dir)
|
2017-11-22 09:50:14 +00:00
|
|
|
return 'rm -rf %s && %s' % (shlex_quote(output_topdir),
|
2017-09-21 07:29:53 +00:00
|
|
|
' '.join([shlex_quote(x) for x in lorax_cmd]))
|
2015-12-08 08:29:24 +00:00
|
|
|
|
2015-02-10 13:19:34 +00:00
|
|
|
def run(self):
|
|
|
|
lorax = LoraxWrapper()
|
2015-07-09 10:58:30 +00:00
|
|
|
product = self.compose.conf["release_name"]
|
|
|
|
version = self.compose.conf["release_version"]
|
|
|
|
release = self.compose.conf["release_version"]
|
2016-08-22 14:08:25 +00:00
|
|
|
disc_type = self.compose.conf['disc_types'].get('dvd', 'dvd')
|
2015-02-10 13:19:34 +00:00
|
|
|
|
2019-05-09 08:53:00 +00:00
|
|
|
# Prepare kickstart file for final images.
|
|
|
|
self.pool.kickstart_file = get_kickstart_file(self.compose)
|
|
|
|
|
2015-02-10 13:19:34 +00:00
|
|
|
for arch in self.compose.get_arches():
|
2015-12-08 15:04:32 +00:00
|
|
|
commands = []
|
|
|
|
|
2017-11-22 09:50:14 +00:00
|
|
|
output_dir = self.compose.paths.work.buildinstall_dir(arch, allow_topdir_override=True)
|
|
|
|
final_output_dir = self.compose.paths.work.buildinstall_dir(arch, allow_topdir_override=False)
|
2019-05-16 08:38:33 +00:00
|
|
|
makedirs(final_output_dir)
|
2015-02-10 13:19:34 +00:00
|
|
|
repo_baseurl = self.compose.paths.work.arch_repo(arch)
|
2017-11-22 09:50:14 +00:00
|
|
|
if final_output_dir != output_dir:
|
|
|
|
repo_baseurl = translate_path(self.compose, repo_baseurl)
|
2015-02-10 13:19:34 +00:00
|
|
|
|
2017-11-08 13:24:01 +00:00
|
|
|
if self.buildinstall_method == "lorax":
|
2018-03-13 14:54:52 +00:00
|
|
|
|
2016-10-17 11:02:35 +00:00
|
|
|
buildarch = get_valid_arches(arch)[0]
|
2015-12-02 13:46:39 +00:00
|
|
|
for variant in self.compose.get_variants(arch=arch, types=['variant']):
|
2016-02-18 15:12:23 +00:00
|
|
|
if variant.is_empty:
|
|
|
|
continue
|
2018-03-13 14:54:52 +00:00
|
|
|
|
|
|
|
skip = get_arch_variant_data(self.compose.conf, "buildinstall_skip", arch, variant)
|
|
|
|
if skip == [True]:
|
|
|
|
self.compose.log_info(
|
|
|
|
'Skipping buildinstall for %s.%s due to config option' % (variant, arch))
|
|
|
|
continue
|
|
|
|
|
2016-03-14 07:20:43 +00:00
|
|
|
volid = get_volid(self.compose, arch, variant=variant, disc_type=disc_type)
|
2015-12-02 13:46:39 +00:00
|
|
|
commands.append(
|
2016-02-08 11:13:56 +00:00
|
|
|
(variant,
|
2018-04-09 13:32:33 +00:00
|
|
|
self._get_lorax_cmd(repo_baseurl, output_dir, variant, arch, buildarch, volid, final_output_dir))
|
2015-12-08 08:29:24 +00:00
|
|
|
)
|
2017-11-08 13:24:01 +00:00
|
|
|
elif self.buildinstall_method == "buildinstall":
|
2016-03-14 07:20:43 +00:00
|
|
|
volid = get_volid(self.compose, arch, disc_type=disc_type)
|
2016-02-08 11:13:56 +00:00
|
|
|
commands.append(
|
|
|
|
(None,
|
|
|
|
lorax.get_buildinstall_cmd(product,
|
|
|
|
version,
|
|
|
|
release,
|
|
|
|
repo_baseurl,
|
|
|
|
output_dir,
|
|
|
|
is_final=self.compose.supported,
|
2016-10-17 11:02:35 +00:00
|
|
|
buildarch=arch,
|
2016-02-08 11:13:56 +00:00
|
|
|
volid=volid))
|
|
|
|
)
|
2015-02-10 13:19:34 +00:00
|
|
|
else:
|
2017-11-08 13:24:01 +00:00
|
|
|
raise ValueError("Unsupported buildinstall method: %s" % self.buildinstall_method)
|
2015-12-02 13:46:39 +00:00
|
|
|
|
2016-02-08 11:13:56 +00:00
|
|
|
for (variant, cmd) in commands:
|
2015-12-08 15:04:32 +00:00
|
|
|
self.pool.add(BuildinstallThread(self.pool))
|
2016-02-08 11:13:56 +00:00
|
|
|
self.pool.queue_put((self.compose, arch, variant, cmd))
|
2015-02-10 13:19:34 +00:00
|
|
|
|
|
|
|
self.pool.start()
|
|
|
|
|
2017-11-08 13:24:01 +00:00
|
|
|
def succeeded(self, variant, arch):
|
2018-04-23 06:18:39 +00:00
|
|
|
# If the phase is skipped, we can treat it as successful. Either there
|
|
|
|
# will be no output, or it's a debug run of compose where anything can
|
|
|
|
# happen.
|
|
|
|
return (super(BuildinstallPhase, self).skip()
|
|
|
|
or (variant.uid if self.used_lorax else None, arch) in self.pool.finished_tasks)
|
2017-11-08 13:24:01 +00:00
|
|
|
|
2015-02-10 13:19:34 +00:00
|
|
|
|
|
|
|
def get_kickstart_file(compose):
|
2016-08-22 14:08:25 +00:00
|
|
|
scm_dict = compose.conf.get("buildinstall_kickstart")
|
2015-02-10 13:19:34 +00:00
|
|
|
if not scm_dict:
|
|
|
|
compose.log_debug("Path to ks.cfg (buildinstall_kickstart) not specified.")
|
|
|
|
return
|
|
|
|
|
|
|
|
msg = "Getting ks.cfg"
|
|
|
|
kickstart_path = os.path.join(compose.paths.work.topdir(arch="global"), "ks.cfg")
|
|
|
|
if os.path.exists(kickstart_path):
|
2016-11-18 20:33:03 +00:00
|
|
|
compose.log_warning("[SKIP ] %s" % msg)
|
2015-02-10 13:19:34 +00:00
|
|
|
return kickstart_path
|
|
|
|
|
|
|
|
compose.log_info("[BEGIN] %s" % msg)
|
|
|
|
if isinstance(scm_dict, dict):
|
|
|
|
kickstart_name = os.path.basename(scm_dict["file"])
|
|
|
|
if scm_dict["scm"] == "file":
|
|
|
|
scm_dict["file"] = os.path.join(compose.config_dir, scm_dict["file"])
|
|
|
|
else:
|
|
|
|
kickstart_name = os.path.basename(scm_dict)
|
|
|
|
scm_dict = os.path.join(compose.config_dir, scm_dict)
|
|
|
|
|
2017-01-09 07:40:24 +00:00
|
|
|
tmp_dir = compose.mkdtemp(prefix="buildinstall_kickstart_")
|
2015-02-10 13:19:34 +00:00
|
|
|
get_file_from_scm(scm_dict, tmp_dir, logger=compose._logger)
|
|
|
|
src = os.path.join(tmp_dir, kickstart_name)
|
|
|
|
shutil.copy2(src, kickstart_path)
|
|
|
|
compose.log_info("[DONE ] %s" % msg)
|
|
|
|
return kickstart_path
|
|
|
|
|
|
|
|
|
2017-02-20 09:34:13 +00:00
|
|
|
BOOT_CONFIGS = [
|
|
|
|
"isolinux/isolinux.cfg",
|
|
|
|
"etc/yaboot.conf",
|
|
|
|
"ppc/ppc64/yaboot.conf",
|
|
|
|
"EFI/BOOT/BOOTX64.conf",
|
|
|
|
"EFI/BOOT/grub.cfg",
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
def tweak_configs(path, volid, ks_file, configs=BOOT_CONFIGS):
|
|
|
|
volid_escaped = volid.replace(" ", r"\x20").replace("\\", "\\\\")
|
|
|
|
volid_escaped_2 = volid_escaped.replace("\\", "\\\\")
|
|
|
|
found_configs = []
|
|
|
|
for config in configs:
|
|
|
|
config_path = os.path.join(path, config)
|
|
|
|
if not os.path.exists(config_path):
|
|
|
|
continue
|
|
|
|
found_configs.append(config)
|
|
|
|
|
|
|
|
with open(config_path, "r") as f:
|
|
|
|
data = f.read()
|
|
|
|
os.unlink(config_path) # break hadlink by removing file writing a new one
|
|
|
|
|
|
|
|
# double-escape volid in yaboot.conf
|
|
|
|
new_volid = volid_escaped_2 if 'yaboot' in config else volid_escaped
|
|
|
|
|
|
|
|
ks = (" ks=hd:LABEL=%s:/ks.cfg" % new_volid) if ks_file else ""
|
|
|
|
|
|
|
|
# pre-f18
|
|
|
|
data = re.sub(r":CDLABEL=[^ \n]*", r":CDLABEL=%s%s" % (new_volid, ks), data)
|
|
|
|
# f18+
|
|
|
|
data = re.sub(r":LABEL=[^ \n]*", r":LABEL=%s%s" % (new_volid, ks), data)
|
|
|
|
data = re.sub(r"(search .* -l) '[^'\n]*'", r"\1 '%s'" % volid, data)
|
|
|
|
|
|
|
|
with open(config_path, "w") as f:
|
|
|
|
f.write(data)
|
|
|
|
|
|
|
|
return found_configs
|
|
|
|
|
|
|
|
|
2015-02-10 13:19:34 +00:00
|
|
|
# HACK: this is a hack!
|
|
|
|
# * it's quite trivial to replace volids
|
|
|
|
# * it's not easy to replace menu titles
|
|
|
|
# * we probably need to get this into lorax
|
2017-01-09 07:40:24 +00:00
|
|
|
def tweak_buildinstall(compose, src, dst, arch, variant, label, volid, kickstart_file=None):
|
|
|
|
tmp_dir = compose.mkdtemp(prefix="tweak_buildinstall_")
|
2015-02-10 13:19:34 +00:00
|
|
|
|
|
|
|
# verify src
|
|
|
|
if not os.path.isdir(src):
|
|
|
|
raise OSError(errno.ENOENT, "Directory does not exist: %s" % src)
|
|
|
|
|
|
|
|
# create dst
|
|
|
|
try:
|
|
|
|
os.makedirs(dst)
|
|
|
|
except OSError as ex:
|
|
|
|
if ex.errno != errno.EEXIST:
|
|
|
|
raise
|
|
|
|
|
|
|
|
# copy src to temp
|
|
|
|
# TODO: place temp on the same device as buildinstall dir so we can hardlink
|
2018-07-12 07:57:12 +00:00
|
|
|
cmd = "cp -dRv --preserve=mode,links,timestamps --remove-destination %s/* %s/" % (
|
|
|
|
shlex_quote(src), shlex_quote(tmp_dir)
|
|
|
|
)
|
2015-02-10 13:19:34 +00:00
|
|
|
run(cmd)
|
|
|
|
|
2017-02-20 09:34:13 +00:00
|
|
|
found_configs = tweak_configs(tmp_dir, volid, kickstart_file)
|
|
|
|
if kickstart_file and found_configs:
|
|
|
|
shutil.copy2(kickstart_file, os.path.join(dst, "ks.cfg"))
|
2015-02-10 13:19:34 +00:00
|
|
|
|
|
|
|
images = [
|
|
|
|
os.path.join(tmp_dir, "images", "efiboot.img"),
|
|
|
|
]
|
|
|
|
for image in images:
|
|
|
|
if not os.path.isfile(image):
|
|
|
|
continue
|
2017-02-20 09:34:55 +00:00
|
|
|
|
2018-01-16 08:13:55 +00:00
|
|
|
with iso.mount(image, logger=compose._logger,
|
|
|
|
use_guestmount=compose.conf.get("buildinstall_use_guestmount")
|
|
|
|
) as mount_tmp_dir:
|
2017-02-20 09:34:55 +00:00
|
|
|
for config in BOOT_CONFIGS:
|
|
|
|
config_path = os.path.join(tmp_dir, config)
|
|
|
|
config_in_image = os.path.join(mount_tmp_dir, config)
|
|
|
|
|
|
|
|
if os.path.isfile(config_in_image):
|
|
|
|
cmd = ["cp", "-v", "--remove-destination", config_path, config_in_image]
|
|
|
|
run(cmd)
|
2015-02-10 13:19:34 +00:00
|
|
|
|
|
|
|
# HACK: make buildinstall files world readable
|
2017-09-21 07:29:53 +00:00
|
|
|
run("chmod -R a+rX %s" % shlex_quote(tmp_dir))
|
2015-02-10 13:19:34 +00:00
|
|
|
|
|
|
|
# copy temp to dst
|
2018-07-12 07:57:12 +00:00
|
|
|
cmd = "cp -dRv --preserve=mode,links,timestamps --remove-destination %s/* %s/" % (
|
|
|
|
shlex_quote(tmp_dir), shlex_quote(dst)
|
|
|
|
)
|
2015-02-10 13:19:34 +00:00
|
|
|
run(cmd)
|
|
|
|
|
|
|
|
shutil.rmtree(tmp_dir)
|
|
|
|
|
|
|
|
|
2016-06-24 07:44:40 +00:00
|
|
|
def link_boot_iso(compose, arch, variant, can_fail):
|
2015-02-10 13:19:34 +00:00
|
|
|
if arch == "src":
|
|
|
|
return
|
|
|
|
|
2016-08-22 14:08:25 +00:00
|
|
|
disc_type = compose.conf['disc_types'].get('boot', 'boot')
|
2016-03-08 11:36:28 +00:00
|
|
|
|
2016-08-22 14:08:25 +00:00
|
|
|
symlink_isos_to = compose.conf.get("symlink_isos_to")
|
2015-02-10 13:19:34 +00:00
|
|
|
os_tree = compose.paths.compose.os_tree(arch, variant)
|
|
|
|
# TODO: find in treeinfo?
|
|
|
|
boot_iso_path = os.path.join(os_tree, "images", "boot.iso")
|
|
|
|
if not os.path.isfile(boot_iso_path):
|
|
|
|
return
|
|
|
|
|
2016-03-08 10:26:14 +00:00
|
|
|
msg = "Linking boot.iso (arch: %s, variant: %s)" % (arch, variant)
|
2016-03-08 11:36:28 +00:00
|
|
|
filename = compose.get_image_name(arch, variant, disc_type=disc_type,
|
2015-12-10 11:51:18 +00:00
|
|
|
disc_num=None, suffix=".iso")
|
|
|
|
new_boot_iso_path = compose.paths.compose.iso_path(arch, variant, filename,
|
|
|
|
symlink_to=symlink_isos_to)
|
|
|
|
new_boot_iso_relative_path = compose.paths.compose.iso_path(arch,
|
|
|
|
variant,
|
|
|
|
filename,
|
|
|
|
relative=True)
|
2015-02-10 13:19:34 +00:00
|
|
|
if os.path.exists(new_boot_iso_path):
|
|
|
|
# TODO: log
|
|
|
|
compose.log_warning("[SKIP ] %s" % msg)
|
|
|
|
return
|
|
|
|
|
|
|
|
compose.log_info("[BEGIN] %s" % msg)
|
2016-02-26 09:31:43 +00:00
|
|
|
# Try to hardlink, and copy if that fails
|
|
|
|
try:
|
|
|
|
os.link(boot_iso_path, new_boot_iso_path)
|
|
|
|
except OSError:
|
|
|
|
shutil.copy2(boot_iso_path, new_boot_iso_path)
|
2015-02-10 13:19:34 +00:00
|
|
|
|
|
|
|
implant_md5 = iso.get_implanted_md5(new_boot_iso_path)
|
|
|
|
iso_name = os.path.basename(new_boot_iso_path)
|
|
|
|
iso_dir = os.path.dirname(new_boot_iso_path)
|
|
|
|
|
|
|
|
# create iso manifest
|
|
|
|
run(iso.get_manifest_cmd(iso_name), workdir=iso_dir)
|
|
|
|
|
|
|
|
img = Image(compose.im)
|
|
|
|
img.path = new_boot_iso_relative_path
|
2016-02-26 09:31:43 +00:00
|
|
|
img.mtime = get_mtime(new_boot_iso_path)
|
|
|
|
img.size = get_file_size(new_boot_iso_path)
|
2015-02-10 13:19:34 +00:00
|
|
|
img.arch = arch
|
|
|
|
img.type = "boot"
|
|
|
|
img.format = "iso"
|
|
|
|
img.disc_number = 1
|
|
|
|
img.disc_count = 1
|
|
|
|
img.bootable = True
|
2017-10-11 06:17:17 +00:00
|
|
|
img.subvariant = variant.uid
|
2015-02-10 13:19:34 +00:00
|
|
|
img.implant_md5 = implant_md5
|
2016-06-24 07:44:40 +00:00
|
|
|
setattr(img, 'can_fail', can_fail)
|
2016-05-03 14:31:20 +00:00
|
|
|
setattr(img, 'deliverable', 'buildinstall')
|
2015-02-10 13:19:34 +00:00
|
|
|
try:
|
|
|
|
img.volume_id = iso.get_volume_id(new_boot_iso_path)
|
|
|
|
except RuntimeError:
|
|
|
|
pass
|
2015-06-06 15:52:08 +00:00
|
|
|
compose.im.add(variant.uid, arch, img)
|
2015-02-10 13:19:34 +00:00
|
|
|
compose.log_info("[DONE ] %s" % msg)
|
|
|
|
|
|
|
|
|
|
|
|
class BuildinstallThread(WorkerThread):
|
|
|
|
def process(self, item, num):
|
2016-02-08 11:13:56 +00:00
|
|
|
# The variant is None unless lorax is used as buildinstall method.
|
|
|
|
compose, arch, variant, cmd = item
|
2016-06-24 07:44:40 +00:00
|
|
|
can_fail = compose.can_fail(variant, arch, 'buildinstall')
|
|
|
|
with failable(compose, can_fail, variant, arch, 'buildinstall'):
|
2016-02-08 11:13:56 +00:00
|
|
|
self.worker(compose, arch, variant, cmd, num)
|
2015-12-10 14:49:00 +00:00
|
|
|
|
2016-02-08 11:13:56 +00:00
|
|
|
def worker(self, compose, arch, variant, cmd, num):
|
2015-02-10 13:19:34 +00:00
|
|
|
buildinstall_method = compose.conf["buildinstall_method"]
|
2016-02-08 11:13:56 +00:00
|
|
|
log_filename = ('buildinstall-%s' % variant.uid) if variant else 'buildinstall'
|
|
|
|
log_file = compose.paths.log.log_file(arch, log_filename)
|
2015-02-10 13:19:34 +00:00
|
|
|
|
2016-08-17 10:30:42 +00:00
|
|
|
msg = "Running buildinstall for arch %s, variant %s" % (arch, variant)
|
2015-02-10 13:19:34 +00:00
|
|
|
|
2017-11-22 09:50:14 +00:00
|
|
|
output_dir = compose.paths.work.buildinstall_dir(
|
|
|
|
arch, allow_topdir_override=True, variant=variant)
|
|
|
|
final_output_dir = compose.paths.work.buildinstall_dir(
|
|
|
|
arch, variant=variant)
|
2016-08-17 10:30:42 +00:00
|
|
|
|
2017-11-22 09:50:14 +00:00
|
|
|
if (os.path.isdir(output_dir) and os.listdir(output_dir) or
|
|
|
|
os.path.isdir(final_output_dir) and os.listdir(final_output_dir)):
|
2016-08-17 10:30:42 +00:00
|
|
|
# output dir is *not* empty -> SKIP
|
|
|
|
self.pool.log_warning(
|
|
|
|
'[SKIP ] Buildinstall for arch %s, variant %s' % (arch, variant))
|
|
|
|
return
|
2015-02-10 13:19:34 +00:00
|
|
|
|
|
|
|
self.pool.log_info("[BEGIN] %s" % msg)
|
|
|
|
|
2019-03-21 09:58:13 +00:00
|
|
|
# Get list of packages which are neded in runroot.
|
|
|
|
packages = []
|
2019-05-22 10:54:26 +00:00
|
|
|
chown_paths = [output_dir]
|
2019-03-21 09:58:13 +00:00
|
|
|
if buildinstall_method == "lorax":
|
|
|
|
packages += ["lorax"]
|
2019-05-16 09:02:04 +00:00
|
|
|
chown_paths.append(_get_log_dir(compose, variant, arch))
|
2019-03-21 09:58:13 +00:00
|
|
|
elif buildinstall_method == "buildinstall":
|
|
|
|
packages += ["anaconda"]
|
|
|
|
|
|
|
|
# This should avoid a possible race condition with multiple processes
|
|
|
|
# trying to get a kerberos ticket at the same time.
|
|
|
|
# Kerberos authentication failed: Permission denied in replay cache code (-1765328215)
|
|
|
|
time.sleep(num * 3)
|
|
|
|
|
|
|
|
# Start the runroot task.
|
|
|
|
runroot = Runroot(compose)
|
|
|
|
runroot.run(
|
|
|
|
cmd, log_file=log_file, arch=arch, packages=packages,
|
2019-05-22 10:54:26 +00:00
|
|
|
mounts=[compose.topdir],
|
2019-05-16 09:02:04 +00:00
|
|
|
weight=compose.conf['runroot_weights'].get('buildinstall'),
|
|
|
|
chown_paths=chown_paths,
|
|
|
|
)
|
2015-02-10 13:19:34 +00:00
|
|
|
|
2017-11-22 09:50:14 +00:00
|
|
|
if final_output_dir != output_dir:
|
|
|
|
if not os.path.exists(final_output_dir):
|
|
|
|
makedirs(final_output_dir)
|
|
|
|
results_dir = os.path.join(output_dir, "results")
|
|
|
|
copy_all(results_dir, final_output_dir)
|
|
|
|
|
|
|
|
# Get the log_dir into which we should copy the resulting log files.
|
|
|
|
log_fname = 'buildinstall-%s-logs/dummy' % variant.uid
|
|
|
|
final_log_dir = os.path.dirname(compose.paths.log.log_file(arch, log_fname))
|
|
|
|
if not os.path.exists(final_log_dir):
|
|
|
|
makedirs(final_log_dir)
|
|
|
|
log_dir = os.path.join(output_dir, "logs")
|
|
|
|
copy_all(log_dir, final_log_dir)
|
|
|
|
|
2016-02-08 11:13:56 +00:00
|
|
|
log_file = compose.paths.log.log_file(arch, log_filename + '-RPMs')
|
2019-03-21 09:58:13 +00:00
|
|
|
rpms = runroot.get_buildroot_rpms()
|
2017-10-10 16:47:21 +00:00
|
|
|
with open(log_file, "w") as f:
|
|
|
|
f.write("\n".join(rpms))
|
2015-02-10 13:19:34 +00:00
|
|
|
|
2017-08-25 10:08:22 +00:00
|
|
|
self.pool.finished_tasks.add((variant.uid if variant else None, arch))
|
2019-05-09 08:53:00 +00:00
|
|
|
|
|
|
|
self.copy_files(compose, variant, arch)
|
|
|
|
|
2015-02-10 13:19:34 +00:00
|
|
|
self.pool.log_info("[DONE ] %s" % msg)
|
2019-05-09 08:53:00 +00:00
|
|
|
|
|
|
|
def copy_files(self, compose, variant, arch):
|
|
|
|
disc_type = compose.conf['disc_types'].get('dvd', 'dvd')
|
|
|
|
|
|
|
|
buildinstall_dir = compose.paths.work.buildinstall_dir(arch)
|
|
|
|
|
|
|
|
# Lorax runs per-variant, so we need to tweak the source path
|
|
|
|
# to include variant.
|
|
|
|
if variant:
|
|
|
|
buildinstall_dir = os.path.join(buildinstall_dir, variant.uid)
|
|
|
|
|
|
|
|
# Find all relevant variants if lorax is not used.
|
|
|
|
variants = [variant] if variant else compose.get_variants(arch=arch, types=["self", "variant"])
|
|
|
|
for var in variants:
|
|
|
|
os_tree = compose.paths.compose.os_tree(arch, var)
|
|
|
|
# TODO: label is not used
|
|
|
|
label = ""
|
|
|
|
volid = get_volid(compose, arch, var, disc_type=disc_type)
|
|
|
|
can_fail = compose.can_fail(var, arch, 'buildinstall')
|
|
|
|
tweak_buildinstall(
|
|
|
|
compose,
|
|
|
|
buildinstall_dir,
|
|
|
|
os_tree,
|
|
|
|
arch,
|
|
|
|
var.uid,
|
|
|
|
label,
|
|
|
|
volid,
|
|
|
|
self.pool.kickstart_file,
|
|
|
|
)
|
|
|
|
link_boot_iso(compose, arch, var, can_fail)
|
2019-05-16 09:02:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _get_log_dir(compose, variant, arch):
|
|
|
|
"""Find directory where to store lorax logs in. If it's inside the compose,
|
|
|
|
create the directory.
|
|
|
|
"""
|
|
|
|
if compose.conf.get("buildinstall_topdir"):
|
|
|
|
log_dir = compose.paths.work.buildinstall_dir(
|
|
|
|
arch, allow_topdir_override=True, variant=variant
|
|
|
|
)
|
|
|
|
return os.path.join(log_dir, "logs")
|
|
|
|
|
|
|
|
# The paths module will modify the filename (by inserting arch). But we
|
|
|
|
# only care about the directory anyway.
|
|
|
|
log_filename = 'buildinstall-%s-logs/dummy' % variant.uid
|
|
|
|
log_dir = os.path.dirname(compose.paths.log.log_file(arch, log_filename))
|
|
|
|
makedirs(log_dir)
|
|
|
|
return log_dir
|