]>
Commit | Line | Data |
---|---|---|
1e180f97 DM |
1 | #!/usr/bin/perl |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use PVE::Tools qw(run_command); | |
6 | ||
7 | use lib qw(..); | |
8 | ||
9 | use PVE::LXC; | |
7af97ad5 | 10 | use PVE::LXC::Setup; |
1e180f97 DM |
11 | |
12 | sub test_file { | |
13 | my ($exp_fn, $real_fn) = @_; | |
14 | ||
55fa4e09 | 15 | return if system("diff -u '$exp_fn' '$real_fn'") == 0; |
1e180f97 DM |
16 | |
17 | die "files does not match\n"; | |
18 | } | |
19 | ||
20 | sub run_test { | |
21 | my ($testdir) = @_; | |
22 | ||
93285df8 DM |
23 | print "prepare $testdir\n"; |
24 | ||
1e180f97 DM |
25 | my $rootfs = "./tmprootfs"; |
26 | ||
27 | run_command("rm -rf $rootfs"); | |
28 | run_command("cp -a $testdir $rootfs"); | |
29 | ||
30 | my $config_fn = "$testdir/config"; | |
31 | ||
32 | my $raw = PVE::Tools::file_get_contents($config_fn); | |
33 | ||
27916659 | 34 | my $conf = PVE::LXC::parse_pct_config("/lxc/100.conf", $raw); |
1e180f97 | 35 | |
27916659 | 36 | $conf->{'testmode'} = 1; |
1e180f97 | 37 | |
7af97ad5 | 38 | my $lxc_setup = PVE::LXC::Setup->new($conf, $rootfs); |
1e180f97 | 39 | |
55fa4e09 DM |
40 | for (my $i = 0; $i < 2; $i++) { |
41 | # run tests twice, to make sure scripts are idempotent | |
42 | ||
4727bd09 | 43 | srand(0); |
168d6b07 | 44 | $lxc_setup->post_create_hook('$TEST$ABCDEF'); |
55fa4e09 | 45 | |
4727bd09 | 46 | my @testfiles = qw(/etc/hostname /etc/hosts /etc/inittab /etc/network/interfaces /etc/resolv.conf /etc/passwd /etc/shadow /etc/sysconfig/network /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth1 /etc/sysconfig/network-scripts/ifcfg-eth2 /etc/sysconfig/network-scripts/ifcfg-eth3 /etc/init/start-ttys.conf /etc/init/tty.conf /etc/init/power-status-changed.conf /etc/securetty /etc/crontab); |
55fa4e09 DM |
47 | foreach my $fn (@testfiles) { |
48 | next if !-f "$testdir/$fn.exp"; | |
49 | test_file("$testdir/$fn.exp", "$rootfs/$fn"); | |
50 | } | |
51 | } | |
52 | ||
1e180f97 DM |
53 | print "TEST $testdir => OK\n"; |
54 | } | |
55 | ||
d66768a2 DM |
56 | if (scalar(@ARGV)) { |
57 | ||
58 | foreach my $testdir (@ARGV) { | |
59 | run_test($testdir); | |
60 | } | |
61 | ||
62 | } else { | |
63 | ||
f80c2125 DM |
64 | foreach my $testdir (<test-*>) {# |
65 | next if ! -d $testdir; | |
66 | run_test($testdir); | |
67 | } | |
d66768a2 | 68 | } |
1e180f97 DM |
69 | |
70 | exit(0); |