From 94a6e6565b98b94eaffb8465b18378e8a8fa8dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Tue, 13 Oct 2026 15:29:23 -0300 Subject: [PATCH] test(xcatconfig): cover the root image check of an upgrade The upgrade step must set rootimgchecksum to no for the stateless and statelite images that do not set it, also for an image without a linuximage row. It must keep an image that sets the attribute, leave other images alone, and set site.rootimgchecksum to yes. A later upgrade, and an upgrade after the administrator set the site attribute, must change no image. --- .../unit/svrutils_rootimg_checksum_upgrade.t | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 xCAT-test/unit/svrutils_rootimg_checksum_upgrade.t diff --git a/xCAT-test/unit/svrutils_rootimg_checksum_upgrade.t b/xCAT-test/unit/svrutils_rootimg_checksum_upgrade.t new file mode 100644 index 000000000..9bec638af --- /dev/null +++ b/xCAT-test/unit/svrutils_rootimg_checksum_upgrade.t @@ -0,0 +1,58 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use FindBin; +use lib "$FindBin::Bin/../lib"; +use lib "$FindBin::Bin/../../perl-xCAT"; +use lib "$FindBin::Bin/../../xCAT-server/lib/perl"; +use File::Path qw(make_path); +use File::Temp qw(tempdir); +use Test::More; + +my $fixture = tempdir(CLEANUP => 1); +make_path("$fixture/db"); +$ENV{XCATCFG} = "SQLite:$fixture/db"; +require xCAT::Table; +require xCAT::SvrUtils; + +my $osimage = xCAT::Table->new('osimage', -create => 1); +my $linuximage = xCAT::Table->new('linuximage', -create => 1); +my $site = xCAT::Table->new('site', -create => 1); + +# The images that a release without the root image check left. +$osimage->setAttribs({ imagename => $_->[0] }, { provmethod => $_->[1] }) + for ([ stateless => 'netboot' ], [ lite => 'statelite' ], [ checked => 'netboot' ], [ diskful => 'install' ], [ bare => 'netboot' ]); +$linuximage->setAttribs({ imagename => $_ }, { rootimgdir => "/install/netboot/$_" }) for qw(stateless lite checked diskful); +$linuximage->setAttribs({ imagename => 'checked' }, { rootimgchecksum => 'yes' }); + +sub checksum { + my ($row) = $linuximage->getAttribs({ imagename => $_[0] }, 'rootimgchecksum'); + return $row ? $row->{rootimgchecksum} : undef; +} + +sub site_value { + my ($row) = $site->getAttribs({ key => 'rootimgchecksum' }, 'value'); + return $row ? $row->{value} : undef; +} + +is(xCAT::SvrUtils->upgrade_rootimg_checksum(), undef, 'the upgrade step reports no error'); +is(checksum('stateless'), 'no', 'a stateless image of the earlier release keeps booting unchecked'); +is(checksum('lite'), 'no', 'a statelite image of the earlier release keeps booting unchecked'); +is(checksum('bare'), 'no', 'a stateless image without a linuximage row keeps booting unchecked'); +is(checksum('checked'), 'yes', 'an image that sets the attribute keeps it'); +is(checksum('diskful'), undef, 'an image that nodes install is left alone'); +is(site_value(), 'yes', 'new images get the check'); + +# A later upgrade finds site.rootimgchecksum set. +$osimage->setAttribs({ imagename => 'new' }, { provmethod => 'netboot' }); +$linuximage->setAttribs({ imagename => 'new' }, { rootimgdir => '/install/netboot/new' }); +is(xCAT::SvrUtils->upgrade_rootimg_checksum(), undef, 'a later upgrade reports no error'); +is(checksum('new'), undef, 'a later upgrade leaves the check of a new image on'); + +# An administrator turned the check off for the site before the upgrade. +$site->setAttribs({ key => 'rootimgchecksum' }, { value => 'no' }); +is(xCAT::SvrUtils->upgrade_rootimg_checksum(), undef, 'an upgrade with the site attribute set reports no error'); +is(checksum('new'), undef, 'an upgrade with the site attribute set changes no image'); +is(site_value(), 'no', 'an upgrade keeps the site attribute that the administrator set'); + +done_testing();