2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2026-12-03 23:57:06 +00:00
Files
xcat-core/xCAT-test/unit/xcattest_conf_object_attr.t
T
Daniel Hilst b5181574ea test(xcattest): a conf cannot set a vm.othersettings with two settings
An [Object_*] line of an xcattest conf declares an xCAT node attribute.
vm.othersettings holds several settings separated by a semicolon, which
is the syntax the kvm plugin reads, and such a line reaches the node cut
at its first semicolon with no message. The reader drops the rest, and
the chdef that applies it runs through /bin/bash -c unquoted, so the
shell would read the semicolon as a command separator.

load_config_file read each line with a regular expression written inline
and built the chdef by concatenation, so neither could be measured
without a database. xCAT::Test::Conf now holds the three readers and the
command builder, and xcattest calls them. The routines keep the behaviour
they replace, and both packages install the module.

xcattest_conf_object_attr.t fails five of its nine checks on this commit:
the semicolon value, the quoting and the order of the assignments.

Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
2026-10-21 19:36:45 -03:00

67 lines
2.9 KiB
Perl

#!/usr/bin/env perl
# The [Object_*] blocks of an xcattest conf declare xCAT node attributes, and xcattest applies
# them with chdef. vm.othersettings holds several settings separated by a semicolon, which is the
# syntax the kvm plugin reads:
#
# vmothersetting=cpumode:host-passthrough;firmware:efi-secureboot
#
# Two things have to hold for that line to reach the node. The reader has to keep the whole
# value, and the chdef command has to quote it, because xcattest runs every command through
# /bin/bash -c and an unquoted semicolon ends the command there.
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../lib";
use Test::More;
require xCAT::Test::Conf;
# The reader keeps every setting of a multi-setting value.
is_deeply(
[ xCAT::Test::Conf::object_attr(' vmothersetting=cpumode:host-passthrough;firmware:efi-secureboot') ],
[ 'vmothersetting', 'cpumode:host-passthrough;firmware:efi-secureboot' ],
'an [Object_*] value keeps the settings after its first semicolon'
);
# The values the reader already took stay as they are.
is_deeply(
[ xCAT::Test::Conf::object_attr(' vmnics=virbr-p147,virbr-p147,virbr-p147') ],
[ 'vmnics', 'virbr-p147,virbr-p147,virbr-p147' ],
'a comma-separated value is unchanged'
);
is_deeply(
[ xCAT::Test::Conf::object_attr(' vmstorage=dir:///var/lib/libvirt/images/') ],
[ 'vmstorage', 'dir:///var/lib/libvirt/images/' ],
'a value with a colon and slashes is unchanged'
);
is_deeply( [ xCAT::Test::Conf::object_attr('Name=xcat147-cn-tmp-243') ],
[ 'Name', 'xcat147-cn-tmp-243' ], 'the Name line is read like any other attribute' );
is_deeply( [ xCAT::Test::Conf::object_attr('this line has no equals sign') ],
[], 'a line with no assignment yields no attribute' );
# chdef runs under /bin/bash -c, so each assignment is quoted. Without the quoting the shell
# reads the semicolon as a command separator and chdef gets half the value.
my $cmd = xCAT::Test::Conf::chdef_command( 'node', 'cn1',
{ vmothersetting => 'cpumode:host-passthrough;firmware:efi-secureboot' } );
like( $cmd, qr/^chdef -t 'node' -o 'cn1' /, 'chdef_command names the type and the object' );
like(
$cmd,
qr/'vmothersetting=cpumode:host-passthrough;firmware:efi-secureboot'/,
'and quotes the assignment, so bash does not read the semicolon as a command separator'
);
# A single quote inside a value must not end the quoting.
like(
xCAT::Test::Conf::chdef_command( 'node', 'cn1', { usercomment => "it's here" } ),
qr/'usercomment=it'\\''s here'/,
'a single quote in a value is escaped inside the quoted assignment'
);
# The order of the assignments is fixed, so two runs of one conf build the same command.
is( xCAT::Test::Conf::chdef_command( 'node', 'cn1', { b => '2', a => '1', c => '3' } ),
"chdef -t 'node' -o 'cn1' 'a=1' 'b=2' 'c=3'",
'the assignments are sorted by attribute name' );
done_testing();