From 719e5aecabb949fbedd408ac71d1690c6d032f60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Mon, 24 Aug 2026 22:54:48 -0300 Subject: [PATCH] fix(genesis): close consumer review gaps --- xCAT-server/lib/xcat/plugins/anaconda.pm | 32 ++++++++++++++--- xCAT-server/lib/xcat/plugins/mknb.pm | 46 ++++++++++++++++++++++++ xCAT-server/sbin/xcatconfig | 3 +- xCAT-server/share/xcat/tools/go-xcat | 42 +++++++++++++++++----- 4 files changed, 108 insertions(+), 15 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/anaconda.pm b/xCAT-server/lib/xcat/plugins/anaconda.pm index 6ad77d3b3..87ec419cc 100644 --- a/xCAT-server/lib/xcat/plugins/anaconda.pm +++ b/xCAT-server/lib/xcat/plugins/anaconda.pm @@ -68,6 +68,31 @@ sub handled_commands }; } +sub _find_genesis_boot_files +{ + my ($tftpdir, $arch) = @_; + return unless defined($arch) && $arch =~ /\A[A-Za-z0-9_]+\z/; + + my $directory = "$tftpdir/xcat"; + my $kernel = "genesis.kernel.$arch"; + return unless -r "$directory/$kernel"; + + my $lzma = "genesis.fs.$arch.lzma"; + my $gzip = "genesis.fs.$arch.gz"; + my $initrd; + if (-r "$directory/$lzma" && -r "$directory/$gzip") { + $initrd = -C "$directory/$lzma" > -C "$directory/$gzip" + ? $gzip + : $lzma; + } elsif (-r "$directory/$lzma") { + $initrd = $lzma; + } elsif (-r "$directory/$gzip") { + $initrd = $gzip; + } + return unless defined($initrd); + return ($kernel, $initrd); +} + sub preprocess_request { my $req = shift; @@ -1854,12 +1879,9 @@ sub mksysclone =cut my $ramdisk_size = 200000; - my $kernpath = `ls -l $tftpdir/xcat/|grep "genesis.kernel.$arch"|awk '{print \$9}'`; - chomp($kernpath); - my $initrdpath = `ls -l $tftpdir/xcat/|grep "genesis.fs.$arch"| awk '{print \$9}'`; - chomp($initrdpath); + my ($kernpath, $initrdpath) = _find_genesis_boot_files($tftpdir, $arch); - if ($kernpath ne '' and $initrdpath ne '') + if (defined($kernpath) && defined($initrdpath)) { #We have a shot... my $ent = $rents{$node}->[0]; diff --git a/xCAT-server/lib/xcat/plugins/mknb.pm b/xCAT-server/lib/xcat/plugins/mknb.pm index 448975226..2635fcdbe 100644 --- a/xCAT-server/lib/xcat/plugins/mknb.pm +++ b/xCAT-server/lib/xcat/plugins/mknb.pm @@ -270,6 +270,29 @@ sub _install_prebuilt_genesis { return ("$destination_dir/genesis.fs.$arch.gz", undef); } +sub _remove_openembedded_genesis { + my ($tftpdir, $requested_arch) = @_; + return (0, 'Missing Genesis architecture') unless defined($requested_arch); + my $arch = $requested_arch eq 'ppc64el' ? 'ppc64le' : $requested_arch; + return (0, "Unsupported Genesis architecture: $requested_arch") + unless $GENESIS_ARCHITECTURES{$arch}; + + my $directory = "$tftpdir/xcat"; + my @artifacts = ( + "$directory/genesis.kernel.$arch", + "$directory/genesis.fs.$arch.gz", + "$directory/genesis.fs.$arch.lzma", + ); + my $removed = 0; + foreach my $artifact (@artifacts) { + next unless -e $artifact || -l $artifact; + return ($removed, "Unable to remove Genesis artifact: $artifact") + unless unlink($artifact); + $removed++; + } + return ($removed, undef); +} + sub genesis_lzma_command { my ($have_lzma, $have_xz) = @_; return 'lzma -C crc32 -9' if $have_lzma; @@ -371,6 +394,29 @@ sub process_request { return; } + my $canonical_arch = $requested_arch eq 'ppc64el' + ? 'ppc64le' + : $requested_arch; + if (($request->{arg}->[1] // '') eq '--remove-openembedded') { + unless ($GENESIS_ARCHITECTURES{$canonical_arch}) { + $callback->({ error => "Unsupported Genesis architecture: $requested_arch", errorcode => [1] }); + return; + } + my $source = "$::XCATROOT/share/xcat/netboot/genesis-openembedded/$canonical_arch"; + if (-d $source || -l $source) { + $callback->({ error => "Cannot remove boot artifacts while OpenEmbedded Genesis $canonical_arch is installed", errorcode => [1] }); + return; + } + my ($removed, $remove_error) = + _remove_openembedded_genesis($tftpdir, $canonical_arch); + if ($remove_error) { + $callback->({ error => $remove_error, errorcode => [1] }); + return; + } + $callback->({ data => "Removed $removed OpenEmbedded Genesis artifacts for $canonical_arch" }); + return; + } + my ($genesis_dir, $arch, $genesis_type) = _select_genesis_source($::XCATROOT, $requested_arch); unless (defined($genesis_dir) && -d $genesis_dir) { diff --git a/xCAT-server/sbin/xcatconfig b/xCAT-server/sbin/xcatconfig index 7553eadc6..f4c1394ab 100755 --- a/xCAT-server/sbin/xcatconfig +++ b/xCAT-server/sbin/xcatconfig @@ -2007,7 +2007,7 @@ sub _installed_genesis_architectures while (my $entry = readdir($dh)) { next unless $supported{$entry}; my $path = "$openembedded/$entry"; - $installed{$entry} = 1 if -d $path; + $installed{$entry} = 1 if -d $path && !-l $path; } closedir($dh); } @@ -2029,6 +2029,7 @@ sub _genesis_architectures_to_build return grep { -d "$xcatroot/share/xcat/netboot/genesis-openembedded/$_" + && !-l "$xcatroot/share/xcat/netboot/genesis-openembedded/$_" } @installed; } diff --git a/xCAT-server/share/xcat/tools/go-xcat b/xCAT-server/share/xcat/tools/go-xcat index 24bc01be1..c8943d303 100755 --- a/xCAT-server/share/xcat/tools/go-xcat +++ b/xCAT-server/share/xcat/tools/go-xcat @@ -1345,6 +1345,7 @@ function add_repo_by_url_yum_or_zypper() [[ "$1" = "-y" ]] && yes=("-y") && shift local url="$1" local repo_id="$2" + local policy="${3:-}" local tmp="" local install_path="${GO_XCAT_DEFAULT_INSTALL_PATH}" case "${url%%://*}" in @@ -1361,7 +1362,8 @@ function add_repo_by_url_yum_or_zypper() ;; *) # assume it is the base url of the repo tmp="${TMP_DIR}/tmp_repo.repo" - while read -r ; do echo "${REPLY}" ; done >"${tmp}" <<-EOF + { + while read -r ; do echo "${REPLY}" ; done <<-EOF [${repo_id}] name=${repo_id} baseurl=${url%/} @@ -1369,6 +1371,11 @@ function add_repo_by_url_yum_or_zypper() gpgcheck=1 gpgkey=${url%/}/repodata/repomd.xml.key EOF + if [[ "${policy}" = "optional" ]]; then + echo "repo_gpgcheck=1" + echo "skip_if_unavailable=1" + fi + } >"${tmp}" add_repo_by_file "${tmp}" "${repo_id}" return "$?" ;; @@ -1397,15 +1404,22 @@ function add_repo_by_url_yum_or_zypper() [[ "${url:0:1}" = "/" ]] || url="${PWD}/${url}" # directory tmp="${TMP_DIR}/tmp_repo.repo" - while read -r ; do echo "${REPLY}" ; done >"${tmp}" <<-EOF + { + while read -r ; do echo "${REPLY}" ; done <<-EOF [${repo_id}] name=${repo_id} baseurl=file://${url%/} enabled=1 EOF + if [[ "${policy}" = "optional" ]]; then + echo "skip_if_unavailable=1" + fi + } >"${tmp}" if [ -f "${url%/}/repodata/repomd.xml.asc" ] then echo "gpgcheck=1" >>"${tmp}" + [[ "${policy}" != "optional" ]] \ + || echo "repo_gpgcheck=1" >>"${tmp}" else echo "gpgcheck=0" >>"${tmp}" fi @@ -1614,7 +1628,6 @@ function add_xcat_dep_common_repo_yum_or_zypper() local ver="$2" local common_url="" local metadata="" - local repo_id="" [[ -z "${ver}" ]] && ver="latest" [[ -z "${url}" ]] && @@ -1645,12 +1658,22 @@ function add_xcat_dep_common_repo_yum_or_zypper() ;; esac - add_repo_by_url_yum_or_zypper "${common_url}" "xcat-dep-common" || return 0 - for repo_id in "${GO_XCAT_DEP_REPOSITORY_IDS[@]}" - do - [[ "${repo_id}" == "xcat-dep-common" ]] && return 0 - done - GO_XCAT_DEP_REPOSITORY_IDS+=(xcat-dep-common) + add_repo_by_url_yum_or_zypper \ + "${common_url}" "xcat-dep-common" optional || return 0 +} + +function xcat_dep_common_repo_configured() +{ + [[ -f /etc/yum.repos.d/xcat-dep-common.repo \ + || -f /etc/zypp/repos.d/xcat-dep-common.repo ]] +} + +function refresh_xcat_dep_repository_ids() +{ + GO_XCAT_DEP_REPOSITORY_IDS=(xcat-dep) + xcat_dep_common_repo_configured \ + && GO_XCAT_DEP_REPOSITORY_IDS+=(xcat-dep-common) + : } function add_xcat_dep_repo_yum_or_zypper() @@ -2521,6 +2544,7 @@ then boo_boo_if_bad "${RET}" fi echo "done" +refresh_xcat_dep_repository_ids case "${GO_XCAT_ACTION}" in "check")