]> git.proxmox.com Git - pve-container.git/blob - src/test/run_setup_tests.pl
fc92dbb10e1ef80d5ec6fee88a3bf2a3dcd2d717
[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 return if system("diff -u '$exp_fn' '$real_fn'") == 0;
16
17 die "files do not match\n";
18 }
19
20 sub run_test {
21 my ($testdir) = @_;
22
23 print "prepare $testdir\n";
24
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
34 my $conf = PVE::LXC::Config::parse_pct_config("/lxc/100.conf", $raw);
35
36 $conf->{'testmode'} = 1;
37
38 my $lxc_setup = PVE::LXC::Setup->new($conf, $rootfs);
39
40 for (my $i = 0; $i < 2; $i++) {
41 # run tests twice, to make sure scripts are idempotent
42
43 srand(0);
44 $lxc_setup->post_create_hook('$TEST$ABCDEF','ssh-rsa ABCDEFG ABC@DEF');
45
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
74 /etc/crontab
75 /root
76 /root/.ssh
77 /root/.ssh/authorized_keys
78 /roothome
79 /roothome/.ssh
80 /roothome/.ssh/authorized_keys);
81 foreach my $fn (@testfiles) {
82 next if !-f "$testdir/$fn.exp";
83 test_file("$testdir/$fn.exp", "$rootfs/$fn");
84 }
85 }
86
87 print "TEST $testdir => OK\n";
88 }
89
90 if (scalar(@ARGV)) {
91
92 foreach my $testdir (@ARGV) {
93 run_test($testdir);
94 }
95
96 } else {
97
98 foreach my $testdir (<test-*>) {#
99 next if ! -d $testdir;
100 run_test($testdir);
101 }
102 }
103
104 exit(0);