diff --git a/.github/workflows/xcat_test.yml b/.github/workflows/xcat_test.yml index a61196daa7..2fb86641ef 100644 --- a/.github/workflows/xcat_test.yml +++ b/.github/workflows/xcat_test.yml @@ -104,7 +104,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/kdump_condition_systemd.t xCAT-test/native/openeuler_post_kdump.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/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 | tee "$log" ! grep -qi skipped "$log" rpm_lifecycle_test: runs-on: ubuntu-24.04 diff --git a/xCAT-test/native/README.md b/xCAT-test/native/README.md index e875373802..8d03a9db8b 100644 --- a/xCAT-test/native/README.md +++ b/xCAT-test/native/README.md @@ -422,13 +422,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. diff --git a/xCAT-test/native/ubuntu_subiquity_install_disk.t b/xCAT-test/native/ubuntu_subiquity_install_disk.t new file mode 100644 index 0000000000..3a5c19480a --- /dev/null +++ b/xCAT-test/native/ubuntu_subiquity_install_disk.t @@ -0,0 +1,85 @@ +#!/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. +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'], +); +for my $case (@cases) { + my ($label, $entries, $expected) = @$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'); + 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'; + }; +} +done_testing();