]> git.proxmox.com Git - pve-container.git/blob - src/test/run_setup_tests.pl
Mark CT as a template after rename volumes.
[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/route6-eth0
57 /etc/sysconfig/network-scripts/ifcfg-eth1
58 /etc/sysconfig/network-scripts/route-eth1
59 /etc/sysconfig/network-scripts/route6-eth1
60 /etc/sysconfig/network-scripts/ifcfg-eth2
61 /etc/sysconfig/network-scripts/route-eth2
62 /etc/sysconfig/network-scripts/route6-eth2
63 /etc/sysconfig/network-scripts/ifcfg-eth3
64 /etc/sysconfig/network-scripts/route-eth3
65 /etc/sysconfig/network-scripts/route6-eth3
66 /etc/sysconfig/network/ifcfg-eth0
67 /etc/sysconfig/network/ifroute-eth0
68 /etc/sysconfig/network/ifcfg-eth1
69 /etc/sysconfig/network/ifroute-eth1
70 /etc/sysconfig/network/ifcfg-eth2
71 /etc/sysconfig/network/ifroute-eth2
72 /etc/sysconfig/network/ifcfg-eth3
73 /etc/sysconfig/network/ifroute-eth3
74 /etc/init/start-ttys.conf
75 /etc/init/tty.conf
76 /etc/init/power-status-changed.conf
77 /etc/securetty
78 /etc/crontab
79 /root
80 /root/.ssh
81 /root/.ssh/authorized_keys
82 /roothome
83 /roothome/.ssh
84 /roothome/.ssh/authorized_keys);
85 foreach my $fn (@testfiles) {
86 next if !-f "$testdir/$fn.exp";
87 test_file("$testdir/$fn.exp", "$rootfs/$fn");
88 }
89 }
90
91 print "TEST $testdir => OK\n";
92 }
93
94 if (scalar(@ARGV)) {
95
96 foreach my $testdir (@ARGV) {
97 run_test($testdir);
98 }
99
100 } else {
101
102 foreach my $testdir (<test-*>) {#
103 next if ! -d $testdir;
104 run_test($testdir);
105 }
106 }
107
108 exit(0);