diff --git a/xCAT-test/bats/vm_machine_type.bats b/xCAT-test/bats/vm_machine_type.bats index 427393085e..6be656567c 100644 --- a/xCAT-test/bats/vm_machine_type.bats +++ b/xCAT-test/bats/vm_machine_type.bats @@ -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 -- the case ends with the exact value it started with. +# assert_round_trip [] -- the case ends with the exact value it +# started with. 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" { diff --git a/xCAT-test/unit/kvm_secureboot_firmware.t b/xCAT-test/unit/kvm_secureboot_firmware.t index 58de679aaf..51e97d2140 100644 --- a/xCAT-test/unit/kvm_secureboot_firmware.t +++ b/xCAT-test/unit/kvm_secureboot_firmware.t @@ -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' ); diff --git a/xCAT-test/unit/media_perms_readable.t b/xCAT-test/unit/media_perms_readable.t index 27c8343c4a..472549cc1c 100644 --- a/xCAT-test/unit/media_perms_readable.t +++ b/xCAT-test/unit/media_perms_readable.t @@ -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.