mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-30 06:12:19 +00:00
Merge branch 'master' into feat/secureboot-ipxe
This commit is contained in:
@@ -15,7 +15,7 @@ jobs:
|
||||
- name: Install lifecycle test dependencies
|
||||
run: sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends --no-install-suggests ucf debconf-utils systemd libxml-simple-perl apache2 curl
|
||||
- name: Test Debian package lifecycle
|
||||
run: prove -v xCAT-test/native/xcatd_debian_lifecycle.t xCAT-test/native/xcatd_restart_callers.t xCAT-test/native/debian_chroot_services.t xCAT-test/native/debian_management_recovery.t xCAT-test/native/apache_package_lifecycle.t xCAT-test/native/package_upgrade_logging.t xCAT-test/native/profile_package_payload.t
|
||||
run: prove -v xCAT-test/native/xcatd_debian_lifecycle.t xCAT-test/native/xcatd_restart_callers.t xCAT-test/native/debian_chroot_services.t xCAT-test/native/debian_management_recovery.t xCAT-test/native/apache_package_lifecycle.t xCAT-test/native/package_upgrade_logging.t xCAT-test/native/profile_package_payload.t xCAT-test/native/xcatd_debian_init_state.t
|
||||
- name: Test optional statelite host keys
|
||||
if: ${{ !cancelled() }}
|
||||
run: prove -v xCAT-test/native/statelite_optional_hostkey.t
|
||||
@@ -50,7 +50,7 @@ jobs:
|
||||
status=0
|
||||
sudo sh -c 'cd "$1" && bats xCAT-test/native/getinstdisk_selection.bats' sh "$workdir" || status=1
|
||||
sudo sh -c 'cd "$1" && bats xCAT-test/native/syslog_log_directory.bats' sh "$workdir" || status=1
|
||||
sudo sh -c 'cd "$1" && prove -v xCAT-test/native/getinstdisk_installer.t xCAT-test/native/enablekdump_per_node.t xCAT-test/native/sudoer_password_source.t xCAT-test/native/remoteshell_credentials.t' sh "$workdir" || status=1
|
||||
sudo sh -c 'cd "$1" && prove -v xCAT-test/native/getinstdisk_installer.t xCAT-test/native/template_root_password.t xCAT-test/native/enablekdump_per_node.t xCAT-test/native/sudoer_password_source.t xCAT-test/native/remoteshell_credentials.t xCAT-test/native/openeuler_xcatroot.t' sh "$workdir" || status=1
|
||||
exit "$status"
|
||||
- name: Prepare xCAT syslog directory
|
||||
if: ${{ !cancelled() }}
|
||||
@@ -69,6 +69,12 @@ jobs:
|
||||
- name: Exercise the UFTP listener
|
||||
if: ${{ !cancelled() }}
|
||||
run: prove xCAT-test/native/uftp_listener.t
|
||||
- name: Exercise the install script library
|
||||
if: ${{ !cancelled() }}
|
||||
run: prove xCAT-test/native/networkmanager_autoconnect.t
|
||||
- name: Exercise the DHCP server detector
|
||||
if: ${{ !cancelled() }}
|
||||
run: prove xCAT-test/native/detect_dhcpd_tcpdump_lookup.t
|
||||
- name: Run tests
|
||||
if: ${{ !cancelled() }}
|
||||
run: perl github_action_xcat_test.pl
|
||||
@@ -104,7 +110,7 @@ jobs:
|
||||
run: |
|
||||
log=$(mktemp)
|
||||
trap 'rm -f -- "$log"' EXIT
|
||||
prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t | tee "$log"
|
||||
prove -v xCAT-test/native/install_profile_riscv64.t xCAT-test/native/netboot_profile_riscv64.t xCAT-test/native/netboot_profile_postinstall.t xCAT-test/native/post_rhels8_link_nics.t xCAT-test/native/selinux_kickstart_relabel.t xCAT-test/native/kdump_condition_systemd.t xCAT-test/native/openeuler_post_kdump.t xCAT-test/native/builddebs_riscv64.t xCAT-test/native/ubuntu_subiquity_template.t xCAT-test/native/ubuntu_subiquity_install_disk.t xCAT-test/native/kickstart_partition_scheme_log.t xCAT-test/native/kickstart_pre_install_log.t | tee "$log"
|
||||
! grep -qi skipped "$log"
|
||||
rpm_lifecycle_test:
|
||||
runs-on: ubuntu-24.04
|
||||
|
||||
@@ -70,10 +70,15 @@ The following describes creating stateless images of the same Operating System,
|
||||
mkdir /install
|
||||
mount -o soft xcatmn:/install /install
|
||||
|
||||
#. Copy the executable files from the ``/opt/xcat/share/xcat/netboot`` from the xCAT Management node to the target node: ::
|
||||
#. Copy ``/opt/xcat/share/xcat/netboot`` and the xCAT Perl library ``/opt/xcat/lib/perl`` from the xCAT Management node to the target node: ::
|
||||
|
||||
mkdir -p /opt/xcat/share/xcat/
|
||||
mkdir -p /opt/xcat/share/xcat/ /opt/xcat/lib/
|
||||
scp -r xcatmn:/opt/xcat/share/xcat/netboot /opt/xcat/share/xcat/
|
||||
scp -r xcatmn:/opt/xcat/lib/perl /opt/xcat/lib/
|
||||
|
||||
#. Install the Perl modules that the xCAT Perl library uses: ::
|
||||
|
||||
yum install perl perl-DBI perl-Digest-SHA perl-JSON perl-Sys-Syslog perl-XML-Simple
|
||||
|
||||
#. Execute the ``genimage`` command obtained from the ``--dryrun``: ::
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
genimage Boot Files
|
||||
===================
|
||||
|
||||
Every ``genimage`` script builds a kernel and one or more initial ramdisks for
|
||||
a diskless image, and writes them to the image directory, the ``rootimgdir`` of
|
||||
the osimage. ``geninitrd`` runs ``genimage --onlyinitrd``, which takes the
|
||||
same steps.
|
||||
``nodeset`` copies the kernel and the ramdisks as one set, so the files in the
|
||||
image directory must always come from the same build.
|
||||
|
||||
Rules
|
||||
-----
|
||||
|
||||
#. Hold the image operation lock of the root image,
|
||||
``xCAT::Utils->acquire_lock_imageop``, also with ``--onlyinitrd``. The
|
||||
rollback of a failed publication restores earlier files, so two runs on
|
||||
the same image must not overlap.
|
||||
#. Build the boot files in a staging directory inside the image directory.
|
||||
Create it with ``File::Temp->newdir`` in the image directory, so that each
|
||||
file moves into place with a ``rename`` on the same file system.
|
||||
#. Copy the kernel of the image with ``imgutils::copy_kernel``.
|
||||
#. Pack a ramdisk without dracut with ``imgutils::pack_initrd``. It stops
|
||||
when any command of the ``find``, ``cpio`` and compression pipeline fails.
|
||||
#. Stop when a step fails: the kernel copy, dracut, the move of a ramdisk into
|
||||
the staging directory, or the cpio pipeline. Exit with a status other than
|
||||
0, and leave the earlier boot files in the image directory.
|
||||
#. Publish the kernel and all the ramdisks with
|
||||
``imgutils::publish_staged_boot_files`` after the last ramdisk is built. If
|
||||
a move fails, it puts back the files that it already replaced.
|
||||
#. Write the ``rootimgcheck`` and UFTP markers after the publication. They
|
||||
describe the published stateless ramdisk.
|
||||
#. Put code that more than one ``genimage`` script needs in ``imgutils.pm``.
|
||||
Do not copy it into another script. When a fix applies to more than one
|
||||
release, do not limit it to one release.
|
||||
|
||||
Scripts
|
||||
-------
|
||||
|
||||
``rh/genimage`` follows these rules. It is the ``genimage`` of RHEL,
|
||||
AlmaLinux, Rocky Linux, CentOS, Oracle Linux, Scientific Linux, Fedora and
|
||||
openEuler. ``ubuntu/genimage`` follows them, except that it does not take
|
||||
the image operation lock.
|
||||
|
||||
The ``sles``, ``suse``, ``debian`` and ``fedora12`` scripts still write the
|
||||
kernel and the ramdisks directly into the image directory.
|
||||
|
||||
Tests
|
||||
-----
|
||||
|
||||
``xCAT-test/unit/imgutils_boot_file_build.t`` and
|
||||
``xCAT-test/unit/imgutils_staged_boot_files.t`` cover the ``imgutils``
|
||||
functions. ``xCAT-test/native/openeuler_genimage_bootfiles.t`` runs
|
||||
``rh/genimage --onlyinitrd`` for openEuler and EL images, with a failure in
|
||||
each step.
|
||||
|
||||
A change to the boot file steps of a ``genimage`` script also needs a
|
||||
``geninitrd`` run on a real image with a failed dracut. After the run, the
|
||||
image directory must hold the earlier kernel and ramdisks.
|
||||
@@ -9,5 +9,6 @@ Code Development
|
||||
debug.rst
|
||||
dhcp_backend_validation_matrix.rst
|
||||
genesis_openembedded_plan.rst
|
||||
genimage_boot_files.rst
|
||||
kea_dhcp_backend_plan.rst
|
||||
tips.rst
|
||||
|
||||
@@ -9,6 +9,8 @@ By default, xCAT will attempt to determine the first physical disk and use a gen
|
||||
|
||||
.. warning:: **partition definition script** has only been verified on RedHat and Ubuntu, use at your own risk for SLES.
|
||||
|
||||
.. note:: Ubuntu 20.04 and later install with Subiquity. There the partition definition file, or the file the partition definition script writes to ``/tmp/partitionfile``, holds a curtin ``storage:`` section with a ``config`` or ``layout`` entry instead of a partman recipe. The installer keeps only that section, and it replaces the default layout. With a partition disk file or script as well, a ``layout`` without a ``match`` is restricted to the disk it selects, and a ``use_gap`` layout is refused. A layout or disk entry that fails, or that writes no layout or disk, stops the install before it partitions. The additional preseed configuration applies to the debian-installer only.
|
||||
|
||||
.. END_Overview
|
||||
|
||||
|
||||
@@ -480,13 +482,14 @@ If not specified, the default value will be used.
|
||||
nodeset <nodename> osimage=<osimage>
|
||||
|
||||
- the ``d:`` preceding the filename tells nodeset that this is a partition disk file.
|
||||
- For Ubuntu, when nodeset runs and generates the ``/install/autoinst`` file for a node, it will generate a script to write the content of the partition disk file to ``/tmp/install_disk``, this context to run the script will replace the ``#XCA_PARTMAN_DISK_SCRIPT#`` directive in ``/install/autoinst/<node>.pre``.
|
||||
- For Ubuntu, when nodeset runs and generates the ``/install/autoinst`` file for a node, it will generate a script to write the content of the partition disk file to ``/tmp/xcat.install_disk``, this context to run the script will replace the ``#XCA_PARTMAN_DISK_SCRIPT#`` directive in ``/install/autoinst/<node>.pre``.
|
||||
- A Subiquity install partitions only the first disk the file names. Use a ``/dev/disk/by-id/`` name when the kernel can enumerate the disks in a different order at each boot.
|
||||
|
||||
.. END_Partition_Disk_File_ubuntu_only
|
||||
|
||||
.. BEGIN_Partition_Disk_Script_ubuntu_only
|
||||
|
||||
The disk script contains a script to generate a partitioning disk file named ``/tmp/install_disk``. for example: ::
|
||||
The disk script contains a script to generate a partitioning disk file named ``/tmp/xcat.install_disk``. for example: ::
|
||||
|
||||
rm /tmp/devs-with-boot 2>/dev/null || true;
|
||||
for d in $(list-devices partition); do
|
||||
@@ -499,12 +502,12 @@ The disk script contains a script to generate a partitioning disk file named ``/
|
||||
fi
|
||||
done;
|
||||
if [[ -e /tmp/devs-with-boot ]]; then
|
||||
head -n1 /tmp/devs-with-boot | egrep -o '\S+[^0-9]' > /tmp/install_disk;
|
||||
head -n1 /tmp/devs-with-boot | egrep -o '\S+[^0-9]' > /tmp/xcat.install_disk;
|
||||
rm /tmp/devs-with-boot 2>/dev/null || true;
|
||||
else
|
||||
DEV=`ls /dev/disk/by-path/* -l | egrep -o '/dev.*[s|h|v]d[^0-9]$' | sort -t : -k 1 -k 2 -k 3 -k 4 -k 5 -k 6 -k 7 -k 8 -g | head -n1 | egrep -o '[s|h|v]d.*$'`;
|
||||
if [[ "$DEV" == "" ]]; then DEV="sda"; fi;
|
||||
echo "/dev/$DEV" > /tmp/install_disk;
|
||||
echo "/dev/$DEV" > /tmp/xcat.install_disk;
|
||||
fi;
|
||||
|
||||
If not specified, the default value will be used.
|
||||
@@ -516,6 +519,7 @@ If not specified, the default value will be used.
|
||||
|
||||
- the ``s:`` prefix tells ``nodeset`` that is a script, the ``s:d:`` preceding the filename tells ``nodeset`` that this is a script to generate the partition disk file.
|
||||
- For Ubuntu, when nodeset runs and generates the ``/install/autoinst`` file for a node, this context to run the script will replace the ``#XCA_PARTMAN_DISK_SCRIPT#`` directive in ``/install/autoinst/<node>.pre``.
|
||||
- A Subiquity install runs the script in the live installer system, under ``dash`` unless its first line names another interpreter. ``list-devices``, which the example uses, exists only in the debian-installer.
|
||||
|
||||
.. END_Partition_Disk_Script_ubuntu_only
|
||||
|
||||
|
||||
@@ -28,6 +28,9 @@ Qualification uses one service pack from each LTS release:
|
||||
* - 24.03 LTS GA
|
||||
- ppc64le
|
||||
- ``openeuler24.03``
|
||||
* - 24.03 LTS SP4
|
||||
- riscv64
|
||||
- ``openeuler24.03sp4``
|
||||
|
||||
Earlier service packs are outside this qualification. The POWER GA image
|
||||
is a functional exception; its qualification does not establish maintained
|
||||
@@ -41,6 +44,18 @@ cpio with gzip compression. SQLite serves standalone management nodes;
|
||||
MariaDB serves the service-node hierarchy. Additional firmware, database,
|
||||
image-format and network combinations need separate qualification.
|
||||
|
||||
On riscv64, the qualification covers installed and stateless compute nodes
|
||||
from the RVA23 media, managed from a riscv64 management node that runs
|
||||
Ubuntu 26.04. xCAT publishes no openEuler riscv64 packages, so riscv64
|
||||
management and service nodes are outside it. The test hardware could not boot
|
||||
from the network, so firmware network boot is not qualified either. See
|
||||
:doc:`/guides/admin-guides/manage_clusters/riscv64/index`.
|
||||
|
||||
openEuler also publishes RVA20 media for riscv64. Both builds of a release
|
||||
have the same target directory, and ``copycds`` refuses to copy one over the
|
||||
other. Import the build that matches the nodes, or copy the other build to
|
||||
another directory with ``-p``.
|
||||
|
||||
The tested provisioning networks use IPv4 and ISC DHCP on isolated links,
|
||||
with separate upstream and downstream interfaces on service nodes. The
|
||||
qualification covers on-link access to the assigned management or service
|
||||
@@ -116,8 +131,13 @@ Stateless compute images
|
||||
|
||||
Build the image on an openEuler host of the target architecture, using its
|
||||
native kernel, modules and package repositories. Check the image's network
|
||||
drivers and interface settings before generation. For the imported compute
|
||||
profile::
|
||||
drivers and interface settings before generation. ``genimage`` checks every
|
||||
package against the signing keys in the build host's RPM keyring. A new
|
||||
openEuler installation has no key there. Import the openEuler key first::
|
||||
|
||||
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-openEuler
|
||||
|
||||
For the imported compute profile::
|
||||
|
||||
genimage openeuler24.03sp4-x86_64-netboot-compute
|
||||
packimage -m cpio -c gzip openeuler24.03sp4-x86_64-netboot-compute
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
RISC-V 64-bit (riscv64)
|
||||
=======================
|
||||
|
||||
xCAT manages RISC-V 64-bit (``riscv64``) compute nodes running EL10 or Ubuntu.
|
||||
xCAT manages RISC-V 64-bit (``riscv64``) compute nodes running EL10, Ubuntu or
|
||||
openEuler.
|
||||
Rocky Linux 10 is the reference EL distribution and the RHEL 10 RISC-V developer
|
||||
preview uses the same media layout; on the Ubuntu side, 24.04 and 26.04 are
|
||||
supported from the live-server media. The general cluster management documentation under
|
||||
supported from the live-server media. openEuler 24.03 LTS SP4 is supported from
|
||||
the RVA23 media. See :doc:`/guides/admin-guides/manage_clusters/openeuler/index`.
|
||||
The general cluster management documentation under
|
||||
:doc:`/guides/admin-guides/manage_clusters/index` applies; this page
|
||||
only covers what is specific to the architecture.
|
||||
|
||||
@@ -27,7 +30,8 @@ What riscv64 nodes need
|
||||
BaseOS tree, which the ``grub2-xcat`` package also installs and
|
||||
:doc:`/guides/install-guides/yum/grub2` describes copying by hand; ``copycds``
|
||||
publishes it when the management node does not have it yet and keeps an image
|
||||
that is already there.
|
||||
that is already there. openEuler media carry the same image as
|
||||
``EFI/BOOT/grubriscv64.EFI``, and ``copycds`` publishes it the same way.
|
||||
|
||||
Ubuntu media are different: the loader they carry boots only from the media,
|
||||
because it holds a built-in configuration that searches for the live
|
||||
|
||||
@@ -16,15 +16,15 @@ Operating System & Hardware Support Matrix
|
||||
+-----------+---------------+---------+----------+-----------+
|
||||
| Ubuntu | 22.04 | yes | yes | no |
|
||||
+-----------+---------------+---------+----------+-----------+
|
||||
| Ubuntu | 24.04 | yes | yes | no |
|
||||
| Ubuntu | 24.04 | yes | yes | yes |
|
||||
+-----------+---------------+---------+----------+-----------+
|
||||
| Ubuntu | 26.04 | yes | yes | no |
|
||||
| Ubuntu | 26.04 | yes | yes | yes |
|
||||
+-----------+---------------+---------+----------+-----------+
|
||||
| openEuler | 20.03 LTS SP4 | yes | no | no |
|
||||
+-----------+---------------+---------+----------+-----------+
|
||||
| openEuler | 22.03 LTS SP4 | yes | no | no |
|
||||
+-----------+---------------+---------+----------+-----------+
|
||||
| openEuler | 24.03 LTS SP4 | yes | no | no |
|
||||
| openEuler | 24.03 LTS SP4 | yes | no | yes |
|
||||
+-----------+---------------+---------+----------+-----------+
|
||||
|
||||
.. note::
|
||||
@@ -32,9 +32,10 @@ Operating System & Hardware Support Matrix
|
||||
EL stands for Enterprise Linux, such as: Red Hat Enterprise Linux (RHEL), Rocky Linux, AlmaLinux, CentOS and Oracle Linux.
|
||||
|
||||
openEuler support covers the management node, installed and diskless service nodes, and
|
||||
stateful and stateless compute nodes.
|
||||
stateful and stateless compute nodes. On riscv64, it covers only stateful and stateless
|
||||
compute nodes.
|
||||
|
||||
riscv64 support covers EL 10 (Rocky Linux 10 and the RHEL 10 RISC-V developer preview), on nodes
|
||||
that boot through UEFI firmware and grub2. Both stateful and stateless nodes are supported, and
|
||||
the management node itself can run on riscv64. See
|
||||
riscv64 support covers EL 10 (Rocky Linux 10 and the RHEL 10 RISC-V developer preview) and
|
||||
Ubuntu 24.04 and 26.04, on nodes that boot through UEFI firmware and grub2. Both stateful and
|
||||
stateless nodes are supported, and the management node itself can run on riscv64. See
|
||||
:doc:`/guides/admin-guides/manage_clusters/riscv64/index` for details.
|
||||
|
||||
@@ -16,6 +16,15 @@ BuildArch: noarch
|
||||
BuildRequires: perl perl-DBI perl-JSON
|
||||
# Do not need the SOAP rpm require, because rpm will generate it automatically if hpoa.pm is included
|
||||
#Requires: perl-SOAP-Lite
|
||||
# openSUSE has no perl-generators, so no perl(...) requirement is generated here and nothing
|
||||
# installs the modules this code loads. xcatd stays inactive without them: xCAT::Table dies
|
||||
# loading JSON. EL and openEuler generate these automatically and need no list.
|
||||
%if 0%{?suse_version}
|
||||
Requires: perl(Expect)
|
||||
Requires: perl(HTML::Form)
|
||||
Requires: perl(JSON)
|
||||
Requires: perl(SNMP)
|
||||
%endif
|
||||
%endif
|
||||
|
||||
%description
|
||||
|
||||
@@ -120,4 +120,98 @@ sub update_discovery_data {
|
||||
}
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
=head3 client_certificate_name
|
||||
|
||||
Descriptions: The name xcatd may record as the verified client certificate of a request.
|
||||
becomeuser and tokens replace the authenticated name with an account name.
|
||||
A name that differs from the certificate CN is therefore not a certificate name.
|
||||
|
||||
Arguments : $cert_cn - the CN of the client certificate, undef when there is none
|
||||
$authname - the authenticated name xcatd uses for the request
|
||||
Returns : $cert_cn when the request is still authenticated by that certificate, else undef
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
sub client_certificate_name {
|
||||
my ($cert_cn, $authname) = @_;
|
||||
return undef unless defined $cert_cn && $cert_cn ne '';
|
||||
return undef unless defined $authname && $authname eq $cert_cn;
|
||||
return $cert_cn;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
=head3 request_client_names
|
||||
|
||||
Descriptions: The names a node-initiated request offers for correlating it to a node, most
|
||||
trustworthy first.
|
||||
|
||||
xcatd fills _xcat_clienthost and _xcat_clientfqdn from a reverse lookup of the
|
||||
peer socket, so both are empty when that lookup fails.
|
||||
_xcat_certname is the CN of the validated client certificate.
|
||||
_xcat_authname is not a candidate: a password or a token can set it.
|
||||
The request's own node attribute is not a candidate: the client sends it.
|
||||
|
||||
Arguments : $request - the request hash xcatd built
|
||||
Returns : the candidate names, without duplicates; an empty list when there are none
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
sub request_client_names {
|
||||
my ($request) = @_;
|
||||
return () unless ref($request) eq 'HASH';
|
||||
my @names;
|
||||
foreach my $key (qw(_xcat_clienthost _xcat_clientfqdn _xcat_certname)) {
|
||||
my $name = _first_value($request, $key);
|
||||
next unless defined $name;
|
||||
push @names, $name unless grep { $_ eq $name } @names;
|
||||
}
|
||||
return @names;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
=head3 request_client_node
|
||||
|
||||
Descriptions: The node a node-initiated request comes from.
|
||||
A peer name is expanded as before, and the first node it gives is used.
|
||||
The certificate name must name exactly one node, with no group or range
|
||||
expansion, because xCAT signs user and node certificates with one CA.
|
||||
|
||||
Arguments : $request - the request hash xcatd built
|
||||
$expand - code ref that expands a noderange to a node list (noderange)
|
||||
Returns : the node name, or undef when no candidate names a node
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
sub request_client_node {
|
||||
my ($request, $expand) = @_;
|
||||
return undef unless ref($request) eq 'HASH' && ref($expand) eq 'CODE';
|
||||
foreach my $key (qw(_xcat_clienthost _xcat_clientfqdn)) {
|
||||
my $name = _first_value($request, $key);
|
||||
next unless defined $name;
|
||||
my ($node) = $expand->($name);
|
||||
return $node if $node;
|
||||
}
|
||||
my $cert = _first_value($request, '_xcat_certname');
|
||||
return undef unless defined $cert;
|
||||
my @nodes = $expand->($cert);
|
||||
return $cert if @nodes == 1 && defined $nodes[0] && $nodes[0] eq $cert;
|
||||
return undef;
|
||||
}
|
||||
|
||||
sub _first_value {
|
||||
my ($request, $key) = @_;
|
||||
my $value = $request->{$key};
|
||||
return undef unless ref($value) eq 'ARRAY';
|
||||
my $name = $value->[0];
|
||||
return undef unless defined $name && $name ne '';
|
||||
return $name;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
@@ -20,8 +20,12 @@ BuildArch: noarch
|
||||
Provides: xCAT-OpenStack-baremetal = %{epoch}:%{version}
|
||||
|
||||
Requires: xCAT-client
|
||||
# Pod::Html ships inside the core perl package on SUSE; there is no perl-Pod-Html
|
||||
%if !0%{?suse_version}
|
||||
# The pod converters are in perl-Pod-Html on EL and in the core perl package on
|
||||
# SUSE, which has no perl-Pod-Html. A SUSE chroot holds perl-base only, and that
|
||||
# ships neither Pod::Man nor pod2man.
|
||||
%if 0%{?suse_version}
|
||||
BuildRequires: perl
|
||||
%else
|
||||
BuildRequires: perl-Pod-Html
|
||||
%endif
|
||||
|
||||
|
||||
@@ -15,8 +15,12 @@ BuildRoot: /var/tmp/%{name}-%{version}-%{release}-root
|
||||
BuildArch: noarch
|
||||
%endif
|
||||
Requires: xCAT-server
|
||||
# Pod::Html ships inside the core perl package on SUSE; there is no perl-Pod-Html
|
||||
%if !0%{?suse_version}
|
||||
# The pod converters are in perl-Pod-Html on EL and in the core perl package on
|
||||
# SUSE, which has no perl-Pod-Html. A SUSE chroot holds perl-base only, and that
|
||||
# ships neither Pod::Man nor pod2man.
|
||||
%if 0%{?suse_version}
|
||||
BuildRequires: perl
|
||||
%else
|
||||
BuildRequires: perl-Pod-Html
|
||||
%endif
|
||||
|
||||
|
||||
@@ -12,8 +12,12 @@ Distribution: %{?_distribution:%{_distribution}}%{!?_distribution:%{_vendor}}
|
||||
Prefix: /opt/xcat
|
||||
BuildRoot: /var/tmp/%{name}-%{version}-%{release}-root
|
||||
|
||||
# Pod::Html ships inside the core perl package on SUSE; there is no perl-Pod-Html
|
||||
%if !0%{?suse_version}
|
||||
# The pod converters are in perl-Pod-Html on EL and in the core perl package on
|
||||
# SUSE, which has no perl-Pod-Html. A SUSE chroot holds perl-base only, and that
|
||||
# ships neither Pod::Man nor pod2man.
|
||||
%if 0%{?suse_version}
|
||||
BuildRequires: perl
|
||||
%else
|
||||
BuildRequires: perl-Pod-Html
|
||||
%endif
|
||||
|
||||
|
||||
@@ -19,8 +19,12 @@ BuildRoot: /var/tmp/%{name}-%{version}-%{release}-root
|
||||
%define s390x %(if [ "$s390x" = "1" ];then echo 1; else echo 0; fi)
|
||||
%define nots390x %(if [ "$s390x" = "1" ];then echo 0; else echo 1; fi)
|
||||
|
||||
# Pod::Html ships inside the core perl package on SUSE; there is no perl-Pod-Html
|
||||
%if !0%{?suse_version}
|
||||
# The pod converters are in perl-Pod-Html on EL and in the core perl package on
|
||||
# SUSE, which has no perl-Pod-Html. A SUSE chroot holds perl-base only, and that
|
||||
# ships neither Pod::Man nor pod2man.
|
||||
%if 0%{?suse_version}
|
||||
BuildRequires: perl
|
||||
%else
|
||||
BuildRequires: perl-Pod-Html
|
||||
%endif
|
||||
|
||||
@@ -31,6 +35,12 @@ BuildArch: noarch
|
||||
|
||||
Requires: perl-xCAT = 4:%{version}-%{release}
|
||||
Requires: cpio
|
||||
# openSUSE has no perl-generators, so no perl(...) requirement is generated here and nothing
|
||||
# installs the modules this code loads. xcatd stays inactive without them: xCAT::Table dies
|
||||
# loading JSON. EL and openEuler generate these automatically and need no list.
|
||||
%if 0%{?suse_version}
|
||||
Requires: perl(Expect)
|
||||
%endif
|
||||
|
||||
# fping or nmap is needed by pping (in case xCAT-client is installed by itself on a remote client)
|
||||
%ifos linux
|
||||
|
||||
@@ -64,7 +64,13 @@ install() {
|
||||
_dracut_install_opt mstflint
|
||||
dracut_install netstat # broadcom update requires
|
||||
dracut_install uniq # mellanox update requires
|
||||
dracut_install grep ip hostname /usr/bin/awk egrep grep dirname expr
|
||||
dracut_install grep ip hostname egrep grep dirname expr
|
||||
|
||||
# allowcred.awk, minixcatd.awk and udpcat.awk open a TCP stream with the gawk |&
|
||||
# coprocess and the /inet/ special file. mawk rejects both at parse time, and mawk is
|
||||
# the awk alternative on this build root, so name gawk and point awk at it.
|
||||
dracut_install gawk
|
||||
ln -sf gawk "$initdir/usr/bin/awk"
|
||||
dracut_install mount.nfs sshd vi reboot lspci parted screen mkfs mkfs.ext4 mkfs.btrfs
|
||||
#dracut_install libvirtd /usr/share/libvirt/cpu_map.xml /usr/bin/qemu-img /usr/libexec/qemu-kvm
|
||||
dracut_install mkswap df ifenslave ssh-keygen scp clear
|
||||
|
||||
@@ -14,7 +14,7 @@ my @BASE_PACKAGES = qw(
|
||||
openssh-server openssh-client rsyslog chrony
|
||||
nfs-common rpcbind pciutils usbutils parted
|
||||
dosfstools e2fsprogs lvm2 mdadm net-tools
|
||||
bc psmisc rsync wget cpio
|
||||
bc psmisc rsync wget cpio gawk
|
||||
isc-dhcp-client ifenslave
|
||||
systemd-sysv hwdata btrfs-progs netcat-openbsd iputils-ping fdisk ncurses-term
|
||||
dpkg-dev debhelper fakeroot devscripts vim-tiny
|
||||
|
||||
@@ -67,6 +67,7 @@ sub module_commands {
|
||||
path is looked for under the payload root.
|
||||
source: the module the commands came from, for the message
|
||||
sshd: the content of usr/sbin/sshd, or undef without one
|
||||
awk: the content of usr/bin/awk, or undef without one
|
||||
Returns:
|
||||
one "<path> (<reason>)" string per missing item, in the order checked.
|
||||
An empty list means the payload is complete.
|
||||
@@ -106,6 +107,15 @@ sub missing_paths {
|
||||
"usr/libexec/openssh/sshd-session (this sshd execs it for every connection)";
|
||||
}
|
||||
|
||||
# allowcred.awk, minixcatd.awk and udpcat.awk open a TCP stream with the gawk |&
|
||||
# coprocess and the /inet/ special file. mawk rejects both at parse time and the node
|
||||
# then asks for no credential, so read the binary back. gawk carries its own name. An
|
||||
# empty file carries no name and is not a program, so there is nothing to read.
|
||||
if (length($opt{awk} // '') && index($opt{awk}, 'GNU Awk') < 0) {
|
||||
push @missing,
|
||||
'usr/bin/awk is not gawk (allowcred.awk opens its TCP stream with the gawk /inet/ coprocess)';
|
||||
}
|
||||
|
||||
# tmux exits under the C locale. The hook then runs doxcat directly, but a Genesis
|
||||
# shell without tmux loses the console attach.
|
||||
if ($have->('usr/bin/tmux') && !$have->('usr/lib/locale/C.utf8/LC_CTYPE')) {
|
||||
@@ -157,17 +167,13 @@ sub check_payload {
|
||||
return (2, $@) if $@;
|
||||
}
|
||||
|
||||
my $sshd;
|
||||
if (open(my $fh, '<:raw', "$payload/usr/sbin/sshd")) {
|
||||
local $/;
|
||||
$sshd = <$fh> // '';
|
||||
close($fh);
|
||||
}
|
||||
my ($sshd, $awk) = (slurp("$payload/usr/sbin/sshd"), slurp("$payload/usr/bin/awk"));
|
||||
my @missing = missing_paths(sub { -e "$payload/$_[0]" },
|
||||
required => \@args,
|
||||
commands => \@commands,
|
||||
source => $commands_from,
|
||||
sshd => $sshd);
|
||||
sshd => $sshd,
|
||||
awk => $awk);
|
||||
return (1, "$ME: $payload is incomplete:" . join('', map { "\n $_" } @missing) . "\n")
|
||||
if @missing;
|
||||
return (0, "$ME: $payload is complete\n");
|
||||
@@ -175,6 +181,29 @@ sub check_payload {
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
=head3 slurp
|
||||
|
||||
Descriptions: read a file whole, in raw mode. usr/bin/awk and usr/sbin/sshd are
|
||||
binaries, and both are read to tell one program from another.
|
||||
Arguments:
|
||||
$path: the path to read
|
||||
Returns:
|
||||
the content, or undef when the file cannot be read
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
sub slurp {
|
||||
my ($path) = @_;
|
||||
open(my $fh, '<:raw', $path) or return undef;
|
||||
local $/;
|
||||
my $content = <$fh> // '';
|
||||
close($fh);
|
||||
return $content;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
=head3 main
|
||||
|
||||
Descriptions: run check_payload and print its message: on STDOUT when the
|
||||
|
||||
@@ -224,15 +224,16 @@ sub subvars {
|
||||
$filepath = $1;
|
||||
}
|
||||
|
||||
# The last entry of each kind wins, with its own s: prefix.
|
||||
if ($filepath =~ /^d:(.*)/) {
|
||||
$diskfile = $1;
|
||||
if ($scriptflag) { $diskscriptflag = 1; }
|
||||
$diskfile = $1;
|
||||
$diskscriptflag = $scriptflag;
|
||||
} elsif ($filepath =~ /^c:(.*)/) {
|
||||
$configfile = $1;
|
||||
if ($scriptflag) { $configscriptflag = 1; }
|
||||
$configfile = $1;
|
||||
$configscriptflag = $scriptflag;
|
||||
} elsif ($filepath) {
|
||||
$partitionfile = $filepath;
|
||||
if ($scriptflag) { $partscriptflag = 1; }
|
||||
$partitionfile = $filepath;
|
||||
$partscriptflag = $scriptflag;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,7 +456,8 @@ sub subvars {
|
||||
$partcontent .= "rm -rf /tmp/partitionfile\n";
|
||||
|
||||
# Put the code to decode the partitionfile
|
||||
$partcontent .= "base64decode</tmp/partscript.enc >/tmp/partscript\n";
|
||||
# A traced decode prints the partition data, which can hold a passphrase.
|
||||
$partcontent .= "(set +x; base64decode</tmp/partscript.enc >/tmp/partscript)\n";
|
||||
$partcontent .= "chmod 755 /tmp/partscript\n";
|
||||
$partcontent .= "/tmp/partscript\n";
|
||||
|
||||
@@ -483,7 +485,7 @@ sub subvars {
|
||||
|
||||
# Put the base64 coded partitionfile into %pre part
|
||||
$partcontent = "cat > /tmp/partscript.enc << EOFEOF\n" . $partcontent . "\nEOFEOF\n";
|
||||
if ($scriptflag) {
|
||||
if ($partscriptflag) {
|
||||
|
||||
# Put the code to decode preseed script and run it to generate pressed recipe file
|
||||
#$partcontent .= "python -c 'import base64; print base64.b64decode(open(\"/tmp/partscript.enc\",\"rb\").read())' >/tmp/partscript\n";
|
||||
@@ -516,7 +518,8 @@ sub subvars {
|
||||
$partcontent .= "rm -rf /tmp/partitionfile\n";
|
||||
|
||||
# Put the code to decode the partitionfile
|
||||
$partcontent .= "base64decode</tmp/partitionfile.enc >/tmp/partitionfile\n";
|
||||
# A traced decode prints the partition data, which can hold a passphrase.
|
||||
$partcontent .= "(set +x; base64decode</tmp/partitionfile.enc >/tmp/partitionfile)\n";
|
||||
|
||||
#replace the #XCA_PARTITION_SCRIPT#
|
||||
$inc =~ s/#XCA_PARTITION_SCRIPT#/$partcontent/;
|
||||
@@ -1657,7 +1660,7 @@ sub envvar
|
||||
return ($ENV{$envvar});
|
||||
}
|
||||
|
||||
sub crydb
|
||||
sub crypt_field
|
||||
{
|
||||
my ($table, $key, $field) = @_;
|
||||
my @fields = [$field, 'cryptmethod'];
|
||||
@@ -1681,10 +1684,19 @@ sub crydb
|
||||
return xCAT::PasswordUtils::crypt_system_password($table, $kp, \@fields);
|
||||
}
|
||||
|
||||
sub crydb
|
||||
{
|
||||
my ( $table, $key, $field ) = @_;
|
||||
my $crypted = crypt_field( $table, $key, $field );
|
||||
return $crypted if defined($crypted) && length($crypted);
|
||||
$tmplerr = "Unable to find requested field <$field> from table <$table>, with key <$key>";
|
||||
return "";
|
||||
}
|
||||
|
||||
sub crydb_or_locked
|
||||
{
|
||||
my ( $table, $key, $field ) = @_;
|
||||
my $crypted = crydb( $table, $key, $field );
|
||||
my $crypted = crypt_field( $table, $key, $field );
|
||||
return $crypted if defined($crypted) && length($crypted);
|
||||
return '*';
|
||||
}
|
||||
|
||||
@@ -115,11 +115,24 @@ sub _openeuler_media_info
|
||||
return { error => 'Unsupported openEuler LTS version in .treeinfo' }
|
||||
unless defined($version);
|
||||
return { error => 'Unsupported openEuler architecture in .treeinfo' }
|
||||
unless defined($general{arch}) && $general{arch} =~ /\A(?:x86_64|ppc64le)\z/;
|
||||
unless defined($general{arch}) && $general{arch} =~ /\A(?:x86_64|ppc64le|riscv64)\z/;
|
||||
|
||||
return { distname => "openeuler$version", arch => $general{arch} };
|
||||
}
|
||||
|
||||
# The second line of .discinfo, or '' when it is missing.
|
||||
sub _discinfo_description
|
||||
{
|
||||
my ($file) = @_;
|
||||
open(my $fh, '<', $file) or return '';
|
||||
<$fh>;
|
||||
my $description = <$fh>;
|
||||
close($fh);
|
||||
return '' unless defined($description);
|
||||
chomp($description);
|
||||
return $description;
|
||||
}
|
||||
|
||||
|
||||
sub _driver_disk_marker_path
|
||||
{
|
||||
@@ -2204,7 +2217,13 @@ sub _install_media_grub2_loader {
|
||||
|
||||
my $image = $MEDIA_GRUB2_LOADERS{$arch};
|
||||
return unless $image;
|
||||
my $source = "$path/EFI/BOOT/$image";
|
||||
|
||||
# UEFI file names are case-insensitive: openEuler ships grubriscv64.EFI.
|
||||
opendir(my $dh, "$path/EFI/BOOT") or return;
|
||||
my ($name) = sort grep { lc($_) eq $image } readdir($dh);
|
||||
closedir($dh);
|
||||
return unless defined($name);
|
||||
my $source = "$path/EFI/BOOT/$name";
|
||||
return unless -r $source;
|
||||
|
||||
my $tftpdir = xCAT::TableUtils->getTftpDir();
|
||||
@@ -2498,6 +2517,17 @@ sub copycd
|
||||
{
|
||||
$path = $defaultpath;
|
||||
}
|
||||
# The RVA20 and RVA23 builds of an openEuler riscv64 release have the same
|
||||
# .treeinfo identity. Only the .discinfo description tells them apart.
|
||||
if ($openeuler_media && -r "$path/.discinfo") {
|
||||
my $copied = _discinfo_description("$path/.discinfo");
|
||||
my $media = defined($desc) ? $desc : '';
|
||||
if (lc($copied) ne lc($media)) {
|
||||
my $build = length($copied) ? $copied : 'no build name';
|
||||
$callback->({ error => "$path holds openEuler media of another build ($build). Copy this media to another directory with -p.", errorcode => [1] });
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ($::XCATSITEVALS{osimagerequired}) {
|
||||
my ($nohaveimages, $errstr) = xCAT::SvrUtils->update_tables_with_templates($distname, $arch, $path, $osdistroname, checkonly => 1);
|
||||
if ($nohaveimages) {
|
||||
|
||||
@@ -305,7 +305,7 @@ sub process_request {
|
||||
}
|
||||
if ($osver =~ /^openeuler/) {
|
||||
unless (defined(xCAT::Utils::normalize_openeuler_version(substr($osver, 9)))
|
||||
&& $arch =~ /^(?:x86_64|ppc64le)$/) {
|
||||
&& $arch =~ /^(?:x86_64|ppc64le|riscv64)$/) {
|
||||
$callback->({ error => ["Unsupported openEuler release or architecture: $osver $arch"], errorcode => [1] });
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -148,8 +148,13 @@ sub geninitrd {
|
||||
xCAT::MsgUtils->message("E", { error => ["The rootimgdir attribute for the osimage should be set."], errorcode => ["1"] }, $callback);
|
||||
return;
|
||||
}
|
||||
my @output = `genimage $osimage --onlyinitrd`;
|
||||
my @output = `genimage $osimage --onlyinitrd 2>&1`;
|
||||
my $status = $?;
|
||||
xCAT::MsgUtils->message("I", { data => \@output }, $callback);
|
||||
if ($status) {
|
||||
my $rc = ($status > 0 && $status >> 8) || 1;
|
||||
xCAT::MsgUtils->message("E", { error => ["genimage $osimage --onlyinitrd failed with rc $rc."] }, $callback, $rc);
|
||||
}
|
||||
|
||||
#$doreq->({ command => ['genimage'],
|
||||
# arg => [$osimage, '--onlyinitrd'] }, $callback);
|
||||
|
||||
@@ -11,6 +11,7 @@ package xCAT_plugin::getpostscript;
|
||||
use xCAT::Utils;
|
||||
use xCAT::MsgUtils;
|
||||
use xCAT::NodeRange;
|
||||
use xCAT::DiscoveryUtils;
|
||||
1;
|
||||
|
||||
#-------------------------------------------------------
|
||||
@@ -59,22 +60,22 @@ sub process_request
|
||||
my $client;
|
||||
if ($::XCATSITEVALS{nodeauthentication}) { #if requiring node authentication, this request will have a certificate associated with it, use it instead of name resolution
|
||||
unless (ref $request->{username}) { return; } #TODO: log an attempt without credentials?
|
||||
$client = $request->{username}->[0];
|
||||
} else {
|
||||
unless ($request->{'_xcat_clienthost'}->[0]) {
|
||||
|
||||
#ERROR? malformed request
|
||||
xCAT::MsgUtils->trace(0, 'E', "Received malformed getpostscript requesting, ignore it.");
|
||||
($client) = noderange($request->{username}->[0]);
|
||||
unless ($client) {
|
||||
xCAT::MsgUtils->trace(0, "E", "Received getpostscript from $request->{username}->[0], which couldn't be correlated to a node (domain mismatch?)");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
my @candidates = xCAT::DiscoveryUtils::request_client_names($request);
|
||||
unless (@candidates) {
|
||||
xCAT::MsgUtils->trace(0, 'E', "Received getpostscript from a client this request does not identify: it carries no peer name and no client certificate name. Ignoring it.");
|
||||
return;
|
||||
}
|
||||
$client = xCAT::DiscoveryUtils::request_client_node($request, \&noderange);
|
||||
unless ($client) { #Not able to do identify the host in question
|
||||
xCAT::MsgUtils->trace(0, "E", "Received getpostscript from " . join(', ', @candidates) . ", none of which could be correlated to a node (domain mismatch?)");
|
||||
return;
|
||||
}
|
||||
$client = $request->{'_xcat_clienthost'}->[0];
|
||||
}
|
||||
|
||||
my $origclient = $client;
|
||||
if ($client) { ($client) = noderange($client) }
|
||||
unless ($client) { #Not able to do identify the host in question
|
||||
xCAT::MsgUtils->trace(0, "E", "Received getpostscript from $origclient, which couldn't be correlated to a node (domain mismatch?)");
|
||||
return;
|
||||
}
|
||||
my $state;
|
||||
if ($request->{scripttype}) { $state = $request->{scripttype}->[0]; }
|
||||
|
||||
@@ -124,7 +124,7 @@ my $cache_dir = "/var/cache/xcat";
|
||||
use xCAT::data::ibmleds;
|
||||
use xCAT::data::ipmigenericevents;
|
||||
use xCAT::data::ipmisensorevents;
|
||||
my $cache_version = 4;
|
||||
my $cache_version = 5;
|
||||
my %sdr_caches; #store sdr cachecs in memory indexed such that identical nodes do not hit the disk multiple times
|
||||
|
||||
#my $status_noop="XXXno-opXXX";
|
||||
@@ -7653,15 +7653,11 @@ sub initsdr_withrepinfo {
|
||||
|
||||
|
||||
if ($sessdata->{sdr_info}->{version} != 0x51) {
|
||||
sendoutput(1, "SDR version unsupported.");
|
||||
xCAT::SvrUtils::sendmsg([ 1, "SDR version unsupported." ], $callback, $sessdata->{node}, %allerrornodes);
|
||||
return (1); #bail, do not try to continue
|
||||
}
|
||||
|
||||
if ($sessdata->{sdr_info}->{resv_sdr} != 1) {
|
||||
sendoutput(1, "SDR reservation unsupported.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
# Some BMCs grant a reservation that Get SDR Repository Info does not advertise.
|
||||
$sessdata->{ipmisession}->subcmd(netfn => 0x0a, command => 0x22, data => [], callback => \&reserved_sdr_repo, callback_args => $sessdata);
|
||||
}
|
||||
|
||||
@@ -7695,7 +7691,7 @@ sub start_sdr_record {
|
||||
my $rsp = shift;
|
||||
my $sessdata = shift;
|
||||
if ($rsp->{error}) {
|
||||
sendoutput(1, $rsp->{error});
|
||||
xCAT::SvrUtils::sendmsg([ 1, $rsp->{error} ], $callback, $sessdata->{node}, %allerrornodes);
|
||||
return;
|
||||
}
|
||||
my $resv_id_ls = shift @{ $sessdata->{sdr_fetch_args} };
|
||||
@@ -7709,7 +7705,7 @@ sub start_sdr_record {
|
||||
if (!$text) {
|
||||
$text = sprintf("unknown response %02x", $code);
|
||||
}
|
||||
sendoutput(1, $text);
|
||||
xCAT::SvrUtils::sendmsg([ 1, $text ], $callback, $sessdata->{node}, %allerrornodes);
|
||||
return;
|
||||
}
|
||||
$sessdata->{sdr_nrid_ls} = $returnd[1];
|
||||
@@ -7763,7 +7759,7 @@ sub add_sdr_data {
|
||||
my $numbytes = $sessdata->{sdr_fetch_args}->[5];
|
||||
my $offset = $sessdata->{sdr_offset}; #shorten typing a little
|
||||
if ($rsp->{error}) {
|
||||
sendoutput([ 1, $rsp->{error} ]);
|
||||
xCAT::SvrUtils::sendmsg([ 1, $rsp->{error} ], $callback, $sessdata->{node}, %allerrornodes);
|
||||
return; #give up
|
||||
}
|
||||
my @returnd = ($rsp->{code}, @{ $rsp->{data} });
|
||||
@@ -7773,7 +7769,7 @@ sub add_sdr_data {
|
||||
if (!$text) {
|
||||
$text = sprintf("unknown response %02x", $code);
|
||||
}
|
||||
sendoutput([ 1, $text ]);
|
||||
xCAT::SvrUtils::sendmsg([ 1, $text ], $callback, $sessdata->{node}, %allerrornodes);
|
||||
return; #abort the whole mess
|
||||
}
|
||||
push @{ $sessdata->{sdr_data} }, @returnd[ 3 .. @returnd - 1 ];
|
||||
@@ -7996,7 +7992,7 @@ sub gotdevid {
|
||||
my $text;
|
||||
|
||||
if ($rsp->{error}) {
|
||||
sendoutput([ 1, $rsp->{error} ]);
|
||||
xCAT::SvrUtils::sendmsg([ 1, $rsp->{error} ], $callback, $sessdata->{node}, %allerrornodes);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
@@ -8007,7 +8003,7 @@ sub gotdevid {
|
||||
if (!$text) {
|
||||
$text = sprintf("unknown response %02x", $code);
|
||||
}
|
||||
sendoutput([ 1, $text ]);
|
||||
xCAT::SvrUtils::sendmsg([ 1, $text ], $callback, $sessdata->{node}, %allerrornodes);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -8093,7 +8089,7 @@ sub got_sdr_rep_info {
|
||||
my $sessdata = shift;
|
||||
|
||||
if ($rsp->{error}) {
|
||||
sendoutput([ 1, $rsp->{error} ]);
|
||||
xCAT::SvrUtils::sendmsg([ 1, $rsp->{error} ], $callback, $sessdata->{node}, %allerrornodes);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
@@ -8104,13 +8100,13 @@ sub got_sdr_rep_info {
|
||||
if (!$text) {
|
||||
$text = sprintf("unknown response %02x", $code);
|
||||
}
|
||||
sendoutput(1, $text);
|
||||
xCAT::SvrUtils::sendmsg([ 1, $text ], $callback, $sessdata->{node}, %allerrornodes);
|
||||
return;
|
||||
}
|
||||
}
|
||||
my @returnd = @{ $rsp->{data} };
|
||||
$sessdata->{sdr_info}->{version} = $returnd[0];
|
||||
$sessdata->{sdr_info}->{rec_count} = $returnd[1] + $returnd[2] << 8;
|
||||
$sessdata->{sdr_info}->{rec_count} = $returnd[1] + ($returnd[2] << 8);
|
||||
$sessdata->{sdr_info}->{resv_sdr} = ($returnd[13] & 0b00000010) >> 1;
|
||||
initsdr_withrepinfo($sessdata);
|
||||
}
|
||||
@@ -8119,7 +8115,7 @@ sub reserved_sdr_repo {
|
||||
my $rsp = shift;
|
||||
my $sessdata = shift;
|
||||
if ($rsp->{error}) {
|
||||
sendoutput([ 1, $rsp->{error} ]);
|
||||
xCAT::SvrUtils::sendmsg([ 1, $rsp->{error} ], $callback, $sessdata->{node}, %allerrornodes);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
@@ -8127,10 +8123,13 @@ sub reserved_sdr_repo {
|
||||
|
||||
if ($code != 0x00) {
|
||||
my $text = $codes{$code};
|
||||
if (!$text) {
|
||||
if ($code == 0xc1 && !$sessdata->{sdr_info}->{resv_sdr}) {
|
||||
$text = "SDR reservation unsupported.";
|
||||
} elsif (!$text) {
|
||||
$text = sprintf("unknown response %02x", $code);
|
||||
}
|
||||
sendoutput([ 1, $text ]);
|
||||
xCAT::SvrUtils::sendmsg([ 1, $text ], $callback, $sessdata->{node}, %allerrornodes);
|
||||
return;
|
||||
}
|
||||
}
|
||||
my @returnd = @{ $rsp->{data} };
|
||||
|
||||
@@ -201,7 +201,7 @@ sub process_request {
|
||||
my $is_openeuler = $osver =~ /^openeuler/;
|
||||
if ($is_openeuler) {
|
||||
unless (defined(xCAT::Utils::normalize_openeuler_version(substr($osver, 9)))
|
||||
&& $arch =~ /^(?:x86_64|ppc64le)$/) {
|
||||
&& $arch =~ /^(?:x86_64|ppc64le|riscv64)$/) {
|
||||
$callback->({ error => ["Unsupported openEuler image release or architecture: $osver $arch"], errorcode => [1] });
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ use xCAT::TLSPolicy qw(resolve_xcatd_tls_settings);
|
||||
use xCAT::TableUtils;
|
||||
use xCAT::NetworkUtils;
|
||||
use xCAT::MsgUtils;
|
||||
use xCAT::DiscoveryUtils;
|
||||
use xCAT::RespawnUtils;
|
||||
use xCAT::xcatd;
|
||||
use xCAT::CmdLog;
|
||||
@@ -3027,6 +3028,8 @@ sub service_connection {
|
||||
my $peerhostorg = shift;
|
||||
my $peerip = shift;
|
||||
my $peerport = $sock->peerport;
|
||||
# becomeuser and tokens replace $peername. Keep the certificate CN to tell the two apart.
|
||||
my $cert_cn = $peername;
|
||||
|
||||
# some paranoid measures could reduce a third party abusing stage3 image to attempting to get USER/PASS for BMCs:
|
||||
# -Well, minimally, ignore requests if requesting node is not in spconfig mode (stage3)
|
||||
@@ -3189,6 +3192,9 @@ sub service_connection {
|
||||
$request = "";
|
||||
if (xCAT::xcatd->validate($peername, $peerhost, $req, $peerhostorg, \@deferredmsgargs)) {
|
||||
$req->{'_xcat_authname'} = [$peername];
|
||||
delete $req->{'_xcat_certname'};
|
||||
my $certname = xCAT::DiscoveryUtils::client_certificate_name($cert_cn, $peername);
|
||||
$req->{'_xcat_certname'} = [$certname] if defined $certname;
|
||||
$req->{'_xcat_clienthost'} = [$peerhost];
|
||||
$req->{'_xcat_clientfqdn'} = [$peerfqdn];
|
||||
if ($req->{command}->[0] eq 'signx509cert') {
|
||||
|
||||
@@ -48,9 +48,13 @@ echo "Running Kickstart Pre-installation script..."
|
||||
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels8#
|
||||
} &>>/tmp/pre-install.log
|
||||
%end
|
||||
# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read.
|
||||
%post --nochroot --interpreter=/bin/bash
|
||||
mkdir -p /mnt/sysimage/var/log/xcat/
|
||||
cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log
|
||||
%end
|
||||
%post --interpreter=/bin/bash
|
||||
mkdir -p /var/log/xcat/
|
||||
cat /tmp/pre-install.log >>/var/log/xcat/xcat.log
|
||||
{
|
||||
echo "Running Kickstart Post-installation script..."
|
||||
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.ng#
|
||||
|
||||
@@ -27,11 +27,16 @@ echo "Running Kickstart Pre-installation script..."
|
||||
} &>>/tmp/pre-install.log
|
||||
%end
|
||||
|
||||
# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read.
|
||||
%post --nochroot --interpreter=/bin/bash
|
||||
mkdir -p /mnt/sysimage/var/log/xcat/
|
||||
cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log
|
||||
%end
|
||||
%post --interpreter=/bin/bash --erroronfail
|
||||
mkdir -p /var/log/xcat/
|
||||
cat /tmp/pre-install.log >>/var/log/xcat/xcat.log
|
||||
{
|
||||
echo "Running Kickstart Post-installation script..."
|
||||
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.openeuler#
|
||||
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.ng#
|
||||
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.rhels8#
|
||||
#SELINUXRELABEL#
|
||||
|
||||
@@ -55,9 +55,13 @@ echo "Running Kickstart Pre-installation script..."
|
||||
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels10#
|
||||
} &>>/tmp/pre-install.log
|
||||
%end
|
||||
# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read.
|
||||
%post --nochroot --interpreter=/bin/bash
|
||||
mkdir -p /mnt/sysimage/var/log/xcat/
|
||||
cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log
|
||||
%end
|
||||
%post --interpreter=/bin/bash
|
||||
mkdir -p /var/log/xcat/
|
||||
cat /tmp/pre-install.log >>/var/log/xcat/xcat.log
|
||||
{
|
||||
echo "Running Kickstart Post-installation script..."
|
||||
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.rhels10#
|
||||
|
||||
@@ -42,9 +42,13 @@ echo "Running Kickstart Pre-installation script..."
|
||||
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels10#
|
||||
} &>>/tmp/pre-install.log
|
||||
%end
|
||||
# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read.
|
||||
%post --nochroot --interpreter=/bin/bash
|
||||
mkdir -p /mnt/sysimage/var/log/xcat/
|
||||
cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log
|
||||
%end
|
||||
%post --interpreter=/bin/bash
|
||||
mkdir -p /var/log/xcat/
|
||||
cat /tmp/pre-install.log >>/var/log/xcat/xcat.log
|
||||
{
|
||||
echo "Running Kickstart Post-installation script..."
|
||||
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.rhels10#
|
||||
|
||||
@@ -47,9 +47,13 @@ echo "Running Kickstart Pre-installation script..."
|
||||
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels8#
|
||||
} &>>/tmp/pre-install.log
|
||||
%end
|
||||
# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read.
|
||||
%post --nochroot --interpreter=/bin/bash
|
||||
mkdir -p /mnt/sysimage/var/log/xcat/
|
||||
cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log
|
||||
%end
|
||||
%post --interpreter=/bin/bash
|
||||
mkdir -p /var/log/xcat/
|
||||
cat /tmp/pre-install.log >>/var/log/xcat/xcat.log
|
||||
{
|
||||
echo "Running Kickstart Post-installation script..."
|
||||
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.ng#
|
||||
|
||||
@@ -42,9 +42,13 @@ echo "Running Kickstart Pre-installation script..."
|
||||
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels8#
|
||||
} &>>/tmp/pre-install.log
|
||||
%end
|
||||
# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read.
|
||||
%post --nochroot --interpreter=/bin/bash
|
||||
mkdir -p /mnt/sysimage/var/log/xcat/
|
||||
cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log
|
||||
%end
|
||||
%post --interpreter=/bin/bash
|
||||
mkdir -p /var/log/xcat/
|
||||
cat /tmp/pre-install.log >>/var/log/xcat/xcat.log
|
||||
{
|
||||
echo "Running Kickstart Post-installation script..."
|
||||
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.ng#
|
||||
|
||||
@@ -55,9 +55,13 @@ echo "Running Kickstart Pre-installation script..."
|
||||
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/pre.rhels8#
|
||||
} &>>/tmp/pre-install.log
|
||||
%end
|
||||
# The pre-installation log is in the installer's /tmp, which a chroot %post cannot read.
|
||||
%post --nochroot --interpreter=/bin/bash
|
||||
mkdir -p /mnt/sysimage/var/log/xcat/
|
||||
cat /tmp/pre-install.log >>/mnt/sysimage/var/log/xcat/xcat.log
|
||||
%end
|
||||
%post --interpreter=/bin/bash
|
||||
mkdir -p /var/log/xcat/
|
||||
cat /tmp/pre-install.log >>/var/log/xcat/xcat.log
|
||||
{
|
||||
echo "Running Kickstart Post-installation script..."
|
||||
#INCLUDE:#ENV:XCATROOT#/share/xcat/install/scripts/post.xcat.ng#
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
# kdump.service fails without dump memory, which the kernel has only when its
|
||||
# command line carries crashkernel= or, on POWER, fadump=.
|
||||
if [ -e /usr/lib/systemd/system/kdump.service ]; then
|
||||
mkdir -p /etc/systemd/system/kdump.service.d
|
||||
printf '[Unit]\nConditionKernelCommandLine=|crashkernel\nConditionKernelCommandLine=|fadump\n' \
|
||||
>/etc/systemd/system/kdump.service.d/xcat-dump-memory.conf
|
||||
fi
|
||||
@@ -16,5 +16,3 @@ do
|
||||
sed -i -e 's/^[[:space:]]*enabled[[:space:]]*=[[:space:]]*1/enabled=0/' /etc/yum.repos.d/$repo_file
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
||||
|
||||
@@ -34,12 +34,15 @@ if [ "$("$xcat_riscv_uname" -m)" = "riscv64" ] && [ -d "$xcat_riscv_install_root
|
||||
disk="$("$xcat_riscv_lsblk" -no PKNAME "$espdev" 2>/dev/null | head -1 | tr -d '[:space:]')"
|
||||
part="$("$xcat_riscv_lsblk" -no PARTN "$espdev" 2>/dev/null | head -1 | tr -d '[:space:]')"
|
||||
if [ -n "$disk" ] && [ -n "$part" ]; then
|
||||
espuuid="$("$xcat_riscv_lsblk" -no PARTUUID "$espdev" 2>/dev/null | head -1 | tr -d '[:space:]' | tr 'A-F' 'a-f')"
|
||||
# drop the x86 entries anaconda created for this install, and any
|
||||
# riscv64 entry a previous provisioning of this node left behind, so
|
||||
# riscv64 entry a previous provisioning of this node left on this ESP, so
|
||||
# reinstalling does not fill the firmware variable store with copies
|
||||
for bootnum in $("$xcat_riscv_efibootmgr" -v 2>/dev/null | awk '/\\EFI\\[^\\]+\\(shimx64|grubx64|grubriscv64)\.efi/ { sub(/^Boot/, "", $1); sub(/\*$/, "", $1); print $1 }'); do
|
||||
"$xcat_riscv_efibootmgr" -q -b "$bootnum" -B || true
|
||||
done
|
||||
if [ -n "$espuuid" ]; then
|
||||
for bootnum in $("$xcat_riscv_efibootmgr" -v 2>/dev/null | awk -v esp=",gpt,$espuuid," 'index(tolower($0), esp) && /\\EFI\\[^\\]+\\(shimx64|grubx64|grubriscv64)\.efi/ { sub(/^Boot/, "", $1); sub(/\*$/, "", $1); print $1 }'); do
|
||||
"$xcat_riscv_efibootmgr" -q -b "$bootnum" -B || true
|
||||
done
|
||||
fi
|
||||
label="$(. "$xcat_riscv_install_root/etc/os-release" 2>/dev/null; echo "${NAME:-Linux}")"
|
||||
if "$xcat_riscv_efibootmgr" -q -c -d "/dev/$disk" -p "$part" -L "$label" -l "\\EFI\\$vendordir\\grubriscv64.efi"; then
|
||||
printf '%s\n' "riscv64: UEFI boot entry \"$label\" -> \\EFI\\$vendordir\\grubriscv64.efi on /dev/$disk part $part"
|
||||
|
||||
@@ -12,6 +12,10 @@ if compgen -G "/etc/sysconfig/network-scripts/ifcfg-*" >/dev/null 2>&1; then
|
||||
do
|
||||
[ "${i##*/}" = "ifcfg-lo" ] && continue
|
||||
nicname="${i##*-}"
|
||||
# A BMC host interface uses a USB class driver and has link but usually no DHCP server.
|
||||
case "$(readlink -f "/sys/class/net/$nicname/device/driver" 2>/dev/null)" in
|
||||
*/cdc_ether|*/cdc_ncm|*/cdc_eem|*/rndis_host) continue ;;
|
||||
esac
|
||||
if ethtool "$nicname" 2>/dev/null | grep -E -i -q "Link detected.*yes" >/dev/null 2>&1
|
||||
then
|
||||
case "$XCATDEBUGMODE" in
|
||||
@@ -41,5 +45,3 @@ do
|
||||
sed -i -e 's/^[[:space:]]*enabled[[:space:]]*=[[:space:]]*1/enabled=0/' /etc/yum.repos.d/$repo_file
|
||||
fi
|
||||
done
|
||||
|
||||
exit 0
|
||||
|
||||
@@ -309,7 +309,12 @@ fi
|
||||
# save the content of /tmp/partitionfile in /var/log/xcat/xcat.log
|
||||
# so that we can inspect the partition scheme after installation
|
||||
echo "================ The Partition Scheme ==============="
|
||||
cat /tmp/partitionfile
|
||||
# A custom partition file can hold credentials, and this log reaches the node.
|
||||
if [ -e /tmp/partitionfile.enc ] || [ -e /tmp/partscript.enc ]; then
|
||||
echo "The custom partition file is not logged."
|
||||
else
|
||||
cat /tmp/partitionfile
|
||||
fi
|
||||
echo "====================================================="
|
||||
msgutil_r "$MASTER_IP" "info" "Generate the repository for the installation" "/var/log/xcat/xcat.log" "$log_label"
|
||||
# The following code is to generate the repository for the installation
|
||||
|
||||
@@ -310,7 +310,12 @@ fi
|
||||
# save the content of /tmp/partitionfile in /var/log/xcat/xcat.log
|
||||
# so that we can inspect the partition scheme after installation
|
||||
echo "================ The Partition Scheme ==============="
|
||||
cat /tmp/partitionfile
|
||||
# A custom partition file can hold credentials, and this log reaches the node.
|
||||
if [ -e /tmp/partitionfile.enc ] || [ -e /tmp/partscript.enc ]; then
|
||||
echo "The custom partition file is not logged."
|
||||
else
|
||||
cat /tmp/partitionfile
|
||||
fi
|
||||
echo "====================================================="
|
||||
msgutil_r "$MASTER_IP" "info" "Generate the repository for the installation" "/var/log/xcat/xcat.log" "$log_label"
|
||||
# The following code is to generate the repository for the installation
|
||||
|
||||
@@ -139,63 +139,29 @@ chmod 755 /tmp/foo.sh
|
||||
|
||||
/tmp/foo.sh >/tmp/foo.log 2>&1 &
|
||||
|
||||
# Subiquity runs this script under dash, which has no read -n, and its live system ships coreutils.
|
||||
base64decode()
|
||||
{
|
||||
h0="0"; h1="1"; h2="2"; h3="3"; h4="4"; h5="5"; h6="6"; h7="7";
|
||||
h8="8"; h9="9"; h10="A"; h11="B"; h12="C"; h13="D"; h14="E"; h15="F";
|
||||
|
||||
while :
|
||||
do
|
||||
i=0
|
||||
while [ "$i" -lt 4 ]
|
||||
do
|
||||
read -n 1 c || return
|
||||
|
||||
case "${c}" in
|
||||
"A") d=0 ;; "B") d=1 ;; "C") d=2 ;; "D") d=3 ;;
|
||||
"E") d=4 ;; "F") d=5 ;; "G") d=6 ;; "H") d=7 ;;
|
||||
"I") d=8 ;; "J") d=9 ;; "K") d=10 ;; "L") d=11 ;;
|
||||
"M") d=12 ;; "N") d=13 ;; "O") d=14 ;; "P") d=15 ;;
|
||||
"Q") d=16 ;; "R") d=17 ;; "S") d=18 ;; "T") d=19 ;;
|
||||
"U") d=20 ;; "V") d=21 ;; "W") d=22 ;; "X") d=23 ;;
|
||||
"Y") d=24 ;; "Z") d=25 ;; "a") d=26 ;; "b") d=27 ;;
|
||||
"c") d=28 ;; "d") d=29 ;; "e") d=30 ;; "f") d=31 ;;
|
||||
"g") d=32 ;; "h") d=33 ;; "i") d=34 ;; "j") d=35 ;;
|
||||
"k") d=36 ;; "l") d=37 ;; "m") d=38 ;; "n") d=39 ;;
|
||||
"o") d=40 ;; "p") d=41 ;; "q") d=42 ;; "r") d=43 ;;
|
||||
"s") d=44 ;; "t") d=45 ;; "u") d=46 ;; "v") d=47 ;;
|
||||
"w") d=48 ;; "x") d=49 ;; "y") d=50 ;; "z") d=51 ;;
|
||||
"0") d=52 ;; "1") d=53 ;; "2") d=54 ;; "3") d=55 ;;
|
||||
"4") d=56 ;; "5") d=57 ;; "6") d=58 ;; "7") d=59 ;;
|
||||
"8") d=60 ;; "9") d=61 ;; "+") d=62 ;; "/") d=63 ;;
|
||||
"=") d=0 ;;
|
||||
*) continue ;;
|
||||
esac
|
||||
|
||||
eval "a${i}=${c}"
|
||||
eval "b${i}=${d}"
|
||||
|
||||
i=$(( i + 1 ))
|
||||
done
|
||||
|
||||
o0=$(( ((b0 << 2) | (b1 >> 4)) & 0xff ))
|
||||
o1=$(( ((b1 << 4) | (b2 >> 2)) & 0xff ))
|
||||
o2=$(( ((b2 << 6) | b3) & 0xff ))
|
||||
|
||||
[ "${a2}" == "=" ] &&
|
||||
eval "printf \"\\x\${h$(( o0 / 16 ))}\${h$(( o0 % 16
|
||||
))}\"" &&
|
||||
return
|
||||
[ "${a3}" == "=" ] &&
|
||||
eval "printf \"\\x\${h$(( o0 / 16 ))}\${h$(( o0 % 16
|
||||
))}\\x\${h$(( o1 / 16 ))}\${h$(( o1 % 16
|
||||
))}\"" &&
|
||||
return
|
||||
eval "printf \"\\x\${h$(( o0 / 16 ))}\${h$(( o0 % 16
|
||||
))}\\x\${h$(( o1 / 16 ))}\${h$(( o1 % 16
|
||||
))}\\x\${h$(( o2 / 16 ))}\${h$(( o2 % 16 ))}\""
|
||||
done
|
||||
base64 -d
|
||||
}
|
||||
|
||||
# A d: or s:d: entry in linuximage.partitionfile replaces the disk getinstdisk chose.
|
||||
rm -f /tmp/diskscript.enc
|
||||
[ -e /tmp/xcat.install_disk ] && mv /tmp/xcat.install_disk /tmp/xcat.install_disk.detected
|
||||
#XCA_PARTMAN_DISK_SCRIPT#
|
||||
override_rc=$?
|
||||
disk_entry=""
|
||||
if [ -e /tmp/diskscript.enc ]; then
|
||||
disk_entry=1
|
||||
# Falling back to the detected disk could wipe the disk the entry protects.
|
||||
if [ "$override_rc" -ne 0 ] || [ -z "$(awk 'NF {print $1; exit}' /tmp/xcat.install_disk 2>/dev/null)" ]; then
|
||||
logger -t $log_label -p "err" "The partitionfile disk entry selected no disk, stopping the install"
|
||||
exit 1
|
||||
fi
|
||||
elif [ -e /tmp/xcat.install_disk.detected ]; then
|
||||
mv /tmp/xcat.install_disk.detected /tmp/xcat.install_disk
|
||||
fi
|
||||
|
||||
# Note that the subiquity/curtin installation config is fairly picky about
|
||||
# the order in which things are specified - you have to specify all the
|
||||
# partitions before you can specify any filesystems, which means this is
|
||||
@@ -211,7 +177,10 @@ base64decode()
|
||||
# to this unwrapped file and must start at column 0.
|
||||
logger -t $log_label -p "info" "Generate partition file..."
|
||||
if [ -e /tmp/xcat.install_disk ]; then
|
||||
INSTALL_DISK=$(cat /tmp/xcat.install_disk)
|
||||
# The layout uses one disk, the first one the disk file names.
|
||||
INSTALL_DISK=$(awk 'NF {print $1; exit}' /tmp/xcat.install_disk)
|
||||
# Subiquity matches the disk path literally, so resolve a link such as /dev/disk/by-id/.
|
||||
INSTALL_DISK=$(readlink -f "$INSTALL_DISK" || echo "$INSTALL_DISK")
|
||||
else
|
||||
logger -t $log_label -p "err" "Failed to find partition file - getinstdisk must be run first"
|
||||
logger -t $log_label -p "err" "Using fallback default disk /dev/sda"
|
||||
@@ -385,8 +354,40 @@ storage:
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Keep only a storage section that holds a config or a layout, rewritten as one YAML fragment
|
||||
# for autoinstall.yaml. Subiquity puts LVM on the largest disk when that section is missing,
|
||||
# and a layout without a match goes to the largest disk too, so it gets the disk in $2, if any.
|
||||
# Some Subiquity releases ignore match in use_gap mode, so such a layout is refused with $2.
|
||||
normalize_storage_layout()
|
||||
{
|
||||
python3 -c 'import sys, yaml
|
||||
s = yaml.safe_load(open(sys.argv[1]))
|
||||
t = s.get("storage") if isinstance(s, dict) else None
|
||||
if not (isinstance(t, dict) and (t.get("config") or t.get("layout"))):
|
||||
sys.exit(1)
|
||||
l = t.get("layout")
|
||||
if sys.argv[2] and isinstance(l, dict):
|
||||
if l.get("mode") == "use_gap":
|
||||
sys.exit(1)
|
||||
l.setdefault("match", {"path": sys.argv[2]})
|
||||
open(sys.argv[1], "w").write(yaml.safe_dump({"storage": t}, default_flow_style=False, sort_keys=False))' "$1" "$2" 2>/dev/null
|
||||
}
|
||||
|
||||
# A partitionfile layout or s: script must come after the default layout, which it replaces.
|
||||
rm -f /tmp/partscript.enc
|
||||
mv /tmp/partitionfile /tmp/partitionfile.default
|
||||
#XCA_PARTMAN_RECIPE_SCRIPT#
|
||||
#XCA_PARTMAN_DISK_SCRIPT#
|
||||
override_rc=$?
|
||||
if [ -e /tmp/partscript.enc ]; then
|
||||
# Keeping the default layout could wipe a disk the administrator layout protects.
|
||||
if [ "$override_rc" -ne 0 ] || ! normalize_storage_layout /tmp/partitionfile "${disk_entry:+$INSTALL_DISK}"; then
|
||||
logger -t $log_label -p "err" "The partitionfile layout entry wrote no usable layout, stopping the install"
|
||||
rm -f /tmp/partitionfile
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
mv /tmp/partitionfile.default /tmp/partitionfile
|
||||
fi
|
||||
#XCA_PARTMAN_ADDITIONAL_CONFIG_SCRIPT#
|
||||
exit 0
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ use strict;
|
||||
use warnings "all";
|
||||
|
||||
use File::Basename;
|
||||
use File::Copy qw(move);
|
||||
use File::Copy ();
|
||||
use File::Find;
|
||||
use File::Path;
|
||||
use Cwd qw(realpath);
|
||||
@@ -118,27 +118,75 @@ sub disable_vendor_repositories {
|
||||
}
|
||||
}
|
||||
|
||||
sub publish_boot_files {
|
||||
my ($native_bootdir, $destdir, $initrd, $mode) = @_;
|
||||
move($initrd, "$native_bootdir/initrd-$mode.gz")
|
||||
or die("Error: failed to move the initial ramdisk for $mode: $!\n");
|
||||
my $old_kernel = -e "$destdir/kernel" || -l "$destdir/kernel";
|
||||
if ($old_kernel) {
|
||||
link("$destdir/kernel", "$native_bootdir/previous-kernel")
|
||||
or die("Error: failed to preserve the previous kernel: $!\n");
|
||||
}
|
||||
rename("$native_bootdir/kernel", "$destdir/kernel")
|
||||
or die("Error: failed to publish the kernel: $!\n");
|
||||
unless (rename("$native_bootdir/initrd-$mode.gz", "$destdir/initrd-$mode.gz")) {
|
||||
my $error = $!;
|
||||
my $restored = $old_kernel
|
||||
? rename("$native_bootdir/previous-kernel", "$destdir/kernel")
|
||||
: unlink("$destdir/kernel");
|
||||
unless ($restored) {
|
||||
$native_bootdir->unlink_on_destroy(0);
|
||||
die("Error: failed to publish the initial ramdisk: $error; kernel rollback failed: $!. Boot files retained in $native_bootdir\n");
|
||||
# kdump.service fails without dump memory, which a stateless command line
|
||||
# reserves only with crashkernel= or, on POWER, fadump=.
|
||||
sub skip_kdump_without_dump_memory {
|
||||
my ($rootimg_dir) = @_;
|
||||
return unless -e "$rootimg_dir/usr/lib/systemd/system/kdump.service";
|
||||
my $dropin_dir = "$rootimg_dir/etc/systemd/system/kdump.service.d";
|
||||
mkpath($dropin_dir);
|
||||
open(my $fh, '>', "$dropin_dir/xcat-dump-memory.conf")
|
||||
or die "Cannot write $dropin_dir/xcat-dump-memory.conf: $!\n";
|
||||
print $fh "[Unit]\nConditionKernelCommandLine=|crashkernel\nConditionKernelCommandLine=|fadump\n";
|
||||
close($fh) or die "Cannot write $dropin_dir/xcat-dump-memory.conf: $!\n";
|
||||
}
|
||||
|
||||
sub copy_kernel {
|
||||
my ($rootimg_dir, $kernelver, $dir) = @_;
|
||||
my ($kernel) = grep { -e $_ } map { "$rootimg_dir/$_" }
|
||||
("boot/vmlinux-$kernelver", "boot/vmlinuz-$kernelver", "boot/image-$kernelver", "lib/modules/$kernelver/vmlinuz");
|
||||
die("couldn't find the kernel file matched $kernelver in $rootimg_dir/boot\n") unless $kernel;
|
||||
File::Copy::cp($kernel, "$dir/kernel") or die("Error: failed to copy the kernel to $dir: $!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
# Removes $dir after packing it, also when a command of the pipeline fails.
|
||||
sub pack_initrd {
|
||||
my ($dir, $initrd, $compress, $mode) = @_;
|
||||
my $command = "cd $dir && find . | cpio -H newc -o | $compress -9 -c - > $initrd";
|
||||
print "\n$command\n";
|
||||
my $rc = system('bash', '-c', "set -o pipefail; $command");
|
||||
rmtree($dir);
|
||||
die("Error: failed to generate the initial ramdisk for $mode.\n") if $rc;
|
||||
return 1;
|
||||
}
|
||||
|
||||
# nodeset copies the kernel and the initial ramdisks as one set, so a failure puts back every file already replaced.
|
||||
sub publish_staged_boot_files {
|
||||
my ($native_bootdir, $destdir, @modes) = @_;
|
||||
my @files = ([ 'kernel', 'kernel' ], map { [ "initrd-$_.gz", "initial ramdisk for $_" ] } @modes);
|
||||
my %backup;
|
||||
foreach my $file (@files) {
|
||||
my ($name, $what) = @$file;
|
||||
if (link("$destdir/$name", "$native_bootdir/previous-$name")) {
|
||||
$backup{$name} = 1;
|
||||
} elsif (!$!{ENOENT}) {
|
||||
die("Error: failed to preserve the previous $what: $!\n");
|
||||
}
|
||||
die("Error: failed to publish the initial ramdisk for $mode: $error\n");
|
||||
}
|
||||
my @published;
|
||||
foreach my $file (@files) {
|
||||
my ($name, $what) = @$file;
|
||||
if (rename("$native_bootdir/$name", "$destdir/$name")) {
|
||||
push @published, $file;
|
||||
next;
|
||||
}
|
||||
my $error = $!;
|
||||
# NFS can apply a rename and still report a failure, so put back a staged file that is gone.
|
||||
my @attempted = (-e "$native_bootdir/$name" || -l "$native_bootdir/$name") ? () : ($file);
|
||||
my @failed;
|
||||
foreach my $done (@attempted, reverse @published) {
|
||||
my ($done_name, $done_what) = @$done;
|
||||
my $restored = $backup{$done_name}
|
||||
? rename("$native_bootdir/previous-$done_name", "$destdir/$done_name")
|
||||
: unlink("$destdir/$done_name");
|
||||
push @failed, "$done_what rollback failed: $!" unless $restored;
|
||||
}
|
||||
if (@failed) {
|
||||
$native_bootdir->unlink_on_destroy(0);
|
||||
die("Error: failed to publish the $what: $error; " . join('; ', @failed) . ". Boot files retained in $native_bootdir\n");
|
||||
}
|
||||
die("Error: failed to publish the $what: $error\n");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -189,6 +237,148 @@ sub mark_uftp_receiver {
|
||||
return !$error;
|
||||
}
|
||||
|
||||
# The initial ramdisk configures $prinic, and bringing it up again breaks an NFS-based boot.
|
||||
# EL10 reads no ifcfg files, so its images get keyfiles.
|
||||
sub write_nic_profiles {
|
||||
my ($rootimg_dir, $osver, $prinic, $othernics) = @_;
|
||||
my @othernics = grep { length } split(/,/, $othernics // '');
|
||||
my $scripts = "$rootimg_dir/etc/sysconfig/network-scripts";
|
||||
my $keyfiles = "$rootimg_dir/etc/NetworkManager/system-connections";
|
||||
my $major = el_major_version($osver);
|
||||
my %profiles;
|
||||
if (defined($major) && $major >= 10) {
|
||||
if (-d $keyfiles) {
|
||||
# The keyfiles of an earlier build can name interfaces that this build no longer requests.
|
||||
opendir(my $dh, $keyfiles) or die("Error: cannot read $keyfiles: $!\n");
|
||||
foreach my $old (grep { /^xcat-genimage-.*\.nmconnection$/ } readdir($dh)) {
|
||||
unlink("$keyfiles/$old") or die("Error: cannot remove $keyfiles/$old: $!\n");
|
||||
}
|
||||
closedir($dh);
|
||||
$profiles{"$keyfiles/xcat-genimage-$_.nmconnection"} =
|
||||
"[connection]\nid=$_\ntype=ethernet\ninterface-name=$_\n\n[ipv4]\nmethod=auto\n" for @othernics;
|
||||
}
|
||||
} elsif (-d $scripts) {
|
||||
$profiles{"$scripts/ifcfg-$prinic"} = "ONBOOT=no\nBOOTPROTO=dhcp\nDEVICE=$prinic\n" if $prinic;
|
||||
$profiles{"$scripts/ifcfg-$_"} = "ONBOOT=yes\nBOOTPROTO=dhcp\nDEVICE=$_\n" for @othernics;
|
||||
}
|
||||
foreach my $file (sort keys %profiles) {
|
||||
# NetworkManager ignores a keyfile that other users can read.
|
||||
my $mode = $file =~ /\.nmconnection$/ ? oct('600') : oct('644');
|
||||
my $fh;
|
||||
open($fh, '>', $file) && chmod($mode, $file) && print($fh $profiles{$file}) && close($fh)
|
||||
or die("Error: cannot write $file: $!\n");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
# NetworkManager otherwise makes a DHCP profile for every Ethernet port without one.
|
||||
sub disable_auto_profiles {
|
||||
my ($rootimg_dir, $osver) = @_;
|
||||
my $major = el_major_version($osver);
|
||||
my $confdir = "$rootimg_dir/etc/NetworkManager/conf.d";
|
||||
return unless defined($major) && $major >= 10 && -d $confdir;
|
||||
my $file = "$confdir/xcat.conf";
|
||||
my $fh;
|
||||
open($fh, '>', $file) && print($fh "[main]\nno-auto-default=*\n") && close($fh)
|
||||
or die("Error: cannot write $file: $!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
# debootstrap deletes $rootimg_dir/debootstrap when it finishes, and its tar -k fails over a finished root.
|
||||
sub debootstrap_finished {
|
||||
my ($rootimg_dir) = @_;
|
||||
die("Error: $rootimg_dir holds an unfinished debootstrap. Remove $rootimg_dir and run genimage again.\n")
|
||||
if -e "$rootimg_dir/debootstrap";
|
||||
return -e "$rootimg_dir/var/lib/dpkg/status" ? 1 : 0;
|
||||
}
|
||||
|
||||
# genimage moves the .bak files back, and a .bak that an interrupted run left holds the image's own file.
|
||||
sub use_host_resolver {
|
||||
my ($rootimg_dir) = @_;
|
||||
foreach my $file ('hosts', 'resolv.conf') {
|
||||
my $image = "$rootimg_dir/etc/$file";
|
||||
File::Copy::move($image, "$image.bak") unless -e "$image.bak" || -l "$image.bak";
|
||||
unlink($image);
|
||||
File::Copy::copy("/etc/$file", $image);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
# A finished image holds the dummy resolv.conf and the apt sources of the run that built it.
|
||||
sub prepare_reused_root {
|
||||
my ($rootimg_dir) = @_;
|
||||
unlink(map { "$rootimg_dir/etc/apt/sources.list.d/$_" } qw(genimage.apt.list genimage1.apt.list));
|
||||
use_host_resolver($rootimg_dir);
|
||||
return;
|
||||
}
|
||||
|
||||
# apt would move a root image of another release or architecture partway to the requested one.
|
||||
sub check_reused_root {
|
||||
my ($rootimg_dir, $suite, $arch) = @_;
|
||||
my ($codename, $image_arch);
|
||||
my $os_release = -e "$rootimg_dir/usr/lib/os-release" ? "$rootimg_dir/usr/lib/os-release" : "$rootimg_dir/etc/os-release";
|
||||
my %field;
|
||||
foreach my $file ($os_release, "$rootimg_dir/etc/lsb-release") {
|
||||
my $fh;
|
||||
next if -l $file || !open($fh, '<', $file);
|
||||
%field = (%field, map { /^(VERSION_CODENAME|UBUNTU_CODENAME|DISTRIB_CODENAME)=(["']?)(\S+?)\2\s*$/ ? ($1 => $3) : () } <$fh>);
|
||||
close($fh);
|
||||
}
|
||||
# Ubuntu 16.04 images before base-files 9.4ubuntu4.3 have only UBUNTU_CODENAME, and 14.04 images only DISTRIB_CODENAME.
|
||||
$codename = $field{VERSION_CODENAME} // $field{UBUNTU_CODENAME} // $field{DISTRIB_CODENAME};
|
||||
if (open(my $fh, '<', "$rootimg_dir/var/lib/dpkg/status")) {
|
||||
local $/ = '';
|
||||
($image_arch) = map { /^Package: dpkg\n(?:.+\n)*?Architecture: (\S+)/ ? $1 : () } <$fh>;
|
||||
close($fh);
|
||||
}
|
||||
(my $release = $suite) =~ s/-(?:updates|security|backports|proposed)$//;
|
||||
die("Error: genimage cannot tell the Ubuntu release and architecture of $rootimg_dir. Remove $rootimg_dir and run genimage again.\n")
|
||||
unless $codename && $image_arch;
|
||||
die("Error: $rootimg_dir holds Ubuntu $codename for $image_arch, not $release for $arch. Remove $rootimg_dir or use another rootimgdir.\n")
|
||||
unless $codename eq $release && $image_arch eq $arch;
|
||||
# dpkg owns bin/uname, so genimage cannot tell whether the backup or the file in place is current.
|
||||
die("Error: $rootimg_dir holds bin/uname-binary, which an interrupted genimage run left. Restore bin/uname from it or remove $rootimg_dir, then run genimage again.\n")
|
||||
if -e "$rootimg_dir/bin/uname-binary" || -l "$rootimg_dir/bin/uname-binary";
|
||||
return 1;
|
||||
}
|
||||
|
||||
# A kernel release compares number by number, so 6.8.0-100-generic is newer than 6.8.0-99-generic.
|
||||
sub newest_kernel_version {
|
||||
my @releases = @_;
|
||||
my $compare = sub {
|
||||
my @left = split(/(\d+)/, $_[0]);
|
||||
my @right = split(/(\d+)/, $_[1]);
|
||||
while (@left && @right) {
|
||||
my ($l, $r) = (shift(@left), shift(@right));
|
||||
my $order = ($l =~ /^\d+$/ && $r =~ /^\d+$/) ? $l <=> $r : $l cmp $r;
|
||||
return $order if $order;
|
||||
}
|
||||
return @left <=> @right;
|
||||
};
|
||||
my ($newest) = sort { $compare->($b, $a) } @releases;
|
||||
return $newest;
|
||||
}
|
||||
|
||||
# Package scripts run this uname in the image, so -r names the kernel that genimage publishes.
|
||||
sub uname_script {
|
||||
my ($kernelver) = @_;
|
||||
my $release = $kernelver ? "echo \"$kernelver\"" : 'ls /lib/modules | sort -V | tail -n 1';
|
||||
return "#!/bin/bash \n"
|
||||
. "case \"\$1\" in \n"
|
||||
. "\"-m\") \n"
|
||||
. " ARCH=\"\$(dpkg --print-architecture || \n"
|
||||
. " rpm -q kernel-\$(\"\$0\" -r) --qf '%{arch}')\" \n"
|
||||
. " case \"\$ARCH\" in \n"
|
||||
. " \"amd64\") ARCH=\"x86_64\" ;; \n"
|
||||
. " \"ppc64el\") ARCH=\"ppc64le\" ;; \n"
|
||||
. " esac \n"
|
||||
. " echo \"\$ARCH\" ;; \n"
|
||||
. "\"-r\") $release ;; \n"
|
||||
. "\"-s\"|\"\") echo \"Linux\" ;; \n"
|
||||
. "esac \n"
|
||||
. "exit 0 \n";
|
||||
}
|
||||
|
||||
sub varsubinline{
|
||||
my $line=shift;
|
||||
my $refvardict=shift;
|
||||
@@ -380,7 +570,7 @@ sub default_net_drivers {
|
||||
x86 => [qw(tg3 bnx2 bnx2x e1000 e1000e igb mlx_en mlx5_core virtio_net be2net)],
|
||||
x86_64 => [qw(tg3 bnx2 bnx2x e1000 e1000e igb mlx_en mlx5_core virtio_net be2net)],
|
||||
aarch64 => [qw(tg3 bnx2 bnx2x e1000e igb mlx_en mlx5_core virtio_net)],
|
||||
riscv64 => [qw(e1000 e1000e igb ixgbe r8169 tg3 bnx2x mlx5_core virtio_net)],
|
||||
riscv64 => [qw(e1000 e1000e igb ixgbe i40e ice r8169 tg3 bnx2x mlx5_core virtio_net)],
|
||||
ppc64 => [qw(e1000 e1000e igb ibmveth ehea)],
|
||||
s390x => [qw(qdio ccwgroup)],
|
||||
},
|
||||
@@ -395,7 +585,7 @@ sub default_net_drivers {
|
||||
x86_64 => [qw(tg3 bnx2 bnx2x e1000 e1000e igb mlx_en mlx5_core virtio_net overlay)],
|
||||
ppc64el => [qw(tg3 bnx2 bnx2x e1000 e1000e igb ibmveth ehea mlx_en mlx4_en mlx5_core virtio_net overlay)],
|
||||
ppc64 => [qw(e1000 e1000e igb ibmveth ehea)],
|
||||
riscv64 => [qw(e1000 e1000e igb ixgbe r8169 tg3 bnx2x mlx5_core virtio_net overlay)],
|
||||
riscv64 => [qw(e1000 e1000e igb ixgbe i40e ice r8169 tg3 bnx2x mlx5_core virtio_net overlay)],
|
||||
s390x => [qw(qdio ccwgroup)],
|
||||
},
|
||||
);
|
||||
|
||||
@@ -394,6 +394,12 @@ if [ -z $STATEMNT ]; then
|
||||
cp $lf "$NEWROOT/var/lib/dhclient/dhclient-$netif.leases"
|
||||
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Saving $NEWROOT/var/lib/dhclient/dhclient-$netif.leases"
|
||||
done
|
||||
# NetworkManager in the root reuses the connection of the initrd and reads its lease by the same name.
|
||||
for lf in /var/lib/NetworkManager/*.lease; do
|
||||
[ -f "$lf" ] || continue
|
||||
mkdir -p "$NEWROOT/var/lib/NetworkManager"
|
||||
cp "$lf" "$NEWROOT/var/lib/NetworkManager/"
|
||||
done
|
||||
|
||||
ifname="$(getarg ifname=)"
|
||||
netdev="$(getarg netdev=)"
|
||||
|
||||
@@ -368,63 +368,6 @@ else
|
||||
fi
|
||||
cd /
|
||||
|
||||
function getdevfrommac() {
|
||||
boothwaddr=$1
|
||||
ip link show | while read line
|
||||
do
|
||||
dev=`echo $line | egrep "^[0-9]+: [0-9A-Za-z]+" | cut -d ' ' -f 2 | cut -d ':' -f 1`
|
||||
if [ "X$dev" != "X" ]; then
|
||||
devname=$dev
|
||||
fi
|
||||
|
||||
if [ "X$devname" != "X" ]; then
|
||||
hwaddr=`echo $line | egrep "^[ ]*link" | awk '{print $2}'`
|
||||
if [ "X$hwaddr" = "X$boothwaddr" ]; then
|
||||
echo $devname
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
if [ -z $STATEMNT ]; then
|
||||
for lf in /tmp/dhclient.*.lease; do
|
||||
netif=${lf#*.}
|
||||
netif=${netif%.*}
|
||||
cp $lf "$NEWROOT/var/lib/dhclient/dhclient-$netif.leases"
|
||||
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Saving $NEWROOT/var/lib/dhclient/dhclient-$netif.leases"
|
||||
done
|
||||
|
||||
ifname="$(getarg ifname=)"
|
||||
netdev="$(getarg netdev=)"
|
||||
BOOTIF="$(getarg BOOTIF=)"
|
||||
if [ ! -z "$ifname" ]; then
|
||||
MACX=${ifname#*:}
|
||||
ETHX=${ifname%:$MACX*}
|
||||
elif [ ! -z "$netdev" ]; then
|
||||
ETHX=$netdev
|
||||
MACX=`ip link show $netdev | grep ether | awk '{print $2}'`
|
||||
elif [ ! -z "$BOOTIF" ]; then
|
||||
MACX=$BOOTIF
|
||||
MACX=${MACX#01-}
|
||||
MACX=${MACX//-/:}
|
||||
ETHX=$(getdevfrommac $MACX)
|
||||
fi
|
||||
|
||||
|
||||
if [ ! -z "$MACX" ] && [ ! -z "$ETHX" ]; then
|
||||
if [ ! -e $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX ]; then
|
||||
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Creating $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX"
|
||||
touch $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
|
||||
fi
|
||||
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Writing $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX: DEVICE=$ETHX;BOOTPROTO=dhcp;HWADDR=$MACX;ONBOOT=yes"
|
||||
echo "DEVICE=$ETHX" > $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
|
||||
echo "BOOTPROTO=dhcp" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
|
||||
echo "HWADDR=$MACX" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
|
||||
echo "ONBOOT=yes" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
|
||||
fi
|
||||
fi
|
||||
|
||||
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Saving $NEWROOT/etc/resolv.conf"
|
||||
cp /etc/resolv.conf "$NEWROOT/etc/"
|
||||
|
||||
|
||||
@@ -143,52 +143,6 @@ mount -n --bind /dev $NEWROOT/dev
|
||||
mount -n --bind /proc $NEWROOT/proc
|
||||
mount -n --bind /sys $NEWROOT/sys
|
||||
|
||||
function getdevfrommac() {
|
||||
boothwaddr=$1
|
||||
ip link show | while read line
|
||||
do
|
||||
dev=`echo $line | egrep "^[0-9]+: [0-9A-Za-z]+" | cut -d ' ' -f 2 | cut -d ':' -f 1`
|
||||
if [ "X$dev" != "X" ]; then
|
||||
devname=$dev
|
||||
fi
|
||||
|
||||
if [ "X$devname" != "X" ]; then
|
||||
hwaddr=`echo $line | egrep "^[ ]*link" | awk '{print $2}'`
|
||||
if [ "X$hwaddr" = "X$boothwaddr" ]; then
|
||||
echo $devname
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
for lf in /tmp/dhclient.*.lease; do
|
||||
netif=${lf#*.}
|
||||
netif=${netif%.*}
|
||||
cp $lf "$NEWROOT/var/lib/dhclient/dhclient-$netif.leases"
|
||||
done
|
||||
|
||||
if [ ! -z "$ifname" ]; then
|
||||
MACX=${ifname#*:}
|
||||
ETHX=${ifname%:$MACX*}
|
||||
elif [ ! -z "$netdev" ]; then
|
||||
ETHX=$netdev
|
||||
MACX=`ip link show $netdev | grep ether | awk '{print $2}'`
|
||||
elif [ ! -z "$BOOTIF" ]; then
|
||||
MACX=$BOOTIF
|
||||
ETHX=$(getdevfrommac $BOOTIF)
|
||||
fi
|
||||
|
||||
if [ ! -z "$MACX" ] && [ ! -z "$ETHX" ]; then
|
||||
if [ ! -e $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX ]; then
|
||||
touch $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
|
||||
fi
|
||||
echo "DEVICE=$ETHX" > $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
|
||||
echo "BOOTPROTO=dhcp" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
|
||||
echo "HWADDR=$MACX" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
|
||||
echo "ONBOOT=yes" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
|
||||
fi
|
||||
|
||||
cp /etc/resolv.conf "$NEWROOT/etc/"
|
||||
|
||||
if [ -d "$NEWROOT/etc/sysconfig" -a ! -e "$NEWROOT/etc/sysconfig/selinux" ]; then
|
||||
|
||||
@@ -317,63 +317,6 @@ else
|
||||
fi
|
||||
cd /
|
||||
|
||||
function getdevfrommac() {
|
||||
boothwaddr=$1
|
||||
ip link show | while read line
|
||||
do
|
||||
dev=`echo $line | egrep "^[0-9]+: [0-9A-Za-z]+" | cut -d ' ' -f 2 | cut -d ':' -f 1`
|
||||
if [ "X$dev" != "X" ]; then
|
||||
devname=$dev
|
||||
fi
|
||||
|
||||
if [ "X$devname" != "X" ]; then
|
||||
hwaddr=`echo $line | egrep "^[ ]*link" | awk '{print $2}'`
|
||||
if [ "X$hwaddr" = "X$boothwaddr" ]; then
|
||||
echo $devname
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
if [ -z $STATEMNT ]; then
|
||||
for lf in /tmp/dhclient.*.lease; do
|
||||
netif=${lf#*.}
|
||||
netif=${netif%.*}
|
||||
cp $lf "$NEWROOT/var/lib/dhclient/dhclient-$netif.leases"
|
||||
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Saving $NEWROOT/var/lib/dhclient/dhclient-$netif.leases"
|
||||
done
|
||||
|
||||
ifname="$(getarg ifname=)"
|
||||
netdev="$(getarg netdev=)"
|
||||
BOOTIF="$(getarg BOOTIF=)"
|
||||
if [ ! -z "$ifname" ]; then
|
||||
MACX=${ifname#*:}
|
||||
ETHX=${ifname%:$MACX*}
|
||||
elif [ ! -z "$netdev" ]; then
|
||||
ETHX=$netdev
|
||||
MACX=`ip link show $netdev | grep ether | awk '{print $2}'`
|
||||
elif [ ! -z "$BOOTIF" ]; then
|
||||
MACX=$BOOTIF
|
||||
MACX=${MACX#01-}
|
||||
MACX=${MACX//-/:}
|
||||
ETHX=$(getdevfrommac $MACX)
|
||||
fi
|
||||
|
||||
|
||||
if [ ! -z "$MACX" ] && [ ! -z "$ETHX" ]; then
|
||||
if [ ! -e $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX ]; then
|
||||
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Creating $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX"
|
||||
touch $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
|
||||
fi
|
||||
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Writing $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX: DEVICE=$ETHX;BOOTPROTO=dhcp;HWADDR=$MACX;ONBOOT=yes"
|
||||
echo "DEVICE=$ETHX" > $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
|
||||
echo "BOOTPROTO=dhcp" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
|
||||
echo "HWADDR=$MACX" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
|
||||
echo "ONBOOT=yes" >> $NEWROOT/etc/sysconfig/network-scripts/ifcfg-$ETHX
|
||||
fi
|
||||
fi
|
||||
|
||||
[ "$xcatdebugmode" > "0" ] && logger -t $log_label -p local4.debug "Saving $NEWROOT/etc/resolv.conf"
|
||||
cp /etc/resolv.conf "$NEWROOT/etc/"
|
||||
|
||||
|
||||
@@ -72,11 +72,11 @@ my $lock;
|
||||
my $envar;
|
||||
my $gpgcheck;
|
||||
my $native_bootdir;
|
||||
my $stateless_uftp_receiver;
|
||||
|
||||
|
||||
sub xdie {
|
||||
unlink("$rootimg_dir/tmp/initrd.$$.gz")
|
||||
if $rootimg_dir && defined(imgutils::openeuler_release_version($osver));
|
||||
unlink("$rootimg_dir/tmp/initrd.$$.gz") if $rootimg_dir;
|
||||
system("rm -rf /tmp/xcatinitrd.$$");
|
||||
umount_chroot($rootimg_dir);
|
||||
die @_;
|
||||
@@ -303,13 +303,11 @@ if($onlyinitrd){
|
||||
print("the root image directory \"$rootimg_dir\"does not exist, please run \"genimage $imagename\" to generate the root image directory first!\n");
|
||||
exit 1;
|
||||
}
|
||||
if (defined(imgutils::openeuler_release_version($osver))) {
|
||||
my $retcode;
|
||||
($retcode, $lock) = xCAT::Utils->acquire_lock_imageop($rootimg_dir);
|
||||
if ($retcode) {
|
||||
print "Could not acquire image operation lock for $rootimg_dir\n";
|
||||
exit 1;
|
||||
}
|
||||
my $retcode;
|
||||
($retcode, $lock) = xCAT::Utils->acquire_lock_imageop($rootimg_dir);
|
||||
if ($retcode) {
|
||||
print "Could not acquire image operation lock for $rootimg_dir\n";
|
||||
exit 1;
|
||||
}
|
||||
}else
|
||||
{
|
||||
@@ -719,26 +717,9 @@ chomp($kernelver);
|
||||
|
||||
#$updates{'kernelver'} = $kernelver if ($tempfile);
|
||||
|
||||
# copy the kernel to $destdir
|
||||
my $kernel_output = "$destdir/kernel";
|
||||
if (defined(imgutils::openeuler_release_version($osver))) {
|
||||
$native_bootdir = File::Temp->newdir('.genimage-boot.XXXXXX', DIR => $destdir, CLEANUP => 1);
|
||||
$kernel_output = "$native_bootdir/kernel";
|
||||
}
|
||||
my $kernel_copy;
|
||||
if (-e "$rootimg_dir/boot/vmlinux-$kernelver") {
|
||||
$kernel_copy = cp("$rootimg_dir/boot/vmlinux-$kernelver", $kernel_output);
|
||||
} elsif (-e "$rootimg_dir/boot/vmlinuz-$kernelver") {
|
||||
$kernel_copy = cp("$rootimg_dir/boot/vmlinuz-$kernelver", $kernel_output);
|
||||
} elsif (-e "$rootimg_dir/boot/image-$kernelver") {
|
||||
$kernel_copy = cp("$rootimg_dir/boot/image-$kernelver", $kernel_output);
|
||||
} elsif (-e "$rootimg_dir/lib/modules/$kernelver/vmlinuz") {
|
||||
$kernel_copy = cp("$rootimg_dir/lib/modules/$kernelver/vmlinuz", $kernel_output);
|
||||
} else {
|
||||
xdie("couldn't find the kernel file matched $kernelver in $rootimg_dir/boot");
|
||||
}
|
||||
xdie("Error: failed to copy the kernel to $kernel_output: $!\n")
|
||||
if $native_bootdir && !$kernel_copy;
|
||||
# The kernel and the initial ramdisks wait here until genimage publishes them together.
|
||||
$native_bootdir = File::Temp->newdir('.genimage-boot.XXXXXX', DIR => $destdir, CLEANUP => 1);
|
||||
eval { imgutils::copy_kernel($rootimg_dir, $kernelver, $native_bootdir) } or xdie($@);
|
||||
|
||||
# Load driver update disk, and copy them to the root image
|
||||
my @dd_drivers = &load_dd();
|
||||
@@ -818,9 +799,10 @@ if ((-d "$rootimg_dir/usr/share/dracut") or (-d "$rootimg_dir/usr/lib/dracut"))
|
||||
print "Enter the dracut mode. Dracut version: $dracutver. Dracut directory: $dracutdir.\n";
|
||||
}
|
||||
xdie("Error: failed to generate the initial ramdisk: native image has no dracut installation\n")
|
||||
if $native_bootdir && !$dracutmode;
|
||||
if !$dracutmode && defined(imgutils::openeuler_release_version($osver));
|
||||
|
||||
imgutils::disable_vendor_repositories($rootimg_dir);
|
||||
imgutils::skip_kdump_without_dump_memory($rootimg_dir);
|
||||
|
||||
#-- run postinstall script
|
||||
unless ($imagename) {
|
||||
@@ -1013,6 +995,12 @@ if ($dracutmode) {
|
||||
mkinitrd("statelite");
|
||||
mkinitrd("stateless");
|
||||
}
|
||||
my @initrd_modes = defined(imgutils::openeuler_release_version($osver)) ? ('stateless') : ('statelite', 'stateless');
|
||||
eval { imgutils::publish_staged_boot_files($native_bootdir, $destdir, @initrd_modes) } or xdie($@);
|
||||
if ($dracutmode) {
|
||||
mark_rootimg_check('stateless');
|
||||
mark_uftp_receiver('stateless', $stateless_uftp_receiver);
|
||||
}
|
||||
|
||||
sub getlibs {
|
||||
my $file = shift;
|
||||
@@ -1304,22 +1292,10 @@ sub mkinitrd_dracut {
|
||||
or xdie("Error: failed to generate the initial ramdisk for $mode.\n");
|
||||
umount_chroot($rootimg_dir);
|
||||
eval { imgutils::check_uftp_initrd($rootimg_dir, "/tmp/initrd.$$.gz", $mode) } or xdie($@) if $uftp_receiver;
|
||||
if ($native_bootdir) {
|
||||
eval {
|
||||
imgutils::publish_boot_files($native_bootdir, $destdir,
|
||||
"$rootimg_dir/tmp/initrd.$$.gz", $mode);
|
||||
} or xdie($@);
|
||||
print "the initial ramdisk for $mode is generated successfully.\n";
|
||||
mark_rootimg_check($mode);
|
||||
mark_uftp_receiver($mode, $uftp_receiver);
|
||||
return;
|
||||
}
|
||||
move("$rootimg_dir/tmp/initrd.$$.gz", "$native_bootdir/initrd-$mode.gz")
|
||||
or xdie("Error: failed to move the initial ramdisk for $mode: $!\n");
|
||||
print "the initial ramdisk for $mode is generated successfully.\n";
|
||||
print("Move $rootimg_dir/tmp/initrd.$$.gz -> $destdir/initrd-$mode.gz\n");
|
||||
if (move("$rootimg_dir/tmp/initrd.$$.gz", "$destdir/initrd-$mode.gz")) {
|
||||
mark_rootimg_check($mode);
|
||||
mark_uftp_receiver($mode, $uftp_receiver);
|
||||
}
|
||||
$stateless_uftp_receiver = $uftp_receiver if $mode eq 'stateless';
|
||||
}
|
||||
|
||||
# nodeset warns unless this marker says that the stateless initial ramdisk checks the root image checksum.
|
||||
@@ -2057,8 +2033,7 @@ EOMS
|
||||
system("mkdir -p /tmp/xcatinitrd.$$/var/run/netreport");
|
||||
|
||||
#copy("$rootimg_dir/lib/modules/*d","/tmp/xcatinitrd.$$/$_");
|
||||
system("cd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|gzip -9 -c - > $destdir/initrd-$mode.gz");
|
||||
system("rm -rf /tmp/xcatinitrd.$$");
|
||||
eval { imgutils::pack_initrd("/tmp/xcatinitrd.$$", "$native_bootdir/initrd-$mode.gz", 'gzip', $mode) } or xdie($@);
|
||||
|
||||
}
|
||||
|
||||
@@ -2166,19 +2141,8 @@ sub generic_post { #This function is meant to leave the image in a state approxi
|
||||
print $cfgfile "#Dummy resolv.conf to make boot cleaner";
|
||||
close($cfgfile);
|
||||
|
||||
# Create the ifcfg-x file for diskless node. But keep the ONBOOT=no
|
||||
# to skip the break of nfs-based boot
|
||||
if ($prinic) {
|
||||
open($cfgfile, ">", "$rootimg_dir/etc/sysconfig/network-scripts/ifcfg-$prinic");
|
||||
print $cfgfile "ONBOOT=no\nBOOTPROTO=dhcp\nDEVICE=$prinic\n";
|
||||
close($cfgfile);
|
||||
}
|
||||
foreach (split /,/, $othernics) {
|
||||
if (/^$/) { next; }
|
||||
open($cfgfile, ">", "$rootimg_dir/etc/sysconfig/network-scripts/ifcfg-$_");
|
||||
print $cfgfile "ONBOOT=yes\nBOOTPROTO=dhcp\nDEVICE=$_\n";
|
||||
close($cfgfile);
|
||||
}
|
||||
imgutils::write_nic_profiles($rootimg_dir, $osver, $prinic, $othernics);
|
||||
imgutils::disable_auto_profiles($rootimg_dir, $osver);
|
||||
|
||||
# securetty not needed on s390x
|
||||
if ($arch ne "s390x") {
|
||||
|
||||
@@ -66,6 +66,7 @@ my $tempfile;
|
||||
my $prompt;
|
||||
my $noupdate;
|
||||
my $kernelimage;
|
||||
my $lock;
|
||||
|
||||
|
||||
sub xdie {
|
||||
@@ -218,6 +219,15 @@ foreach (@ndrivers, @default_ndrivers) {
|
||||
my $uarch = xCAT::Utils->debian_arch($arch);
|
||||
|
||||
|
||||
# The lock is named after the real path of the root image, which must exist.
|
||||
mkpath($rootimg_dir) unless ($onlyinitrd);
|
||||
my $lockerror;
|
||||
($lockerror, $lock) = xCAT::Utils->acquire_lock_imageop($rootimg_dir);
|
||||
if ($lockerror) {
|
||||
print "Error: $lock\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
unless ($onlyinitrd) {
|
||||
@aptdirs = ();
|
||||
|
||||
@@ -317,11 +327,6 @@ unless ($onlyinitrd) {
|
||||
close($aptconfig);
|
||||
mkpath "$rootimg_dir/etc";
|
||||
|
||||
my $fd;
|
||||
open($fd, ">>", "$rootimg_dir/etc/fstab");
|
||||
print $fd "#Dummy fstab for dpkg postscripts to see\n";
|
||||
close($fd);
|
||||
|
||||
my $non_interactive;
|
||||
if (!$prompt) { $non_interactive = "-y"; }
|
||||
|
||||
@@ -359,8 +364,19 @@ unless ($onlyinitrd) {
|
||||
$aptcmd2 = "--verbose --arch $uarch $dist $rootimg_dir file://$srcdir";
|
||||
}
|
||||
|
||||
print "Run cmd [$aptcmd1 $aptcmd2] to create rootimage bootstraps\n";
|
||||
my $rc = system("$aptcmd1 $aptcmd2");
|
||||
my $rc = 0;
|
||||
if (imgutils::debootstrap_finished($rootimg_dir)) {
|
||||
imgutils::check_reused_root($rootimg_dir, $dist, $uarch);
|
||||
print "Updating the existing root image in $rootimg_dir\n";
|
||||
imgutils::prepare_reused_root($rootimg_dir);
|
||||
} else {
|
||||
my $fd;
|
||||
open($fd, ">>", "$rootimg_dir/etc/fstab");
|
||||
print $fd "#Dummy fstab for dpkg postscripts to see\n";
|
||||
close($fd);
|
||||
print "Run cmd [$aptcmd1 $aptcmd2] to create rootimage bootstraps\n";
|
||||
$rc = system("$aptcmd1 $aptcmd2");
|
||||
}
|
||||
if ($rc) {
|
||||
my $os=xCAT::Utils->osver("os");
|
||||
if ($os ne 'ubuntu') {
|
||||
@@ -521,13 +537,7 @@ unless ($onlyinitrd) {
|
||||
}
|
||||
close($aptconfig);
|
||||
|
||||
#backup the /etc/hosts & /etc/resolv.conf
|
||||
move("$rootimg_dir/etc/hosts", "$rootimg_dir/etc/hosts.bak");
|
||||
move("$rootimg_dir/etc/resolv.conf", "$rootimg_dir/etc/resolv.conf.bak");
|
||||
|
||||
#copy the mn's /etc/hosts & /etc/resolv.conf to the rootimage
|
||||
copy("/etc/hosts", "$rootimg_dir/etc/hosts");
|
||||
copy("/etc/resolv.conf", "$rootimg_dir/etc/resolv.conf");
|
||||
imgutils::use_host_resolver($rootimg_dir);
|
||||
|
||||
#Now let's handle extra packages
|
||||
unless ($imagename) {
|
||||
@@ -723,7 +733,7 @@ foreach (@KVERS) {
|
||||
|
||||
@KVERS = <$rootimg_dir/lib/modules/*> unless (scalar(@KVERS));
|
||||
|
||||
$basekernelver = basename(pop @KVERS) if (scalar(@KVERS));
|
||||
$basekernelver = imgutils::newest_kernel_version(map { basename($_) } @KVERS) if (scalar(@KVERS));
|
||||
|
||||
$basekernelver = `uname -r` unless ($basekernelver);
|
||||
|
||||
@@ -732,16 +742,10 @@ chomp($kernelver);
|
||||
|
||||
#$updates{'kernelver'} = $kernelver if ($tempfile);
|
||||
|
||||
# copy the kernel to $destdir
|
||||
if (-e "$rootimg_dir/boot/vmlinux-$kernelver") {
|
||||
cp("$rootimg_dir/boot/vmlinux-$kernelver", "$destdir/kernel");
|
||||
} elsif (-e "$rootimg_dir/boot/vmlinuz-$kernelver") {
|
||||
cp("$rootimg_dir/boot/vmlinuz-$kernelver", "$destdir/kernel");
|
||||
} elsif (-e "$rootimg_dir/boot/image-$kernelver") {
|
||||
cp("$rootimg_dir/boot/image-$kernelver", "$destdir/kernel");
|
||||
} else {
|
||||
xdie("couldn't find the kernel file matched $kernelver in $rootimg_dir/boot");
|
||||
}
|
||||
# The kernel and the initial ramdisks wait here until genimage publishes them together.
|
||||
my $native_bootdir = File::Temp->newdir('.genimage-boot.XXXXXX', DIR => $destdir, CLEANUP => 1);
|
||||
my $stateless_uftp_receiver;
|
||||
eval { imgutils::copy_kernel($rootimg_dir, $kernelver, $native_bootdir) } or xdie($@);
|
||||
|
||||
# Load driver update disk, and copy them to the root image
|
||||
my @dd_drivers = &load_dd();
|
||||
@@ -938,6 +942,11 @@ if ($dracutmode) {
|
||||
push @ndrivers, @drivers;
|
||||
mkinitrd("stateless");
|
||||
}
|
||||
eval { imgutils::publish_staged_boot_files($native_bootdir, $destdir, 'statelite', 'stateless') } or die($@);
|
||||
if ($dracutmode) {
|
||||
mark_rootimg_check('stateless');
|
||||
imgutils::mark_uftp_receiver("$destdir/initrd-stateless.gz", $stateless_uftp_receiver);
|
||||
}
|
||||
|
||||
sub getlibs {
|
||||
my $file = shift;
|
||||
@@ -1061,10 +1070,9 @@ sub mkinitrd_dracut {
|
||||
or die("Error: failed to generate the initial ramdisk for $mode.\n");
|
||||
eval { imgutils::check_uftp_initrd($rootimg_dir, "/tmp/initrd.$$.gz", $mode) } or xdie($@) if $uftp_receiver;
|
||||
print "the initial ramdisk for $mode is generated successfully.\n";
|
||||
if (move("$rootimg_dir/tmp/initrd.$$.gz", "$destdir/initrd-$mode.gz")) {
|
||||
mark_rootimg_check($mode);
|
||||
imgutils::mark_uftp_receiver("$destdir/initrd-$mode.gz", $uftp_receiver) if $mode eq 'stateless';
|
||||
}
|
||||
move("$rootimg_dir/tmp/initrd.$$.gz", "$native_bootdir/initrd-$mode.gz")
|
||||
or die("Error: failed to stage the initial ramdisk for $mode: $!\n");
|
||||
$stateless_uftp_receiver = $uftp_receiver if $mode eq 'stateless';
|
||||
}
|
||||
|
||||
# nodeset warns unless this marker says that the stateless initial ramdisk checks the root image checksum.
|
||||
@@ -1884,9 +1892,7 @@ EOMS
|
||||
}
|
||||
|
||||
#copy("$rootimg_dir/lib/modules/*d","/tmp/xcatinitrd.$$/$_");
|
||||
print "\ncd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|$compress -9 -c - > $destdir/initrd-$mode.gz \n";
|
||||
system("cd /tmp/xcatinitrd.$$;find .|cpio -H newc -o|$compress -9 -c - > $destdir/initrd-$mode.gz");
|
||||
system("rm -rf /tmp/xcatinitrd.$$");
|
||||
imgutils::pack_initrd("/tmp/xcatinitrd.$$", "$native_bootdir/initrd-$mode.gz", $compress, $mode);
|
||||
|
||||
}
|
||||
|
||||
@@ -2259,20 +2265,7 @@ sub use_hackuname {
|
||||
# write the hacked uname script
|
||||
my $unamefile;
|
||||
open($unamefile, ">", "$rootimg_dir/bin/uname");
|
||||
print $unamefile "#!/bin/bash \n";
|
||||
print $unamefile "case \"\$1\" in \n";
|
||||
print $unamefile "\"-m\") \n";
|
||||
print $unamefile " ARCH=\"\$(dpkg --print-architecture || \n";
|
||||
print $unamefile " rpm -q kernel-\$(\"\$0\" -r) --qf '%{arch}')\" \n";
|
||||
print $unamefile " case \"\$ARCH\" in \n";
|
||||
print $unamefile " \"amd64\") ARCH=\"x86_64\" ;; \n";
|
||||
print $unamefile " \"ppc64el\") ARCH=\"ppc64le\" ;; \n";
|
||||
print $unamefile " esac \n";
|
||||
print $unamefile " echo \"\$ARCH\" ;; \n";
|
||||
print $unamefile "\"-r\") cd /lib/modules && for d in * ; do : ; done && echo \$d ;; \n";
|
||||
print $unamefile "\"-s\"|\"\") echo \"Linux\" ;; \n";
|
||||
print $unamefile "esac \n";
|
||||
print $unamefile "exit 0 \n";
|
||||
print $unamefile imgutils::uname_script($kernelver);
|
||||
close $unamefile;
|
||||
chmod(0755, "$rootimg_dir/bin/uname");
|
||||
}
|
||||
|
||||
@@ -185,6 +185,7 @@ function version()
|
||||
|
||||
GO_XCAT_DEFAULT_BASE_URL="http://xcat.org/files/xcat/repos"
|
||||
GO_XCAT_DEFAULT_INSTALL_PATH="/install/xcat"
|
||||
GO_XCAT_APT_KEY_FILE="/etc/apt/trusted.gpg.d/xcat.gpg"
|
||||
|
||||
# The package list of xcat-core
|
||||
GO_XCAT_CORE_PACKAGE_LIST=()
|
||||
@@ -949,6 +950,9 @@ function check_repo_version_apt()
|
||||
type apt-cache >/dev/null 2>&1 || return 255
|
||||
local name=""
|
||||
local ver=""
|
||||
local policy=""
|
||||
local rc=0
|
||||
policy="$(LC_ALL="C" apt-cache policy "$@" 2>/dev/null)" || rc="$?"
|
||||
while read -r name ver
|
||||
do
|
||||
if [[ "${name}" =~ ^[a-z] ]]
|
||||
@@ -965,13 +969,13 @@ function check_repo_version_apt()
|
||||
echo "$ver"
|
||||
shift
|
||||
fi
|
||||
done < <(apt-cache policy "$@" 2>/dev/null)
|
||||
done <<<"${policy}"
|
||||
while [[ -n "$1" ]]
|
||||
do
|
||||
echo "(not found)"
|
||||
shift
|
||||
done
|
||||
return 0
|
||||
return "${rc}"
|
||||
}
|
||||
|
||||
function check_repo_version()
|
||||
@@ -1646,7 +1650,17 @@ function add_xcat_core_repo_apt()
|
||||
local tmp="${TMP_DIR}/tmp_xcat.key"
|
||||
download_file "${url}" "${tmp}"
|
||||
warn_if_bad "$?" "download xcat apt key failed" || return 1
|
||||
apt-key add "${tmp}"
|
||||
# apt 3 has no apt-key, and apt before 1.4 reads only binary keyrings, which start with 0x98, 0x99 or 0xc6.
|
||||
# A truncated download has a block without its END line, so it is refused.
|
||||
awk '/^-----BEGIN PGP PUBLIC KEY BLOCK-----$/ { o = h = 1; b = 0; next }
|
||||
/^-----END PGP PUBLIC KEY BLOCK-----$/ { if (!o) bad = 1; o = h = b = 0; n++; next }
|
||||
h && /^$/ { h = 0; b = 1; next }
|
||||
b && /^=/ { b = 0; next }
|
||||
b { print }
|
||||
END { exit (bad || o || !n) }' "${tmp}" >"${tmp}.b64" &&
|
||||
base64 -d "${tmp}.b64" >"${tmp}.gpg" 2>/dev/null &&
|
||||
od -An -tx1 -N1 "${tmp}.gpg" | grep -qE '^ (98|99|c6)$' &&
|
||||
install -D -m 0644 "${tmp}.gpg" "${GO_XCAT_APT_KEY_FILE}"
|
||||
warn_if_bad "$?" "import xcat apt key failed" || return 1
|
||||
case "${ver}" in
|
||||
"devel")
|
||||
@@ -1978,7 +1992,27 @@ function install_packages_apt()
|
||||
type apt-get >/dev/null 2>&1 || return 255
|
||||
local -a yes=()
|
||||
[[ "$1" = "-y" ]] && yes=("-y") && shift
|
||||
apt-get --allow-unauthenticated install "${yes[@]}" "$@"
|
||||
local -a available=()
|
||||
local package="" ver="" versions=""
|
||||
versions="$(check_repo_version_apt "$@")"
|
||||
warn_if_bad "$?" "query apt package candidates failed" || return 1
|
||||
# As with dnf --setopt=strict=0, a package the repositories lack must not stop the install.
|
||||
for package in "$@"
|
||||
do
|
||||
read -r ver
|
||||
case "${ver}" in
|
||||
"(none)"|"(not found)")
|
||||
# The xcat metapackage depends on every package a management node needs.
|
||||
[[ "${package}" = "xcat" ]] &&
|
||||
{ warn_if_bad 1 "xcat: the repositories do not provide it"; return 1; }
|
||||
warn_if_bad 1 "${package}: the repositories do not provide it, skipped"
|
||||
;;
|
||||
*)
|
||||
available+=("${package}")
|
||||
;;
|
||||
esac
|
||||
done <<<"${versions}"
|
||||
apt-get --allow-unauthenticated install "${yes[@]}" "${available[@]}"
|
||||
}
|
||||
|
||||
function install_packages()
|
||||
@@ -2194,6 +2228,7 @@ function trash_xcat()
|
||||
rm -rf /etc/xcat
|
||||
rm -rf /etc/xcatdockerca
|
||||
rm -f /etc/apt/sources.list.d/xcat-{core,dep}.list
|
||||
rm -f "${GO_XCAT_APT_KEY_FILE}"
|
||||
rm -f /etc/yum.repos.d/xCAT-{core,dep,dep-common}.repo{,.nouse}
|
||||
rm -f /etc/yum.repos.d/xcat-{core,dep,dep-common}.repo
|
||||
rm -f /etc/zypp/repos.d/xCAT-{core,dep,dep-common}.repo{,.nouse}
|
||||
@@ -2242,7 +2277,8 @@ function list_xcat_packages()
|
||||
warn_if_bad "$?" "Failed to get package list from repository \`xcat-dep'." || return 1
|
||||
|
||||
local -i cols
|
||||
cols="$(type tput >/dev/null 2>&1 && tput cols)"
|
||||
# The tput of ncurses 5 reads the width through stderr, so only the terminal type check is silenced.
|
||||
cols="$(type tput >/dev/null 2>&1 && tput longname >/dev/null 2>&1 && tput cols)"
|
||||
[[ "${cols}" -lt 80 ]] && cols=80
|
||||
[[ "${cols}" -gt 90 ]] && cols=90
|
||||
[[ -t 1 ]] || cols=90
|
||||
|
||||
@@ -52,19 +52,34 @@ Requires: perl-IO-Socket-SSL perl-XML-Simple perl-XML-Parser perl-Digest-SHA1 pe
|
||||
# Time::HiRes and Text::Balanced) are not pulled in transitively by perl-xCAT
|
||||
# either. List them here or the affected subcommands die at load time.
|
||||
Requires: perl-Net-Telnet perl-Net-DNS perl-Crypt-CBC perl-Crypt-Rijndael
|
||||
# openSUSE has no perl-generators, so no perl(...) requirement is generated here and nothing
|
||||
# installs the modules this code loads. xcatd stays inactive without them: xCAT::Table dies
|
||||
# loading JSON. EL and openEuler generate these automatically and need no list.
|
||||
%if 0%{?suse_version}
|
||||
Requires: perl(Date::Parse)
|
||||
Requires: perl(Expect)
|
||||
Requires: perl(JSON)
|
||||
Requires: perl(SNMP)
|
||||
%endif
|
||||
# DB_File is only used by the Confluent client (lib/xcat/Confluent/Client.pm). EL10
|
||||
# dropped libdb: EPEL still carries perl-DB_File for x86_64 and ppc64le, but riscv64 has
|
||||
# no EPEL at all, so on EL10 ask for the module weakly -- it is installed where it exists
|
||||
# and skipped where it cannot. The dependency generator still turns that "use DB_File"
|
||||
# into a hard perl(DB_File) requirement; drop it there too, appending to any filter the
|
||||
# build root already set. Every other platform keeps the hard requirement it has today.
|
||||
# openSUSE has no package of that name: Leap 15.6 calls it perl-core-DB_File and 42.3 has
|
||||
# neither, but both provide the capability, so ask for the capability there.
|
||||
%if 0%{?rhel} >= 10
|
||||
Recommends: perl-DB_File
|
||||
%global __requires_exclude %{?__requires_exclude:%{__requires_exclude}|}^perl\\(DB_File\\)$
|
||||
%else
|
||||
%if 0%{?suse_version}
|
||||
Requires: perl(DB_File)
|
||||
%else
|
||||
Requires: perl-DB_File
|
||||
%endif
|
||||
%endif
|
||||
%endif
|
||||
Obsoletes: atftp-xcat
|
||||
%endif
|
||||
|
||||
|
||||
@@ -1,5 +1,47 @@
|
||||
#!/bin/bash
|
||||
|
||||
# How many times to ask ICMP, and how long to wait between asks. Overridable so a test can drive
|
||||
# node_pingable without sleeping.
|
||||
PING_TRIES=${PING_TRIES:-5}
|
||||
PING_RETRY_SLEEP=${PING_RETRY_SLEEP:-2}
|
||||
|
||||
#--- node_pingable
|
||||
# Descriptions: whether the node answers ICMP, asked more than once.
|
||||
#
|
||||
# ICMP to a node is lossy for a few seconds after it finishes booting. One sample on an
|
||||
# openSUSE Leap 15.6 cluster lost 2 of 2 packets while xdsh to the same node succeeded a second
|
||||
# later; the caller ANDs both answers, so that one sample forced a second full rinstall and cost
|
||||
# 401 seconds. A second run of the same cell lost 2 of 3 packets at a moment that was not the
|
||||
# decision point and passed. The difference between the two runs was which side of a
|
||||
# two-packet sample landed, not the state of the node.
|
||||
#
|
||||
# So ask again before concluding. A node that never answers still reports non-pingable, because
|
||||
# that is a real defect and the caller must keep vetoing it.
|
||||
# Arguments: $1 - the node
|
||||
# Returns: 0 if the node answered, non-zero if it never did
|
||||
#---
|
||||
node_pingable() {
|
||||
local node=$1
|
||||
local i
|
||||
for (( i = 1; i <= PING_TRIES; ++i )); do
|
||||
if ping -c 2 "$node"; then
|
||||
return 0
|
||||
fi
|
||||
echo "[$i/$PING_TRIES] $node did not answer ICMP; asking again"
|
||||
if [ "$i" -lt "$PING_TRIES" ]; then
|
||||
sleep "$PING_RETRY_SLEEP"
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# Sourcing stops here. BASH_SOURCE[0] differs from $0 only when this file is sourced, so a bats
|
||||
# test can drive node_pingable without running a provisioning loop -- and without the lsdef below,
|
||||
# which needs an xCAT database.
|
||||
if [ "${BASH_SOURCE[0]}" != "${0}" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
declare -i installsuccess=0
|
||||
declare -i a=0
|
||||
declare -i tryreinstall=1
|
||||
@@ -64,7 +106,7 @@ do
|
||||
tobooted=$?
|
||||
echo "The tobooted is $tobooted"
|
||||
|
||||
ping -c 2 $node
|
||||
node_pingable $node
|
||||
pingable=$?
|
||||
echo "The pingable is $pingable"
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
PATH=""
|
||||
source /tmp/go-xcat || exit 70
|
||||
TMP_DIR=/tmp/fixture
|
||||
GO_XCAT_DEFAULT_BASE_URL=https://repo.example.invalid
|
||||
|
||||
# apt 3 has no apt-key: a call to it is the defect under test.
|
||||
apt-key() { printf '%s\n' "$*" >> /tmp/fixture/apt-key.log; return 127; }
|
||||
dpkg() { [ "$1" = --print-architecture ] && echo riscv64; }
|
||||
download_file()
|
||||
{
|
||||
printf '%s\n' "$1" >> /tmp/fixture/download.log
|
||||
cp /tmp/fixture/key.asc "$2"
|
||||
}
|
||||
|
||||
case "$1" in
|
||||
add) add_xcat_core_repo_apt "" latest ;;
|
||||
trash) trash_xcat ;;
|
||||
*) exit 64 ;;
|
||||
esac
|
||||
@@ -0,0 +1,69 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# The awk the Ubuntu Genesis image carries.
|
||||
#
|
||||
# allowcred.awk, minixcatd.awk and udpcat.awk open a TCP stream with the gawk |& coprocess
|
||||
# and the /inet/ special file. mawk rejects both at parse time, and mawk is the awk
|
||||
# alternative on a Debian or Ubuntu build root, so the module cannot stage the host's
|
||||
# /usr/bin/awk.
|
||||
|
||||
load 'helpers/shell_source'
|
||||
|
||||
setup()
|
||||
{
|
||||
MODULE="$(repo_path 'xCAT-genesis-base/dracut_105/ubuntu/module-setup.sh')"
|
||||
[ -r "$MODULE" ] || skip "$MODULE is required"
|
||||
export MODULE
|
||||
}
|
||||
|
||||
# Run install() from the dracut module with the dracut helpers replaced by stubs. Sets
|
||||
# INSTALLED to one installed name per line, and INITDIR to the staged image root.
|
||||
run_install()
|
||||
{
|
||||
local dir="${BATS_TEST_TMPDIR}/module"
|
||||
|
||||
rm -rf "$dir"
|
||||
mkdir -p "$dir/initdir/usr/bin" "$dir/initdir/bin"
|
||||
|
||||
# No "set -u": _dracut_install_opt() in the module reads $2 unset, which real dracut
|
||||
# allows.
|
||||
cat >"$dir/drive.sh" <<'SH'
|
||||
initdir="$1"
|
||||
record="$2"
|
||||
moddir=/dev/null
|
||||
kernel=
|
||||
dracut_install() { for name in "$@"; do printf '%s\n' "$name" >>"$record"; done; }
|
||||
instmods() { :; }
|
||||
inst() { :; }
|
||||
inst_script() { :; }
|
||||
inst_dir() { :; }
|
||||
inst_hook() { :; }
|
||||
inst_symlink() { :; }
|
||||
. "$MODULE"
|
||||
install >/dev/null 2>&1
|
||||
SH
|
||||
|
||||
/bin/bash "$dir/drive.sh" "$dir/initdir" "$dir/installed" || true
|
||||
INSTALLED="$(read_file_or_empty "$dir/installed")"
|
||||
INITDIR="$dir/initdir"
|
||||
}
|
||||
|
||||
@test "the module installs gawk by name" {
|
||||
run_install
|
||||
printf '%s\n' "$INSTALLED" | grep -qx 'gawk'
|
||||
}
|
||||
|
||||
@test "the module does not stage the build host's awk alternative" {
|
||||
# On Ubuntu /usr/bin/awk resolves to mawk, so staging it ships an awk that cannot parse
|
||||
# the Genesis awk programs.
|
||||
run_install
|
||||
refute_grep -qx '/usr/bin/awk' <(printf '%s\n' "$INSTALLED")
|
||||
refute_grep -qx 'awk' <(printf '%s\n' "$INSTALLED")
|
||||
}
|
||||
|
||||
@test "awk in the image points at gawk" {
|
||||
# The awk programs start with #!/usr/bin/awk -f, so the name awk has to be gawk.
|
||||
run_install
|
||||
[ -L "$INITDIR/usr/bin/awk" ]
|
||||
[ "$(readlink "$INITDIR/usr/bin/awk")" = 'gawk' ]
|
||||
}
|
||||
@@ -33,7 +33,14 @@ SH
|
||||
#!/bin/sh
|
||||
if grep -Fxq "$3" /run/fixture/installed; then printf 'install ok installed'; else exit 1; fi
|
||||
SH
|
||||
printf '#!/bin/sh\nexit 0\n' >"$fixture/tools/apt-cache"
|
||||
cat >"$fixture/tools/apt-cache" <<'SH'
|
||||
#!/bin/sh
|
||||
[ "$1" = policy ] || exit 0
|
||||
shift
|
||||
for package do
|
||||
printf '%s:\n Installed: (none)\n Candidate: 1\n' "$package"
|
||||
done
|
||||
SH
|
||||
printf '#!/bin/sh\nexit 22\n' >"$fixture/bin/curl"
|
||||
chmod +x "$fixture/bin/curl" "$fixture/tools/"*
|
||||
: >"$fixture/installed"
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# On apt, go-xcat installs the packages the repositories provide and warns about each one they
|
||||
# do not, as dnf does with strict=0. Only a missing xcat metapackage stops the install, and a
|
||||
# translated apt must not hide the packages that are there.
|
||||
|
||||
load 'helpers/go_xcat'
|
||||
load 'helpers/go_xcat_apt'
|
||||
|
||||
setup()
|
||||
{
|
||||
go_xcat_require_source
|
||||
}
|
||||
|
||||
# Run install_packages_apt with the apt-cache double. apt-get records its arguments.
|
||||
#
|
||||
# $@ Package names, answered as helpers/go_xcat_apt describes.
|
||||
install_with_apt()
|
||||
{
|
||||
(
|
||||
log="$BATS_TEST_TMPDIR/apt-get.log"
|
||||
PATH=""
|
||||
source "$GO_XCAT_SOURCE" || exit 70
|
||||
apt-get() { printf '%s\n' "$*" >>"$log"; }
|
||||
install_packages_apt -y "$@"
|
||||
)
|
||||
}
|
||||
|
||||
@test "packages the repositories do not provide are skipped with a warning" {
|
||||
run install_with_apt first missing nocandidate last
|
||||
[ "$status" -eq 0 ] || { printf '%s\n' "$output"; return 1; }
|
||||
[ "$(cat "$BATS_TEST_TMPDIR/apt-get.log")" = '--allow-unauthenticated install -y first last' ]
|
||||
grep -Fq 'missing: the repositories do not provide it, skipped' <<<"$output"
|
||||
grep -Fq 'nocandidate: the repositories do not provide it, skipped' <<<"$output"
|
||||
}
|
||||
|
||||
@test "a translated apt still installs the packages the repositories provide" {
|
||||
LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 run install_with_apt first last
|
||||
[ "$status" -eq 0 ] || { printf '%s\n' "$output"; return 1; }
|
||||
[ "$(cat "$BATS_TEST_TMPDIR/apt-get.log")" = '--allow-unauthenticated install -y first last' ]
|
||||
! grep -Fq 'skipped' <<<"$output"
|
||||
}
|
||||
|
||||
@test "the install stops when the repositories do not provide the xcat metapackage" {
|
||||
APT_UNKNOWN=xcat run install_with_apt perl-xcat xcat xcat-server
|
||||
[ "$status" -ne 0 ]
|
||||
[ ! -e "$BATS_TEST_TMPDIR/apt-get.log" ]
|
||||
grep -Fq 'xcat: the repositories do not provide it' <<<"$output"
|
||||
}
|
||||
|
||||
@test "the install stops when apt cannot answer the candidate query" {
|
||||
APT_FAIL_AFTER=xcat run install_with_apt xcat xcat-server xcat-buildkit
|
||||
[ "$status" -ne 0 ]
|
||||
[ ! -e "$BATS_TEST_TMPDIR/apt-get.log" ]
|
||||
grep -Fq 'query apt package candidates failed' <<<"$output"
|
||||
! grep -Fq 'skipped' <<<"$output"
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# go-xcat trusts the xcat.org apt key without apt-key, which apt 3 does not ship. It installs
|
||||
# the key as a binary keyring, which apt before 1.4 needs, and a complete uninstall removes it
|
||||
# with the repository files.
|
||||
|
||||
load 'helpers/go_xcat'
|
||||
|
||||
setup()
|
||||
{
|
||||
[ "$(uname -s)" = Linux ] || skip 'repository checks require Linux namespaces'
|
||||
command -v bwrap >/dev/null || skip 'bwrap is required'
|
||||
go_xcat_require_source
|
||||
[ -n "$BATS_TEST_TMPDIR" ] || return 1
|
||||
fixture="$BATS_TEST_TMPDIR/apt"
|
||||
mkdir -p "$fixture/etc/apt/sources.list.d"
|
||||
printf 'DISTRIB_CODENAME=resolute\n' >"$fixture/etc/lsb-release"
|
||||
# Two armored blocks, as xcat.org publishes, each holding a public key packet (0x99).
|
||||
printf '\231\000\002ab\231\000\002cd' >"$fixture/keyring.gpg"
|
||||
{
|
||||
armored_block "$(printf '\231\000\002ab' | base64)" 'Version: GnuPG v1'
|
||||
armored_block "$(printf '\231\000\002cd' | base64)"
|
||||
} >"$fixture/key.asc"
|
||||
}
|
||||
|
||||
# Print an armored public key block with the base64 body $1 and the optional header $2.
|
||||
armored_block()
|
||||
{
|
||||
printf -- '-----BEGIN PGP PUBLIC KEY BLOCK-----\n'
|
||||
[ -z "$2" ] || printf '%s\n' "$2"
|
||||
printf '\n%s\n=AAAA\n-----END PGP PUBLIC KEY BLOCK-----\n' "$1"
|
||||
}
|
||||
|
||||
run_go_xcat_apt()
|
||||
{
|
||||
# Debian reaches awk through /etc/alternatives, which the fixture /etc hides.
|
||||
local -a alternatives=()
|
||||
[ -d /etc/alternatives ] && alternatives=(--ro-bind /etc/alternatives /etc/alternatives)
|
||||
bwrap --die-with-parent --unshare-net --ro-bind / / --dev /dev --proc /proc \
|
||||
--tmpfs /tmp --ro-bind "$BATS_TEST_DIRNAME/../.." /tmp/source \
|
||||
--ro-bind "$GO_XCAT_SOURCE" /tmp/go-xcat \
|
||||
--bind "$fixture" /tmp/fixture --bind "$fixture/etc" /etc "${alternatives[@]}" \
|
||||
--chdir /tmp/fixture \
|
||||
bash /tmp/source/xCAT-test/bats/fixtures/go-xcat-apt.sh "$@"
|
||||
}
|
||||
|
||||
@test "the default xcat-core repository trusts the xCAT key as a binary keyring" {
|
||||
run run_go_xcat_apt add
|
||||
[ "$status" -eq 0 ] || { printf '%s\n' "$output"; return 1; }
|
||||
[ ! -e "$fixture/apt-key.log" ]
|
||||
[ "$(cat "$fixture/download.log")" = 'https://repo.example.invalid/apt/apt.key' ]
|
||||
key="$fixture/etc/apt/trusted.gpg.d/xcat.gpg"
|
||||
cmp "$fixture/keyring.gpg" "$key"
|
||||
[ "$(stat -c %a "$key")" = 644 ]
|
||||
[ "$(cat "$fixture/etc/apt/sources.list.d/xcat-core.list")" = \
|
||||
'deb [arch=riscv64] https://repo.example.invalid/apt/latest/xcat-core resolute main' ]
|
||||
}
|
||||
|
||||
@test "a download that holds no public key keeps the installed key and stops" {
|
||||
mkdir -p "$fixture/etc/apt/trusted.gpg.d"
|
||||
key="$fixture/etc/apt/trusted.gpg.d/xcat.gpg"
|
||||
local -a downloads=(
|
||||
''
|
||||
'<html>Not Found</html>'
|
||||
'-----BEGIN PGP PUBLIC KEY BLOCK-----'
|
||||
"$(armored_block '!!!!')"
|
||||
"$(armored_block "$(printf '\264\001a' | base64)")"
|
||||
"$(printf -- '-----BEGIN PGP PUBLIC KEY BLOCK-----\n\nmQEN')"
|
||||
"$(head -n 9 "$fixture/key.asc")"
|
||||
)
|
||||
for download in "${downloads[@]}"; do
|
||||
cp "$fixture/keyring.gpg" "$key"
|
||||
printf '%s\n' "$download" >"$fixture/key.asc"
|
||||
run run_go_xcat_apt add
|
||||
[ "$status" -ne 0 ] || { printf 'accepted %s\n' "$download"; return 1; }
|
||||
grep -Fq 'import xcat apt key failed' <<<"$output"
|
||||
cmp "$fixture/keyring.gpg" "$key"
|
||||
[ ! -e "$fixture/etc/apt/sources.list.d/xcat-core.list" ]
|
||||
done
|
||||
}
|
||||
|
||||
@test "a complete uninstall removes the xCAT key and keeps other keys" {
|
||||
mkdir -p "$fixture/etc/apt/trusted.gpg.d"
|
||||
cp "$fixture/keyring.gpg" "$fixture/etc/apt/trusted.gpg.d/xcat.gpg"
|
||||
cp "$fixture/keyring.gpg" "$fixture/etc/apt/trusted.gpg.d/other.gpg"
|
||||
run run_go_xcat_apt trash
|
||||
[ ! -e "$fixture/etc/apt/trusted.gpg.d/xcat.gpg" ]
|
||||
[ -e "$fixture/etc/apt/trusted.gpg.d/other.gpg" ]
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# go-xcat check, install and update print a table of the xCAT packages, with the installed version
|
||||
# and the version that the repositories offer. On apt, the table must show the candidates that a
|
||||
# translated apt reports. A terminal type that tput does not know must not add tput errors to it.
|
||||
|
||||
load 'helpers/go_xcat'
|
||||
load 'helpers/go_xcat_apt'
|
||||
|
||||
setup()
|
||||
{
|
||||
go_xcat_require_source
|
||||
}
|
||||
|
||||
# Print the package table of list_xcat_packages with the apt-cache double. xcat-core offers xcat and
|
||||
# xcat-server, xcat-dep offers ipmitool-xcat, and none of them is installed.
|
||||
list_packages()
|
||||
{
|
||||
(
|
||||
PATH=""
|
||||
source "$GO_XCAT_SOURCE" || exit 70
|
||||
get_package_list()
|
||||
{
|
||||
case "$1" in
|
||||
xcat-core) echo xcat xcat-server ;;
|
||||
xcat-dep) echo ipmitool-xcat ;;
|
||||
esac
|
||||
}
|
||||
check_package_version()
|
||||
{
|
||||
local package
|
||||
for package in "$@"; do
|
||||
echo '(not installed)'
|
||||
done
|
||||
}
|
||||
list_xcat_packages
|
||||
)
|
||||
}
|
||||
|
||||
# Succeed when the table offers version 1.0-1 of every package.
|
||||
offers_every_package()
|
||||
{
|
||||
local package
|
||||
for package in xcat xcat-server ipmitool-xcat; do
|
||||
grep -Eq "^${package} +\\(not installed\\) +1\\.0-1 *\$" <<<"$1" || return 1
|
||||
done
|
||||
}
|
||||
|
||||
@test "the package table shows the apt candidates" {
|
||||
LANG=C LC_ALL=C run list_packages
|
||||
[ "$status" -eq 0 ] || { printf '%s\n' "$output"; return 1; }
|
||||
offers_every_package "$output" || { printf '%s\n' "$output"; return 1; }
|
||||
}
|
||||
|
||||
@test "the package table shows the candidates that a translated apt reports" {
|
||||
LANG=zh_CN.UTF-8 LC_ALL=zh_CN.UTF-8 run list_packages
|
||||
[ "$status" -eq 0 ] || { printf '%s\n' "$output"; return 1; }
|
||||
offers_every_package "$output" || { printf '%s\n' "$output"; return 1; }
|
||||
}
|
||||
|
||||
@test "an unknown terminal type adds no tput error to the package table" {
|
||||
command -v tput >/dev/null || skip "tput is required"
|
||||
TERM=xcat-unknown-terminal run list_packages
|
||||
[ "$status" -eq 0 ] || { printf '%s\n' "$output"; return 1; }
|
||||
offers_every_package "$output" || { printf '%s\n' "$output"; return 1; }
|
||||
if grep -F 'tput' <<<"$output"; then return 1; fi
|
||||
}
|
||||
|
||||
@test "an empty TERM adds no tput error to the package table" {
|
||||
command -v tput >/dev/null || skip "tput is required"
|
||||
TERM= run list_packages
|
||||
[ "$status" -eq 0 ] || { printf '%s\n' "$output"; return 1; }
|
||||
offers_every_package "$output" || { printf '%s\n' "$output"; return 1; }
|
||||
if grep -F 'tput' <<<"$output"; then return 1; fi
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Answer "apt-cache policy" as apt does, with translated labels unless LC_ALL or LANG is C.
|
||||
#
|
||||
# $@ Package names. The names in APT_UNKNOWN (default "missing") are unknown to apt, and
|
||||
# "nocandidate" is known with no candidate. apt-cache fails after it reports the
|
||||
# package in APT_FAIL_AFTER.
|
||||
apt-cache()
|
||||
{
|
||||
[ "$1" = policy ] || return 1
|
||||
shift
|
||||
local installed='Installed:' candidate='Candidate:' package
|
||||
if [ "${LC_ALL:-${LANG:-}}" != C ]; then
|
||||
installed='已安装:'
|
||||
candidate='候选:'
|
||||
fi
|
||||
for package in "$@"; do
|
||||
case " ${APT_UNKNOWN:-missing} " in
|
||||
*" $package "*) continue ;;
|
||||
esac
|
||||
case "$package" in
|
||||
nocandidate) printf '%s:\n %s (none)\n %s (none)\n' "$package" "$installed" "$candidate" ;;
|
||||
*) printf '%s:\n %s (none)\n %s 1.0-1\n Version table:\n 1.0-1 500\n' \
|
||||
"$package" "$installed" "$candidate" ;;
|
||||
esac
|
||||
[ "$package" != "${APT_FAIL_AFTER:-}" ] || return 100
|
||||
done
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env bats
|
||||
#
|
||||
# retry_install.sh decides a provision succeeded only if all three of tobooted, pingable and
|
||||
# canruncmd are 0. pingable came from a single `ping -c 2`, and ICMP to a node is lossy for a few
|
||||
# seconds after it finishes booting.
|
||||
#
|
||||
# Measured on an openSUSE Leap 15.6 cluster: one sample reported "2 packets transmitted, 0
|
||||
# received" while `xdsh <node> date` returned the node's own clock a second later, so the node was
|
||||
# up and answering SSH. The conjunction failed on ICMP alone and the case did a second full
|
||||
# rinstall, which cost 401 of the 404 seconds between two runs of the same cell. The second run
|
||||
# lost 2 of 3 packets at a moment that was not the decision point and passed first try. The
|
||||
# difference between the runs was which side of a two-packet sample landed.
|
||||
#
|
||||
# node_pingable asks again before concluding. These tests drive it with a stubbed ping, because
|
||||
# what matters is how many times it asks and what it answers -- not whether this host can reach
|
||||
# anything.
|
||||
#
|
||||
# The discriminator is "a node that never answers still reports non-pingable". Removing the
|
||||
# retry must fail the transient case and leave that one passing, or the change cannot be told
|
||||
# apart from deleting the check -- which would turn a flaky probe into one that cannot fail.
|
||||
|
||||
load 'helpers/shell_source'
|
||||
|
||||
NODE=cn01
|
||||
|
||||
setup()
|
||||
{
|
||||
SCRIPT="$(require_repo_file 'xCAT-test/autotest/testcase/commoncmd/retry_install.sh')"
|
||||
COUNT="${BATS_TEST_TMPDIR}/ping-calls"
|
||||
: >"$COUNT"
|
||||
# No sleeping: the retry interval is not what these tests are about.
|
||||
export PING_RETRY_SLEEP=0
|
||||
export PING_TRIES=5
|
||||
}
|
||||
|
||||
# Replaces the ping(8) the function calls. Answers non-zero for the first $1 calls, then zero.
|
||||
# A negative count never answers.
|
||||
stub_ping()
|
||||
{
|
||||
FAIL_FIRST="$1"
|
||||
ping()
|
||||
{
|
||||
local n
|
||||
n=$(( $(read_file_or_empty "$COUNT" | wc -l) + 1 ))
|
||||
echo "call $n" >>"$COUNT"
|
||||
if [ "$FAIL_FIRST" -lt 0 ] || [ "$n" -le "$FAIL_FIRST" ]; then
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
ping_calls()
|
||||
{
|
||||
read_file_or_empty "$COUNT" | wc -l | tr -d ' '
|
||||
}
|
||||
|
||||
@test "sourcing retry_install.sh defines node_pingable and runs no provisioning" {
|
||||
# The main-guard. Without it, sourcing runs lsdef and the rinstall loop.
|
||||
run bash -c "source '$SCRIPT'; type -t node_pingable"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$output" = "function" ]
|
||||
}
|
||||
|
||||
# `run` is required, not stylistic: bats fails a test on any non-zero command in its body, and
|
||||
# `set +e` does not suppress that. Asserting on a non-zero return without `run` aborts the test
|
||||
# instead of measuring it -- which made the veto assertion below fail under a mutation for the
|
||||
# wrong reason, so it could not discriminate.
|
||||
@test "a node whose first samples are lost is pingable once it answers" {
|
||||
# xcat20-mn, exactly: ICMP lost in the window after the boot, then fine.
|
||||
source "$SCRIPT"
|
||||
stub_ping 2
|
||||
run node_pingable "$NODE"
|
||||
[ "$status" -eq 0 ]
|
||||
[ "$(ping_calls)" -eq 3 ]
|
||||
}
|
||||
|
||||
@test "a node that never answers is still not pingable, so a real defect keeps vetoing" {
|
||||
# THE DISCRIMINATOR, and it asserts ONE thing on purpose. Bundling the ask count in here made
|
||||
# it fail under the mutation as a retry property, which is the opposite of discriminating:
|
||||
# this assertion exists to show the change is not "delete the check", so it has to pass
|
||||
# whether or not the retry is present.
|
||||
source "$SCRIPT"
|
||||
stub_ping -1
|
||||
run node_pingable "$NODE"
|
||||
[ "$status" -ne 0 ]
|
||||
}
|
||||
|
||||
@test "a node that never answers is asked PING_TRIES times before giving up" {
|
||||
source "$SCRIPT"
|
||||
stub_ping -1
|
||||
run node_pingable "$NODE"
|
||||
[ "$(ping_calls)" -eq "$PING_TRIES" ]
|
||||
}
|
||||
|
||||
@test "a node that answers at once costs no extra asks" {
|
||||
# The happy path must not get slower: one ask, as before.
|
||||
source "$SCRIPT"
|
||||
stub_ping 0
|
||||
node_pingable "$NODE"
|
||||
[ "$(ping_calls)" -eq 1 ]
|
||||
}
|
||||
@@ -174,7 +174,7 @@ run_xcatroot()
|
||||
done
|
||||
# genimage puts the helper in every initial ramdisk that can receive the root image over UFTP.
|
||||
[ -n "$NO_UFTP_HELPER" ] || sandbox+=(--ro-bind "$(repo_path xCAT-server/share/xcat/netboot/imgutils/xcat-rootimg-fetch.sh)" /lib/xcat-rootimg-fetch.sh)
|
||||
echo "imgurl=$URL XCAT=192.0.2.1:3001 nonodestatus $CMDLINE $UFTP" >"$FX/cmdline"
|
||||
echo "imgurl=$URL XCAT=192.0.2.1:3001 nonodestatus $CMDLINE $UFTP $KERNEL_ARGS" >"$FX/cmdline"
|
||||
echo "$IMAGE_PLAN" >"$FX/image.plan"
|
||||
echo "$CHECKSUM_PLAN" >"$FX/checksum.plan"
|
||||
echo "${MAXWAITS:-100}" >"$FX/maxwaits"
|
||||
@@ -309,3 +309,11 @@ check_each_script()
|
||||
CMDLINE= SCRIPTS=$UFTP_SCRIPTS UFTP="xcat.uftp=1045 xcat.uftpfp=$FP"
|
||||
check_each_script 'packed image' "$URL " 0 'Cannot receive .*rootimg.cpio.gz over UFTP'
|
||||
}
|
||||
|
||||
@test 'the EL10 initial ramdisk copies no dhclient lease and writes no ifcfg file' {
|
||||
SCRIPTS='xCAT-server/share/xcat/netboot/rh/dracut_105/stateless/xcatroot bash'
|
||||
KERNEL_ARGS='ifname=eth0:52:54:00:12:34:56'
|
||||
check_each_script 'packed image' "$URL.sha256 $URL $URL.sha256 " 0 ''
|
||||
run grep -E 'dhclient|network-scripts' "$FX/console"
|
||||
[ "$status" -eq 1 ] || { echo "$output"; return 1; }
|
||||
}
|
||||
|
||||
@@ -8,7 +8,10 @@ Homepage: https://xcat.org/
|
||||
|
||||
Package: xcat-test
|
||||
Architecture: all
|
||||
Depends: ${perl:Depends}, python3-scapy
|
||||
Depends: ${perl:Depends}, python3
|
||||
# blackboxtest needs python3. Only its DHCP steps need scapy, and dhcp.py reports a missing
|
||||
# scapy itself. A hard Depends: on scapy also installs about 255 MB of its Recommends.
|
||||
Recommends: python3-scapy
|
||||
Description: xCAT automated test tool
|
||||
Provides automated test tool and buckets to help test xCAT commands
|
||||
automatically.
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
1772722427.779849
|
||||
RVA23
|
||||
riscv64
|
||||
@@ -0,0 +1,17 @@
|
||||
[general]
|
||||
timestamp = 1772724994.9646769
|
||||
family = openEuler
|
||||
version = 24.03-LTS-SP3
|
||||
name = openEuler-24.03-LTS-SP3
|
||||
variant = Server
|
||||
arch = riscv64
|
||||
packagedir =
|
||||
|
||||
[stage2]
|
||||
mainimage = images/install.img
|
||||
|
||||
[images-riscv64]
|
||||
kernel = images/pxeboot/vmlinuz
|
||||
initrd = images/pxeboot/initrd.img
|
||||
efiboot.img = images/efiboot.img
|
||||
|
||||
@@ -4,5 +4,8 @@ These files are the upstream expanded installation-tree metadata:
|
||||
|
||||
- https://repo.openeuler.org/openEuler-24.03-LTS/OS/ppc64le/
|
||||
- https://repo.openeuler.org/openEuler-24.03-LTS-SP4/OS/x86_64/
|
||||
- https://repo.openeuler.org/openEuler-24.03-LTS-SP3/ISO/riscv64/rva23/,
|
||||
from `openEuler-24.03-LTS-SP3-RVA23-riscv64-dvd.iso`
|
||||
|
||||
Both `.discinfo` descriptions are empty. POWER uses `2403-LTS` in `.treeinfo`.
|
||||
The x86_64 and POWER `.discinfo` descriptions are empty, and the riscv64 one is
|
||||
`RVA23`. POWER uses `2403-LTS` in `.treeinfo`.
|
||||
|
||||
@@ -59,7 +59,14 @@ sub object_attr {
|
||||
sub table_attr {
|
||||
my ($line) = @_;
|
||||
return () unless defined $line;
|
||||
return ($1, $2) if $line =~ /(\w+)\s*=\s*([\w\.\-]+)/;
|
||||
# The same value class as object_attr. A table value holds the same kinds of thing an object
|
||||
# value does: an IPv6 prefix (2001:db8::/64), a path (/install), a comma-separated list of
|
||||
# name servers. The narrower ([\w\.\-]+) this replaces stopped at the first colon or slash and
|
||||
# wrote the truncated value, so `net=2001:db8:176::/64` reached chtab as `net=2001` and
|
||||
# xcattest re-applied that row on every run. Nothing warned.
|
||||
#
|
||||
# The class holds no whitespace and no '#', so a trailing inline comment is still excluded.
|
||||
return ($1, $2) if $line =~ /(\w+)\s*=\s*([:,;\w\.\-\/]+)/;
|
||||
return ();
|
||||
}
|
||||
|
||||
@@ -118,6 +125,39 @@ sub chdef_command {
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
=head3 chtab_command
|
||||
|
||||
Descriptions:
|
||||
The chtab command that applies one row of a [Table_*] block.
|
||||
|
||||
xcattest runs every command through /bin/bash -c, so each word is quoted, the row
|
||||
selector too. A vm.othersettings value carries a semicolon.
|
||||
|
||||
The assignments are sorted, so one conf builds one command.
|
||||
Arguments:
|
||||
$table - the table name, as the section name spells it
|
||||
$key - the key column of the row
|
||||
$name - the value of the key column
|
||||
$attrs - a hash reference of column to value
|
||||
Returns:
|
||||
the command
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
sub chtab_command {
|
||||
my ($table, $key, $name, $attrs) = @_;
|
||||
my @words = ("$key=$name");
|
||||
foreach my $attr (sort keys %$attrs) {
|
||||
next if $attr eq '__KEY__';
|
||||
my $value = defined $attrs->{$attr} ? $attrs->{$attr} : '';
|
||||
push @words, "$table.$attr=$value";
|
||||
}
|
||||
return join ' ', 'chtab', map { _quote($_) } @words;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
=head3 _quote
|
||||
|
||||
Descriptions:
|
||||
|
||||
@@ -247,6 +247,24 @@ answers what the store answers for each path it measures.
|
||||
Check the TAP output for skipped prerequisites. A successful `prove` exit with
|
||||
skipped cases does not qualify those cases.
|
||||
|
||||
`networkmanager_autoconnect.t` runs the NetworkManager helper of the install
|
||||
script library under Bash, with an `nmcli` command fixture, in a private
|
||||
filesystem. It needs Bubblewrap and unprivileged user namespaces:
|
||||
|
||||
```
|
||||
prove xCAT-test/native/networkmanager_autoconnect.t
|
||||
```
|
||||
|
||||
`detect_dhcpd_tcpdump_lookup.t` runs the DHCP server detectors of xCAT-server
|
||||
and xCAT-probe with a `tcpdump` command fixture. The capture cases need a
|
||||
default route on the loopback interface, so they run in mount and network
|
||||
namespaces from `unshare` instead of Bubblewrap. They need `unshare`, `mount`,
|
||||
`ip` and a writable `/var/tmp`, and skip without a private network namespace:
|
||||
|
||||
```
|
||||
prove xCAT-test/native/detect_dhcpd_tcpdump_lookup.t
|
||||
```
|
||||
|
||||
## FIPS policy and discovery keys
|
||||
|
||||
Run the unchanged statelite and Cumulus callers in private filesystems:
|
||||
@@ -295,7 +313,8 @@ On Debian or Ubuntu, install `bubblewrap`, `debhelper`, `devscripts`, `fakeroot`
|
||||
prove xCAT-test/native/xcatd_debian_lifecycle.t \
|
||||
xCAT-test/native/xcatd_restart_callers.t \
|
||||
xCAT-test/native/apache_package_lifecycle.t \
|
||||
xCAT-test/native/package_upgrade_logging.t
|
||||
xCAT-test/native/package_upgrade_logging.t \
|
||||
xCAT-test/native/xcatd_debian_init_state.t
|
||||
```
|
||||
|
||||
On EL8 or EL10, install `bubblewrap`, `rpm-build`, `systemd`, `chkconfig`,
|
||||
@@ -422,13 +441,14 @@ prove xCAT-test/native/install_profile_riscv64.t \
|
||||
xCAT-test/native/netboot_profile_riscv64.t \
|
||||
xCAT-test/native/netboot_profile_postinstall.t \
|
||||
xCAT-test/native/builddebs_riscv64.t \
|
||||
xCAT-test/native/ubuntu_subiquity_template.t
|
||||
xCAT-test/native/ubuntu_subiquity_template.t \
|
||||
xCAT-test/native/ubuntu_subiquity_install_disk.t
|
||||
```
|
||||
|
||||
The renderers need the system Perl with the xCAT dependencies, XML::Simple,
|
||||
DBD::SQLite, Capture::Tiny, and File::Slurper. The sandbox clears the environment
|
||||
and does not mount perlbrew or local::lib directories. The Subiquity case also
|
||||
needs /usr/bin/python3 with PyYAML; on EL8, install python36 for that path.
|
||||
and does not mount perlbrew or local::lib directories. The Subiquity cases also
|
||||
need /usr/bin/python3 with PyYAML; on EL8, install python36 for that path.
|
||||
The Debian case needs debhelper, devscripts, fakeroot, and reprepro, and skips
|
||||
on non-Debian hosts. Each case creates its own temporary files and database.
|
||||
The temporary directory must allow execution; set TMPDIR if /tmp is noexec.
|
||||
|
||||
@@ -129,9 +129,11 @@ my $findmnt = fake_command('findmnt', <<'SH');
|
||||
printf '/dev/vda1\n'
|
||||
SH
|
||||
my $lsblk = fake_command('lsblk', <<'SH');
|
||||
[ -n "$XCAT_TEST_NO_PARTUUID" ] && case "$*" in *PARTUUID*) exit 0 ;; esac
|
||||
case "$*" in
|
||||
*PKNAME*) printf "vda\n" ;;
|
||||
*PARTN*) printf "1\n" ;;
|
||||
*PARTUUID*) printf "0b8f4c1e-6a51-4b4e-9d7e-2f3a1c5d7e90\n" ;;
|
||||
esac
|
||||
SH
|
||||
my $efibootmgr = fake_command('efibootmgr', <<'SH');
|
||||
@@ -139,9 +141,10 @@ printf '%s\n' "$*" >> "$XCAT_EFI_LOG"
|
||||
case "$*" in
|
||||
'') exit 0 ;;
|
||||
'-v')
|
||||
printf 'Boot0001* Rocky HD(1,GPT,...)/File(\\EFI\\rocky\\shimx64.efi)\n'
|
||||
printf 'Boot0002* OldRiscv HD(1,GPT,...)/File(\\EFI\\rocky\\grubriscv64.efi)\n'
|
||||
printf 'Boot0001* Rocky Linux\tHD(1,GPT,0b8f4c1e-6a51-4b4e-9d7e-2f3a1c5d7e90,0x800,0x80000)/File(\\EFI\\rocky\\shimx64.efi)\n'
|
||||
printf 'Boot0002* Rocky Linux\tHD(1,GPT,0B8F4C1E-6A51-4B4E-9D7E-2F3A1C5D7E90,0x800,0x80000)/File(\\EFI\\rocky\\grubriscv64.efi)\n'
|
||||
printf 'Boot0003* Network PXE\n'
|
||||
printf 'Boot0004* Ubuntu\tHD(1,GPT,5d2e8a47-0c3b-4f19-8e6a-91b7c4d2f063,0x800,0x100000)/\\EFI\\ubuntu\\grubriscv64.efi\n'
|
||||
exit 0
|
||||
;;
|
||||
*'-c'*) exit "${XCAT_EFI_CREATE_RC:-0}" ;;
|
||||
@@ -170,7 +173,8 @@ for my $rendered (@rendered_profiles) {
|
||||
my $root = installed_root(1, sandbox_root());
|
||||
make_path("$root/etc/systemd/system/multi-user.target.wants", "$root/etc/yum.repos.d");
|
||||
write_text("$root/etc/yum.repos.d/rocky.repo", "[baseos]\nname=BaseOS\nenabled=1\n");
|
||||
write_text("$root/tmp/pre-install.log", "pre-install fixture diagnostic\n");
|
||||
make_path("$root/installer-tmp");
|
||||
write_text("$root/installer-tmp/pre-install.log", "pre-install fixture diagnostic\n");
|
||||
copy(repo_path('xCAT/postscripts/xcatlib.sh'), "$root/xcatlib.sh") or die $!;
|
||||
write_text("$root/mypostscript.node", "#!/bin/bash\nMASTER=192.0.2.1\ntouch /fixture/postscript-ran\n");
|
||||
for my $name (qw(uname findmnt lsblk efibootmgr)) {
|
||||
@@ -186,9 +190,14 @@ for my $rendered (@rendered_profiles) {
|
||||
my ($interpreter) = $post->[0] =~ /--interpreter=(\S+)/;
|
||||
$interpreter //= '/bin/sh';
|
||||
write_text("$root/post.sh", $post->[1]);
|
||||
my ($rc, $log) = sandbox_run($root, {
|
||||
env => {XCAT_EFI_LOG => '/fixture/efi.log'},
|
||||
}, 'timeout', '30', $interpreter, '/fixture/post.sh');
|
||||
my %options = (env => {XCAT_EFI_LOG => '/fixture/efi.log'});
|
||||
# anaconda runs a --nochroot block in the installer, which has its own /tmp and the installed system at /mnt/sysimage
|
||||
if ($post->[0] =~ /(?:^|\s)--nochroot(?:\s|$)/) {
|
||||
$options{writable} = {map { ("$root/$_->[0]" => $_->[1]) }
|
||||
['installer-tmp', '/tmp'], ['boot', '/mnt/sysimage/boot'],
|
||||
['etc', '/mnt/sysimage/etc'], ['log', '/mnt/sysimage/var/log']};
|
||||
}
|
||||
my ($rc, $log) = sandbox_run($root, \%options, 'timeout', '30', $interpreter, '/fixture/post.sh');
|
||||
is($rc, 0, 'post block ' . ++$index . ' completes')
|
||||
or diag($log, read_text("$root/log/xcat/xcat.log"));
|
||||
}
|
||||
@@ -239,6 +248,7 @@ my $efi_calls = read_text($efi_log);
|
||||
like($efi_calls, qr/^-q -b 0001 -B$/m, 'the invalid x86 boot entry is removed');
|
||||
like($efi_calls, qr/^-q -b 0002 -B$/m, 'the prior RISC-V boot entry is removed');
|
||||
unlike($efi_calls, qr/0003/, 'unrelated firmware entries are retained');
|
||||
unlike($efi_calls, qr/-b 0004 /, 'the boot entry of a system on another disk is retained');
|
||||
like(
|
||||
$efi_calls,
|
||||
qr/^-q -c -d \/dev\/vda -p 1 -L Rocky Linux -l \\EFI\\rocky\\grubriscv64\.efi$/m,
|
||||
@@ -262,4 +272,11 @@ unlink($efi_log);
|
||||
is($status, 0, 'an efibootmgr create failure remains nonfatal');
|
||||
like($output, qr/firmware will use \\EFI\\BOOT\\BOOTRISCV64\.EFI/, 'the fallback path is reported after an efibootmgr failure');
|
||||
|
||||
unlink($efi_log);
|
||||
($status, $output) = run_post($root, XCAT_TEST_NO_PARTUUID => 1);
|
||||
is($status, 0, 'the fix-up completes when lsblk reports no ESP partition GUID');
|
||||
my $unknown_calls = read_text($efi_log);
|
||||
unlike($unknown_calls, qr/ -B$/m, 'no boot entry is removed when the ESP partition GUID is unknown');
|
||||
like($unknown_calls, qr/^-q -c -d \/dev\/vda -p 1 -L Rocky Linux /m, 'the boot entry is still registered without the ESP partition GUID');
|
||||
|
||||
done_testing();
|
||||
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use FindBin;
|
||||
use File::Slurper qw(read_text write_text);
|
||||
use File::Path qw(make_path);
|
||||
use File::Temp qw(tempdir);
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use lib "$FindBin::Bin/../../perl-xCAT";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils";
|
||||
use Test::More;
|
||||
use XCAT::Test::Process qw(run_command);
|
||||
use imgutils;
|
||||
|
||||
plan skip_all => 'systemd condition evaluation requires Linux' unless $^O eq 'linux';
|
||||
my ($analyze) = grep { -x $_ } qw(/usr/bin/systemd-analyze /bin/systemd-analyze);
|
||||
BAIL_OUT('Install systemd to run this test') unless $analyze;
|
||||
|
||||
# systemd evaluates the drop-in's own conditions; SYSTEMD_PROC_CMDLINE stands in
|
||||
# for the kernel command line of the node.
|
||||
my $root = tempdir(CLEANUP => 1);
|
||||
make_path("$root/usr/lib/systemd/system");
|
||||
write_text("$root/usr/lib/systemd/system/kdump.service", "[Service]\n");
|
||||
imgutils::skip_kdump_without_dump_memory($root);
|
||||
my @conditions = grep { /^Condition/ }
|
||||
split /\n/, read_text("$root/etc/systemd/system/kdump.service.d/xcat-dump-memory.conf");
|
||||
ok(@conditions, 'the drop-in carries conditions');
|
||||
|
||||
for my $case (
|
||||
['crashkernel=256M quiet', 1, 'a crashkernel= reservation'],
|
||||
['fadump=on fadump_reserve_mem=1G dump=nfs://192.0.2.1/dumps', 1, 'a POWER firmware-assisted dump'],
|
||||
['quiet console=ttyS0,115200', 0, 'no dump memory'],
|
||||
) {
|
||||
my ($cmdline, $start, $label) = @$case;
|
||||
local $ENV{SYSTEMD_PROC_CMDLINE} = $cmdline;
|
||||
my ($status, $output) = run_command($analyze, 'condition', @conditions);
|
||||
is($status == 0 ? 1 : 0, $start, ($start ? 'kdump.service starts with ' : 'kdump.service does not start with ') . $label)
|
||||
or diag($output);
|
||||
}
|
||||
|
||||
done_testing();
|
||||
@@ -0,0 +1,101 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use File::Path qw(make_path);
|
||||
use File::Slurper qw(read_binary write_binary);
|
||||
use Test::More;
|
||||
use XCAT::Test::File qw(repo_path);
|
||||
use XCAT::Test::Sandbox qw(sandbox_root sandbox_run);
|
||||
use XCAT::Test::Template qw(template_database set_row render_template);
|
||||
|
||||
plan skip_all => 'installer execution requires Linux namespaces' unless $^O eq 'linux';
|
||||
my $database = template_database();
|
||||
set_row('site', {key => 'nodestatus'}, {value => 0});
|
||||
write_binary("$database/image.pkglist", '');
|
||||
|
||||
# Credentials in the forms that kickstart's shell-style parser accepts.
|
||||
my $custom = join("\n",
|
||||
'part /data --fstype=xfs --size=1024 --encrypted --passphrase=s3cret-one --ondisk=sdb',
|
||||
'logvol /home --vgname=vg --name=home --size=1 --encrypted --passphrase "s3cret two"',
|
||||
"raid /srv --level=1 --device=md0 --encrypted --passphrase='s3cret three' raid.01 raid.02",
|
||||
'part /esc --size=1 --encrypted --passphrase=prefix\\ s3cret\\ four --ondisk=sdb',
|
||||
'part /quote --size=1 --encrypted --pass"phrase"="s3cret \\"five\\"" --ondisk=sdb',
|
||||
'bootloader --iscrypted --password=s3cret-six',
|
||||
'rootpw --plaintext s3cret-seven');
|
||||
write_binary("$database/partitionfile", "$custom\n");
|
||||
write_binary("$database/partscript", "#!/bin/sh\ncat >/tmp/partitionfile <<'EOF'\n$custom\nEOF\n");
|
||||
|
||||
# Commands that the pre-installation scripts call in the installer.
|
||||
sub installer_root {
|
||||
my $root = sandbox_root();
|
||||
make_path("$root/libexec");
|
||||
write_binary("$root/partitions", "major minor #blocks name\n\n 8 16 524288000 sdb\n");
|
||||
write_binary("$root/bin/udevadm", <<'SH');
|
||||
#!/bin/sh
|
||||
case "$*" in
|
||||
'info --attribute-walk --name=sdb') printf ' ATTRS{size}=="1024000000"\n DRIVERS=="ahci"\n' ;;
|
||||
'info --query=property --name='*) printf 'DEVTYPE=disk\n' ;;
|
||||
*) exit 97 ;;
|
||||
esac
|
||||
SH
|
||||
write_binary("$root/bin/find", "#!/bin/sh\nprintf '/usr/bin/awk\\n'\n");
|
||||
write_binary("$root/libexec/platform-python", "#!/bin/sh\nexit 0\n");
|
||||
write_binary("$root/bin/mknod", "#!/bin/sh\n: >\"\$1\"\n");
|
||||
for my $name (qw(logger vgs vgchange vgremove chown)) {
|
||||
write_binary("$root/bin/$name", "#!/bin/sh\nexit 0\n");
|
||||
}
|
||||
chmod oct('755'), glob("$root/bin/*"), "$root/libexec/platform-python" or die $!;
|
||||
return $root;
|
||||
}
|
||||
|
||||
for my $case (['rh/compute.rhels9.tmpl', 'alma9.6'], ['rh/compute.rhels10.tmpl', 'rhels10']) {
|
||||
my ($template, $os) = @$case;
|
||||
for my $input (['generated', undef], ['custom file', "$database/partitionfile"],
|
||||
['custom script', "s:$database/partscript"]) {
|
||||
my ($kind, $partitionfile) = @$input;
|
||||
for my $mode (0, 1, 2) {
|
||||
subtest "$template, $kind, xcatdebugmode $mode" => sub {
|
||||
set_row('site', {key => 'xcatdebugmode'}, {value => $mode});
|
||||
set_row('nodetype', {node => 'node'}, {os => $os, arch => 'x86_64', provmethod => 'install'});
|
||||
render_template($database, repo_path("xCAT-server/share/xcat/install/$template"), "$database/ks",
|
||||
'node', "$database/image.pkglist", "/install/$os/x86_64", 'rh', $partitionfile,
|
||||
{xcatmaster => '192.0.2.1'}, osarch => 'x86_64');
|
||||
my ($pre) = read_binary("$database/ks") =~ /^%pre\b[^\n]*\n(.*?)^%end$/ms;
|
||||
write_binary("$database/pre.sh", $pre // '');
|
||||
my $root = installer_root();
|
||||
my ($rc, $output) = sandbox_run($root, {
|
||||
read_only => {"$root/partitions" => '/proc/partitions', "$root/libexec" => '/usr/libexec',
|
||||
"$database/pre.sh" => '/pre.sh'},
|
||||
env => {MASTER_IP => '192.0.2.1', log_label => 'install'},
|
||||
}, '/bin/bash', '-c', '. /pre.sh');
|
||||
is($rc, 0, 'the %pre block completes') or diag($output);
|
||||
my $log = -f "$root/tmp/pre-install.log" ? read_binary("$root/tmp/pre-install.log") : '';
|
||||
my ($scheme) = $log =~ /^=+ The Partition Scheme =+\n(.*?)^=+$/ms;
|
||||
if ($mode) {
|
||||
like($log, qr/^\++ /m, 'traces the %pre block into the pre-install log');
|
||||
}
|
||||
if (!defined $partitionfile) {
|
||||
like($scheme // '', qr/^volgroup xcatvg /m, 'logs the partition scheme that xCAT generated');
|
||||
return;
|
||||
}
|
||||
like($scheme // '', qr/^The custom partition file is not logged\.$/m,
|
||||
'logs a notice in place of the custom partition file');
|
||||
unlike($scheme // '', qr/^(?:part|logvol|raid|bootloader|rootpw) /m,
|
||||
'logs no line of the custom partition file');
|
||||
unlike($log . $output, qr/s3cret/, 'leaves no credential in the log or the trace');
|
||||
# The decoder prints three bytes at a time, so a traced decode spells them out in hex.
|
||||
my $traced = join('', map { pack('H*', join('', /\\x([0-9A-Fa-f]{2})/g)) }
|
||||
$log =~ /^\++ printf '([^']*)'$/mg);
|
||||
unlike($traced, qr/s3cret/, 'traces no decoded byte of the custom input');
|
||||
like(read_binary("$root/tmp/partitionfile"), qr/\A\Q$custom\E\n?\z/,
|
||||
'hands anaconda the custom partition definitions');
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
set_row('site', {key => 'xcatdebugmode'}, {value => 0});
|
||||
|
||||
done_testing();
|
||||
@@ -0,0 +1,80 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use File::Path qw(make_path);
|
||||
use File::Slurper qw(read_text write_text);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use Test::More;
|
||||
|
||||
use XCAT::Test::File qw(repo_path);
|
||||
use XCAT::Test::Sandbox qw(sandbox_root sandbox_run);
|
||||
use XCAT::Test::Template qw(template_database set_row render_template);
|
||||
|
||||
plan skip_all => 'kickstart execution requires Linux' unless $^O eq 'linux';
|
||||
my $database = template_database();
|
||||
|
||||
# The kickstart templates whose %pre writes /tmp/pre-install.log, each with an OS that uses it.
|
||||
my @templates = (
|
||||
[ 'rh/compute.rhels10.tmpl', 'rhels10.0', 'x86_64', 'rh' ],
|
||||
[ 'rh/compute.rhels9.tmpl', 'alma9.6', 'x86_64', 'rh' ],
|
||||
[ 'rh/compute.rhels8.tmpl', 'rocky8.10', 'x86_64', 'rh' ],
|
||||
[ 'centos/compute.centos8.tmpl', 'centos8', 'x86_64', 'centos' ],
|
||||
[ 'openeuler/compute.openeuler.tmpl', 'openeuler24.03sp3', 'x86_64', 'openeuler' ],
|
||||
[ 'rh/compute.rhels10.riscv64.tmpl', 'rhels10.0', 'riscv64', 'rh' ],
|
||||
[ 'rocky/service.rocky10.riscv64.tmpl', 'rocky10.2', 'riscv64', 'rocky' ],
|
||||
);
|
||||
my $diagnostic = "pre-install fixture diagnostic\n";
|
||||
|
||||
for my $case (@templates) {
|
||||
my ($template, $os, $arch, $platform) = @$case;
|
||||
subtest $template => sub {
|
||||
set_row('nodetype', {node => 'node'}, {os => $os, arch => $arch, provmethod => 'install'});
|
||||
my $path = repo_path("xCAT-server/share/xcat/install/$template");
|
||||
(my $pkglist = $path) =~ s/\.tmpl$/.pkglist/;
|
||||
$pkglist = '' unless -r $pkglist;
|
||||
my $output = "$database/ks";
|
||||
render_template($database, $path, $output, 'node', $pkglist, '/install/media', $platform, undef,
|
||||
{xcatmaster => '192.0.2.1'});
|
||||
my $ks = read_text($output);
|
||||
like($ks, qr/^%pre\b.*?pre-install\.log.*?^%end/ms, 'the %pre block writes the pre-install log');
|
||||
|
||||
my @posts;
|
||||
while ($ks =~ /^%post([^\n]*)\n(.*?)^%end/msg) {
|
||||
push @posts, [$1, $2];
|
||||
}
|
||||
my @installer = grep { $posts[$_][0] =~ /(?:^|\s)--nochroot(?:\s|$)/ } 0 .. $#posts;
|
||||
my ($chroot) = grep { $posts[$_][0] !~ /(?:^|\s)--nochroot(?:\s|$)/ } 0 .. $#posts;
|
||||
ok(defined $chroot, 'has a %post block that runs in the installed system');
|
||||
|
||||
# anaconda keeps the installer's /tmp out of the chroot, so only a --nochroot block can read the log
|
||||
for my $earlier ('', "earlier entry\n") {
|
||||
my $label = length($earlier) ? 'an existing log' : 'a new log';
|
||||
my $root = sandbox_root();
|
||||
my $xcatlog = "$root/log/xcat/xcat.log";
|
||||
make_path("$root/installer-tmp");
|
||||
write_text("$root/installer-tmp/pre-install.log", $diagnostic);
|
||||
if (length($earlier)) {
|
||||
make_path("$root/log/xcat");
|
||||
write_text($xcatlog, $earlier);
|
||||
chmod(oct('644'), $xcatlog) or die $!;
|
||||
}
|
||||
for my $index (@installer) {
|
||||
my ($interpreter) = $posts[$index][0] =~ /--interpreter=(\S+)/;
|
||||
write_text("$root/post.sh", $posts[$index][1]);
|
||||
my ($rc, $log) = sandbox_run($root, {
|
||||
writable => {"$root/installer-tmp" => '/tmp', "$root/log" => '/mnt/sysimage/var/log'},
|
||||
}, $interpreter // '/bin/sh', '/fixture/post.sh');
|
||||
is($rc, 0, "%post --nochroot block $index completes for $label") or diag($log);
|
||||
}
|
||||
is(-f $xcatlog ? read_text($xcatlog) : '', $earlier . $diagnostic,
|
||||
"appends the pre-install log to $label of the installed system");
|
||||
}
|
||||
ok(@installer && defined $chroot && $installer[0] < $chroot,
|
||||
'copies it before the first %post block in the installed system writes that log');
|
||||
};
|
||||
}
|
||||
|
||||
done_testing();
|
||||
+25
-24
@@ -2,15 +2,16 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use File::Path qw(make_path);
|
||||
use File::Slurper qw(read_binary write_binary);
|
||||
use File::Spec;
|
||||
use File::Temp qw(tempdir);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use Test::More;
|
||||
|
||||
use XCAT::Test::File qw(repo_path);
|
||||
use XCAT::Test::Sandbox qw(sandbox_root sandbox_run);
|
||||
|
||||
plan skip_all => 'scriptlib execution requires Linux namespaces' unless $^O eq 'linux';
|
||||
|
||||
my $scriptlib = repo_path(
|
||||
File::Spec->catfile(
|
||||
@@ -19,17 +20,14 @@ my $scriptlib = repo_path(
|
||||
);
|
||||
-r $scriptlib or die("$scriptlib is required");
|
||||
|
||||
is( system( 'bash', '-n', $scriptlib ), 0,
|
||||
my $root = sandbox_root();
|
||||
is( ( sandbox_run( $root, { read_only => { $scriptlib => '/scriptlib' } },
|
||||
'/bin/bash', '-n', '/scriptlib' ) )[0], 0,
|
||||
'the install script library has valid Bash syntax' );
|
||||
|
||||
my $tmpdir = tempdir( CLEANUP => 1 );
|
||||
my $test_bin = File::Spec->catdir( $tmpdir, 'bin' );
|
||||
my $empty_bin = File::Spec->catdir( $tmpdir, 'empty-bin' );
|
||||
make_path( $test_bin, $empty_bin );
|
||||
|
||||
my $nmcli_log = File::Spec->catfile( $tmpdir, 'nmcli.log' );
|
||||
my $message_log = File::Spec->catfile( $tmpdir, 'messages.log' );
|
||||
my $fake_nmcli = File::Spec->catfile( $test_bin, 'nmcli' );
|
||||
my $nmcli_log = File::Spec->catfile( $root, 'nmcli.log' );
|
||||
my $message_log = File::Spec->catfile( $root, 'messages.log' );
|
||||
my $fake_nmcli = File::Spec->catfile( $root, 'bin', 'nmcli' );
|
||||
write_binary( $fake_nmcli, <<'SH' );
|
||||
#!/bin/sh
|
||||
{
|
||||
@@ -47,8 +45,7 @@ fi
|
||||
SH
|
||||
chmod 0755, $fake_nmcli or die "Unable to make $fake_nmcli executable: $!";
|
||||
|
||||
my $driver = File::Spec->catfile( $tmpdir, 'run-helper' );
|
||||
write_binary( $driver, <<'SH' );
|
||||
write_binary( File::Spec->catfile( $root, 'run-helper' ), <<'SH' );
|
||||
#!/bin/bash
|
||||
msgutil_r() {
|
||||
{
|
||||
@@ -62,7 +59,7 @@ msgutil_r() {
|
||||
. "$XCAT_TEST_SCRIPTLIB"
|
||||
xcat_enable_active_nm_autoconnect "$@"
|
||||
SH
|
||||
chmod 0755, $driver or die "Unable to make $driver executable: $!";
|
||||
my $driver = '/fixture/run-helper';
|
||||
|
||||
my $connections = join( "\n",
|
||||
'primary uplink:activated', 'backup:deactivated',
|
||||
@@ -170,15 +167,19 @@ sub run_program {
|
||||
write_binary( $nmcli_log, '' );
|
||||
write_binary( $message_log, '' );
|
||||
|
||||
local %ENV = %ENV;
|
||||
$ENV{PATH} = $has_nmcli ? "$test_bin:$ENV{PATH}" : $empty_bin;
|
||||
$ENV{XCATDEBUGMODE} = $options{debug} // '0';
|
||||
$ENV{MASTER_IP} = '192.0.2.10';
|
||||
$ENV{XCAT_TEST_MESSAGE_LOG} = $message_log;
|
||||
$ENV{XCAT_TEST_NMCLI_LOG} = $nmcli_log;
|
||||
$ENV{XCAT_TEST_NMCLI_OUTPUT} = $options{connections} // '';
|
||||
$ENV{XCAT_TEST_SCRIPTLIB} = $scriptlib;
|
||||
my %env = (
|
||||
XCATDEBUGMODE => $options{debug} // '0',
|
||||
MASTER_IP => '192.0.2.10',
|
||||
XCAT_TEST_MESSAGE_LOG => '/fixture/messages.log',
|
||||
XCAT_TEST_NMCLI_LOG => '/fixture/nmcli.log',
|
||||
XCAT_TEST_NMCLI_OUTPUT => $options{connections} // '',
|
||||
XCAT_TEST_SCRIPTLIB => '/scriptlib',
|
||||
);
|
||||
$env{PATH} = '/fixture/empty-bin' unless $has_nmcli;
|
||||
|
||||
my $status = system( '/bin/bash', $program, @{$arguments} );
|
||||
return $status == -1 ? 255 : $status >> 8;
|
||||
my ( $status, $output ) = sandbox_run( $root,
|
||||
{ read_only => { $scriptlib => '/scriptlib' }, env => \%env },
|
||||
'/bin/bash', $program, @{$arguments} );
|
||||
diag($output) if $status;
|
||||
return $status;
|
||||
}
|
||||
@@ -49,23 +49,39 @@ for my $kernel (qw(vmlinux image modules)) {
|
||||
is(read_text("$case/image/kernel"), "new kernel\n", "$kernel layout publishes its kernel");
|
||||
is(read_text("$case/image/initrd-stateless.gz"), "new initrd\n", "$kernel layout publishes its initrd");
|
||||
}
|
||||
my ($rc, $state, $output, $case) = run_case('openeuler24.03sp3', 'lock', 'vmlinuz', 1);
|
||||
isnt($rc, 0, 'lock refusal is fatal');
|
||||
like($output, qr/Could not acquire image operation lock/, 'lock refusal reports the contested image');
|
||||
is($state->{lock_calls}, 1, 'lock refusal uses the existing lock owner');
|
||||
is($state->{dracut_calls}, 0, 'lock refusal does not run dracut');
|
||||
is(read_text("$case/image/kernel"), "old kernel\n", 'lock refusal preserves kernel');
|
||||
is(read_text("$case/image/initrd-stateless.gz"), "old initrd\n", 'lock refusal preserves initrd');
|
||||
is_deeply($state->{commands}, [], 'lock refusal does not run mount cleanup against the active build');
|
||||
is_deeply([glob("$case/image/.genimage*")], [], 'lock refusal creates no staging directory');
|
||||
my ($rc, $state, $output, $case);
|
||||
for my $os (qw(openeuler24.03sp3 rhels9.6)) {
|
||||
($rc, $state, $output, $case) = run_case($os, 'lock', 'vmlinuz', 1);
|
||||
isnt($rc, 0, "$os lock refusal is fatal");
|
||||
like($output, qr/Could not acquire image operation lock/, "$os lock refusal reports the contested image");
|
||||
is($state->{lock_calls}, 1, "$os lock refusal uses the existing lock owner");
|
||||
is($state->{dracut_calls}, 0, "$os lock refusal does not run dracut");
|
||||
is(read_text("$case/image/kernel"), "old kernel\n", "$os lock refusal preserves kernel");
|
||||
is(read_text("$case/image/initrd-$_.gz"), "old initrd\n", "$os lock refusal preserves the $_ initrd")
|
||||
for qw(statelite stateless);
|
||||
is_deeply($state->{commands}, [], "$os lock refusal does not run mount cleanup against the active build");
|
||||
is_deeply([glob("$case/image/.genimage*")], [], "$os lock refusal creates no staging directory");
|
||||
}
|
||||
|
||||
for my $failure (qw(none kernel-copy dracut move-initrd)) {
|
||||
my %el_dracut_calls = (none => 2, 'kernel-copy' => 0, dracut => 1, 'move-initrd' => 1, 'publish-initrd' => 2);
|
||||
for my $failure (qw(none kernel-copy dracut move-initrd publish-initrd)) {
|
||||
($rc, $state, $output, $case) = run_case('rhels9.6', $failure, 'vmlinuz', 1);
|
||||
is($rc == 0 ? 0 : 1, $failure eq 'dracut' ? 1 : 0, "EL $failure retains its exit behavior") or diag($output);
|
||||
is(read_text("$case/image/kernel"), $failure eq 'kernel-copy' ? "old kernel\n" : "new kernel\n",
|
||||
"EL $failure retains kernel copy behavior");
|
||||
is($state->{dracut_calls}, $failure eq 'dracut' ? 1 : 2, "EL $failure retains both initrd modes");
|
||||
is($state->{lock_calls}, 0, "EL $failure retains its existing onlyinitrd lock behavior");
|
||||
my $label = "EL $failure";
|
||||
my $set = $failure eq 'none' ? 'new' : 'old';
|
||||
if ($failure eq 'none') {
|
||||
is($rc, 0, "$label completes") or diag($output);
|
||||
} else {
|
||||
isnt($rc, 0, "$label fails");
|
||||
like($output, qr/Error: failed to (?:copy|generate|move|publish).*?(?:kernel|ramdisk)/i,
|
||||
"$label reports the failed boot file operation");
|
||||
}
|
||||
is(read_text("$case/image/kernel"), "$set kernel\n", "$label leaves the $set kernel");
|
||||
is(read_text("$case/image/initrd-$_.gz"), "$set initrd\n", "$label leaves the $set $_ initrd")
|
||||
for qw(statelite stateless);
|
||||
is($state->{dracut_calls}, $el_dracut_calls{$failure}, "$label stops at the first failed step");
|
||||
is($state->{lock_calls}, 1, "$label acquires the image operation lock");
|
||||
is_deeply([glob("$case/image/rootimg/tmp/initrd.*.gz")], [], "$label removes temporary dracut output");
|
||||
is_deeply([glob("$case/image/.genimage*")], [], "$label removes boot staging files");
|
||||
}
|
||||
|
||||
done_testing();
|
||||
@@ -86,7 +102,7 @@ sub run_case {
|
||||
chmod 0000, $kernel_file if $failure eq 'kernel-copy';
|
||||
if ($old) {
|
||||
write_text("$case/image/kernel", "old kernel\n");
|
||||
write_text("$case/image/initrd-stateless.gz", "old initrd\n");
|
||||
write_text("$case/image/initrd-$_.gz", "old initrd\n") for qw(statelite stateless);
|
||||
}
|
||||
if ($repositories) {
|
||||
make_path("$root/etc/yum.repos.d");
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use File::Copy qw(copy);
|
||||
use File::Path qw(make_path);
|
||||
use File::Slurper qw(read_text write_text);
|
||||
use File::Temp qw(tempdir);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils";
|
||||
use Test::More;
|
||||
|
||||
use imgutils;
|
||||
use XCAT::Test::File qw(repo_path);
|
||||
use XCAT::Test::Sandbox qw(sandbox_root sandbox_run);
|
||||
use XCAT::Test::Template qw(template_database set_row render_template);
|
||||
|
||||
plan skip_all => 'kickstart %post execution requires Linux' unless $^O eq 'linux';
|
||||
my $database = template_database();
|
||||
require xCAT::SvrUtils;
|
||||
set_row('passwd', {key => 'system', username => 'root'}, {password => '$6$fixture$encrypted'});
|
||||
set_row('nodetype', {node => 'node'}, {os => 'openeuler24.03sp4', arch => 'riscv64', provmethod => 'install'});
|
||||
|
||||
my $dropin = 'etc/systemd/system/kdump.service.d/xcat-dump-memory.conf';
|
||||
my $image = tempdir(CLEANUP => 1);
|
||||
make_path("$image/usr/lib/systemd/system");
|
||||
write_text("$image/usr/lib/systemd/system/kdump.service", "[Service]\n");
|
||||
imgutils::skip_kdump_without_dump_memory($image);
|
||||
my $stateless = read_text("$image/$dropin");
|
||||
|
||||
sub post_root {
|
||||
my (%units) = @_;
|
||||
my $root = sandbox_root();
|
||||
make_path("$root/units", "$root/etc/systemd/system", "$root/etc/yum.repos.d");
|
||||
write_text("$root/units/$_", $units{$_}) for keys %units;
|
||||
write_text("$root/tmp/pre-install.log", "pre-install fixture diagnostic\n");
|
||||
copy(repo_path('xCAT/postscripts/xcatlib.sh'), "$root/xcatlib.sh") or die $!;
|
||||
write_text("$root/mypostscript.node", "#!/bin/bash\nMASTER=192.0.2.1\ntouch /fixture/postscript-ran\n");
|
||||
for my $name (qw(curl logger sleep updateflag.awk nmcli openssl)) {
|
||||
copy(repo_path('xCAT-test/fixtures/install-profile/command'), "$root/bin/$name") or die $!;
|
||||
chmod 0755, "$root/bin/$name" or die $!;
|
||||
}
|
||||
return $root;
|
||||
}
|
||||
|
||||
my $base = repo_path('xCAT-server/share/xcat/install/openeuler');
|
||||
for my $profile (qw(compute service)) {
|
||||
subtest "$profile post-install sequence" => sub {
|
||||
my $tmpl = xCAT::SvrUtils->get_tmpl_file_name($base, $profile, 'openeuler24.03sp4', 'riscv64');
|
||||
my $pkglist = xCAT::SvrUtils->get_pkglist_file_name($base, $profile, 'openeuler24.03sp4', 'riscv64');
|
||||
my $output = "$database/$profile.ks";
|
||||
render_template($database, $tmpl, $output, 'node', $pkglist, '/install/media', 'openeuler', undef,
|
||||
{xcatmaster => '192.0.2.1'});
|
||||
my @posts;
|
||||
my $rendered = read_text($output);
|
||||
while ($rendered =~ /^%post([^\n]*)\n(.*?)^%end/msg) {
|
||||
push @posts, [$1, $2];
|
||||
}
|
||||
ok(@posts, 'renders a %post section');
|
||||
|
||||
for my $case (
|
||||
[{'kdump.service' => "[Service]\nExecStart=/usr/bin/kdumpctl start\n"}, $stateless,
|
||||
'installs the drop-in that stateless images get'],
|
||||
[{'NetworkManager.service' => "[Service]\n"}, undef, 'adds no drop-in without kdump.service'],
|
||||
) {
|
||||
my ($units, $expected, $label) = @$case;
|
||||
my $root = post_root(%$units);
|
||||
my $index = 0;
|
||||
for my $post (@posts) {
|
||||
my ($interpreter) = $post->[0] =~ /--interpreter=(\S+)/;
|
||||
write_text("$root/post.sh", $post->[1]);
|
||||
my ($rc, $log) = sandbox_run($root, {read_only => {"$root/units" => '/usr/lib/systemd/system'}},
|
||||
'timeout', '30', $interpreter // '/bin/sh', '/fixture/post.sh');
|
||||
is($rc, 0, '%post section ' . ++$index . ' completes')
|
||||
or diag($log, read_text("$root/log/xcat/xcat.log"));
|
||||
}
|
||||
ok(-e "$root/postscript-ran", 'runs the rendered sequence through the downloaded postscript');
|
||||
ok(!-e "$root/unexpected-command", 'external fixtures accept the requested operations');
|
||||
is(-f "$root/$dropin" ? read_text("$root/$dropin") : undef, $expected, $label);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
done_testing();
|
||||
@@ -28,6 +28,9 @@ exec chroot "$root" /bin/bash -c '
|
||||
printf "PAYLOAD="; cat /sysroot/native-marker
|
||||
if [ -f /sysroot/localdisk-ran ]; then echo LOCALDISK_RAN; fi
|
||||
if [ -f /hooks/initqueue/xcat.sh ]; then echo INITQUEUE_READY; fi
|
||||
for lease in /sysroot/var/lib/NetworkManager/*.lease; do
|
||||
[ -f "$lease" ] && printf "NMLEASE=%s:%s\n" "${lease##*/}" "$(cat "$lease")"
|
||||
done
|
||||
exit "$rc"
|
||||
'
|
||||
SH
|
||||
@@ -40,7 +43,7 @@ for my $variant (qw(dracut_047 dracut_105/stateless dracut_105/statelite)) {
|
||||
my $case = tempdir(DIR => $dir, CLEANUP => 1);
|
||||
my $root = "$case/root";
|
||||
my $payload = "$case/payload";
|
||||
make_path(map { "$root/$_" } qw(usr lib etc tmp sysroot hooks/initqueue));
|
||||
make_path(map { "$root/$_" } qw(usr lib etc tmp sysroot hooks/initqueue var/lib/NetworkManager));
|
||||
symlink('usr/bin', "$root/bin") or die $!;
|
||||
symlink('usr/sbin', "$root/sbin") or die $!;
|
||||
symlink('usr/lib64', "$root/lib64") or die $!;
|
||||
@@ -53,6 +56,7 @@ for my $variant (qw(dracut_047 dracut_105/stateless dracut_105/statelite)) {
|
||||
}
|
||||
write_file("$root/etc/resolv.conf", "nameserver 192.0.2.1\n");
|
||||
write_file("$root/tmp/dhclient.eth0.lease", "fixture lease\n");
|
||||
write_file("$root/var/lib/NetworkManager/$_-0f3e5a12-eth0.lease", "$_ lease\n") for qw(dhclient internal);
|
||||
write_file("$root/lib/dracut-lib.sh", <<'SH');
|
||||
hookdir=/hooks
|
||||
logger() { :; }
|
||||
@@ -93,6 +97,10 @@ SH
|
||||
like($output, qr/^PAYLOAD=native payload$/m, "$label extracts the actual image payload");
|
||||
like($output, qr/^INITQUEUE_READY$/m, "$label reaches the initqueue handoff");
|
||||
unlike($output, qr{localdisk: (?:No such file|Permission denied)}, "$label avoids an invalid optional script invocation");
|
||||
if ($variant eq 'dracut_047') {
|
||||
like($output, qr/^NMLEASE=$_-0f3e5a12-eth0\.lease:$_ lease$/m,
|
||||
"$label hands the $_ lease of NetworkManager to the root") for qw(dhclient internal);
|
||||
}
|
||||
if ($localdisk eq 'executable') {
|
||||
like($output, qr/^LOCALDISK_RAN$/m, "$label retains the legacy executable hook");
|
||||
} else {
|
||||
|
||||
@@ -46,7 +46,8 @@ for my $platform (@platforms) {
|
||||
like($requires, qr/^perl\(Digest::SHA\)$/m, "$name server s390x=$s390 requires Digest::SHA");
|
||||
next if $s390;
|
||||
my $recommends = query('xCAT-server', 'x86_64', $macro, '--recommends');
|
||||
is(scalar(grep { $_ eq 'perl-DB_File' } split /\n/, $requires), $name eq 'EL10' ? 0 : 1,
|
||||
my $db_file = $name =~ /^SLES/ ? 'perl(DB_File)' : 'perl-DB_File';
|
||||
is(scalar(grep { $_ eq $db_file } split /\n/, $requires), $name eq 'EL10' ? 0 : 1,
|
||||
"$name server hard DB_File dependency");
|
||||
is(scalar(grep { $_ eq 'perl-DB_File' } split /\n/, $recommends), $name eq 'EL10' ? 1 : 0,
|
||||
"$name server weak DB_File dependency");
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use File::Path qw(make_path);
|
||||
use File::Slurper qw(read_text write_text);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use Test::More;
|
||||
|
||||
use XCAT::Test::File qw(repo_path);
|
||||
use XCAT::Test::Sandbox qw(sandbox_root sandbox_run);
|
||||
use XCAT::Test::Template qw(template_database render_template);
|
||||
|
||||
plan skip_all => 'kickstart %post execution requires Linux' unless $^O eq 'linux';
|
||||
my $database = template_database();
|
||||
my $script = "$database/post.rhels8";
|
||||
render_template($database, repo_path('xCAT-server/share/xcat/install/scripts/post.rhels8'), $script,
|
||||
'node', '', '/install/media', 'rh', undef, {xcatmaster => '192.0.2.1'});
|
||||
|
||||
my %device = (
|
||||
e1000e => ['/sys/devices/pci0000:00/0000:00:03.0', '/sys/bus/pci/drivers/e1000e'],
|
||||
cdc_ether => ['/sys/devices/pci0000:00/0000:00:14.0/usb1/1-4/1-4:1.0', '/sys/bus/usb/drivers/cdc_ether'],
|
||||
r8152 => ['/sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0', '/sys/bus/usb/drivers/r8152'],
|
||||
);
|
||||
|
||||
# Each NIC has an ifcfg file with ONBOOT=no, a driver (or no sysfs entry) and a link state.
|
||||
sub run_post {
|
||||
my (%nics) = @_;
|
||||
my $root = sandbox_root();
|
||||
make_path("$root/etc/sysconfig/network-scripts", "$root/link");
|
||||
for my $nic (keys %nics) {
|
||||
my ($driver, $link) = @{$nics{$nic}};
|
||||
write_text("$root/etc/sysconfig/network-scripts/ifcfg-$nic", "DEVICE=$nic\nBOOTPROTO=dhcp\nONBOOT=no\n");
|
||||
write_text("$root/link/$nic", '') if $link;
|
||||
next unless $driver;
|
||||
my ($bus, $module) = @{$device{$driver}};
|
||||
my $device = "$bus/$nic";
|
||||
make_path("$root$device", "$root$module", "$root/sys/class/net/$nic");
|
||||
symlink($device, "$root/sys/class/net/$nic/device") or die $!;
|
||||
symlink($module, "$root$device/driver") or die $!;
|
||||
}
|
||||
write_text("$root/bin/ethtool",
|
||||
"#!/bin/sh\n[ -e \"/fixture/link/\$1\" ] && state=yes || state=no\nprintf '\\tLink detected: %s\\n' \"\$state\"\n");
|
||||
write_text("$root/bin/nmcli", "#!/bin/sh\nprintf '%s\\n' \"\$*\" >>/fixture/nmcli.calls\n");
|
||||
chmod 0755, "$root/bin/ethtool", "$root/bin/nmcli" or die $!;
|
||||
write_text("$root/post.sh", read_text($script));
|
||||
my ($rc, $log) = sandbox_run($root, {read_only => {"$root/sys" => '/sys'}}, '/bin/bash', '/fixture/post.sh');
|
||||
is($rc, 0, 'post.rhels8 completes') or diag($log);
|
||||
my %onboot = map {
|
||||
my ($value) = read_text("$root/etc/sysconfig/network-scripts/ifcfg-$_") =~ /^ONBOOT=(\w+)$/m;
|
||||
($_ => $value)
|
||||
} keys %nics;
|
||||
return (\%onboot, -e "$root/nmcli.calls" ? read_text("$root/nmcli.calls") : '');
|
||||
}
|
||||
|
||||
{
|
||||
my ($onboot, $nmcli) = run_post(
|
||||
eno1 => ['e1000e', 1], usb0 => ['cdc_ether', 1], enx1 => ['r8152', 1], eno2 => ['e1000e', 0],
|
||||
renamed0 => [undef, 1],
|
||||
);
|
||||
is_deeply($onboot, {eno1 => 'yes', usb0 => 'no', enx1 => 'yes', eno2 => 'no', renamed0 => 'yes'},
|
||||
'activates the NICs with link, a USB Ethernet adapter included, except the USB NIC of the BMC');
|
||||
is($nmcli, '', 'leaves the NetworkManager profiles to the ifcfg files');
|
||||
}
|
||||
|
||||
{
|
||||
my ($onboot, $nmcli) = run_post(eno1 => ['e1000e', 0], usb0 => ['cdc_ether', 1]);
|
||||
is_deeply($onboot, {eno1 => 'no', usb0 => 'no'}, 'does not activate a USB NIC that is the only one with link');
|
||||
like($nmcli, qr/^-g NAME,STATE con show$/m, 'falls back to the connections active in the installer');
|
||||
}
|
||||
|
||||
done_testing();
|
||||
@@ -0,0 +1,100 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use File::Copy qw(copy);
|
||||
use File::Path qw(make_path);
|
||||
use File::Slurper qw(read_text write_text);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use Test::More;
|
||||
|
||||
use XCAT::Test::File qw(repo_path);
|
||||
use XCAT::Test::Sandbox qw(sandbox_root sandbox_run);
|
||||
use XCAT::Test::Template qw(template_database set_row render_template);
|
||||
|
||||
plan skip_all => 'kickstart %post execution requires Linux' unless $^O eq 'linux';
|
||||
my $database = template_database();
|
||||
set_row('passwd', {key => 'system', username => 'root'}, {password => '$6$fixture$encrypted'});
|
||||
|
||||
my $install = repo_path('xCAT-server/share/xcat/install');
|
||||
my @templates = (
|
||||
['rh/compute.rhels8.tmpl', 'rocky8.10', 'x86_64', 'rh'],
|
||||
['rh/compute.rhels9.tmpl', 'alma9.6', 'x86_64', 'rh'],
|
||||
['rh/compute.rhels10.tmpl', 'rhels10.0', 'x86_64', 'rh'],
|
||||
['rh/compute.rhels10.riscv64.tmpl', 'rhels10.0', 'riscv64', 'rh'],
|
||||
['rocky/service.rocky10.riscv64.tmpl', 'rocky10.2', 'riscv64', 'rocky'],
|
||||
['openeuler/compute.openeuler.tmpl', 'openeuler24.03sp3', 'x86_64', 'openeuler'],
|
||||
);
|
||||
|
||||
# The stand-in records what the xCAT post scripts had done when the relabel ran.
|
||||
my $restorecon = <<'SH';
|
||||
#!/bin/sh
|
||||
{
|
||||
printf 'args=%s\n' "$*"
|
||||
[ -e /fixture/postscript-ran ] && echo 'postscript=ran'
|
||||
grep -q '^enabled=0$' /etc/yum.repos.d/rocky.repo && echo 'vendor-repository=disabled'
|
||||
} >>/fixture/restorecon.calls
|
||||
SH
|
||||
|
||||
sub post_root {
|
||||
my $root = sandbox_root();
|
||||
make_path("$root/sbin", "$root/etc/systemd/system", "$root/etc/yum.repos.d", "$root/boot/efi/EFI/BOOT");
|
||||
write_text("$root/sbin/restorecon", $restorecon);
|
||||
chmod 0755, "$root/sbin/restorecon" or die $!;
|
||||
write_text("$root/etc/yum.repos.d/rocky.repo", "[baseos]\nname=BaseOS\nenabled=1\n");
|
||||
write_text("$root/boot/efi/EFI/BOOT/BOOTRISCV64.EFI", "loader\n");
|
||||
write_text("$root/tmp/pre-install.log", "pre-install fixture diagnostic\n");
|
||||
copy(repo_path('xCAT/postscripts/xcatlib.sh'), "$root/xcatlib.sh") or die $!;
|
||||
write_text("$root/mypostscript.node", "#!/bin/bash\nMASTER=192.0.2.1\ntouch /fixture/postscript-ran\n");
|
||||
for my $name (qw(curl logger sleep updateflag.awk nmcli openssl)) {
|
||||
copy(repo_path('xCAT-test/fixtures/install-profile/command'), "$root/bin/$name") or die $!;
|
||||
chmod 0755, "$root/bin/$name" or die $!;
|
||||
}
|
||||
return $root;
|
||||
}
|
||||
|
||||
for my $case (@templates) {
|
||||
my ($template, $os, $arch, $platform) = @$case;
|
||||
for my $mode (qw(enforcing disabled)) {
|
||||
subtest "$template $mode" => sub {
|
||||
set_row('nodetype', {node => 'node'}, {os => $os, arch => $arch, provmethod => 'install'});
|
||||
set_row('noderes', {node => 'node'}, {selinux => $mode});
|
||||
(my $pkglist = "$install/$template") =~ s/\.tmpl$/.pkglist/;
|
||||
my $output = "$database/ks";
|
||||
render_template($database, "$install/$template", $output, 'node', (-r $pkglist ? $pkglist : ''),
|
||||
'/install/media', $platform, undef, {xcatmaster => '192.0.2.1'});
|
||||
my $rendered = read_text($output);
|
||||
my @posts;
|
||||
while ($rendered =~ /^%post([^\n]*)\n(.*?)^%end/msg) {
|
||||
push @posts, [$1, $2];
|
||||
}
|
||||
ok(@posts, 'renders a %post section');
|
||||
|
||||
my $root = post_root();
|
||||
my $index = 0;
|
||||
for my $post (@posts) {
|
||||
my ($interpreter) = $post->[0] =~ /--interpreter=(\S+)/;
|
||||
write_text("$root/post.sh", $post->[1]);
|
||||
my ($rc, $log) = sandbox_run($root, {read_only => {"$root/sbin" => '/usr/sbin'}},
|
||||
'timeout', '30', $interpreter // '/bin/sh', '/fixture/post.sh');
|
||||
is($rc, 0, '%post section ' . ++$index . ' completes')
|
||||
or diag($log, read_text("$root/log/xcat/xcat.log"));
|
||||
}
|
||||
ok(-e "$root/postscript-ran", 'runs the rendered sequence through the downloaded postscript');
|
||||
ok(!-e "$root/unexpected-command", 'external fixtures accept the requested operations');
|
||||
is(read_text("$root/etc/yum.repos.d/rocky.repo"), "[baseos]\nname=BaseOS\nenabled=0\n",
|
||||
'disables the installed vendor repository');
|
||||
my $calls = -e "$root/restorecon.calls" ? read_text("$root/restorecon.calls") : undef;
|
||||
if ($mode eq 'disabled') {
|
||||
is($calls, undef, 'does not relabel a disabled node');
|
||||
} else {
|
||||
is($calls, "args=-RF /xcatpost /opt/xcat /etc /root /var/log\npostscript=ran\nvendor-repository=disabled\n",
|
||||
'relabels once, after the xCAT post scripts wrote their files');
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
done_testing();
|
||||
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use File::Slurper qw(read_text write_text);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use Test::More;
|
||||
|
||||
use XCAT::Test::File qw(repo_path);
|
||||
use XCAT::Test::Template qw(template_database set_row render_template);
|
||||
|
||||
plan skip_all => 'template rendering requires Linux namespaces' unless $^O eq 'linux';
|
||||
my $database = template_database();
|
||||
set_row('site', {key => 'secureroot'}, {value => 0});
|
||||
set_row('nodetype', {node => 'node'}, {os => 'rhels10.0', arch => 'x86_64', provmethod => 'install'});
|
||||
my $kickstart = repo_path('xCAT-server/share/xcat/install/rh/compute.rhels10.tmpl');
|
||||
(my $pkglist = $kickstart) =~ s/\.tmpl$/.pkglist/;
|
||||
my $output = "$database/ks";
|
||||
|
||||
sub render_kickstart {
|
||||
return eval {
|
||||
render_template($database, $kickstart, $output, 'node', $pkglist, '/install/media', 'rh', undef,
|
||||
{xcatmaster => '192.0.2.1'});
|
||||
1;
|
||||
} ? '' : $@;
|
||||
}
|
||||
|
||||
my $error = render_kickstart();
|
||||
like($error, qr/Unable to find requested field <password> from table <passwd>, with key <key=system,username=root>/,
|
||||
'a kickstart without a root password row is refused');
|
||||
|
||||
set_row('passwd', {key => 'system', username => 'root'}, {password => 'cluster'});
|
||||
$error = render_kickstart();
|
||||
is($error, '', 'a kickstart with a root password row renders') or diag($error);
|
||||
my ($hash) = (-f $output ? read_text($output) : '') =~ /^rootpw --iscrypted (\S+)$/m;
|
||||
ok(defined($hash) && crypt('cluster', $hash) eq $hash, 'the kickstart carries the hash of the root password');
|
||||
|
||||
set_row('nodetype', {node => 'node'}, {os => 'ubuntu24.04', arch => 'x86_64', provmethod => 'install'});
|
||||
my $passwd = xCAT::Table->new('passwd') or die 'Cannot open passwd';
|
||||
$passwd->delEntries({key => 'system', username => 'root'});
|
||||
$passwd->close();
|
||||
write_text("$database/image.pkglist", "vim\n");
|
||||
my $autoinstall = "$database/autoinstall.yaml";
|
||||
my $locked = eval {
|
||||
render_template($database, repo_path('xCAT-server/share/xcat/install/ubuntu/compute.subiquity.tmpl'),
|
||||
$autoinstall, 'node', "$database/image.pkglist", '/install/ubuntu24.04/x86_64', 'ubuntu', undef,
|
||||
{xcatmaster => '192.0.2.1'}, osarch => 'x86_64');
|
||||
1;
|
||||
};
|
||||
ok($locked, 'an autoinstall without a root password row renders') or diag($@);
|
||||
like(-f $autoinstall ? read_text($autoinstall) : '', qr/^\s+password: "\*"$/m,
|
||||
'the autoinstall locks the password that has no row');
|
||||
|
||||
done_testing();
|
||||
@@ -0,0 +1,137 @@
|
||||
#!/usr/bin/env perl
|
||||
# The storage config a Subiquity install receives for each linuximage.partitionfile form.
|
||||
use strict;
|
||||
use warnings;
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use File::Path qw(make_path);
|
||||
use File::Slurper qw(read_text write_text);
|
||||
use Test::More;
|
||||
use XCAT::Test::File qw(repo_path);
|
||||
use XCAT::Test::Sandbox qw(sandbox_root sandbox_run);
|
||||
use XCAT::Test::Template qw(template_database render_template);
|
||||
|
||||
plan skip_all => 'installer execution requires Linux namespaces' unless $^O eq 'linux';
|
||||
my $database = template_database();
|
||||
# Subiquity runs its early commands under dash.
|
||||
my ($shell) = grep { -x $_ } qw(/usr/bin/dash /bin/dash /bin/sh);
|
||||
my $sequence = 0;
|
||||
|
||||
sub render_part {
|
||||
my ($script, $pattern, @entries) = @_;
|
||||
my $dir = "$database/case-" . ++$sequence;
|
||||
make_path($dir);
|
||||
my @partitionfile;
|
||||
for my $n (0 .. $#entries) {
|
||||
my ($prefix, $contents) = @{ $entries[$n] };
|
||||
write_text("$dir/partition-$n", $contents);
|
||||
push @partitionfile, "$prefix$dir/partition-$n";
|
||||
}
|
||||
render_template($database, repo_path("xCAT-server/share/xcat/install/scripts/$script"), "$dir/node.pre",
|
||||
'node', '', '', '', join(',', @partitionfile), {xcatmaster => '192.0.2.1'});
|
||||
my ($part) = read_text("$dir/node.pre") =~ $pattern;
|
||||
return $part;
|
||||
}
|
||||
|
||||
# getinstdisk has already chosen /dev/sdz.
|
||||
sub installer_root {
|
||||
my $root = sandbox_root();
|
||||
make_path("$root/efi", "$root/by-id");
|
||||
write_text("$root/bin/logger", "#!/bin/sh\nexit 0\n");
|
||||
chmod 0755, "$root/bin/logger" or die $!;
|
||||
write_text("$root/tmp/xcat.install_disk", "/dev/sdz\n");
|
||||
write_text("$root/nvme7n1", '');
|
||||
symlink('../../nvme7n1', "$root/by-id/nvme-link") or die $!;
|
||||
return $root;
|
||||
}
|
||||
|
||||
sub storage_config {
|
||||
my ($root) = @_;
|
||||
return -e "$root/tmp/partitionfile" ? read_text("$root/tmp/partitionfile") : '';
|
||||
}
|
||||
|
||||
# Written as PyYAML writes it, so it reads the same before and after the pre-script rewrites it.
|
||||
my $layout = "storage:\n version: 1\n config:\n - id: custom-disk\n type: disk\n path: /dev/disk/by-id/custom\n";
|
||||
my $writer = "#!/bin/sh\ncat >/tmp/partitionfile <<'EOF'\n${layout}EOF\n";
|
||||
my $diskscript = "#!/bin/sh\necho /dev/disk/by-id/scripted >/tmp/xcat.install_disk\n";
|
||||
|
||||
# Each case: label, the partitionfile entries as [prefix, file contents], and the disk the storage
|
||||
# config must name, or undef when the install must stop before a storage config exists. A fourth
|
||||
# value is the whole storage config of a layout.
|
||||
my @cases = (
|
||||
['no partitionfile', [], '/dev/sdz'],
|
||||
['a disk file', [['d:', "/dev/disk/by-id/nvme-pinned /dev/sdb\n"]], '/dev/disk/by-id/nvme-pinned'],
|
||||
['a disk file naming a link', [['d:', "/dev/disk/by-id/nvme-link\n"]], '/dev/nvme7n1'],
|
||||
['a disk script', [['s:d:', $diskscript]], '/dev/disk/by-id/scripted'],
|
||||
['a layout file', [['', $layout]], '/dev/disk/by-id/custom'],
|
||||
['a layout script', [['s:', $writer]], '/dev/disk/by-id/custom'],
|
||||
['a layout file after a layout script', [['s:', "#!/bin/sh\nexit 0\n"], ['', $layout]], '/dev/disk/by-id/custom'],
|
||||
['a disk file after a disk script', [['s:d:', "#!/bin/sh\nexit 0\n"], ['d:', "/dev/disk/by-id/nvme-pinned\n"]],
|
||||
'/dev/disk/by-id/nvme-pinned'],
|
||||
['a layout file before a disk script', [['', $layout], ['s:d:', $diskscript]], '/dev/disk/by-id/custom'],
|
||||
['a layout script before a disk file', [['s:', $writer], ['d:', "/dev/disk/by-id/nvme-pinned\n"]], '/dev/disk/by-id/custom'],
|
||||
['a disk script that fails', [['s:d:', "#!/bin/sh\nexit 42\n"]], undef],
|
||||
['a disk script that selects no disk', [['s:d:', "#!/bin/sh\nexit 0\n"]], undef],
|
||||
['a layout script that fails', [['s:', "#!/bin/sh\nexit 42\n"]], undef],
|
||||
['a layout script that writes no layout', [['s:', "#!/bin/sh\nexit 0\n"]], undef],
|
||||
['a layout file with only blank lines', [['', "\n \n"]], undef],
|
||||
['a layout file with only comments', [['', "# no layout yet\n"]], undef],
|
||||
['a disk file with only blank lines', [['d:', " \n\n"]], undef],
|
||||
['a layout file with an empty storage section', [['', "storage:\n"]], undef],
|
||||
['a layout file with a null storage section', [['', "storage: null\n"]], undef],
|
||||
['a layout file that starts a YAML document', [['', "---\n$layout"]], '/dev/disk/by-id/custom'],
|
||||
['a layout without a match after a disk file', [['', "storage:\n layout:\n name: direct\n"],
|
||||
['d:', "/dev/disk/by-id/nvme-link\n"]], undef,
|
||||
"storage:\n layout:\n name: direct\n match:\n path: /dev/nvme7n1\n"],
|
||||
['a layout with its own match after a disk file', [['', "storage:\n layout:\n name: direct\n match:\n ssd: true\n"],
|
||||
['d:', "/dev/disk/by-id/nvme-link\n"]], undef,
|
||||
"storage:\n layout:\n name: direct\n match:\n ssd: true\n"],
|
||||
['a layout without a match and no disk entry', [['', "storage:\n layout:\n name: direct\n"]], undef,
|
||||
"storage:\n layout:\n name: direct\n"],
|
||||
['a use_gap layout after a disk file', [['', "storage:\n layout:\n name: direct\n mode: use_gap\n"],
|
||||
['d:', "/dev/disk/by-id/nvme-link\n"]], undef],
|
||||
);
|
||||
for my $case (@cases) {
|
||||
my ($label, $entries, $expected, $expected_layout) = @$case;
|
||||
subtest $label => sub {
|
||||
my $part = render_part('pre.ubuntu.subiquity', qr/(^base64decode\(\)\n.*^exit 0$)/ms, @$entries);
|
||||
ok($part, 'the rendered script defines base64decode before the partitioning') or return;
|
||||
my $root = installer_root();
|
||||
write_text("$root/part.sh", $part);
|
||||
my ($rc, $output) = sandbox_run($root, {read_only => {"$root/efi" => '/sys/firmware/efi',
|
||||
"$root/by-id" => '/dev/disk/by-id', "$root/nvme7n1" => '/dev/nvme7n1'}}, $shell, '/fixture/part.sh');
|
||||
if (defined $expected_layout) {
|
||||
is($rc, 0, "the partitioning runs under $shell") or diag($output);
|
||||
is(storage_config($root), $expected_layout, 'the storage config is the expected layout');
|
||||
return;
|
||||
}
|
||||
if (!defined $expected) {
|
||||
isnt($rc, 0, "the pre-install script fails under $shell");
|
||||
ok(!-e "$root/tmp/partitionfile", 'and leaves no storage config to inject');
|
||||
return;
|
||||
}
|
||||
is($rc, 0, "the partitioning runs under $shell") or diag($output);
|
||||
my $config = storage_config($root);
|
||||
my ($disk) = $config =~ /^\s+type: disk\n(?:\s+\S+:.*\n)*?\s+path: (\S+)$/m;
|
||||
is($disk, $expected, "the storage config partitions $expected");
|
||||
is($config, $layout, 'the administrator layout replaces the default one') if $expected eq '/dev/disk/by-id/custom';
|
||||
# The early command appends the storage config to Subiquity's autoinstall.yaml.
|
||||
write_text("$root/autoinstall.yaml", "version: 1\nidentity:\n hostname: node\n$config");
|
||||
is(system('/usr/bin/python3', '-I', '-c', 'import sys, yaml; sys.exit("storage" not in yaml.safe_load(open(sys.argv[1])))',
|
||||
"$root/autoinstall.yaml"), 0, 'autoinstall.yaml stays one YAML document with a storage section');
|
||||
};
|
||||
}
|
||||
|
||||
# The debian-installer path renders the same entries into pre.ubuntu, under a shell with read -n.
|
||||
subtest 'a debian-installer recipe file after a recipe script' => sub {
|
||||
my $part = render_part('pre.ubuntu', qr/(^base64decode\(\)\n.*?^exit 0$)/ms,
|
||||
['s:', "#!/bin/sh\nexit 0\n"], ['', "recipe ::\n .\n"]);
|
||||
ok($part, 'the rendered script defines base64decode before the recipe') or return;
|
||||
my $root = installer_root();
|
||||
write_text("$root/part.sh", $part);
|
||||
my ($rc, $output) = sandbox_run($root, '/bin/bash', '/fixture/part.sh');
|
||||
is($rc, 0, 'the recipe step runs') or diag($output);
|
||||
is(storage_config($root), "recipe ::\n .\n", 'the later recipe file replaces the default recipe');
|
||||
};
|
||||
done_testing();
|
||||
+18
-8
@@ -2,17 +2,19 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use File::Basename qw(basename);
|
||||
use File::Basename qw(basename dirname);
|
||||
use File::Copy qw(copy);
|
||||
use File::Path qw(make_path);
|
||||
use File::Slurper qw(read_binary write_binary);
|
||||
use File::Spec;
|
||||
use File::Temp qw(tempdir);
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use Test::More;
|
||||
|
||||
use XCAT::Test::File qw(repo_path);
|
||||
use XCAT::Test::Sandbox qw(sandbox_root sandbox_run);
|
||||
|
||||
plan skip_all => 'init helper execution requires Linux namespaces' unless $^O eq 'linux';
|
||||
|
||||
my $state_helper = repo_path('xCAT-server/debian/xcatd-init-state');
|
||||
my $compat_helper = repo_path('xCAT-server/share/xcat/scripts/xcatd-init-compat');
|
||||
@@ -30,7 +32,8 @@ sub path_mode {
|
||||
}
|
||||
|
||||
sub stage_root {
|
||||
my $root = tempdir( CLEANUP => 1 );
|
||||
# The compatibility root stays apart from the /etc of the sandbox.
|
||||
my $root = File::Spec->catdir( sandbox_root(), 'compat' );
|
||||
my $scripts = File::Spec->catdir(
|
||||
$root, 'opt', 'xcat', 'share', 'xcat', 'scripts'
|
||||
);
|
||||
@@ -188,11 +191,18 @@ SH
|
||||
|
||||
sub run_script {
|
||||
my ( $root, $script, @arguments ) = @_;
|
||||
local $ENV{XCAT_COMPAT_ROOT} = $root;
|
||||
local $ENV{XCATROOT} = '/opt/xcat';
|
||||
local $ENV{PATH} = File::Spec->catdir( $root, 'test-bin' ) . ':/usr/bin:/bin';
|
||||
system( '/bin/sh', $script, @arguments );
|
||||
return $? >> 8;
|
||||
my $source = repo_path('.');
|
||||
$script =~ s{^\Q$root\E/}{/fixture/compat/};
|
||||
my ( $status, $output ) = sandbox_run( dirname($root), {
|
||||
read_only => { $source => $source },
|
||||
env => {
|
||||
XCAT_COMPAT_ROOT => '/fixture/compat',
|
||||
XCATROOT => '/opt/xcat',
|
||||
PATH => '/fixture/compat/test-bin:/usr/bin:/bin',
|
||||
},
|
||||
}, '/bin/sh', $script, @arguments );
|
||||
note($output) if length $output;
|
||||
return $status;
|
||||
}
|
||||
|
||||
sub run_state {
|
||||
@@ -2,7 +2,8 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use File::Slurper qw(write_text);
|
||||
use File::Path qw(make_path);
|
||||
use File::Slurper qw(read_text write_text);
|
||||
use File::Temp qw(tempdir);
|
||||
use FindBin;
|
||||
use Storable qw(dclone);
|
||||
@@ -51,6 +52,7 @@ sub media_tree {
|
||||
for my $case (
|
||||
['24.03-ppc64le', 'openeuler24.03', 'ppc64le'],
|
||||
['24.03sp4-x86_64', 'openeuler24.03sp4', 'x86_64'],
|
||||
['24.03sp3-riscv64', 'openeuler24.03sp3', 'riscv64'],
|
||||
) {
|
||||
my ($fixture, $os, $arch) = @$case;
|
||||
my $responses = inspect_media(repo_path("xCAT-test/fixtures/openeuler-media/$fixture"));
|
||||
@@ -142,4 +144,69 @@ ok(!xCAT_plugin::anaconda::using_dracut('openeuler24.09'), 'a non-LTS token is n
|
||||
is_deeply($request, $original, 'missing payload is rejected before claiming or changing media');
|
||||
}
|
||||
|
||||
# Complete riscv64 media whose .discinfo names a build, as the RVA23 DVD does.
|
||||
sub build_media {
|
||||
my ($description, $arch) = @_;
|
||||
$arch ||= 'riscv64';
|
||||
my $root = media_tree('24.03-LTS-SP3', $arch, '', $arch);
|
||||
write_text("$root/.discinfo", "1234567890\n$description\n$arch\n");
|
||||
make_path("$root/images/pxeboot", "$root/repodata");
|
||||
write_text("$root/$_", "payload\n")
|
||||
for qw(images/pxeboot/vmlinuz images/pxeboot/initrd.img images/install.img repodata/repomd.xml);
|
||||
return $root;
|
||||
}
|
||||
|
||||
# Copies media to $target. The table stub stops a copy that passes the build
|
||||
# check at its first table, before anything is written.
|
||||
sub copy_media {
|
||||
my ($media, $target) = @_;
|
||||
my $request = { command => ['copycd'], arg => ['-m', $media, '-p', $target] };
|
||||
my (@responses, $output, $stopped);
|
||||
{
|
||||
open(my $stdout, '>', \$output) or die "open scalar output: $!";
|
||||
local *STDOUT = $stdout;
|
||||
no warnings 'redefine';
|
||||
local *xCAT::Table::new = sub {
|
||||
my ($class, $table, @args) = @_;
|
||||
die "copy reached table $table\n" if $table ne 'site' || @args;
|
||||
return bless {}, 'Local::OpenEulerSite';
|
||||
};
|
||||
local *xCAT::TableUtils::get_site_attribute = sub { return '/unused-install-root'; };
|
||||
eval {
|
||||
xCAT_plugin::anaconda::process_request($request, sub { push @responses, @_ }, sub {
|
||||
die "copy dispatched a request\n";
|
||||
});
|
||||
1;
|
||||
} or $stopped = $@;
|
||||
}
|
||||
return (\@responses, $stopped);
|
||||
}
|
||||
|
||||
sub copied_target {
|
||||
my ($description) = @_;
|
||||
my $target = tempdir(CLEANUP => 1);
|
||||
write_text("$target/.discinfo", "1234567800\n$description\nriscv64\n") if defined $description;
|
||||
return $target;
|
||||
}
|
||||
|
||||
for my $case (['RVA23', '', 'RVA23'], ['', 'RVA23', 'no build name']) {
|
||||
my ($copied, $media, $named) = @$case;
|
||||
my $target = copied_target($copied);
|
||||
my ($responses, $stopped) = copy_media(build_media($media), $target);
|
||||
like($responses->[0]{error} || '', qr/\Q$target\E holds openEuler media of another build \(\Q$named\E\)/,
|
||||
"media of build '$media' are refused over a copy of build '$copied'");
|
||||
is_deeply($responses->[0]{errorcode}, [1], 'the refusal reports failure');
|
||||
is($stopped, undef, 'the refusal comes before any table is opened');
|
||||
is(read_text("$target/.discinfo"), "1234567800\n$copied\nriscv64\n", 'the existing copy is unchanged');
|
||||
}
|
||||
|
||||
for my $case (['RVA23', 'RVA23', 'riscv64'], ['rva23', 'RVA23', 'riscv64'], [undef, 'RVA23', 'riscv64'],
|
||||
['', '', 'x86_64']) {
|
||||
my ($copied, $media, $arch) = @$case;
|
||||
my $label = defined $copied ? "a copy of build '$copied'" : 'an empty target';
|
||||
my ($responses, $stopped) = copy_media(build_media($media, $arch), copied_target($copied));
|
||||
ok(!grep({ ($_->{error} // '') =~ /another build/ } @$responses), "$arch media of build '$media' copy over $label");
|
||||
is($stopped, "copy reached table osdistro\n", 'the copy continues past the build check');
|
||||
}
|
||||
|
||||
done_testing();
|
||||
|
||||
@@ -94,4 +94,15 @@ is( scalar xCAT_plugin::anaconda::_install_media_grub2_loader( $bare_media, 'ris
|
||||
is( messages( \@responses ), '', 'media without a grub2 image report nothing' );
|
||||
ok( !-d File::Spec->catdir( $tftpdir, 'boot' ), 'media without a grub2 image create no directories' );
|
||||
|
||||
# openEuler spells the image grubriscv64.EFI; UEFI names are case-insensitive
|
||||
$tftpdir = File::Spec->catdir( $root, 'tftpboot-openeuler' );
|
||||
make_path($tftpdir);
|
||||
my $oe_media = media( $root, 'openeuler24.03sp3-riscv64', 'grubriscv64.EFI' );
|
||||
@responses = ();
|
||||
$loader = File::Spec->catfile( $tftpdir, 'boot', 'grub2', 'grub2.riscv64' );
|
||||
is( scalar xCAT_plugin::anaconda::_install_media_grub2_loader( $oe_media, 'riscv64', sub { push @responses, @_; } ),
|
||||
$loader, 'an upper-case image name is published as the riscv64 boot loader' );
|
||||
is( -f $loader ? read_text($loader) : undef, "boot loader from the media\n",
|
||||
'the published image is the one from the openEuler media' );
|
||||
|
||||
done_testing();
|
||||
|
||||
@@ -88,11 +88,10 @@ ok(
|
||||
'POWER media retain their separate architecture route',
|
||||
);
|
||||
|
||||
is_deeply(
|
||||
[ imgutils::default_net_drivers( 'rh', 'riscv64' ) ],
|
||||
[qw(e1000 e1000e igb ixgbe r8169 tg3 bnx2x mlx5_core virtio_net)],
|
||||
'riscv64 diskless images receive the intended default network drivers',
|
||||
);
|
||||
my %riscv64_drivers = map { $_ => 1 } imgutils::default_net_drivers( 'rh', 'riscv64' );
|
||||
for my $driver (qw(e1000 e1000e igb ixgbe i40e ice r8169 tg3 bnx2x mlx5_core virtio_net)) {
|
||||
ok( $riscv64_drivers{$driver}, "riscv64 diskless images receive the $driver network driver" );
|
||||
}
|
||||
is_deeply(
|
||||
[ imgutils::resolver_library_paths('riscv64') ],
|
||||
[ 'lib64/libnss_dns.so.2', 'lib64/libresolv.so.2' ],
|
||||
|
||||
@@ -19,6 +19,12 @@ use XCAT::GenesisPayload qw(module_commands missing_paths check_payload);
|
||||
my $OPENSSH_99 = "OpenSSH_9.9p1\n/usr/libexec/openssh/sshd-session\n";
|
||||
my $OPENSSH_80 = "OpenSSH_8.0p1\n";
|
||||
|
||||
# The two awk programs name themselves in their own binary.
|
||||
my $GAWK = "GNU Awk 5.2.2, API 3.2\n";
|
||||
my $MAWK = "mawk 1.3.4 20240123\n";
|
||||
my $AWK_NOT_GAWK =
|
||||
'usr/bin/awk is not gawk (allowcred.awk opens its TCP stream with the gawk /inet/ coprocess)';
|
||||
|
||||
# A complete payload: OpenSSH 9.9 sshd plus its session helper, tmux plus a UTF-8 locale.
|
||||
my @COMPLETE = qw(
|
||||
usr/sbin/sshd usr/libexec/openssh/sshd-session usr/bin/tmux
|
||||
@@ -72,6 +78,18 @@ is_deeply([ missing_paths(all_but('usr/libexec/openssh/sshd-session'), sshd => $
|
||||
is_deeply([ missing_paths(all_but('usr/lib/locale/C.utf8/LC_CTYPE', 'usr/bin/tmux'), sshd => $OPENSSH_99) ],
|
||||
[], 'a payload without tmux needs no locale');
|
||||
|
||||
# allowcred.awk, minixcatd.awk and udpcat.awk open a TCP stream with the gawk |& coprocess
|
||||
# and the /inet/ special file. mawk rejects both at parse time, so the node asks for no
|
||||
# credential and reports no flag, and nothing in the build says why.
|
||||
is_deeply([ missing_paths(carries(@COMPLETE), sshd => $OPENSSH_99, awk => $GAWK) ],
|
||||
[], 'a payload whose awk is gawk passes');
|
||||
is_deeply([ missing_paths(carries(@COMPLETE), sshd => $OPENSSH_99, awk => $MAWK) ],
|
||||
[$AWK_NOT_GAWK], 'a payload whose awk is mawk fails and says so');
|
||||
|
||||
# An awk with no name in it is not gawk either. busybox awk has no /inet/ support.
|
||||
is_deeply([ missing_paths(carries(@COMPLETE), sshd => $OPENSSH_99, awk => "busybox\n") ],
|
||||
[$AWK_NOT_GAWK], 'an awk that is neither gawk nor mawk fails too');
|
||||
|
||||
# dracut_install reports a missing binary and returns, so every name the dracut module
|
||||
# installs has to be checked against the payload. A name starting with "/" is installed at
|
||||
# that same path; the rest are commands.
|
||||
@@ -149,6 +167,20 @@ is_deeply([ check_payload($nohelper) ],
|
||||
[ 1, "verify-genesis-payload: $nohelper is incomplete:\n"
|
||||
. " usr/libexec/openssh/sshd-session (this sshd execs it for every connection)\n" ],
|
||||
'the command line reads usr/sbin/sshd to decide on sshd-session');
|
||||
|
||||
my $mawk = payload_tree(@COMPLETE);
|
||||
write_text("$mawk/usr/sbin/sshd", $OPENSSH_99);
|
||||
write_text("$mawk/usr/bin/awk", $MAWK);
|
||||
is_deeply([ check_payload($mawk) ],
|
||||
[ 1, "verify-genesis-payload: $mawk is incomplete:\n $AWK_NOT_GAWK\n" ],
|
||||
'the command line reads usr/bin/awk back out of the payload');
|
||||
|
||||
my $gawk = payload_tree(@COMPLETE);
|
||||
write_text("$gawk/usr/sbin/sshd", $OPENSSH_99);
|
||||
write_text("$gawk/usr/bin/awk", $GAWK);
|
||||
is_deeply([ check_payload($gawk) ],
|
||||
[ 0, "verify-genesis-payload: $gawk is complete\n" ],
|
||||
'a payload whose awk is gawk passes on the command line');
|
||||
is_deeply([ check_payload('--commands-from', $module, $nodhcp) ],
|
||||
[ 0, "verify-genesis-payload: $nodhcp is complete\n" ],
|
||||
'--commands-from does not require a name installed under a condition');
|
||||
|
||||
@@ -31,6 +31,10 @@ my %PACKAGES_FOR = (
|
||||
dhclient => ['isc-dhcp-client'],
|
||||
ifenslave => ['ifenslave'],
|
||||
hwclock => [ 'util-linux-extra', 'util-linux' ],
|
||||
|
||||
# mawk is the awk alternative on a Debian or Ubuntu root, and it rejects the gawk
|
||||
# /inet/ coprocess at parse time, so the module names gawk rather than awk.
|
||||
gawk => ['gawk'],
|
||||
);
|
||||
|
||||
# A release carries exactly the names in its list.
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
## no critic (TestingAndDebugging::ProhibitNoWarnings)
|
||||
use File::Path qw(make_path);
|
||||
use File::Temp qw(tempdir);
|
||||
use FindBin;
|
||||
use Storable qw(dclone);
|
||||
use Test::More;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use lib "$FindBin::Bin/../../perl-xCAT";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use XCAT::Test::File qw(repo_path);
|
||||
|
||||
local $ENV{XCATROOT} = repo_path('xCAT-server');
|
||||
require(repo_path('xCAT-server/lib/xcat/plugins/geninitrd.pm'));
|
||||
|
||||
my $rootimgdir = tempdir(CLEANUP => 1);
|
||||
make_path("$rootimgdir/rootimg/lib/modules");
|
||||
my %attribs = (
|
||||
osimage => { provmethod => 'netboot', osvers => 'ubuntu26.04', osarch => 'riscv64' },
|
||||
linuximage => { rootimgdir => $rootimgdir, pkgdir => '/install/ubuntu26.04/riscv64' },
|
||||
);
|
||||
|
||||
# The genimage client prints build output on stdout and its own errors on stderr.
|
||||
my $bindir = tempdir(CLEANUP => 1);
|
||||
open(my $script, '>', "$bindir/genimage") or die "genimage: $!";
|
||||
print $script <<'EOS';
|
||||
#!/bin/sh
|
||||
echo "$@" > "$GENIMAGE_ARGS"
|
||||
echo 'the initial ramdisks are built'
|
||||
echo 'Error: genimage command failed' >&2
|
||||
exit "$GENIMAGE_RC"
|
||||
EOS
|
||||
close($script) or die "genimage: $!";
|
||||
chmod(0755, "$bindir/genimage") or die "genimage: $!";
|
||||
my $emptydir = tempdir(CLEANUP => 1);
|
||||
|
||||
sub geninitrd_with {
|
||||
my (%case) = @_;
|
||||
my $args = "$bindir/args";
|
||||
unlink($args);
|
||||
my @responses;
|
||||
{
|
||||
no warnings qw(redefine once);
|
||||
local *xCAT::Table::new = sub {
|
||||
my ($class, $table) = @_;
|
||||
die "Unexpected table $table\n" unless $attribs{$table};
|
||||
return bless { attribs => $attribs{$table} }, 'Local::ImageTable';
|
||||
};
|
||||
local $ENV{PATH} = $case{path};
|
||||
local $ENV{GENIMAGE_RC} = $case{rc} // 0;
|
||||
local $ENV{GENIMAGE_ARGS} = $args;
|
||||
xCAT_plugin::geninitrd::process_request({ command => ['geninitrd'], arg => ['compute'] },
|
||||
sub { push @responses, dclone($_[0]) }, sub { die "Unexpected subrequest\n" });
|
||||
}
|
||||
my %result;
|
||||
if (open(my $fh, '<', $args)) {
|
||||
$result{args} = do { local $/; <$fh> };
|
||||
close($fh);
|
||||
}
|
||||
for my $key (qw(info error errorcode)) {
|
||||
$result{$key} = [ map { @{ $_->{$key} // [] } } @responses ];
|
||||
}
|
||||
return \%result;
|
||||
}
|
||||
|
||||
{
|
||||
my $result = geninitrd_with(path => $bindir, rc => 0);
|
||||
is($result->{args}, "compute --onlyinitrd\n", 'geninitrd runs genimage --onlyinitrd for the image');
|
||||
is_deeply($result->{error}, [], 'a genimage that succeeds reports no error');
|
||||
is_deeply($result->{errorcode}, [], 'a genimage that succeeds sets no exit code');
|
||||
ok((grep { /the initial ramdisks are built/ } @{ $result->{info} }), 'the genimage output reaches the client');
|
||||
}
|
||||
|
||||
for my $rc (1, 2, 17) {
|
||||
my $result = geninitrd_with(path => $bindir, rc => $rc);
|
||||
is_deeply($result->{error}, ["genimage compute --onlyinitrd failed with rc $rc."], "a genimage that ends with $rc reports the failure");
|
||||
is_deeply($result->{errorcode}, [$rc], "the exit code of geninitrd is $rc");
|
||||
ok((grep { /Error: genimage command failed/ } @{ $result->{info} }), "the genimage error output reaches the client after rc $rc");
|
||||
}
|
||||
|
||||
{
|
||||
my $result = geninitrd_with(path => $emptydir);
|
||||
is_deeply($result->{error}, ['genimage compute --onlyinitrd failed with rc 1.'], 'a genimage that cannot run reports the failure');
|
||||
is_deeply($result->{errorcode}, [1], 'the exit code of geninitrd is 1 when genimage cannot run');
|
||||
}
|
||||
|
||||
done_testing();
|
||||
|
||||
package Local::ImageTable;
|
||||
|
||||
sub getAttribs {
|
||||
my ($self) = @_;
|
||||
return { %{ $self->{attribs} } };
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
#!/usr/bin/env perl
|
||||
# getpostscript correlates a node-initiated request to a node. When the reverse lookup of the
|
||||
# peer socket fails, the CN of the validated client certificate is the only other identity.
|
||||
# A password or token login, and the request's own node attribute, must never select a node.
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use FindBin;
|
||||
use File::Spec;
|
||||
use Test::More;
|
||||
use lib File::Spec->catdir($FindBin::Bin, '..', '..', 'perl-xCAT'),
|
||||
File::Spec->catdir($FindBin::Bin, '..', '..', 'xCAT-server', 'lib', 'perl');
|
||||
use xCAT::DiscoveryUtils;
|
||||
|
||||
# Ninety xCAT modules put "$::XCATROOT/lib/perl" in @INC, so an installed product can shadow
|
||||
# the checkout. Say which file answered.
|
||||
my $under_test = $INC{'xCAT/DiscoveryUtils.pm'} // '';
|
||||
ok(length $under_test, 'xCAT::DiscoveryUtils was loaded at all');
|
||||
unlike($under_test, qr{^/opt/xcat/}, "the module under test is this checkout's, not an installed one ($under_test)");
|
||||
can_ok('xCAT::DiscoveryUtils', qw(request_client_names request_client_node client_certificate_name));
|
||||
|
||||
sub names_for { return xCAT::DiscoveryUtils::request_client_names($_[0]) }
|
||||
|
||||
# --- client_certificate_name: what xcatd records as _xcat_certname -------------------------
|
||||
|
||||
is(xCAT::DiscoveryUtils::client_certificate_name('xcat59-cn', 'xcat59-cn'), 'xcat59-cn',
|
||||
'a request authenticated by its certificate records the certificate CN');
|
||||
is(xCAT::DiscoveryUtils::client_certificate_name(undef, 'compute'), undef,
|
||||
'a token or password login without a certificate records no certificate name');
|
||||
is(xCAT::DiscoveryUtils::client_certificate_name('root', 'compute'), undef,
|
||||
'becomeuser to another account records no certificate name');
|
||||
is(xCAT::DiscoveryUtils::client_certificate_name('', ''), undef,
|
||||
'an empty certificate CN is not a name');
|
||||
|
||||
# --- request_client_names: the names logged and tried -------------------------------------
|
||||
|
||||
is_deeply([ names_for({ _xcat_clienthost => ['xcat58-cn'],
|
||||
_xcat_clientfqdn => ['xcat58-cn.xcat58.lab'],
|
||||
_xcat_certname => ['xcat58-cn'] }) ],
|
||||
[ 'xcat58-cn', 'xcat58-cn.xcat58.lab' ],
|
||||
'the resolved peer host comes first, and the certificate name adds no duplicate');
|
||||
|
||||
is_deeply([ names_for({ _xcat_clienthost => [''],
|
||||
_xcat_clientfqdn => [''],
|
||||
_xcat_certname => ['xcat59-cn'] }) ],
|
||||
[ 'xcat59-cn' ],
|
||||
'an empty peer host is skipped and the certificate name is offered instead');
|
||||
|
||||
is_deeply([ names_for({ _xcat_clientfqdn => ['xcat59-cn.xcat59.lab'] }) ],
|
||||
[ 'xcat59-cn.xcat59.lab' ],
|
||||
'the fully qualified peer name is offered when the short name is missing');
|
||||
|
||||
is_deeply([ names_for({ _xcat_clienthost => [''], _xcat_authname => ['compute'] }) ], [],
|
||||
'the authenticated name of a password or token login is never offered');
|
||||
|
||||
for my $request ({ node => ['xcat59-cn'] },
|
||||
{ node => ['xcat59-cn'], _xcat_clienthost => [''] },
|
||||
{ node => ['some-other-node'], _xcat_certname => ['xcat59-cn'] }) {
|
||||
my @got = names_for($request);
|
||||
ok(!grep({ $_ eq ($request->{node}->[0]) } @got),
|
||||
"the request's own node attribute is never offered as an identity ("
|
||||
. join(',', @got) . ')');
|
||||
}
|
||||
|
||||
is_deeply([ names_for({}) ], [], 'a request with no identity at all offers no name');
|
||||
is_deeply([ names_for(undef) ], [], 'an undefined request offers no name');
|
||||
is_deeply([ names_for('string') ], [], 'a request that is not a hash offers no name');
|
||||
my @unwrapped = eval { names_for({ _xcat_clienthost => 'xcat59-cn' }) };
|
||||
is($@, '', 'a value xcatd did not wrap in an array ref does not kill the lookup');
|
||||
is_deeply(\@unwrapped, [], 'and is ignored rather than dereferenced');
|
||||
|
||||
# --- request_client_node: the node selected -------------------------------------------------
|
||||
|
||||
# node01 and node02 are nodes, compute is a group of both.
|
||||
my %groups = (compute => [qw(node01 node02)]);
|
||||
my %nodes = map { $_ => 1 } qw(node01 node02);
|
||||
sub expand {
|
||||
my ($range) = @_;
|
||||
return @{ $groups{$range} } if $groups{$range};
|
||||
return ('node01', 'node02') if $range eq 'node0[1-2]';
|
||||
return $nodes{$range} ? ($range) : ();
|
||||
}
|
||||
sub node_for { return xCAT::DiscoveryUtils::request_client_node($_[0], \&expand) }
|
||||
|
||||
is(node_for({ _xcat_clienthost => ['node01'] }), 'node01', 'a resolved peer host selects its node');
|
||||
is(node_for({ _xcat_clienthost => [''], _xcat_certname => ['node02'] }), 'node02',
|
||||
'a certificate CN that names exactly one node selects it');
|
||||
is(node_for({ _xcat_clienthost => [''], _xcat_certname => ['compute'] }), undef,
|
||||
'a certificate CN that names a group selects no node');
|
||||
is(node_for({ _xcat_clienthost => [''], _xcat_certname => ['node0[1-2]'] }), undef,
|
||||
'a certificate CN that is a node range selects no node');
|
||||
is(node_for({ _xcat_clienthost => [''], _xcat_certname => ['nosuchnode'] }), undef,
|
||||
'a certificate CN that is not a node selects no node');
|
||||
is(node_for({ _xcat_clienthost => [''], _xcat_authname => ['node01'] }), undef,
|
||||
'the authenticated name alone selects no node');
|
||||
is(node_for({ _xcat_clienthost => ['node01'], _xcat_certname => ['node02'] }), 'node01',
|
||||
'the resolved peer host wins over the certificate CN');
|
||||
|
||||
# --- the plugin -----------------------------------------------------------------------------
|
||||
|
||||
require File::Spec->catfile($FindBin::Bin, '..', '..', 'xCAT-server', 'lib', 'xcat', 'plugins', 'getpostscript.pm');
|
||||
require xCAT::Postage;
|
||||
|
||||
sub served {
|
||||
my ($request) = @_;
|
||||
my @served;
|
||||
no warnings qw(redefine once);
|
||||
local $::XCATSITEVALS{nodeauthentication} = 0;
|
||||
local *xCAT_plugin::getpostscript::noderange = \&expand;
|
||||
local *xCAT::Postage::makescript = sub { push @served, @{ $_[0] }; return ('#script') };
|
||||
local *xCAT::MsgUtils::trace = sub { };
|
||||
xCAT_plugin::getpostscript::process_request(
|
||||
{ command => ['getpostscript'], node => [], %$request }, sub { });
|
||||
return @served;
|
||||
}
|
||||
|
||||
is_deeply([ served({ _xcat_clienthost => [''], _xcat_authname => ['compute'] }) ], [],
|
||||
'the plugin serves no node to a password or token login named after a group');
|
||||
is_deeply([ served({ _xcat_clienthost => [''], _xcat_authname => ['node01'] }) ], [],
|
||||
'the plugin serves no node to a password or token login named after a node');
|
||||
is_deeply([ served({ _xcat_clienthost => [''], _xcat_certname => ['compute'] }) ], [],
|
||||
'the plugin serves no node to a certificate named after a group');
|
||||
is_deeply([ served({ _xcat_clienthost => [''], _xcat_certname => ['node02'] }) ], ['node02'],
|
||||
'the plugin serves the node its certificate names when the reverse lookup fails');
|
||||
is_deeply([ served({ _xcat_clienthost => ['node01'] }) ], ['node01'],
|
||||
'the plugin serves the node its peer host resolves to');
|
||||
|
||||
done_testing();
|
||||
@@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use FindBin;
|
||||
use File::Path qw(make_path);
|
||||
use File::Slurper qw(read_text write_text);
|
||||
use File::Temp qw(tempdir);
|
||||
use lib "$FindBin::Bin/../../perl-xCAT";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils";
|
||||
use Test::More;
|
||||
use imgutils;
|
||||
|
||||
my $release = '6.12.0-124.el10.x86_64';
|
||||
|
||||
# Copies the kernel of $release from an image root that holds the named files.
|
||||
sub copy_case {
|
||||
my (@files) = @_;
|
||||
my $root = tempdir(CLEANUP => 1);
|
||||
for my $file (@files) {
|
||||
make_path("$root/" . ($file =~ s{/[^/]+$}{}r));
|
||||
write_text("$root/$file", "$file\n");
|
||||
chmod(0755, "$root/$file");
|
||||
}
|
||||
my $dir = tempdir(CLEANUP => 1);
|
||||
my $ok = eval { imgutils::copy_kernel($root, $release, $dir) };
|
||||
return ($ok, $@, $dir);
|
||||
}
|
||||
|
||||
for my $files (
|
||||
[ "boot/vmlinux-$release", "boot/vmlinuz-$release", "boot/image-$release", "lib/modules/$release/vmlinuz" ],
|
||||
[ "boot/vmlinuz-$release", "boot/image-$release", "lib/modules/$release/vmlinuz" ],
|
||||
[ "boot/image-$release", "lib/modules/$release/vmlinuz" ],
|
||||
[ "lib/modules/$release/vmlinuz" ],
|
||||
) {
|
||||
my ($ok, $error, $dir) = copy_case(@$files);
|
||||
ok($ok, "copies a kernel from an image with @$files") or diag($error);
|
||||
is(read_text("$dir/kernel"), "$files->[0]\n", "copies $files->[0] from an image with @$files");
|
||||
is((stat("$dir/kernel"))[2] & oct(7777), oct(755), "keeps the mode of $files->[0]");
|
||||
}
|
||||
|
||||
{
|
||||
my ($ok, $error, $dir) = copy_case('boot/vmlinuz-6.12.0-55.el10.x86_64', 'lib/modules/6.12.0-55.el10.x86_64/vmlinuz');
|
||||
ok(!$ok, 'fails when the image has no kernel of the release');
|
||||
like($error, qr/couldn't find the kernel file matched \Q$release\E/, 'names the release of the missing kernel');
|
||||
ok(!-e "$dir/kernel", 'copies no kernel of another release');
|
||||
}
|
||||
|
||||
{
|
||||
my $root = tempdir(CLEANUP => 1);
|
||||
make_path("$root/boot");
|
||||
write_text("$root/boot/vmlinuz-$release", "kernel\n");
|
||||
my $ok = eval { imgutils::copy_kernel($root, $release, "$root/missing") };
|
||||
ok(!$ok, 'fails when the kernel cannot be copied');
|
||||
like($@, qr/^Error: failed to copy the kernel to \Q$root\E\/missing: /, 'reports the failed copy');
|
||||
}
|
||||
|
||||
# Packs a directory of two files, with each named command replaced by one that fails without output.
|
||||
sub pack_case {
|
||||
my (@failing) = @_;
|
||||
my $dir = tempdir(CLEANUP => 1);
|
||||
my $src = "$dir/initrd";
|
||||
make_path("$src/bin", "$dir/bin");
|
||||
write_text("$src/init", "init\n");
|
||||
write_text("$src/bin/netstart", "netstart\n");
|
||||
for my $command (@failing) {
|
||||
write_text("$dir/bin/$command", "#!/bin/sh\nexit 1\n");
|
||||
chmod(0755, "$dir/bin/$command");
|
||||
}
|
||||
my ($ok, $error);
|
||||
{
|
||||
local $ENV{PATH} = "$dir/bin:$ENV{PATH}";
|
||||
local *STDOUT;
|
||||
open(STDOUT, '>', \my $printed) or die "STDOUT: $!";
|
||||
$ok = eval { imgutils::pack_initrd($src, "$dir/initrd.gz", 'gzip', 'stateless') };
|
||||
$error = $@;
|
||||
}
|
||||
return ($ok, $error, $dir, $src);
|
||||
}
|
||||
|
||||
{
|
||||
my ($ok, $error, $dir, $src) = pack_case();
|
||||
ok($ok, 'packs the initial ramdisk') or diag($error);
|
||||
my @listing = sort map { chomp; $_ } `gzip -dc $dir/initrd.gz | cpio -it 2>/dev/null`;
|
||||
is_deeply(\@listing, [ '.', 'bin', 'bin/netstart', 'init' ], 'the initial ramdisk holds the packed directory');
|
||||
ok(!-e $src, 'removes the packed directory');
|
||||
}
|
||||
|
||||
for my $command (qw(find cpio gzip)) {
|
||||
my ($ok, $error, $dir, $src) = pack_case($command);
|
||||
ok(!$ok, "fails when $command fails");
|
||||
is($error, "Error: failed to generate the initial ramdisk for stateless.\n", "reports the failed $command");
|
||||
ok(!-e $src, "removes the packed directory when $command fails");
|
||||
}
|
||||
|
||||
{
|
||||
my $dir = tempdir(CLEANUP => 1);
|
||||
local *STDOUT;
|
||||
open(STDOUT, '>', \my $printed) or die "STDOUT: $!";
|
||||
my $ok = eval { imgutils::pack_initrd("$dir/missing", "$dir/initrd.gz", 'gzip', 'statelite') };
|
||||
ok(!$ok, 'fails when the directory to pack does not exist');
|
||||
is($@, "Error: failed to generate the initial ramdisk for statelite.\n", 'reports the missing directory');
|
||||
}
|
||||
|
||||
done_testing();
|
||||
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use FindBin;
|
||||
use File::Path qw(make_path);
|
||||
use File::Slurper qw(write_text);
|
||||
use File::Temp qw(tempdir);
|
||||
use lib "$FindBin::Bin/../../perl-xCAT";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils";
|
||||
use Test::More;
|
||||
use imgutils;
|
||||
|
||||
sub image_root {
|
||||
my (@files) = @_;
|
||||
my $root = tempdir(CLEANUP => 1) . '/rootimg';
|
||||
make_path($root);
|
||||
for my $file (@files) {
|
||||
if ($file =~ m{/$}) {
|
||||
make_path("$root/$file");
|
||||
} else {
|
||||
make_path("$root/" . ($file =~ s{/[^/]+$}{}r));
|
||||
write_text("$root/$file", '');
|
||||
}
|
||||
}
|
||||
return $root;
|
||||
}
|
||||
|
||||
is(imgutils::debootstrap_finished(tempdir(CLEANUP => 1) . '/rootimg'), 0,
|
||||
'a missing root image needs debootstrap');
|
||||
is(imgutils::debootstrap_finished(image_root('etc/fstab')), 0,
|
||||
'a root image with only the dummy fstab of genimage needs debootstrap');
|
||||
is(imgutils::debootstrap_finished(image_root('var/lib/dpkg/')), 0,
|
||||
'a root image without a dpkg status file needs debootstrap');
|
||||
is(imgutils::debootstrap_finished(image_root('etc/fstab', 'var/lib/dpkg/status')), 1,
|
||||
'a root image that debootstrap finished is reused');
|
||||
|
||||
for my $case (
|
||||
[ 'debootstrap/debootstrap.log', 'var/lib/dpkg/status' ],
|
||||
[ 'debootstrap/' ],
|
||||
) {
|
||||
my $root = image_root(@$case);
|
||||
my $finished = eval { imgutils::debootstrap_finished($root) };
|
||||
is($finished, undef, "an unfinished root image with @$case stops genimage");
|
||||
like($@, qr/^Error: \Q$root\E holds an unfinished debootstrap\. Remove \Q$root\E /,
|
||||
"the error for a root image with @$case names the root image to remove");
|
||||
}
|
||||
|
||||
done_testing();
|
||||
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use FindBin;
|
||||
use File::Path qw(make_path);
|
||||
use File::Slurper qw(read_text write_text);
|
||||
use File::Temp qw(tempdir);
|
||||
use lib "$FindBin::Bin/../../perl-xCAT";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils";
|
||||
use Test::More;
|
||||
use imgutils;
|
||||
|
||||
plan skip_all => 'the build host has no /etc/hosts or /etc/resolv.conf'
|
||||
unless -r '/etc/hosts' && -r '/etc/resolv.conf';
|
||||
|
||||
my %host = map { $_ => read_text("/etc/$_") } qw(hosts resolv.conf);
|
||||
my $stub = '../run/systemd/resolve/stub-resolv.conf';
|
||||
my $dummy = '#Dummy resolv.conf to make boot cleaner';
|
||||
|
||||
# A root image as an earlier genimage run leaves it: resolv.conf links to the stub that holds the dummy.
|
||||
sub image_root {
|
||||
my $root = tempdir(CLEANUP => 1);
|
||||
make_path("$root/etc", "$root/run/systemd/resolve");
|
||||
write_text("$root/etc/hosts", "127.0.0.1 localhost\n");
|
||||
write_text("$root/run/systemd/resolve/stub-resolv.conf", $dummy);
|
||||
symlink($stub, "$root/etc/resolv.conf") or die "symlink: $!";
|
||||
return $root;
|
||||
}
|
||||
|
||||
sub has_host_files {
|
||||
my ($root, $label) = @_;
|
||||
for my $file (qw(hosts resolv.conf)) {
|
||||
ok(!-l "$root/etc/$file", "$label: etc/$file is a file, not a link");
|
||||
is(read_text("$root/etc/$file"), $host{$file}, "$label: etc/$file holds the file of the build host");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
my $root = image_root();
|
||||
for my $pass (1, 2) {
|
||||
imgutils::use_host_resolver($root);
|
||||
has_host_files($root, "pass $pass");
|
||||
is(read_text("$root/etc/hosts.bak"), "127.0.0.1 localhost\n", "pass $pass: hosts.bak holds the hosts of the image");
|
||||
is(readlink("$root/etc/resolv.conf.bak"), $stub, "pass $pass: resolv.conf.bak is the link of the image");
|
||||
}
|
||||
is(read_text("$root/run/systemd/resolve/stub-resolv.conf"), $dummy, 'the stub that the link names is not written');
|
||||
}
|
||||
|
||||
{
|
||||
my $root = image_root();
|
||||
my $outside = tempdir(CLEANUP => 1) . '/stub-resolv.conf';
|
||||
write_text($outside, "nameserver 192.0.2.1\n");
|
||||
unlink("$root/etc/resolv.conf");
|
||||
symlink($outside, "$root/etc/resolv.conf") or die "symlink: $!";
|
||||
imgutils::use_host_resolver($root);
|
||||
is(readlink("$root/etc/resolv.conf.bak"), $outside, 'an absolute link is moved aside, not followed');
|
||||
|
||||
# A package script can turn resolv.conf back into a link while the .bak files exist.
|
||||
unlink("$root/etc/resolv.conf");
|
||||
symlink($outside, "$root/etc/resolv.conf") or die "symlink: $!";
|
||||
imgutils::use_host_resolver($root);
|
||||
has_host_files($root, 'after resolv.conf is linked again');
|
||||
is(readlink("$root/etc/resolv.conf.bak"), $outside, 'after resolv.conf is linked again: resolv.conf.bak still holds the link of the image');
|
||||
is(read_text($outside), "nameserver 192.0.2.1\n", 'a file outside the image is never written through a link');
|
||||
}
|
||||
|
||||
{
|
||||
my $root = image_root();
|
||||
unlink("$root/etc/hosts");
|
||||
imgutils::use_host_resolver($root);
|
||||
has_host_files($root, 'an image without hosts');
|
||||
ok(!-e "$root/etc/hosts.bak", 'an image without hosts gets no hosts.bak');
|
||||
}
|
||||
|
||||
done_testing();
|
||||
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use FindBin;
|
||||
use File::Path qw(make_path);
|
||||
use File::Slurper qw(read_text write_text);
|
||||
use File::Temp qw(tempdir);
|
||||
use lib "$FindBin::Bin/../../perl-xCAT";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils";
|
||||
use Test::More;
|
||||
use imgutils;
|
||||
|
||||
my $dropin = 'etc/systemd/system/kdump.service.d/xcat-dump-memory.conf';
|
||||
my $condition = "[Unit]\nConditionKernelCommandLine=|crashkernel\nConditionKernelCommandLine=|fadump\n";
|
||||
|
||||
sub image_root {
|
||||
my (%units) = @_;
|
||||
my $root = tempdir(CLEANUP => 1);
|
||||
for my $unit (keys %units) {
|
||||
make_path("$root/usr/lib/systemd/system");
|
||||
write_text("$root/usr/lib/systemd/system/$unit", $units{$unit});
|
||||
}
|
||||
return $root;
|
||||
}
|
||||
|
||||
{
|
||||
my $root = image_root('kdump.service' => "[Service]\nExecStart=/usr/bin/kdumpctl start\n",
|
||||
'NetworkManager.service' => "[Service]\n");
|
||||
make_path("$root/etc/systemd/system/kdump.service.d");
|
||||
write_text("$root/etc/systemd/system/kdump.service.d/site.conf", "[Service]\nTimeoutSec=600\n");
|
||||
for my $pass (1, 2) {
|
||||
imgutils::skip_kdump_without_dump_memory($root);
|
||||
is(read_text("$root/$dropin"), $condition,
|
||||
"pass $pass: kdump.service runs only with crashkernel= or fadump=");
|
||||
}
|
||||
opendir(my $dh, "$root/etc/systemd/system/kdump.service.d") or die "opendir: $!";
|
||||
is_deeply([sort grep { !/^\./ } readdir($dh)], ['site.conf', 'xcat-dump-memory.conf'],
|
||||
'the drop-in is written once next to the site drop-ins');
|
||||
closedir($dh);
|
||||
is(read_text("$root/etc/systemd/system/kdump.service.d/site.conf"), "[Service]\nTimeoutSec=600\n",
|
||||
'a site drop-in is unchanged');
|
||||
ok(!-e "$root/etc/systemd/system/NetworkManager.service.d", 'other units get no drop-in');
|
||||
}
|
||||
|
||||
{
|
||||
my $root = image_root('NetworkManager.service' => "[Service]\n");
|
||||
imgutils::skip_kdump_without_dump_memory($root);
|
||||
ok(!-e "$root/etc/systemd/system/kdump.service.d", 'an image without kdump.service is unchanged');
|
||||
}
|
||||
|
||||
done_testing();
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../../perl-xCAT";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils";
|
||||
use Test::More;
|
||||
use imgutils;
|
||||
|
||||
for my $case (
|
||||
[ [qw(6.8.0-99-generic 6.8.0-100-generic)], '6.8.0-100-generic', 'an ABI of 100 is newer than an ABI of 99' ],
|
||||
[ [qw(6.10.0-1-generic 6.9.0-1-generic)], '6.10.0-1-generic', 'kernel 6.10 is newer than kernel 6.9' ],
|
||||
[ [qw(6.8.0-100-generic 7.0.0-42-generic)], '7.0.0-42-generic', 'a newer kernel wins over a larger ABI' ],
|
||||
[ [qw(7.0.0-42-generic)], '7.0.0-42-generic', 'an image with one kernel gets that kernel' ],
|
||||
) {
|
||||
my ($releases, $newest, $label) = @$case;
|
||||
is(imgutils::newest_kernel_version(@$releases), $newest, $label);
|
||||
is(imgutils::newest_kernel_version(reverse @$releases), $newest, "$label, in either order");
|
||||
}
|
||||
|
||||
is(imgutils::newest_kernel_version(), undef, 'an image without a kernel gets no kernel release');
|
||||
|
||||
done_testing();
|
||||
@@ -0,0 +1,87 @@
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use FindBin;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use lib "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use Fcntl qw(S_IMODE);
|
||||
use File::Path qw(make_path);
|
||||
use File::Slurper qw(read_text write_text);
|
||||
use File::Temp qw(tempdir);
|
||||
use Test::More;
|
||||
use XCAT::Test::File qw(repo_path);
|
||||
|
||||
$ENV{XCATROOT} = repo_path('xCAT-server');
|
||||
require(repo_path('xCAT-server/share/xcat/netboot/imgutils/imgutils.pm'));
|
||||
|
||||
my @both = ('etc/sysconfig/network-scripts', 'etc/NetworkManager/system-connections');
|
||||
|
||||
sub image {
|
||||
my $root = tempdir(CLEANUP => 1);
|
||||
make_path(map { "$root/$_" } @_);
|
||||
return $root;
|
||||
}
|
||||
|
||||
sub mode {
|
||||
my ($file) = @_;
|
||||
return -f $file ? sprintf('%04o', S_IMODE((stat $file)[2])) : 'missing';
|
||||
}
|
||||
|
||||
sub profiles {
|
||||
my ($root) = @_;
|
||||
return [map { substr($_, length($root) + 1) } sort glob("$root/{$both[0],$both[1]}/*")];
|
||||
}
|
||||
|
||||
for my $case (['rhels10.1', 'etc/NetworkManager/system-connections'], ['alma10.1', @both]) {
|
||||
my ($os, @dirs) = @$case;
|
||||
my $root = image(@dirs);
|
||||
imgutils::write_nic_profiles($root, $os, 'eth0', 'eth1,,eth2');
|
||||
is_deeply(profiles($root), [map { "$both[1]/xcat-genimage-$_.nmconnection" } qw(eth1 eth2)],
|
||||
"a $os image with " . join(' and ', @dirs) . ' gets keyfiles for the requested interfaces only');
|
||||
for my $nic (qw(eth1 eth2)) {
|
||||
my $file = "$root/$both[1]/xcat-genimage-$nic.nmconnection";
|
||||
is(-f $file ? read_text($file) : '',
|
||||
"[connection]\nid=$nic\ntype=ethernet\ninterface-name=$nic\n\n[ipv4]\nmethod=auto\n",
|
||||
"the $os keyfile for $nic asks for DHCP");
|
||||
is(mode($file), '0600', "only root can read the $os keyfile for $nic");
|
||||
}
|
||||
}
|
||||
|
||||
my $rebuilt = image($both[1]);
|
||||
write_text("$rebuilt/$both[1]/site.nmconnection", "site profile\n");
|
||||
imgutils::write_nic_profiles($rebuilt, 'rhels10.1', 'eth0', 'eth1,eth2');
|
||||
imgutils::write_nic_profiles($rebuilt, 'rhels10.1', 'eth0', 'eth2');
|
||||
is_deeply(profiles($rebuilt), ["$both[1]/site.nmconnection", "$both[1]/xcat-genimage-eth2.nmconnection"],
|
||||
'a rebuilt EL10 image drops the keyfile of an interface that is no longer requested and keeps other profiles');
|
||||
|
||||
my $el9 = image(@both);
|
||||
imgutils::write_nic_profiles($el9, 'rhels9.6', 'eth0', 'eth1');
|
||||
is_deeply(profiles($el9), ["$both[0]/ifcfg-eth0", "$both[0]/ifcfg-eth1"], 'an EL9 image gets ifcfg files only');
|
||||
is(read_text("$el9/$both[0]/ifcfg-eth0"), "ONBOOT=no\nBOOTPROTO=dhcp\nDEVICE=eth0\n",
|
||||
'the EL9 interface of the initial ramdisk stays off at boot');
|
||||
is(read_text("$el9/$both[0]/ifcfg-eth1"), "ONBOOT=yes\nBOOTPROTO=dhcp\nDEVICE=eth1\n",
|
||||
'the EL9 interface eth1 gets DHCP');
|
||||
is(mode("$el9/$both[0]/ifcfg-eth1"), '0644', 'the EL9 ifcfg file keeps its permissions');
|
||||
|
||||
for my $os (qw(rhels10.1 rhels9.6)) {
|
||||
my $bare = image('etc');
|
||||
imgutils::write_nic_profiles($bare, $os, 'eth0', 'eth1');
|
||||
ok(!-e "$bare/etc/sysconfig" && !-e "$bare/etc/NetworkManager", "a $os image without either directory gets no profile");
|
||||
}
|
||||
|
||||
for my $case (['rhels10.1', 1], ['rocky10.2', 1], ['rhels9.6', 0]) {
|
||||
my ($os, $disabled) = @$case;
|
||||
my $root = image('etc/NetworkManager/conf.d');
|
||||
imgutils::disable_auto_profiles($root, $os);
|
||||
my $conf = "$root/etc/NetworkManager/conf.d/xcat.conf";
|
||||
if ($disabled) {
|
||||
is(-f $conf ? read_text($conf) : '', "[main]\nno-auto-default=*\n", "a $os image turns off the automatic DHCP profiles");
|
||||
} else {
|
||||
ok(!-e $conf, "a $os image keeps the NetworkManager defaults");
|
||||
}
|
||||
}
|
||||
my $without = image('etc');
|
||||
imgutils::disable_auto_profiles($without, 'rhels10.1');
|
||||
ok(!-e "$without/etc/NetworkManager", 'an image without NetworkManager gets no NetworkManager configuration');
|
||||
|
||||
done_testing();
|
||||
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use FindBin;
|
||||
use File::Path qw(make_path);
|
||||
use File::Slurper qw(read_text write_text);
|
||||
use File::Temp qw(tempdir);
|
||||
use lib "$FindBin::Bin/../../perl-xCAT";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils";
|
||||
use Test::More;
|
||||
use imgutils;
|
||||
|
||||
plan skip_all => 'the build host has no /etc/hosts or /etc/resolv.conf'
|
||||
unless -r '/etc/hosts' && -r '/etc/resolv.conf';
|
||||
|
||||
sub sources {
|
||||
my ($dir) = @_;
|
||||
opendir(my $dh, $dir) or die "opendir $dir: $!";
|
||||
my @files = sort grep { !/^\./ } readdir($dh);
|
||||
closedir($dh);
|
||||
return \@files;
|
||||
}
|
||||
|
||||
my $root = tempdir(CLEANUP => 1);
|
||||
my $sources = "$root/etc/apt/sources.list.d";
|
||||
my $site = "deb http://192.0.2.2/site ./\n";
|
||||
make_path($sources);
|
||||
write_text("$sources/$_", "deb http://192.0.2.1/retired ./\n") for qw(genimage.apt.list genimage1.apt.list);
|
||||
write_text("$sources/site.list", $site);
|
||||
write_text("$root/etc/hosts", "127.0.0.1 localhost\n");
|
||||
write_text("$root/etc/resolv.conf", '#Dummy resolv.conf to make boot cleaner');
|
||||
|
||||
for my $pass (1, 2) {
|
||||
imgutils::prepare_reused_root($root);
|
||||
is_deeply(sources($sources), ['site.list'], "pass $pass: only the apt sources that genimage writes are removed");
|
||||
is(read_text("$sources/site.list"), $site, "pass $pass: a site source is kept as it is");
|
||||
is(read_text("$root/etc/resolv.conf"), read_text('/etc/resolv.conf'),
|
||||
"pass $pass: the image gets the resolv.conf of the build host");
|
||||
is(read_text("$root/etc/resolv.conf.bak"), '#Dummy resolv.conf to make boot cleaner',
|
||||
"pass $pass: resolv.conf.bak holds the resolv.conf of the image");
|
||||
}
|
||||
|
||||
{
|
||||
my $bare = tempdir(CLEANUP => 1);
|
||||
make_path("$bare/etc");
|
||||
imgutils::prepare_reused_root($bare);
|
||||
is(read_text("$bare/etc/hosts"), read_text('/etc/hosts'), 'an image without apt sources still gets the hosts of the build host');
|
||||
}
|
||||
|
||||
done_testing();
|
||||
@@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use FindBin;
|
||||
use File::Find;
|
||||
use File::Path qw(make_path);
|
||||
use File::Slurper qw(write_text);
|
||||
use File::Temp qw(tempdir);
|
||||
use lib "$FindBin::Bin/../../perl-xCAT";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils";
|
||||
use Test::More;
|
||||
use imgutils;
|
||||
|
||||
# A finished root image with the os-release and the dpkg status that Ubuntu writes.
|
||||
sub image_root {
|
||||
my (%overrides) = @_;
|
||||
my %image = (codename => 'resolute', arch => 'riscv64', field => 'VERSION_CODENAME', %overrides);
|
||||
my $root = tempdir(CLEANUP => 1);
|
||||
make_path("$root/usr/lib", "$root/etc", "$root/var/lib/dpkg");
|
||||
write_text("$root/usr/lib/os-release", "NAME=\"Ubuntu\"\nVERSION_ID=\"26.04\"\n$image{field}=$image{codename}\nID=ubuntu\n")
|
||||
if defined $image{codename};
|
||||
symlink('../usr/lib/os-release', "$root/etc/os-release") or die "symlink: $!";
|
||||
write_text("$root/var/lib/dpkg/status",
|
||||
"Package: debconf\nStatus: install ok installed\nArchitecture: all\n\n"
|
||||
. "Package: dpkg\nEssential: yes\nStatus: install ok installed\nArchitecture: $image{arch}\nVersion: 1.23.5ubuntu1\n\n"
|
||||
. "Package: dpkg-dev\nStatus: install ok installed\nArchitecture: all\n");
|
||||
return $root;
|
||||
}
|
||||
|
||||
sub snapshot {
|
||||
my ($root) = @_;
|
||||
my @entries;
|
||||
find({ wanted => sub { push @entries, join(' ', $File::Find::name, (lstat)[1, 2, 7, 9]) }, no_chdir => 1 }, $root);
|
||||
return [sort @entries];
|
||||
}
|
||||
|
||||
for my $case (
|
||||
[ 'resolute', 'riscv64', 'the release and architecture that built the image' ],
|
||||
[ 'resolute-updates', 'riscv64', 'the updates pocket of that release' ],
|
||||
[ 'resolute-security', 'riscv64', 'the security pocket of that release' ],
|
||||
) {
|
||||
my ($suite, $arch, $label) = @$case;
|
||||
is(eval { imgutils::check_reused_root(image_root(), $suite, $arch) }, 1, "a root image is reused for $label") or diag($@);
|
||||
}
|
||||
|
||||
{
|
||||
my $root = image_root(codename => '"resolute"');
|
||||
is(eval { imgutils::check_reused_root($root, 'resolute', 'riscv64') }, 1, 'a quoted VERSION_CODENAME is read') or diag($@);
|
||||
}
|
||||
|
||||
{
|
||||
my $root = image_root(codename => 'xenial', arch => 'amd64', field => 'UBUNTU_CODENAME');
|
||||
is(eval { imgutils::check_reused_root($root, 'xenial', 'amd64') }, 1, 'an Ubuntu 16.04 image with only UBUNTU_CODENAME is reused') or diag($@);
|
||||
}
|
||||
|
||||
{
|
||||
# Ubuntu 14.04 names its release only in lsb-release.
|
||||
my $root = image_root(codename => undef, arch => 'amd64');
|
||||
unlink("$root/etc/os-release");
|
||||
write_text("$root/etc/os-release", "NAME=\"Ubuntu\"\nVERSION_ID=\"14.04\"\nID=ubuntu\n");
|
||||
write_text("$root/etc/lsb-release", "DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=14.04\nDISTRIB_CODENAME=trusty\n");
|
||||
is(eval { imgutils::check_reused_root($root, 'trusty', 'amd64') }, 1, 'an Ubuntu 14.04 image with only DISTRIB_CODENAME is reused') or diag($@);
|
||||
is(eval { imgutils::check_reused_root($root, 'xenial', 'amd64') }, undef, 'an Ubuntu 14.04 image is not reused for Ubuntu 16.04');
|
||||
like($@, qr/holds Ubuntu trusty for amd64, not xenial for amd64/, 'the error names the release of the Ubuntu 14.04 image');
|
||||
}
|
||||
|
||||
for my $case (
|
||||
[ [], 'noble', 'riscv64', qr/holds Ubuntu resolute for riscv64, not noble for riscv64\. Remove /, 'another release' ],
|
||||
[ [], 'resolute', 'amd64', qr/holds Ubuntu resolute for riscv64, not resolute for amd64\. Remove /, 'another architecture' ],
|
||||
[ [ codename => undef ], 'resolute', 'riscv64', qr/cannot tell the Ubuntu release and architecture/, 'no os-release' ],
|
||||
[ [ arch => '' ], 'resolute', 'riscv64', qr/cannot tell the Ubuntu release and architecture/, 'no dpkg architecture' ],
|
||||
) {
|
||||
my ($image, $suite, $arch, $error, $label) = @$case;
|
||||
my $root = image_root(@$image);
|
||||
my $before = snapshot($root);
|
||||
my $result = eval { imgutils::check_reused_root($root, $suite, $arch) };
|
||||
is($result, undef, "a root image is not reused for $label");
|
||||
like($@, $error, "the error for $label names the mismatch");
|
||||
is_deeply(snapshot($root), $before, "a root image refused for $label is left as it was");
|
||||
}
|
||||
|
||||
{
|
||||
my $root = image_root();
|
||||
make_path("$root/bin");
|
||||
write_text("$root/bin/uname-binary", "uname\n");
|
||||
my $before = snapshot($root);
|
||||
is(eval { imgutils::check_reused_root($root, 'resolute', 'riscv64') }, undef,
|
||||
'a root image with the uname backup of an interrupted run is not reused');
|
||||
like($@, qr/holds bin\/uname-binary, which an interrupted genimage run left\. Restore bin\/uname from it or remove /,
|
||||
'the error says how to recover the uname of the image');
|
||||
is_deeply(snapshot($root), $before, 'a root image with the uname backup is left as it was');
|
||||
}
|
||||
|
||||
{
|
||||
# An absolute link would read the os-release of the build host, which can name the same release.
|
||||
my $root = image_root(codename => undef);
|
||||
my $host = tempdir(CLEANUP => 1) . '/os-release';
|
||||
write_text($host, "VERSION_CODENAME=resolute\n");
|
||||
unlink("$root/etc/os-release");
|
||||
symlink($host, "$root/etc/os-release") or die "symlink: $!";
|
||||
is(eval { imgutils::check_reused_root($root, 'resolute', 'riscv64') }, undef, 'an os-release link that leaves the image is not followed');
|
||||
}
|
||||
|
||||
done_testing();
|
||||
@@ -0,0 +1,155 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
## no critic (TestingAndDebugging::ProhibitNoWarnings, Variables::RequireLocalizedPunctuationVars)
|
||||
use Errno qw(EACCES EIO);
|
||||
use FindBin;
|
||||
use File::Slurper qw(read_text write_text);
|
||||
use File::Temp qw(tempdir);
|
||||
use lib "$FindBin::Bin/../../perl-xCAT";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils";
|
||||
use Test::More;
|
||||
|
||||
BEGIN {
|
||||
*CORE::GLOBAL::rename = sub { return CORE::rename($_[0], $_[1]); };
|
||||
*CORE::GLOBAL::link = sub { return CORE::link($_[0], $_[1]); };
|
||||
}
|
||||
use imgutils;
|
||||
|
||||
my @modes = qw(statelite stateless);
|
||||
my @names = ('kernel', map { "initrd-$_.gz" } @modes);
|
||||
|
||||
# Publishes a staged kernel and two ramdisks over an older set, with the faults that %case names.
|
||||
sub publish_case {
|
||||
my (%case) = @_;
|
||||
my $dir = tempdir(CLEANUP => 1);
|
||||
my $staging = File::Temp->newdir('.genimage-boot.XXXXXX', DIR => $dir, CLEANUP => 1);
|
||||
write_text("$staging/$_", "new $_\n") for @names;
|
||||
if ($case{old}) {
|
||||
write_text("$dir/$_", "old $_\n") for @names;
|
||||
}
|
||||
my ($ok, $error);
|
||||
{
|
||||
no warnings 'redefine';
|
||||
local *CORE::GLOBAL::link = sub {
|
||||
if (defined $case{link} && $_[0] eq "$dir/$case{link}") {
|
||||
$! = EACCES;
|
||||
return 0;
|
||||
}
|
||||
return CORE::link($_[0], $_[1]);
|
||||
};
|
||||
local *CORE::GLOBAL::rename = sub {
|
||||
if (defined $case{applied} && $_[0] eq "$staging/$case{applied}") {
|
||||
CORE::rename($_[0], $_[1]);
|
||||
$! = EIO;
|
||||
return 0;
|
||||
}
|
||||
if ((defined $case{rename} && $_[0] eq "$staging/$case{rename}")
|
||||
|| (defined $case{rollback} && $_[0] eq "$staging/previous-$case{rollback}")) {
|
||||
unlink("$staging/previous-$case{lost}") if defined $case{lost};
|
||||
$! = EACCES;
|
||||
return 0;
|
||||
}
|
||||
return CORE::rename($_[0], $_[1]);
|
||||
};
|
||||
$ok = eval { imgutils::publish_staged_boot_files($staging, $dir, @modes) };
|
||||
$error = $@;
|
||||
}
|
||||
undef $staging;
|
||||
my %state = map { $_ => (-e "$dir/$_" ? read_text("$dir/$_") : undef) } @names;
|
||||
return ($ok, $error, $dir, \%state);
|
||||
}
|
||||
|
||||
sub set_of {
|
||||
my ($age) = @_;
|
||||
return { map { $_ => "$age $_\n" } @names };
|
||||
}
|
||||
|
||||
for my $old (1, 0) {
|
||||
my $label = $old ? 'over an older set' : 'on a first build';
|
||||
my ($ok, $error, $dir, $state) = publish_case(old => $old);
|
||||
ok($ok, "publication $label completes") or diag($error);
|
||||
is_deeply($state, set_of('new'), "publication $label puts the new kernel and both ramdisks in place");
|
||||
is_deeply([ glob("$dir/.genimage*") ], [], "publication $label removes the staging directory");
|
||||
}
|
||||
|
||||
for my $name (@names) {
|
||||
my ($ok, $error, $dir, $state) = publish_case(old => 1, link => $name);
|
||||
ok(!$ok, "a failed backup of $name stops the publication");
|
||||
like($error, qr/^Error: failed to preserve the previous (?:kernel|initial ramdisk for \w+): /, "the error names the $name backup");
|
||||
is_deeply($state, set_of('old'), "a failed backup of $name keeps the older set");
|
||||
}
|
||||
|
||||
for my $name (@names) {
|
||||
my ($ok, $error, $dir, $state) = publish_case(old => 1, rename => $name);
|
||||
ok(!$ok, "a failed rename of $name stops the publication");
|
||||
like($error, qr/^Error: failed to publish the (?:kernel|initial ramdisk for \w+): /, "the error names the $name rename");
|
||||
is_deeply($state, set_of('old'), "a failed rename of $name puts the older set back");
|
||||
is_deeply([ glob("$dir/.genimage*") ], [], "a failed rename of $name removes the staging directory");
|
||||
}
|
||||
|
||||
for my $name (@names) {
|
||||
my ($ok, $error, $dir, $state) = publish_case(old => 1, applied => $name);
|
||||
ok(!$ok, "a rename of $name that reports a failure after it moved the file stops the publication");
|
||||
is_deeply($state, set_of('old'), "a rename of $name that reports a failure after it moved the file puts the older set back");
|
||||
is_deeply([ glob("$dir/.genimage*") ], [], "a rename of $name that reports a failure after it moved the file removes the staging directory");
|
||||
}
|
||||
|
||||
{
|
||||
my ($ok, $error, $dir, $state) = publish_case(old => 0, applied => 'initrd-stateless.gz');
|
||||
ok(!$ok, 'a rename that reports a failure after it moved the file on a first build stops the publication');
|
||||
is_deeply($state, { map { $_ => undef } @names }, 'a rename that reports a failure after it moved the file on a first build leaves no kernel or ramdisk');
|
||||
}
|
||||
|
||||
{
|
||||
my ($ok, $error, $dir, $state) = publish_case(old => 0, rename => 'initrd-stateless.gz');
|
||||
ok(!$ok, 'a failed rename on a first build stops the publication');
|
||||
is_deeply($state, { map { $_ => undef } @names }, 'a failed rename on a first build leaves no kernel or ramdisk');
|
||||
}
|
||||
|
||||
SKIP: {
|
||||
skip 'link() of a symbolic link is checked on Linux', 2 unless $^O eq 'linux';
|
||||
my $dir = tempdir(CLEANUP => 1);
|
||||
my $staging = File::Temp->newdir('.genimage-boot.XXXXXX', DIR => $dir, CLEANUP => 1);
|
||||
write_text("$staging/$_", "new $_\n") for @names;
|
||||
symlink('missing-kernel', "$dir/kernel") or die "symlink: $!";
|
||||
write_text("$dir/$_", "old $_\n") for grep { $_ ne 'kernel' } @names;
|
||||
my $ok;
|
||||
{
|
||||
no warnings 'redefine';
|
||||
local *CORE::GLOBAL::rename = sub {
|
||||
if ($_[0] eq "$staging/initrd-stateless.gz") {
|
||||
$! = EACCES;
|
||||
return 0;
|
||||
}
|
||||
return CORE::rename($_[0], $_[1]);
|
||||
};
|
||||
$ok = eval { imgutils::publish_staged_boot_files($staging, $dir, @modes) };
|
||||
}
|
||||
ok(!$ok, 'a failed rename over a dangling kernel link stops the publication');
|
||||
is(readlink("$dir/kernel"), 'missing-kernel', 'a dangling kernel link is put back instead of removed');
|
||||
}
|
||||
|
||||
{
|
||||
my ($ok, $error, $dir, $state) = publish_case(old => 1, rename => 'initrd-stateless.gz', rollback => 'initrd-statelite.gz');
|
||||
ok(!$ok, 'a failed rollback stops the publication');
|
||||
like($error, qr/initial ramdisk for statelite rollback failed: .*Boot files retained in \Q$dir\E\/\.genimage-boot\./,
|
||||
'the error names the file that could not be put back and the directory that keeps it');
|
||||
is($state->{kernel}, "old kernel\n", 'the kernel is still put back after a failed rollback of a ramdisk');
|
||||
my ($kept) = glob("$dir/.genimage-boot.*/previous-initrd-statelite.gz");
|
||||
ok(defined $kept, 'the staging directory keeps the previous ramdisk that could not be put back');
|
||||
is(defined $kept ? read_text($kept) : undef, "old initrd-statelite.gz\n", 'the kept file is the previous ramdisk');
|
||||
}
|
||||
|
||||
{
|
||||
my ($ok, $error, $dir, $state) = publish_case(old => 1, rename => 'initrd-stateless.gz', lost => 'kernel');
|
||||
ok(!$ok, 'a rollback whose backup is gone stops the publication');
|
||||
like($error, qr/kernel rollback failed: .*Boot files retained in \Q$dir\E\/\.genimage-boot\./,
|
||||
'the error names the kernel whose backup is gone');
|
||||
is($state->{kernel}, "new kernel\n", 'the published kernel is not removed when its backup is gone');
|
||||
is($state->{'initrd-statelite.gz'}, "old initrd-statelite.gz\n", 'the ramdisk with a backup is still put back');
|
||||
ok(scalar(glob("$dir/.genimage-boot.*")), 'the staging directory is kept when a backup is gone');
|
||||
}
|
||||
|
||||
done_testing();
|
||||
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use FindBin;
|
||||
use File::Slurper qw(write_text);
|
||||
use File::Temp qw(tempdir);
|
||||
use lib "$FindBin::Bin/../../perl-xCAT";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils";
|
||||
use Test::More;
|
||||
use imgutils;
|
||||
|
||||
plan skip_all => 'bash is not installed' unless -x '/bin/bash';
|
||||
|
||||
# The script runs in the image, which lists its kernels in /lib/modules. This ls lists two of them.
|
||||
my $bin = tempdir(CLEANUP => 1);
|
||||
write_text("$bin/ls", "#!/bin/sh\n[ \"\$1\" = /lib/modules ] && printf '6.8.0-99-generic\\n6.8.0-100-generic\\n'\n");
|
||||
chmod(0755, "$bin/ls") or die "chmod: $!";
|
||||
|
||||
sub uname {
|
||||
my ($kernelver, @options) = @_;
|
||||
my $script = tempdir(CLEANUP => 1) . '/uname';
|
||||
write_text($script, imgutils::uname_script($kernelver));
|
||||
local $ENV{PATH} = "$bin:$ENV{PATH}";
|
||||
my $output = `/bin/bash $script @options`;
|
||||
chomp($output);
|
||||
return $output;
|
||||
}
|
||||
|
||||
is(uname('', '-r'), '6.8.0-100-generic', 'uname -r names the newest kernel of the image');
|
||||
is(uname('6.8.0-99-generic', '-r'), '6.8.0-99-generic', 'uname -r names an explicit kernelver');
|
||||
is(uname('', '-s'), 'Linux', 'uname -s names Linux');
|
||||
is(uname(''), 'Linux', 'uname without an option names Linux');
|
||||
|
||||
done_testing();
|
||||
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use FindBin;
|
||||
use File::Path qw(make_path);
|
||||
use File::Slurper qw(read_text write_text);
|
||||
use File::Temp qw(tempdir);
|
||||
use lib "$FindBin::Bin/../../perl-xCAT";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils";
|
||||
use Test::More;
|
||||
use imgutils;
|
||||
|
||||
plan skip_all => 'requires Linux sed' unless $^O eq 'linux';
|
||||
my $dir = tempdir(CLEANUP => 1);
|
||||
|
||||
my @legacy_repositories = qw(Rocky-BaseOS.repo almalinux.repo CentOS-Base.repo oracle-linux-ol10.repo);
|
||||
my @custom_repositories = qw(local-repository-0.repo xCAT-custom.repo administrator.repo);
|
||||
my $enabled = "[fixture]\nenabled=1\ngpgcheck=1\nbaseurl=https://repo.invalid/\n";
|
||||
my $disabled = "[fixture]\nenabled=0\ngpgcheck=1\nbaseurl=https://repo.invalid/\n";
|
||||
my $native = "[OS]\nenabled=1\ngpgcheck=1\n[update]\n \tenabled = 1\n[disabled]\nenabled=0\n#enabled=1\n";
|
||||
my $native_disabled = "[OS]\nenabled=0\ngpgcheck=1\n[update]\nenabled=0\n[disabled]\nenabled=0\n#enabled=1\n";
|
||||
for my $repository_case (
|
||||
['enabled', $native, $native_disabled],
|
||||
['already-disabled', $native_disabled, $native_disabled],
|
||||
['absent', undef, undef],
|
||||
) {
|
||||
my ($name, $input, $expected) = @$repository_case;
|
||||
subtest $name => sub {
|
||||
my $root = tempdir(DIR => $dir, CLEANUP => 1);
|
||||
my $repos = "$root/etc/yum.repos.d";
|
||||
make_path($repos);
|
||||
write_text("$repos/$_", $enabled) for (@legacy_repositories, @custom_repositories);
|
||||
write_text("$repos/openEuler.repo", $input) if defined $input;
|
||||
for my $pass (1, 2) {
|
||||
imgutils::disable_vendor_repositories($root);
|
||||
if (defined $expected) {
|
||||
is(read_text("$repos/openEuler.repo"), $expected,
|
||||
"pass $pass disables only active native repository assignments");
|
||||
} else {
|
||||
ok(!-e "$repos/openEuler.repo", "pass $pass does not create an absent vendor file");
|
||||
}
|
||||
is(read_text("$repos/$_"), $disabled, "pass $pass preserves policy for $_")
|
||||
for @legacy_repositories;
|
||||
is(read_text("$repos/$_"), $enabled, "pass $pass leaves $_ unchanged")
|
||||
for @custom_repositories;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
done_testing();
|
||||
@@ -0,0 +1,131 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
## no critic (Modules::RequireFilenameMatchesPackage, TestingAndDebugging::ProhibitNoStrict, TestingAndDebugging::ProhibitNoWarnings)
|
||||
no warnings qw(once redefine);
|
||||
|
||||
use File::Spec;
|
||||
use FindBin;
|
||||
use Test::More;
|
||||
|
||||
# An IPMI command reads the device ID and then the SDR repository before it can answer.
|
||||
# A failure in that chain must reach the administrator as an error of the node and must end
|
||||
# the chain, instead of being dropped or reported under no node.
|
||||
|
||||
BEGIN {
|
||||
for my $module (qw(
|
||||
xCAT::GlobalDef xCAT_monitoring::monitorctrl xCAT::IPMI
|
||||
xCAT::BMCUtils xCAT::PasswordUtils xCAT::Utils xCAT::TableUtils
|
||||
xCAT::IMMUtils xCAT::ServiceNodeUtils xCAT::NetworkUtils xCAT::Usage
|
||||
xCAT::data::ibmhwtypes xCAT::data::ibmleds
|
||||
xCAT::data::ipmigenericevents xCAT::data::ipmisensorevents
|
||||
IBM::EnergyManager
|
||||
)) {
|
||||
(my $file = $module) =~ s{::}{/}g;
|
||||
$INC{"$file.pm"} = __FILE__;
|
||||
no strict 'refs';
|
||||
*{"${module}::import"} = sub { };
|
||||
}
|
||||
|
||||
package xCAT::SvrUtils;
|
||||
our @messages;
|
||||
sub import { }
|
||||
sub sendmsg { push @messages, { text => $_[0], node => $_[2] }; }
|
||||
$INC{'xCAT/SvrUtils.pm'} = __FILE__;
|
||||
|
||||
package xCAT::SPD;
|
||||
sub import {
|
||||
my $caller = caller;
|
||||
no strict 'refs';
|
||||
*{"${caller}::decode_spd"} = sub { return; };
|
||||
}
|
||||
$INC{'xCAT/SPD.pm'} = __FILE__;
|
||||
|
||||
package File::Path;
|
||||
sub import {
|
||||
my $caller = caller;
|
||||
no strict 'refs';
|
||||
*{"${caller}::mkpath"} = sub { return; };
|
||||
}
|
||||
$INC{'File/Path.pm'} = __FILE__;
|
||||
|
||||
package Thread;
|
||||
sub import {
|
||||
my $caller = caller;
|
||||
no strict 'refs';
|
||||
*{"${caller}::yield"} = sub { return; };
|
||||
}
|
||||
$INC{'Thread.pm'} = __FILE__;
|
||||
|
||||
package LWP;
|
||||
our $VERSION = 5.64;
|
||||
sub import { }
|
||||
$INC{'LWP.pm'} = __FILE__;
|
||||
|
||||
package HTTP::Request::Common;
|
||||
sub import {
|
||||
my $caller = caller;
|
||||
no strict 'refs';
|
||||
*{"${caller}::GET"} = sub { return; };
|
||||
*{"${caller}::POST"} = sub { return; };
|
||||
}
|
||||
$INC{'HTTP/Request/Common.pm'} = __FILE__;
|
||||
|
||||
package main;
|
||||
*CORE::GLOBAL::chmod = sub (@) { return 1; };
|
||||
}
|
||||
|
||||
package FakeSession;
|
||||
sub new { return bless { calls => [] }, shift; }
|
||||
sub subcmd { my ($self, %args) = @_; push @{ $self->{calls} }, \%args; return; }
|
||||
|
||||
package main;
|
||||
|
||||
my $repo_root = File::Spec->catdir($FindBin::Bin, '..', '..');
|
||||
$ENV{XCATROOT} = File::Spec->catdir($repo_root, 'xCAT-server');
|
||||
my $plugin = File::Spec->catfile($repo_root, qw(xCAT-server lib xcat plugins ipmi.pm));
|
||||
do $plugin or die $@ || "Unable to load $plugin: $!";
|
||||
|
||||
# Run one callback of the chain with a reply and return what it reported and requested.
|
||||
sub run_step {
|
||||
my ($step, $rsp, %state) = @_;
|
||||
my $sessdata = { node => 'node01', ipmisession => FakeSession->new(), %state };
|
||||
local @xCAT::SvrUtils::messages = ();
|
||||
my $ok = eval { $step->($rsp, $sessdata); 1 };
|
||||
return {
|
||||
died => $ok ? '' : ($@ || 'died'),
|
||||
messages => [@xCAT::SvrUtils::messages],
|
||||
requests => $sessdata->{ipmisession}->{calls},
|
||||
};
|
||||
}
|
||||
|
||||
sub assert_node_error {
|
||||
my ($result, $text, $case) = @_;
|
||||
is($result->{died}, '', "$case: the callback returns");
|
||||
is(scalar @{ $result->{messages} }, 1, "$case: one message");
|
||||
my $message = $result->{messages}->[0] || {};
|
||||
is($message->{node}, 'node01', "$case: the message names the node");
|
||||
is_deeply($message->{text}, [ 1, $text ], "$case: the message is an error with the reply text");
|
||||
is(scalar @{ $result->{requests} }, 0, "$case: the chain stops");
|
||||
}
|
||||
|
||||
my $invalid_command = { code => 0xc1, data => [] };
|
||||
my $timeout = { error => 'timeout' };
|
||||
|
||||
for my $step (
|
||||
[ 'Get Device ID', \&xCAT_plugin::ipmi::gotdevid ],
|
||||
[ 'Get SDR Repository Info', \&xCAT_plugin::ipmi::got_sdr_rep_info ],
|
||||
[ 'Reserve SDR Repository', \&xCAT_plugin::ipmi::reserved_sdr_repo ],
|
||||
[ 'the first Get SDR', \&xCAT_plugin::ipmi::start_sdr_record ],
|
||||
[ 'a following Get SDR', \&xCAT_plugin::ipmi::add_sdr_data ],
|
||||
) {
|
||||
my ($name, $callback) = @$step;
|
||||
assert_node_error(run_step($callback, $timeout), 'timeout', "$name times out");
|
||||
}
|
||||
|
||||
my $result = run_step(\&xCAT_plugin::ipmi::reserved_sdr_repo, $invalid_command,
|
||||
sdr_info => { resv_sdr => 1 });
|
||||
assert_node_error($result, "Invalid or unsupported command", "a refused SDR reservation");
|
||||
|
||||
done_testing();
|
||||
@@ -0,0 +1,226 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
## no critic (Modules::RequireFilenameMatchesPackage, TestingAndDebugging::ProhibitNoStrict, TestingAndDebugging::ProhibitNoWarnings)
|
||||
no warnings qw(once redefine);
|
||||
|
||||
use File::Spec;
|
||||
use File::Temp qw(tempdir);
|
||||
use FindBin;
|
||||
use Storable qw(nstore_fd);
|
||||
use Test::More;
|
||||
|
||||
# Get SDR Repository Info can leave the reservation bit clear on a BMC that grants Reserve
|
||||
# SDR Repository. The SDR read must still ask for the reservation and use it. The record count
|
||||
# of the reply names the SDR cache, so a changed count must select another cache, and a cache
|
||||
# named with the record count of an earlier release must be read again.
|
||||
|
||||
BEGIN {
|
||||
for my $module (qw(
|
||||
xCAT::GlobalDef xCAT_monitoring::monitorctrl xCAT::IPMI
|
||||
xCAT::BMCUtils xCAT::PasswordUtils xCAT::Utils xCAT::TableUtils
|
||||
xCAT::IMMUtils xCAT::ServiceNodeUtils xCAT::NetworkUtils xCAT::Usage
|
||||
xCAT::data::ibmhwtypes xCAT::data::ibmleds
|
||||
xCAT::data::ipmigenericevents xCAT::data::ipmisensorevents
|
||||
IBM::EnergyManager
|
||||
)) {
|
||||
(my $file = $module) =~ s{::}{/}g;
|
||||
$INC{"$file.pm"} = __FILE__;
|
||||
no strict 'refs';
|
||||
*{"${module}::import"} = sub { };
|
||||
}
|
||||
|
||||
package xCAT::SvrUtils;
|
||||
our @messages;
|
||||
sub import { }
|
||||
sub sendmsg { push @messages, { text => $_[0], node => $_[2] }; }
|
||||
$INC{'xCAT/SvrUtils.pm'} = __FILE__;
|
||||
|
||||
package xCAT::SPD;
|
||||
sub import {
|
||||
my $caller = caller;
|
||||
no strict 'refs';
|
||||
*{"${caller}::decode_spd"} = sub { return; };
|
||||
}
|
||||
$INC{'xCAT/SPD.pm'} = __FILE__;
|
||||
|
||||
package File::Path;
|
||||
sub import {
|
||||
my $caller = caller;
|
||||
no strict 'refs';
|
||||
*{"${caller}::mkpath"} = sub { return; };
|
||||
}
|
||||
$INC{'File/Path.pm'} = __FILE__;
|
||||
|
||||
package Thread;
|
||||
sub import {
|
||||
my $caller = caller;
|
||||
no strict 'refs';
|
||||
*{"${caller}::yield"} = sub { return; };
|
||||
}
|
||||
$INC{'Thread.pm'} = __FILE__;
|
||||
|
||||
package LWP;
|
||||
our $VERSION = 5.64;
|
||||
sub import { }
|
||||
$INC{'LWP.pm'} = __FILE__;
|
||||
|
||||
package HTTP::Request::Common;
|
||||
sub import {
|
||||
my $caller = caller;
|
||||
no strict 'refs';
|
||||
*{"${caller}::GET"} = sub { return; };
|
||||
*{"${caller}::POST"} = sub { return; };
|
||||
}
|
||||
$INC{'HTTP/Request/Common.pm'} = __FILE__;
|
||||
|
||||
package main;
|
||||
*CORE::GLOBAL::chmod = sub (@) { return 1; };
|
||||
# storsdrcache creates the cache directory of the management node.
|
||||
*CORE::GLOBAL::system = sub { return 0; };
|
||||
}
|
||||
|
||||
package FakeSession;
|
||||
sub new { return bless { calls => [] }, shift; }
|
||||
sub subcmd { my ($self, %args) = @_; push @{ $self->{calls} }, \%args; return; }
|
||||
|
||||
package main;
|
||||
|
||||
my $repo_root = File::Spec->catdir($FindBin::Bin, '..', '..');
|
||||
$ENV{XCATROOT} = File::Spec->catdir($repo_root, 'xCAT-server');
|
||||
my $plugin = File::Spec->catfile($repo_root, qw(xCAT-server lib xcat plugins ipmi.pm));
|
||||
do $plugin or die $@ || "Unable to load $plugin: $!";
|
||||
|
||||
# A device identity that no SDR cache file holds, so the SDR is read from the BMC.
|
||||
sub new_sessdata {
|
||||
return {
|
||||
node => 'node01',
|
||||
ipmisession => FakeSession->new(),
|
||||
mfg_id => 0xfffe,
|
||||
prod_id => 0xfffe,
|
||||
device_id => 0xfe,
|
||||
device_rev => 0,
|
||||
firmware_rev1 => 0,
|
||||
firmware_rev2 => 0,
|
||||
};
|
||||
}
|
||||
|
||||
# The Get SDR Repository Info reply of an OpenBMC that grants reservations, with the
|
||||
# record count (43 by default) and the operation support byte last.
|
||||
sub repository_info {
|
||||
my ($operation_support, $records) = @_;
|
||||
$records //= 0x2b;
|
||||
return { code => 0,
|
||||
data => [ 0x51, $records & 0xff, $records >> 8, 0xff, 0xff, (0) x 8, $operation_support ] };
|
||||
}
|
||||
|
||||
sub requests { return $_[0]->{ipmisession}->{calls}; }
|
||||
|
||||
subtest 'a BMC that does not advertise the reservation is asked for one' => sub {
|
||||
my $sessdata = new_sessdata();
|
||||
local @xCAT::SvrUtils::messages = ();
|
||||
xCAT_plugin::ipmi::got_sdr_rep_info(repository_info(0x00), $sessdata);
|
||||
is_deeply(\@xCAT::SvrUtils::messages, [], 'no error is reported');
|
||||
is(scalar @{ requests($sessdata) }, 1, 'one request follows');
|
||||
my $request = requests($sessdata)->[0] || {};
|
||||
is($request->{netfn}, 0x0a, 'the request is a storage command');
|
||||
is($request->{command}, 0x22, 'the request is Reserve SDR Repository');
|
||||
|
||||
ok($request->{callback}, "the request has a reply handler") or return;
|
||||
$sessdata->{ipmisession}->{calls} = [];
|
||||
$request->{callback}->({ code => 0, data => [ 0x01, 0x00 ] }, $request->{callback_args});
|
||||
is_deeply(\@xCAT::SvrUtils::messages, [], 'the granted reservation reports no error');
|
||||
my $fetch = requests($sessdata)->[0] || {};
|
||||
is($fetch->{command}, 0x23, 'Get SDR follows the reservation');
|
||||
is_deeply([ @{ $fetch->{data} || [] }[ 0, 1 ] ], [ 0x01, 0x00 ],
|
||||
'Get SDR carries the granted reservation ID');
|
||||
};
|
||||
|
||||
subtest 'a refused reservation that was not advertised is reported as unsupported' => sub {
|
||||
my $sessdata = new_sessdata();
|
||||
local @xCAT::SvrUtils::messages = ();
|
||||
xCAT_plugin::ipmi::got_sdr_rep_info(repository_info(0x00), $sessdata);
|
||||
my $request = requests($sessdata)->[0] || {};
|
||||
ok($request->{callback}, "a reservation is requested") or return;
|
||||
$sessdata->{ipmisession}->{calls} = [];
|
||||
$request->{callback}->({ code => 0xc1, data => [] }, $request->{callback_args});
|
||||
is(scalar @xCAT::SvrUtils::messages, 1, 'one message');
|
||||
my $message = $xCAT::SvrUtils::messages[0] || {};
|
||||
is($message->{node}, 'node01', 'the message names the node');
|
||||
is_deeply($message->{text}, [ 1, 'SDR reservation unsupported.' ], 'the message keeps its text');
|
||||
is(scalar @{ requests($sessdata) }, 0, 'no Get SDR request follows');
|
||||
};
|
||||
|
||||
subtest 'other refusals of a reservation that was not advertised keep their reason' => sub {
|
||||
for my $refusal (
|
||||
[ 0xc0, 'Node busy, command could not be processed' ],
|
||||
[ 0xd4, 'Insufficient privilege level' ],
|
||||
) {
|
||||
my ($code, $reason) = @$refusal;
|
||||
my $sessdata = new_sessdata();
|
||||
local @xCAT::SvrUtils::messages = ();
|
||||
xCAT_plugin::ipmi::got_sdr_rep_info(repository_info(0x00), $sessdata);
|
||||
my $request = requests($sessdata)->[0] || {};
|
||||
ok($request->{callback}, "a reservation is requested") or next;
|
||||
$sessdata->{ipmisession}->{calls} = [];
|
||||
$request->{callback}->({ code => $code, data => [] }, $request->{callback_args});
|
||||
is_deeply([ map { $_->{text} } @xCAT::SvrUtils::messages ], [ [ 1, $reason ] ],
|
||||
sprintf('completion code %02x is reported as itself', $code));
|
||||
is(scalar @{ requests($sessdata) }, 0, 'no Get SDR request follows');
|
||||
}
|
||||
};
|
||||
|
||||
subtest 'a BMC that advertises the reservation is still asked for one' => sub {
|
||||
my $sessdata = new_sessdata();
|
||||
local @xCAT::SvrUtils::messages = ();
|
||||
xCAT_plugin::ipmi::got_sdr_rep_info(repository_info(0x02), $sessdata);
|
||||
is_deeply(\@xCAT::SvrUtils::messages, [], 'no error is reported');
|
||||
my $request = requests($sessdata)->[0] || {};
|
||||
is($request->{command}, 0x22, 'the request is Reserve SDR Repository');
|
||||
};
|
||||
|
||||
sub cache_file_for {
|
||||
my ($records) = @_;
|
||||
my $sessdata = new_sessdata();
|
||||
local @xCAT::SvrUtils::messages = ();
|
||||
xCAT_plugin::ipmi::got_sdr_rep_info(repository_info(0x02, $records), $sessdata);
|
||||
return $sessdata->{sdrcache_file};
|
||||
}
|
||||
|
||||
subtest 'a changed record count selects another SDR cache' => sub {
|
||||
for my $change ([ 39, 294 ], [ 1, 256 ]) {
|
||||
my ($before, $after) = @$change;
|
||||
isnt(cache_file_for($after), cache_file_for($before),
|
||||
"a BMC that goes from $before to $after records does not reuse its SDR cache");
|
||||
}
|
||||
is(cache_file_for(294), cache_file_for(294), 'the same record count keeps the SDR cache');
|
||||
};
|
||||
|
||||
sub sdr_record {
|
||||
return SDR->new(sensor_owner_id => 0x20, sensor_owner_lun => 0, sensor_number => 1);
|
||||
}
|
||||
|
||||
subtest 'an SDR cache of an earlier release is read again' => sub {
|
||||
my $dir = tempdir(CLEANUP => 1);
|
||||
|
||||
# Earlier releases wrote version 4 and named the cache of 257 records like that of 512.
|
||||
my $legacy = "$dir/sdr_legacy";
|
||||
open(my $fh, '>', $legacy) or die "$legacy: $!";
|
||||
nstore_fd({ xcat_sdrcacheversion => 4 }, $fh);
|
||||
nstore_fd(sdr_record(), $fh);
|
||||
close($fh);
|
||||
my $sessdata = new_sessdata();
|
||||
is(xCAT_plugin::ipmi::loadsdrcache($sessdata, $legacy), 1, 'the cache is not loaded');
|
||||
is_deeply($sessdata->{sdr_hash} || {}, {}, 'no SDR record comes from it');
|
||||
|
||||
my $current = "$dir/sdr_current";
|
||||
my $writer = new_sessdata();
|
||||
$writer->{sdr_hash} = { '32.0.1' => sdr_record() };
|
||||
is(xCAT_plugin::ipmi::storsdrcache($current, $writer), 0, 'a new cache is written');
|
||||
my $reader = new_sessdata();
|
||||
is(xCAT_plugin::ipmi::loadsdrcache($reader, $current), 0, 'the new cache is loaded');
|
||||
is_deeply([ keys %{ $reader->{sdr_hash} || {} } ], ['32.0.1'], 'its SDR record is read back');
|
||||
};
|
||||
|
||||
done_testing();
|
||||
@@ -1,140 +0,0 @@
|
||||
#!/usr/bin/env perl
|
||||
use strict;
|
||||
use warnings;
|
||||
use Errno qw(EACCES EIO);
|
||||
use FindBin;
|
||||
use File::Path qw(make_path);
|
||||
use File::Slurper qw(read_text write_text);
|
||||
use File::Temp qw(tempdir);
|
||||
use lib "$FindBin::Bin/../../perl-xCAT";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
|
||||
use lib "$FindBin::Bin/../../xCAT-server/share/xcat/netboot/imgutils";
|
||||
use Test::More;
|
||||
|
||||
BEGIN {
|
||||
*CORE::GLOBAL::rename = sub { return CORE::rename($_[0], $_[1]); };
|
||||
*CORE::GLOBAL::link = sub { return CORE::link($_[0], $_[1]); };
|
||||
}
|
||||
use imgutils;
|
||||
|
||||
my $dir = tempdir(CLEANUP => 1);
|
||||
|
||||
for my $mode (qw(stateless statelite)) {
|
||||
for my $failure (qw(none move-initrd backup-kernel publish-kernel publish-initrd)) {
|
||||
my ($ok, $error, $case) = publish_case($mode, $failure, 1);
|
||||
my $label = "$mode $failure";
|
||||
if ($failure eq 'none') {
|
||||
ok($ok, "$label completes") or diag($error);
|
||||
is(read_text("$case/kernel"), "new kernel\n", "$label publishes the kernel");
|
||||
is(read_text("$case/initrd-$mode.gz"), "new initrd\n", "$label publishes the initrd");
|
||||
} else {
|
||||
ok(!$ok, "$label fails");
|
||||
like($error, qr/Error: failed to (?:move|publish|preserve).*?(?:kernel|ramdisk)/i,
|
||||
"$label reports the failed boot file operation");
|
||||
is(read_text("$case/kernel"), "old kernel\n", "$label preserves the previous kernel");
|
||||
is(read_text("$case/initrd-$mode.gz"), "old initrd\n", "$label preserves the previous initrd");
|
||||
}
|
||||
is_deeply([glob("$case/.genimage*")], [], "$label removes boot staging files");
|
||||
}
|
||||
}
|
||||
|
||||
my ($ok, $error, $case) = publish_case('stateless', 'publish-initrd', 0);
|
||||
ok(!$ok, 'first build publication failure is fatal');
|
||||
ok(!-e "$case/kernel", 'first build failure removes the unpaired kernel');
|
||||
ok(!-e "$case/initrd-stateless.gz", 'first build failure does not expose an initrd');
|
||||
is_deeply([glob("$case/.genimage*")], [], 'first build failure removes boot staging files');
|
||||
|
||||
($ok, $error, $case) = publish_case('stateless', 'rollback', 1);
|
||||
ok(!$ok, 'rollback failure is fatal');
|
||||
my @backups = glob("$case/.genimage*/previous-kernel");
|
||||
is(scalar(@backups), 1, 'rollback failure retains one previous kernel backup');
|
||||
is(read_text($backups[0]), "old kernel\n", 'retained backup contains the previous kernel');
|
||||
like($error, qr/kernel rollback failed: .*Boot files retained in \Q$case\E\/\.genimage/,
|
||||
'rollback failure reports the recoverable backup directory');
|
||||
is(read_text("$case/initrd-stateless.gz"), "old initrd\n", 'rollback failure preserves previous initrd');
|
||||
|
||||
subtest 'vendor repositories' => sub {
|
||||
plan skip_all => 'requires Linux sed' unless $^O eq 'linux';
|
||||
my @legacy_repositories = qw(Rocky-BaseOS.repo almalinux.repo CentOS-Base.repo oracle-linux-ol10.repo);
|
||||
my @custom_repositories = qw(local-repository-0.repo xCAT-custom.repo administrator.repo);
|
||||
my $enabled = "[fixture]\nenabled=1\ngpgcheck=1\nbaseurl=https://repo.invalid/\n";
|
||||
my $disabled = "[fixture]\nenabled=0\ngpgcheck=1\nbaseurl=https://repo.invalid/\n";
|
||||
my $native = "[OS]\nenabled=1\ngpgcheck=1\n[update]\n \tenabled = 1\n[disabled]\nenabled=0\n#enabled=1\n";
|
||||
my $native_disabled = "[OS]\nenabled=0\ngpgcheck=1\n[update]\nenabled=0\n[disabled]\nenabled=0\n#enabled=1\n";
|
||||
for my $repository_case (
|
||||
['enabled', $native, $native_disabled],
|
||||
['already-disabled', $native_disabled, $native_disabled],
|
||||
['absent', undef, undef],
|
||||
) {
|
||||
my ($name, $input, $expected) = @$repository_case;
|
||||
subtest $name => sub {
|
||||
my $root = tempdir(DIR => $dir, CLEANUP => 1);
|
||||
my $repos = "$root/etc/yum.repos.d";
|
||||
make_path($repos);
|
||||
write_text("$repos/$_", $enabled) for (@legacy_repositories, @custom_repositories);
|
||||
write_text("$repos/openEuler.repo", $input) if defined $input;
|
||||
for my $pass (1, 2) {
|
||||
imgutils::disable_vendor_repositories($root);
|
||||
if (defined $expected) {
|
||||
is(read_text("$repos/openEuler.repo"), $expected,
|
||||
"pass $pass disables only active native repository assignments");
|
||||
} else {
|
||||
ok(!-e "$repos/openEuler.repo", "pass $pass does not create an absent vendor file");
|
||||
}
|
||||
is(read_text("$repos/$_"), $disabled, "pass $pass preserves policy for $_")
|
||||
for @legacy_repositories;
|
||||
is(read_text("$repos/$_"), $enabled, "pass $pass leaves $_ unchanged")
|
||||
for @custom_repositories;
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
done_testing();
|
||||
|
||||
sub publish_case {
|
||||
my ($mode, $failure, $old) = @_;
|
||||
my $case = tempdir(DIR => $dir, CLEANUP => 1);
|
||||
make_path("$case/tmp");
|
||||
my $staging = File::Temp->newdir('.genimage-boot.XXXXXX', DIR => $case, CLEANUP => 1);
|
||||
write_text("$staging/kernel", "new kernel\n");
|
||||
write_text("$case/tmp/initrd.gz", "new initrd\n");
|
||||
if ($old) {
|
||||
write_text("$case/kernel", "old kernel\n");
|
||||
write_text("$case/initrd-$mode.gz", "old initrd\n");
|
||||
}
|
||||
|
||||
my $move = \&imgutils::move;
|
||||
my ($ok, $error);
|
||||
{
|
||||
no warnings 'redefine';
|
||||
local *imgutils::move = sub {
|
||||
if ($failure eq 'move-initrd') {
|
||||
$! = EIO;
|
||||
return 0;
|
||||
}
|
||||
return $move->(@_);
|
||||
};
|
||||
local *CORE::GLOBAL::link = sub {
|
||||
if ($failure eq 'backup-kernel') {
|
||||
$! = EACCES;
|
||||
return 0;
|
||||
}
|
||||
return CORE::link($_[0], $_[1]);
|
||||
};
|
||||
local *CORE::GLOBAL::rename = sub {
|
||||
if (($failure =~ /^(?:publish-initrd|rollback)$/
|
||||
&& $_[1] eq "$case/initrd-$mode.gz")
|
||||
|| ($failure eq 'publish-kernel' && $_[1] eq "$case/kernel")
|
||||
|| ($failure eq 'rollback' && $_[0] =~ m{/previous-kernel$})) {
|
||||
$! = EACCES;
|
||||
return 0;
|
||||
}
|
||||
return CORE::rename($_[0], $_[1]);
|
||||
};
|
||||
$ok = eval { imgutils::publish_boot_files($staging, $case, "$case/tmp/initrd.gz", $mode); };
|
||||
$error = $@;
|
||||
}
|
||||
undef $staging;
|
||||
return ($ok, $error, $case);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user