2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-07-31 18:19:40 +00:00

fix(template): preserve explicit XCATROOT values

This commit is contained in:
Vinícius Ferrão
2026-07-24 13:07:51 -03:00
parent 34866ebc23
commit a64b6c647e
3 changed files with 59 additions and 3 deletions
+1 -3
View File
@@ -1617,9 +1617,7 @@ sub envvar
$envvar =~ s/^\$//;
}
# $XCATROOT is reliably set as a package global even when it is absent from
# %ENV, so a template referencing it does not expand to undef.
if ($envvar eq 'XCATROOT') { return $::XCATROOT; }
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();