From bc5da0fe8856e60f1e57475cb361cb64be3da1c9 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 23:22:35 -0300 Subject: [PATCH] test(imgport): cover the column quoting of the litefile lookup When the configured database is MySQL, the litefile lookup of a statelite import must quote the image column with backticks. An ALL entry must still cover the same file of the image. --- xCAT-test/unit/imgport_litefile_lookup.t | 50 ++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 xCAT-test/unit/imgport_litefile_lookup.t diff --git a/xCAT-test/unit/imgport_litefile_lookup.t b/xCAT-test/unit/imgport_litefile_lookup.t new file mode 100644 index 000000000..1fce1964c --- /dev/null +++ b/xCAT-test/unit/imgport_litefile_lookup.t @@ -0,0 +1,50 @@ +#!/usr/bin/env perl +use strict; +use warnings; +no warnings 'once'; +use FindBin; +use lib "$FindBin::Bin/../lib", "$FindBin::Bin/../../perl-xCAT", "$FindBin::Bin/../../xCAT-server/lib/perl"; +use Test::More; +use File::Path qw(make_path); +use File::Temp qw(tempdir); +use File::Slurper qw(write_binary); +use Capture::Tiny qw(capture); +use XCAT::Test::File qw(repo_path); + +my $root = tempdir(CLEANUP => 1); +local $ENV{XCATCFG} = "$root/cfg"; +make_path($ENV{XCATCFG}, "$root/import", "$root/install"); +require(repo_path('xCAT-server/lib/xcat/plugins/imgport.pm')); +xCAT::Table->new('litefile', -create => 1)->setAttribs({ image => 'ALL', file => '/etc/hosts' }, { options => 'tmpfs' }); +write_binary("$root/import/litefile.csv", qq{"image","/etc/hosts","tmpfs",,\n"image","/var/log/","tmpfs",,\n}); + +my (@where, $result, @messages); +{ + no warnings 'redefine'; + local *xCAT::TableUtils::getInstallDir = sub { "$root/install" }; + + # The configured database is MySQL, which takes a name in double quotes for a string. The fixture stays SQLite. + my $xcatcfg = \&xCAT::Table::get_xcatcfg; + local *xCAT::Table::get_xcatcfg = sub { + return (caller(1))[3] eq 'xCAT::Table::delimitcol' ? 'mysql:dbname=xcatdb;host=localhost' : $xcatcfg->(@_); + }; + my $lookup = \&xCAT::Table::getAllAttribsWhere; + local *xCAT::Table::getAllAttribsWhere = sub { + push @where, $_[1] if $_[0]{tabname} eq 'litefile'; + goto &$lookup; + }; + my $data = { + osimage => { imagename => 'image', osvers => 'rhels9.6', osarch => 'x86_64', profile => 'compute', provmethod => 'statelite' }, + litefile => "$root/install/litefile.csv", + }; + my ($out, $err); + ($out, $err, $result) = capture { xCAT_plugin::imgport::make_files($data, "$root/import", sub { push @messages, $_[0] }) }; +} +is($result, 1, 'a statelite import with a litefile succeeds'); +is_deeply([ map { @{ $_->{error} || [] } } @messages ], [], 'no error is reported'); +is_deeply(\@where, ["`image` = 'ALL'"], 'the litefile lookup quotes the image column the way the database needs'); + +my %files = map { ($_->{file} => 1) } xCAT::Table->new('litefile')->getAllAttribsWhere("image = 'image'", 'file'); +is_deeply(\%files, { '/var/log/' => 1 }, 'the import adds only the entries that no ALL entry covers'); + +done_testing();