]>
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 | 16 | |
fa7cb12b | 17 | die "files do not match\n"; |
1e180f97 DM |
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 | ||
1b4cf758 | 34 | my $conf = PVE::LXC::Config::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); |
6325584e | 44 | $lxc_setup->post_create_hook('$TEST$ABCDEF','ssh-rsa ABCDEFG ABC@DEF'); |
55fa4e09 | 45 | |
fa7cb12b WB |
46 | my @testfiles = qw(/etc/hostname |
47 | /etc/hosts | |
48 | /etc/inittab | |
49 | /etc/network/interfaces | |
50 | /etc/resolv.conf | |
51 | /etc/passwd | |
52 | /etc/shadow | |
53 | /etc/sysconfig/network | |
54 | /etc/sysconfig/network-scripts/ifcfg-eth0 | |
55 | /etc/sysconfig/network-scripts/route-eth0 | |
56 | /etc/sysconfig/network-scripts/ifcfg-eth1 | |
57 | /etc/sysconfig/network-scripts/route-eth1 | |
58 | /etc/sysconfig/network-scripts/ifcfg-eth2 | |
59 | /etc/sysconfig/network-scripts/route-eth2 | |
60 | /etc/sysconfig/network-scripts/ifcfg-eth3 | |
61 | /etc/sysconfig/network-scripts/route-eth3 | |
62 | /etc/sysconfig/network/ifcfg-eth0 | |
63 | /etc/sysconfig/network/ifroute-eth0 | |
64 | /etc/sysconfig/network/ifcfg-eth1 | |
65 | /etc/sysconfig/network/ifroute-eth1 | |
66 | /etc/sysconfig/network/ifcfg-eth2 | |
67 | /etc/sysconfig/network/ifroute-eth2 | |
68 | /etc/sysconfig/network/ifcfg-eth3 | |
69 | /etc/sysconfig/network/ifroute-eth3 | |
70 | /etc/init/start-ttys.conf | |
71 | /etc/init/tty.conf | |
72 | /etc/init/power-status-changed.conf | |
73 | /etc/securetty | |
6325584e FG |
74 | /etc/crontab |
75 | /root | |
76 | /root/.ssh | |
77 | /root/.ssh/authorized_keys | |
78 | /roothome | |
79 | /roothome/.ssh | |
80 | /roothome/.ssh/authorized_keys); | |
55fa4e09 DM |
81 | foreach my $fn (@testfiles) { |
82 | next if !-f "$testdir/$fn.exp"; | |
83 | test_file("$testdir/$fn.exp", "$rootfs/$fn"); | |
84 | } | |
85 | } | |
86 | ||
1e180f97 DM |
87 | print "TEST $testdir => OK\n"; |
88 | } | |
89 | ||
d66768a2 DM |
90 | if (scalar(@ARGV)) { |
91 | ||
92 | foreach my $testdir (@ARGV) { | |
93 | run_test($testdir); | |
94 | } | |
95 | ||
96 | } else { | |
97 | ||
f80c2125 DM |
98 | foreach my $testdir (<test-*>) {# |
99 | next if ! -d $testdir; | |
100 | run_test($testdir); | |
101 | } | |
d66768a2 | 102 | } |
1e180f97 DM |
103 | |
104 | exit(0); |