OpenVZ
view release on metacpan or search on metacpan
t/100-OpenVZ-Vzctl-set.t view on Meta::CPAN
# If the code pointed to by coderefs are bad, later testing will catch it. We'll ignore it for testing the structure of the hash.
my $expected_spec = { # <<<--- Change this to match expected hash from subcommand_specs
ctid => { type => SCALAR, callbacks => { 'validate ctid' => ignore() } },
flag => { type => SCALAR, optional => 1, regex => qr{^quiet|verbose$}i },
applyconfig => { type => SCALAR, optional => 1, callbacks => { 'do not want empty strings' => ignore(), }, },
avnumproc => { type => SCALAR, optional => 1, regex => qr{^\d+[gmkp]?(?::\d+[gmkp]?)?$}i },
bootorder => { type => SCALAR, optional => 1, regex => qr{^\d+$} },
cpumask => { type => SCALAR, optional => 1, regex => qr{^\d+(?:[,-]\d+)*|all$}i },
devices => { type => SCALAR, optional => 1, regex => qr{^(?:(?:[bc]:\d+:\d+)|all:(?:r?w?))|none$}i },
devnodes => { type => SCALAR, optional => 1, callbacks => { 'setting access to devnode' => ignore() }, },
force => { type => UNDEF, optional => 1 },
ioprio => { type => SCALAR, optional => 1, regex => qr{^[0-7]$} },
ipadd => { type => SCALAR | ARRAYREF, optional => 1, callbacks => { 'do these look like valid ip(s)?' => ignore() }, },
ipdel => { type => SCALAR | ARRAYREF, optional => 1, callbacks => { 'do these look like valid ip(s)?' => ignore() }, },
nameserver => { type => SCALAR | ARRAYREF, optional => 1, callbacks => { 'do these look like valid ip(s)?' => ignore() }, },
onboot => { type => SCALAR, optional => 1, regex => qr{^yes|no$}i },
save => { type => UNDEF, optional => 1 },
setmode => { type => SCALAR, optional => 1, regex => qr{^restart|ignore$}i },
userpasswd => { type => SCALAR, optional => 1, regex => qr{^(?:\w+):(?:\w+)$} },
iptables =>
{ type => SCALAR | ARRAYREF, optional => 1, callbacks => { 'see manpage for list of valid iptables names' => ignore() }, },
};
my %same = (
applyconfig => [ qw(
applyconfig_map hostname name netif_add netif_del pci_add pci_del searchdomain
),
],
avnumproc => [ qw(
dcachesize dgramrcvbuf diskinodes diskspace kmemsize lockedpages numfile numflock numiptent numothersock numproc numpty
numsiginfo numtcpsock oomguarpages othersockbuf physpages privvmpages shmpages swappages tcprcvbuf tcpsndbuf vmguarpages
),
],
bootorder => [qw( cpulimit cpus cpuunits quotatime quotaugidlimit )],
onboot => [qw( disabled noatime )],
);
for my $key ( keys %same ) {
$expected_spec->{ $_ } = $expected_spec->{ $key } for @{ $same{ $key } };
}
my %goodbad; @goodbad{ @parms } = t::Util::type( @parms );
#########################################################################################
my @cap_names = capabilities();
cmp_bag(
\@cap_names, [ qw(
chown dac_override dac_read_search fowner fsetid ipc_lock ipc_owner kill lease linux_immutable mknod net_admin
net_bind_service net_broadcast net_raw setgid setpcap setuid setveid sys_admin sys_boot sys_chroot sys_module sys_nice
sys_pacct sys_ptrace sys_rawio sys_resource sys_time sys_tty_config ve_admin
),
],
'got expected capablity names',
);
my @good_cap_names = map { ( "$_:on", "$_:off" ) } @cap_names;
my @bad_cap_names = map { ( "$_:bad", t::Util::did_not_pass() ) } @cap_names;
push @bad_cap_names, 'justallaroundbad', t::Util::did_not_pass();
my $capability_names = join q{|}, @cap_names;
$expected_spec->{ capability } = { type => SCALAR, optional => 1, regex => qr{^(?:$capability_names):(?:on|off)$}i };
$goodbad{ capability }{ good } = \@good_cap_names;
push @{ $goodbad{ capability }{ bad } }, @bad_cap_names;
#########################################################################################
my @features_names = features();
cmp_bag( \@features_names, [qw( sysfs nfs sit ipip ppp ipgre bridge nfsd)], 'got expected features names' );
my @good_features_names = map { ( "$_:on", "$_:off" ) } @features_names;
my @bad_features_names = map { ( "$_:bad", t::Util::did_not_pass() ) } @features_names;
push @bad_features_names, 'justallaroundbad', t::Util::did_not_pass();
my $features_names = join q{|}, @features_names;
$expected_spec->{ features } = { type => SCALAR, optional => 1, regex => qr{^(?:$features_names):(?:on|off)$}i };
$goodbad{ features }{ good } = \@good_features_names;
push @{ $goodbad{ features }{ bad } }, @bad_features_names;
#########################################################################################
my @iptables_modules = iptables_modules();
cmp_bag(
\@iptables_modules, [ qw(
ip_conntrack ip_conntrack_ftp ip_conntrack_irc ip_nat_ftp ip_nat_irc iptable_filter iptable_mangle iptable_nat
ipt_conntrack ipt_helper ipt_length ipt_limit ipt_LOG ipt_multiport ipt_owner ipt_recent ipt_REDIRECT ipt_REJECT
ipt_state ipt_tcpmss ipt_TCPMSS ipt_tos ipt_TOS ipt_ttl xt_mac
),
],
'got expected iptables modules',
);
my @iptables_names = map { ( "$_:on", "$_:off" ) } @iptables_modules;
$goodbad{ iptables }{ good } = \@iptables_names;
#
###################################################################################################################################
# XXX: The rest of this should be moved to t::Util somehow ...
my %invalid_regex = %{ t::Util::invalid_regex() };
note( 'Testing known_options' );
my @expected_parms = sort ( qw( flag ctid ), ( map { "[$_]" } @parms ) );
( run in 0.598 second using v1.01-cache-2.11-cpan-5511b514fd6 )