2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-08-03 16:06:59 +00:00

Merge pull request #7689 from xcat2/backport-7629-to-2.18

[Backport 2.18] fix(template): fall back to $::XCATROOT when XCATROOT is not in %ENV
This commit is contained in:
xcat2-backport-automation[bot]
2026-07-24 22:04:18 +00:00
committed by GitHub
3 changed files with 60 additions and 0 deletions
+2
View File
@@ -1617,6 +1617,8 @@ sub envvar
$envvar =~ s/^\$//;
}
return $::XCATROOT if $envvar eq 'XCATROOT' && !exists $ENV{XCATROOT};
return ($ENV{$envvar});
}
@@ -0,0 +1,8 @@
start:template_envvar_unit_tests
description:Run the template environment-variable unit test through xcattest.
os:Linux
label:mn_only,ci_test,unit,template_unit
cmd:prove -I/opt/xcat/lib/perl /opt/xcat/share/xcat/tools/autotest/unit/template_envvar.t
check:rc==0
check:output=~All tests successful
end
+50
View File
@@ -0,0 +1,50 @@
#!/usr/bin/env perl
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../../perl-xCAT";
use lib "$FindBin::Bin/../../xCAT-server/lib/perl";
use Test::More;
use xCAT::Template;
local $::XCATROOT = '/opt/xcat-from-package';
{
local $ENV{XCATROOT} = '/opt/xcat-from-environment';
is(
xCAT::Template::envvar('XCATROOT'),
'/opt/xcat-from-environment',
'an explicit XCATROOT environment value keeps precedence',
);
}
{
local $ENV{XCATROOT};
delete $ENV{XCATROOT};
is(
xCAT::Template::envvar('$XCATROOT'),
'/opt/xcat-from-package',
'the package global supplies XCATROOT when the environment omits it',
);
}
{
local $ENV{XCATROOT} = '';
is(
xCAT::Template::envvar('XCATROOT'),
'',
'an explicitly empty XCATROOT is not replaced by the fallback',
);
}
{
local $ENV{TEMPLATE_ENVVAR_TEST} = 'from-environment';
is(
xCAT::Template::envvar('TEMPLATE_ENVVAR_TEST'),
'from-environment',
'other template environment variables remain unchanged',
);
}
done_testing();