]>
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 | ||
b442fc3f DC |
15 | # replace @DAYS@ with the current correct value |
16 | if ($exp_fn =~ m/shadow.exp$/) { | |
17 | my $expecteddays = int(time()/(60*60*24)); | |
18 | system ("sed -i.bak 's/\@DAYS\@/$expecteddays/' $exp_fn"); | |
19 | my $ret = system("diff -u '$exp_fn' '$real_fn'"); | |
20 | system("mv '$exp_fn.bak' '$exp_fn'"); | |
21 | return if $ret == 0; | |
22 | } else { | |
23 | return if system("diff -u '$exp_fn' '$real_fn'") == 0; | |
24 | } | |
1e180f97 | 25 | |
fa7cb12b | 26 | die "files do not match\n"; |
1e180f97 DM |
27 | } |
28 | ||
29 | sub run_test { | |
30 | my ($testdir) = @_; | |
31 | ||
93285df8 DM |
32 | print "prepare $testdir\n"; |
33 | ||
1e180f97 DM |
34 | my $rootfs = "./tmprootfs"; |
35 | ||
36 | run_command("rm -rf $rootfs"); | |
37 | run_command("cp -a $testdir $rootfs"); | |
38 | ||
39 | my $config_fn = "$testdir/config"; | |
40 | ||
41 | my $raw = PVE::Tools::file_get_contents($config_fn); | |
42 | ||
1b4cf758 | 43 | my $conf = PVE::LXC::Config::parse_pct_config("/lxc/100.conf", $raw); |
1e180f97 | 44 | |
27916659 | 45 | $conf->{'testmode'} = 1; |
1e180f97 | 46 | |
7af97ad5 | 47 | my $lxc_setup = PVE::LXC::Setup->new($conf, $rootfs); |
1e180f97 | 48 | |
55fa4e09 DM |
49 | for (my $i = 0; $i < 2; $i++) { |
50 | # run tests twice, to make sure scripts are idempotent | |
51 | ||
4727bd09 | 52 | srand(0); |
a46b2fb3 | 53 | $lxc_setup->post_create_hook('$5$SALT$PASS','ssh-rsa ABCDEFG ABC@DEF'); |
55fa4e09 | 54 | |
fa7cb12b WB |
55 | my @testfiles = qw(/etc/hostname |
56 | /etc/hosts | |
57 | /etc/inittab | |
58 | /etc/network/interfaces | |
59 | /etc/resolv.conf | |
60 | /etc/passwd | |
61 | /etc/shadow | |
62 | /etc/sysconfig/network | |
63 | /etc/sysconfig/network-scripts/ifcfg-eth0 | |
64 | /etc/sysconfig/network-scripts/route-eth0 | |
85e4f0cd | 65 | /etc/sysconfig/network-scripts/route6-eth0 |
fa7cb12b WB |
66 | /etc/sysconfig/network-scripts/ifcfg-eth1 |
67 | /etc/sysconfig/network-scripts/route-eth1 | |
85e4f0cd | 68 | /etc/sysconfig/network-scripts/route6-eth1 |
fa7cb12b WB |
69 | /etc/sysconfig/network-scripts/ifcfg-eth2 |
70 | /etc/sysconfig/network-scripts/route-eth2 | |
85e4f0cd | 71 | /etc/sysconfig/network-scripts/route6-eth2 |
fa7cb12b WB |
72 | /etc/sysconfig/network-scripts/ifcfg-eth3 |
73 | /etc/sysconfig/network-scripts/route-eth3 | |
85e4f0cd | 74 | /etc/sysconfig/network-scripts/route6-eth3 |
fa7cb12b WB |
75 | /etc/sysconfig/network/ifcfg-eth0 |
76 | /etc/sysconfig/network/ifroute-eth0 | |
77 | /etc/sysconfig/network/ifcfg-eth1 | |
78 | /etc/sysconfig/network/ifroute-eth1 | |
79 | /etc/sysconfig/network/ifcfg-eth2 | |
80 | /etc/sysconfig/network/ifroute-eth2 | |
81 | /etc/sysconfig/network/ifcfg-eth3 | |
82 | /etc/sysconfig/network/ifroute-eth3 | |
83 | /etc/init/start-ttys.conf | |
84 | /etc/init/tty.conf | |
85 | /etc/init/power-status-changed.conf | |
86 | /etc/securetty | |
6325584e FG |
87 | /etc/crontab |
88 | /root | |
89 | /root/.ssh | |
90 | /root/.ssh/authorized_keys | |
91 | /roothome | |
92 | /roothome/.ssh | |
93 | /roothome/.ssh/authorized_keys); | |
55fa4e09 DM |
94 | foreach my $fn (@testfiles) { |
95 | next if !-f "$testdir/$fn.exp"; | |
96 | test_file("$testdir/$fn.exp", "$rootfs/$fn"); | |
97 | } | |
98 | } | |
99 | ||
1e180f97 DM |
100 | print "TEST $testdir => OK\n"; |
101 | } | |
102 | ||
d66768a2 DM |
103 | if (scalar(@ARGV)) { |
104 | ||
105 | foreach my $testdir (@ARGV) { | |
106 | run_test($testdir); | |
107 | } | |
108 | ||
109 | } else { | |
110 | ||
f80c2125 DM |
111 | foreach my $testdir (<test-*>) {# |
112 | next if ! -d $testdir; | |
113 | run_test($testdir); | |
114 | } | |
d66768a2 | 115 | } |
1e180f97 DM |
116 | |
117 | exit(0); |