2
0
mirror of https://github.com/xcat2/xcat-dep.git synced 2026-09-12 04:26:25 +00:00
Files
xcat-dep/conserver/mockbuild.pl
T
Daniel Hilst 9f01a153e0 fix(conserver): build on EL8-EL10 x86_64; add per-EL mockbuild.pl
conserver.spec had not been built on a modern EL toolchain and no longer
compiled on EL9/EL10:

- %prep used the bare %patch / %patch1 macros, which rpm 4.18+ (EL9/EL10)
  rejects with "Patch number not specified". Switched to explicit
  Patch0:/Patch1: with the numbered %patch0/%patch1 macros, which apply
  cleanly on EL8 through EL10.
- BuildRequires listed only openssl-devel, so on EL9/EL10's minimal mock
  buildroot the toolchain was absent and %configure failed with
  "C compiler cannot create executables". Added gcc, make and glibc-devel.

Also add conserver/mockbuild.pl, a standalone per-EL builder matching the
other xcat-dep builders (goconserver/ipmitool): it stages the sources and
spec, builds the SRPM, mock-rebuilds it in the target chroot, copies the
RPMs to --result-dir, and smoke-tests console/conserver in the chroot.
conserver is not in the default mockbuild-all.pl set (xCAT uses goconserver),
so this builder is run on demand. Built + smoke-tested conserver-xcat-8.2.1
for alma+epel-{8,9,10}-x86_64.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-07-05 16:47:12 -03:00

136 lines
5.5 KiB
Perl
Executable File

