mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-11-19 17:02:15 +00:00
fix(test): five checks of the Secure Boot branch pass without the code they name
Each of these five checks held with the behaviour it describes removed. kvm_secureboot_firmware.t asked firmware_machine_error for machine virt on riscv64 to measure the x86_64 guard. virt matches neither pc nor the i440fx pattern, so the answer was undef with the guard removed as well. The file now asks for pc and for a versioned i440fx on another architecture, and for pc with nodetype.arch unset. media_perms_readable.t asked make_readable for a directory that does not exist to measure the -d test. File::Find returns without changing a path there in either case, so only the warning it prints differs. The check now also reads the warnings, which is what copycds shows the admin. MediaPerms.pm skipped a symbolic link and nothing measured it, so the fixture now holds one that names a file outside the tree. vm_machine_type.bats kept two cases that a machine:pc answer for every x86_64 node left green. "x86_64 without a firmware" repeats the second line of test 2 and is deleted. assert_round_trip never read the machine type apply wrote, so it now takes the expected machine type and the Secure Boot round trip states q35. Four mutations turn the three files red: the x86_64 guard, the -d test, the symbolic-link test, and machine:pc for every x86_64 node. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
This commit is contained in:
@@ -92,12 +92,8 @@ assert_arch()
|
||||
assert_arch x86_64 q35 'cpumode:host-passthrough;firmware:efi-secureboot'
|
||||
}
|
||||
|
||||
@test "x86_64 without a firmware: the case still sets pc" {
|
||||
assert_arch x86_64 pc 'cpumode:host-passthrough'
|
||||
}
|
||||
|
||||
@test "round trip: x86_64 with firmware:efi-secureboot" {
|
||||
assert_round_trip x86_64 'cpumode:host-passthrough;firmware:efi-secureboot'
|
||||
assert_round_trip x86_64 'cpumode:host-passthrough;firmware:efi-secureboot' q35
|
||||
}
|
||||
|
||||
@test "riscv64: the case sets and clears virt" {
|
||||
@@ -110,10 +106,11 @@ assert_arch()
|
||||
assert_arch aarch64 virt 'cpumode:host-passthrough'
|
||||
}
|
||||
|
||||
# assert_round_trip <arch> <original> -- the case ends with the exact value it started with.
|
||||
# assert_round_trip <arch> <original> [<machine>] -- the case ends with the exact value it
|
||||
# started with. <machine> is the machine type apply is to have written, when the caller knows it.
|
||||
assert_round_trip()
|
||||
{
|
||||
local arch="$1" original="$2" machine
|
||||
local arch="$1" original="$2" expected="$3" machine
|
||||
|
||||
set_vmother "$original"
|
||||
vm_machine_type_main invalid cn1
|
||||
@@ -122,6 +119,10 @@ assert_round_trip()
|
||||
[ "$machine" = "machine:invalid" ]
|
||||
|
||||
vm_machine_type_main apply cn1 "$arch"
|
||||
if [ -n "$expected" ]; then
|
||||
machine="$(vmother | tr ';' '\n' | grep '^machine:' | tail -n 1)"
|
||||
[ "$machine" = "machine:$expected" ]
|
||||
fi
|
||||
vm_machine_type_main restore cn1 "$arch"
|
||||
[ "$(vmother)" = "$original" ]
|
||||
[ -z "$(ls -A "$VM_MACHINE_TYPE_STATE_DIR")" ]
|
||||
@@ -136,7 +137,7 @@ assert_round_trip()
|
||||
}
|
||||
|
||||
@test "round trip: cpumode:host-passthrough" {
|
||||
assert_round_trip x86_64 'cpumode:host-passthrough'
|
||||
assert_round_trip x86_64 'cpumode:host-passthrough' pc
|
||||
}
|
||||
|
||||
@test "round trip: x86_64 with a versioned machine type" {
|
||||
|
||||
@@ -112,6 +112,16 @@ is( xCAT::KVMUtils::firmware_machine_error( 'efi-secureboot', undef, 'x86_64', '
|
||||
undef, 'a node that names no machine type is not refused' );
|
||||
is( xCAT::KVMUtils::firmware_machine_error( undef, 'pc', 'x86_64', 'cn1' ),
|
||||
undef, 'a node that asks for no firmware keeps i440fx' );
|
||||
# Only x86_64 is judged. The i440fx family and the q35 the refusal names belong to that
|
||||
# architecture, so a node of another one goes to libvirt whatever it names. The machine type
|
||||
# has to be one the x86_64 branch would refuse, or the test measures the i440fx match instead
|
||||
# of the architecture guard.
|
||||
is( xCAT::KVMUtils::firmware_machine_error( 'efi', 'pc', 'ppc64le', 'cn1' ),
|
||||
undef, 'a machine type of the i440fx family is not judged on another architecture' );
|
||||
is( xCAT::KVMUtils::firmware_machine_error( 'efi', 'pc-i440fx-rhel10.0.0', 'aarch64', 'cn1' ),
|
||||
undef, 'and neither is a versioned one' );
|
||||
is( xCAT::KVMUtils::firmware_machine_error( 'efi', 'pc', undef, 'cn1' ),
|
||||
undef, 'a node whose nodetype.arch is unset is not judged either' );
|
||||
is( xCAT::KVMUtils::firmware_machine_error( 'efi', 'virt', 'riscv64', 'cn1' ),
|
||||
undef, 'the machine types of another architecture are not judged here' );
|
||||
|
||||
|
||||
@@ -41,8 +41,19 @@ chmod 0444, "$root/EFI/BOOT/grub.cfg";
|
||||
chmod 0600, "$root/EFI/BOOT/fonts/unicode.pf2";
|
||||
chmod 0700, "$root/EFI/BOOT/fonts";
|
||||
|
||||
# A symbolic link out of the tree. chmod follows a link, so make_readable has to skip it: the
|
||||
# install directory of one osimage must not change the mode of a path in another.
|
||||
my $outside = tempdir( CLEANUP => 1 );
|
||||
open my $out_fh, '>', "$outside/vmlinuz" or die "write vmlinuz: $!";
|
||||
close $out_fh or die "close vmlinuz: $!";
|
||||
chmod 0600, "$outside/vmlinuz";
|
||||
symlink "$outside/vmlinuz", "$root/EFI/BOOT/vmlinuz" or die "symlink: $!";
|
||||
|
||||
my $changed = xCAT::MediaPerms::make_readable("$root/EFI");
|
||||
|
||||
is( mode_of("$outside/vmlinuz"), '0600',
|
||||
'a symbolic link is skipped, so the path it names outside the tree keeps its mode' );
|
||||
|
||||
is( mode_of("$root/EFI/BOOT/BOOTX64.EFI"), '0744',
|
||||
'a boot loader the media ships 0700 becomes readable, and keeps its owner execute bit' );
|
||||
is( mode_of("$root/EFI/BOOT/mmx64.efi"), '0744', 'and so does the MOK manager beside it' );
|
||||
@@ -56,8 +67,16 @@ is( $changed, 4, 'make_readable reports the number of paths it changed' );
|
||||
is( xCAT::MediaPerms::make_readable("$root/EFI"), 0,
|
||||
'a second call changes nothing, so copycds can be re-run' );
|
||||
|
||||
is( xCAT::MediaPerms::make_readable("$root/no-such-directory"), 0,
|
||||
'a directory that does not exist changes nothing' );
|
||||
# An osimage whose media carries no EFI directory is the common case, and copycds calls
|
||||
# make_readable for it too. Without the -d test File::Find warns "Can't stat", which reaches
|
||||
# the output of copycds as an error the admin cannot act on.
|
||||
my @warnings;
|
||||
my $absent = do {
|
||||
local $SIG{__WARN__} = sub { push @warnings, $_[0] };
|
||||
xCAT::MediaPerms::make_readable("$root/no-such-directory");
|
||||
};
|
||||
is( $absent, 0, 'a directory that does not exist changes nothing' );
|
||||
is_deeply( \@warnings, [], 'and it is not reported, because copycds calls it for every osimage' );
|
||||
|
||||
# No write permission is ever added. /install holds the media of every osimage on the
|
||||
# management node.
|
||||
|
||||
Reference in New Issue
Block a user