6 my $parser = XML::LibXML->new();
7 my $dom = $parser->parse_file($ARGV[1] || "$Bin/test_runner.xml");
8 chomp (my $whoami = `whoami`);
10 # XML file looks like this:
13 # <report_path>~/public_html/</report_path>
14 # <installer_path>/home/phasefx/git/random/</installer_path>
19 # <description>qa01</description>
20 # <target_ssh_user>phasefx</target_ssh_user>
21 # <target_ssh_host>192.168.1.79</target_ssh_host>
22 # <!-- Local Copy, relative to installer_path -->
23 # <installer_scripts>installer/wheezy/</installer_scripts>
24 # <!-- On Remote Host -->
25 # <installer_invocation>/home/phasefx/eg_installer/wheezy/installer_installer2.sh /home/phasefx/eg_installer/wheezy/</installer_invocation>
30 my $localconf = $dom->findnodes('//local')->[0];
31 my $installer_path = $localconf->findvalue('./installer_path');
33 foreach my $host ($dom->findnodes('//host')) {
36 next if $pid = fork; # Parent goes to next server.
37 die "fork failed: $!" unless defined $pid;
39 # inside the child process
41 my $name = $host->findvalue('./name');
42 my $description = $host->findvalue('./description');
43 my $target_ssh_user = $host->findvalue('./target_ssh_user') || $whoami;
44 my $target_ssh_host = $host->findvalue('./target_ssh_host');
45 my $target_ssh_path = $host->findvalue('./target_ssh_path') || "/home/$whoami/eg_installer";
46 my $installer_scripts = $host->findvalue('./installer_scripts');
47 my $installer_invocation = $host->findvalue('./installer_invocation');
48 my $output_path = $host->findvalue('./output_path') || "/home/$whoami/public_html/hosts/$name";
49 my $output_parser = $host->findvalue('./output_parser') || "$Bin/test_output_webifier.pl";
51 print "$pid *** Ensuring $output_path and related paths exist\n";
52 my @args = ('mkdir','-p',$output_path);
53 system(@args) == 0 or die "system @args failed: $?";
54 @args = ('mkdir','-p',"$output_path/archive/");
55 system(@args) == 0 or die "system @args failed: $?";
56 chomp(my $month = `date +%Y-%m`);
57 @args = ('mkdir','-p',"$output_path/archive/$month/");
58 system(@args) == 0 or die "system @args failed: $?";
59 chomp(my $time = `date +%F_%T`);
60 @args = ('mkdir','-p',"$output_path/archive/$month/$time/");
61 system(@args) == 0 or die "system @args failed: $?";
63 print "$pid *** Archiving previous output\n";
64 `(cd $output_path && mv *.* $output_path/archive/$month/$time/ && cp $output_path/archive/$month/$time/*.hash .)`;
66 print "$pid *** In Progress Page\n";
67 `cp test_output.css $output_path/`;
68 open FILE, ">$output_path/test.html";
69 print FILE '<html><head></head><body><h1>Testing in progress</h1>[<a href="archive/">Previous Runs</a>]</body></html>';
71 `(cd $output_path && ln -s test.html index.html)`;
73 print "$pid *** Ensuring $target_ssh_user\@$target_ssh_host:$target_ssh_path exists\n";
74 my @args = ('ssh',"$target_ssh_user\@$target_ssh_host", 'mkdir','-p',$target_ssh_path);
75 system(@args) == 0 or die "system @args failed: $?";
77 print "$pid *** Pushing $installer_path$installer_scripts to $target_ssh_user\@$target_ssh_host:$target_ssh_path\n";
78 @args = ('scp', '-r', $installer_path . $installer_scripts, "$target_ssh_user\@$target_ssh_host:$target_ssh_path");
79 system(@args) == 0 or die "system @args failed: $?";
81 print "$pid *** Test starting, writing to $output_path/output.txt\n";
82 my $cmd = "ssh $target_ssh_user\@$target_ssh_host $installer_invocation 1>$output_path/output.txt 2>&1";
86 print "$pid *** Test complete, prettifying results\n";
87 `cd $output_path && $output_parser output.txt`;
89 exit; # end the child process
92 1 while (wait() != -1); # wait for all child processes