#!/usr/bin/perl
#
# mockbuild.pl - build conserver-xcat (the traditional C conserver, 8.2.1) for one
# mock target and smoke-test the resulting binaries. Mirrors the other xcat-dep
# builders (goconserver/mockbuild.pl, ipmitool/mockbuild.pl): stage sources + spec,
# build a SRPM, `mock --rebuild` it in the target chroot, copy the RPMs to
# --result-dir, then (unless --skip-install) install into the chroot and run
# `console -V` / `conserver -V` to confirm the binaries work.
#
# conserver is NOT part of the default mockbuild-all.pl dep set (xCAT uses goconserver),
# so this builder is standalone. Usage:
# ./mockbuild.pl --mock-cfg alma+epel-9-x86_64 --result-dir /path/out
#
use strict;
use warnings;
use Cwd qw(abs_path);
use File::Basename qw(dirname basename);
use File::Path qw(make_path remove_tree);
use File::Copy qw(copy);
use Getopt::Long qw(GetOptions);
my $script_dir = abs_path(dirname(__FILE__));
my $pkg_dir = $script_dir; # tarball + patches + spec live alongside this script
my $version = '8.2.1';
my $work_dir = '/tmp/conserver-mockbuild';
my $mock_cfg = '';
my $mock_uniqueext = '';
my $result_dir = "$script_dir/../build-output/list-conserver/conserver";
my $log_dir = "$script_dir/../build-logs/list-conserver/conserver";
my $skip_install = 0;
GetOptions(
'work-dir=s' => \$work_dir,
'mock-cfg=s' => \$mock_cfg,
'mock-uniqueext=s' => \$mock_uniqueext,
'result-dir=s' => \$result_dir,
'log-dir=s' => \$log_dir,
'skip-install!' => \$skip_install,
) or die usage();
die "Run as root (current uid=$>)\n" if $> != 0;
for my $bin (qw(mock rpmbuild rpm)) {
run("command -v " . sh_quote($bin) . " >/dev/null 2>&1");
}
my $arch = capture('uname -m');
if (!$mock_cfg) {
my $os_id = capture(q{bash -lc 'source /etc/os-release; echo $ID'});
$os_id = 'alma' if $os_id eq 'almalinux';
my ($rel) = capture('rpm -E %rhel');
$mock_cfg = "${os_id}+epel-${rel}-${arch}";
}
my $uniq = $mock_uniqueext ne '' ? ' --uniqueext ' . sh_quote($mock_uniqueext) : '';
make_path($result_dir, $log_dir);
print "package: conserver-xcat\n";
print "version: $version\n";
print "arch: $arch\n";
print "mock-cfg: $mock_cfg\n";
print "result-dir: $result_dir\n";
# ---- stage sources + spec into a private rpmbuild tree -----------------------
remove_tree($work_dir) if -d $work_dir;
make_path("$work_dir/SOURCES", "$work_dir/SPECS");
copy("$pkg_dir/conserver-$version.tar.gz", "$work_dir/SOURCES/")
or die "FATAL: cannot stage conserver-$version.tar.gz: $!\n";
for my $p (glob("$pkg_dir/*.patch")) {
copy($p, "$work_dir/SOURCES/") or die "FATAL: cannot stage patch $p: $!\n";
}
copy("$pkg_dir/conserver.spec", "$work_dir/SPECS/")
or die "FATAL: cannot stage conserver.spec: $!\n";
# ---- build the SRPM (host rpm just packages sources+spec; no %prep here) ------
print "== Build SRPM ==\n";
run("rpmbuild -bs --define " . sh_quote("_topdir $work_dir")
. " " . sh_quote("$work_dir/SPECS/conserver.spec")
. " > " . sh_quote("$log_dir/srpm.log") . " 2>&1");
my ($srpm) = glob("$work_dir/SRPMS/conserver-xcat-$version-*.src.rpm");
die "FATAL: SRPM not produced (see $log_dir/srpm.log)\n" unless $srpm && -f $srpm;
print "SRPM: $srpm\n";
# ---- mock rebuild in the target chroot --------------------------------------
print "== mock --rebuild ($mock_cfg) ==\n";
my $mock_result = "$work_dir/mock-result";
make_path($mock_result);
run("mock -r " . sh_quote($mock_cfg) . $uniq
. " --rebuild " . sh_quote($srpm)
. " --resultdir " . sh_quote($mock_result)
. " > " . sh_quote("$log_dir/mock-rebuild.log") . " 2>&1");
my @rpms = grep { $_ !~ /\.src\.rpm$/ && $_ !~ /-debug(info|source)-/ }
glob("$mock_result/*.rpm");
die "FATAL: no binary RPM produced (see $log_dir/mock-rebuild.log)\n" unless @rpms;
my ($main) = grep { basename($_) =~ /^conserver-xcat-\Q$version\E-.*\.(?:$arch|noarch)\.rpm$/ } @rpms;
die "FATAL: main conserver-xcat RPM not found among: @rpms\n" unless $main;
for my $r (@rpms) {
copy($r, $result_dir) or die "FATAL: cannot copy $r -> $result_dir: $!\n";
}
print "built: " . join(', ', map { basename($_) } @rpms) . "\n";
# ---- smoke test: install into the chroot and run the binaries ---------------
unless ($skip_install) {
print "== Smoke test (install + run) ==\n";
run("mock -r " . sh_quote($mock_cfg) . $uniq . " --install " . sh_quote($main)
. " > " . sh_quote("$log_dir/install.log") . " 2>&1");
# console (client) and conserver (daemon) both print their version to stderr/stdout.
my $smoke = capture("mock -r " . sh_quote($mock_cfg) . $uniq
. " --chroot -- " . sh_quote('/usr/bin/console -V 2>&1; /usr/sbin/conserver -V 2>&1')
. " 2>&1");
print " output: $smoke\n";
die "FATAL: smoke test did not report version $version\n" unless $smoke =~ /\Q$version\E/;
print "smoke test PASSED (console/conserver report $version)\n";
}
print "DONE: conserver-xcat $version for $mock_cfg -> $result_dir\n";
# ---- helpers ----------------------------------------------------------------
sub run {
my ($cmd) = @_;
my $rc = system('bash', '-c', $cmd);
die "FATAL: command failed (rc=" . ($rc >> 8) . "): $cmd\n" if $rc != 0;
return 1;
}
sub capture {
my ($cmd) = @_;
my $out = `$cmd`;
chomp $out if defined $out;
return $out // '';
}
sub sh_quote { my ($s) = @_; $s =~ s/'/'\\''/g; return "'$s'"; }
sub usage {
return "usage: mockbuild.pl --mock-cfg <cfg> [--result-dir DIR] [--work-dir DIR]\n"
. " [--log-dir DIR] [--mock-uniqueext EXT] [--skip-install]\n";
}