]> git.proxmox.com Git - pve-container.git/blob - src/test/run_setup_tests.pl
use better regex for detecting pre crypt()'d passwords
[pve-container.git] / src / test / run_setup_tests.pl
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;
10 use PVE::LXC::Setup;
11
12 sub test_file {
13 my ($exp_fn, $real_fn) = @_;
14
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 }
25
26 die "files do not match\n";
27 }
28
29 sub run_test {
30 my ($testdir) = @_;
31
32 print "prepare $testdir\n";
33
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
43 my $conf = PVE::LXC::Config::parse_pct_config("/lxc/100.conf", $raw);
44
45 $conf->{'testmode'} = 1;
46
47 my $lxc_setup = PVE::LXC::Setup->new($conf, $rootfs);
48
49 for (my $i = 0; $i < 2; $i++) {
50 # run tests twice, to make sure scripts are idempotent
51
52 srand(0);
53 $lxc_setup->post_create_hook('$5$SALT$PASS','ssh-rsa ABCDEFG ABC@DEF');
54
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
65 /etc/sysconfig/network-scripts/route6-eth0
66 /etc/sysconfig/network-scripts/ifcfg-eth1
67 /etc/sysconfig/network-scripts/route-eth1
68 /etc/sysconfig/network-scripts/route6-eth1
69 /etc/sysconfig/network-scripts/ifcfg-eth2
70 /etc/sysconfig/network-scripts/route-eth2
71 /etc/sysconfig/network-scripts/route6-eth2
72 /etc/sysconfig/network-scripts/ifcfg-eth3
73 /etc/sysconfig/network-scripts/route-eth3
74 /etc/sysconfig/network-scripts/route6-eth3
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
87 /etc/crontab
88 /root
89 /root/.ssh
90 /root/.ssh/authorized_keys
91 /roothome
92 /roothome/.ssh
93 /roothome/.ssh/authorized_keys);
94 foreach my $fn (@testfiles) {
95 next if !-f "$testdir/$fn.exp";
96 test_file("$testdir/$fn.exp", "$rootfs/$fn");
97 }
98 }
99
100 print "TEST $testdir => OK\n";
101 }
102
103 if (scalar(@ARGV)) {
104
105 foreach my $testdir (@ARGV) {
106 run_test($testdir);
107 }
108
109 } else {
110
111 foreach my $testdir (<test-*>) {#
112 next if ! -d $testdir;
113 run_test($testdir);
114 }
115 }
116
117 exit(0);