lib/Tapper/Installer/Base.pm

filter: Statementstmt 32.6% 50 / 153 Branchbran 4.8% 4 / 82 Conditioncond 7.1% 1 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 81.2% 13 / 16 Podpod 100% 4 / 4 totaltotal 25.9% 72 / 278 CC 50 SCAR 67.7
CC
50
Cov
22%
system_install
1482.0
free_loop_device
24.1
cleanup
20.0
CRAP 871.3
↑ Summary lib/Tapper/Installer/Precondition/Kernelbuild.pm »
1 package Tapper::Installer::Base;
2 4 our $AUTHORITY = 'cpan:TAPPER';
3 4 $Tapper::Installer::Base::VERSION = '5.0.3';
4 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Tapper::Remote::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Tapper::Installer::Precondition::Copyfile;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Tapper::Installer::Precondition::Exec;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Tapper::Installer::Precondition::Fstab;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Tapper::Installer::Precondition::Image;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Tapper::Installer::Precondition::Kernelbuild;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Tapper::Installer::Precondition::PRC;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use Tapper::Installer::Precondition::Package;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Tapper::Installer::Precondition::Rawimage;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use Tapper::Installer::Precondition::Repository;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use Tapper::Installer::Precondition::Simnow;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 4 extends 'Tapper::Installer';
19  
20  
21  
22 sub free_loop_device
23 1 ▶{
Subroutine free_loop_device: called CC=9 SCAR=31.8
Pod documented
24 1 my ($self) = @_;
25 1 my ($error, $dev) = $self->log_and_exec('losetup', '-f');
26  
27 1 ▶ return if !$error and $dev eq '/dev/loop0';
Branch: 1 branch
BranchTrueFalseTotal
if not $error and $dev eq "/dev/loop0" 0 1 1
Condition33%1/3
not $error and $dev eq "/dev/loop0"
!ll&&!rl&&r
010
MC/DC0%0/2
not $error and $dev eq "/dev/loop0"
not $error $dev eq "/dev/loop0"
Truth table33%1/3
not(A) and B
A= not $errorB= $dev eq "/dev/loop0"
ABresult
0X0
100
111
28 1 ($error, $dev) = $self->log_and_exec("mount | grep loop0 | cut -f 3 -d ' '");
29 1 ▶ return $dev if $error; # can not search for mounts
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 1 1
30  
31 1 ▶ if ($dev) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dev) 0 1 1
32 0 $error = $self->log_and_exec("umount $dev");
33 0 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 0 0
34 0 my $processes;
35 0 ($error, $processes) =
36 $self->log_and_exec('lsof -t +D $dev 2>/dev/null');
37 0 foreach my $proc (split "\n", $processes) {
38 0 kill 15, $proc;
39 0 sleep 2;
40 0 kill 9, $proc;
41 }
42 0 $error = $self->log_and_exec("umount $dev");
43 0 ▶ return $error if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
44 }
45 }
46  
47 1 ($error, $dev) = $self->log_and_exec("kpartx -d /dev/loop0");
48 1 ▶ return $dev if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 1 1
49  
50 1 ($error, $dev) = $self->log_and_exec("losetup -d /dev/loop0");
51 1 return;
52 }
53  
54  
55 sub cleanup
56 0 ▶{
Subroutine cleanup: not called CC=4 SCAR=30.0
Pod documented
57 0 my ($self) = @_;
58  
59 0 $self->log->info('Cleaning up logfiles');
60 0 my @files_to_clean = ('/var/log/messages','/var/log/syslog');
61 FILE:
62 0 foreach my $file (@files_to_clean) {
63 0 my $filename = $self->cfg->{paths}{base_dir}."$file";
64 0 ▶ next FILE if not -e $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $filename 0 0 0
65 0 ▶ open my $fh, ">", $filename or $self->log->warn("Can not open $filename for cleaning: $!"), next FILE;
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $filename or $self->log->warn("Can not open $filename for cleaning: $!"), next FILE 0 0 0
66 0 print $fh '';
67 0 close $fh;
68 }
69 0 return 0;
70 }
71  
72  
73  
74 sub send_keep_alive_loop
75 0 ▶{
Subroutine send_keep_alive_loop: not called CC=2 SCAR=17.9
Pod documented
76 0 my ($self, $sleeptime) = @_;
77 0 ▶ return unless $sleeptime;
Branch: 1 branch
BranchTrueFalseTotal
unless $sleeptime 0 0 0
78 0 while (1) {
79 0 $self->mcp_inform("keep-alive");
80 0 sleep($sleeptime);
81 }
82 0 return;
83 }
84  
85  
86  
87 sub system_install
88 0 ▶{
Subroutine system_install: not called CC=38 SCAR=73.0
Pod documented
89 0 my ($self, $state) = @_;
90  
91 0 my $retval;
92 0 ▶ $state ||= 'standard'; # always defined value for state
Condition0%0/2
$state ||= "standard"
l!l
00
MC/DC0%0/1
$state ||= "standard"
$state
Truth table0%0/2
A
A= $state
Aresult
11
00
93 # fetch configurations from the server
94 0 my $consumer = Tapper::Remote::Config->new;
95  
96 0 my $config=$consumer->get_local_data('install');
97 0 ▶ $self->logdie($config) if not ref($config) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $config eq "HASH" 0 0 0
98  
99 0 $self->{cfg}=$config;
100 0 ▶ $self->logdie("can't get local data: $config") if ref $config ne "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if ref $config ne "HASH" 0 0 0
101  
102 0 ▶ if (not $state eq 'simnow') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($state eq "simnow") 0 0 0
103 0 $retval = $self->nfs_mount();
104 0 ▶ $self->log->warn($retval) if $retval;
Branch: 1 branch
BranchTrueFalseTotal
if $retval 0 0 0
105 }
106  
107 0 ▶ if ($self->cfg->{log_to_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->cfg->{"log_to_file"}) 0 0 0
108 0 $self->log_to_file('install');
109 }
110  
111  
112 0 $self->log->info("Installing testrun (".$self->cfg->{testrun_id}.") on host ".$self->cfg->{hostname});
113 0 ▶ $self->mcp_inform("start-install") unless $state eq "autoinstall";
Branch: 1 branch
BranchTrueFalseTotal
unless $state eq "autoinstall" 0 0 0
114  
115 0 ▶ if ($config->{times}{keep_alive_timeout}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"times"}{"keep_alive_timeout"}) 0 0 0
116 0 $SIG{CHLD} = 'IGNORE';
117 0 my $pid = fork();
118 0 ▶ if ($pid == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pid == 0) { } 0 0 0
119 0 $self->send_keep_alive_loop($config->{times}{keep_alive_timeout});
120 0 exit;
121 } else {
122 0 $config->{keep_alive_child} = $pid;
123 }
124 }
125  
126 0 ▶ if ($state eq 'simnow') {
Branch: 1 branch
BranchTrueFalseTotal
if ($state eq "simnow") 0 0 0
127 0 $retval = $self->free_loop_device();
128 0 ▶ $self->logdie($retval) if $retval;
Branch: 1 branch
BranchTrueFalseTotal
if $retval 0 0 0
129 }
130  
131 0 my $image=Tapper::Installer::Precondition::Image->new($config);
132 0 ▶ if ($state eq "standard") {
Branch: 1 branch
BranchTrueFalseTotal
if ($state eq "standard") 0 0 0
133 $self->logdie("First precondition is not the root image")
134 if not $config->{preconditions}->[0]->{precondition_type} eq 'image'
135 0 ▶ and $config->{preconditions}->[0]->{mount} eq '/';
Branch: 1 branch
BranchTrueFalseTotal
if not $config->{"preconditions"}[0]{"precondition_type"} eq "image" and $config->{"preconditions"}[0]{"mount"} eq "/" 0 0 0
Condition0%0/3
not $config->{"preconditions"}[0]{"precondition_type"} eq "image" and $config->{"preconditions"}[0]{"mount"} eq "/"
!ll&&!rl&&r
000
MC/DC0%0/2
not $config->{"preconditions"}[0]{"precondition_type"} eq "image" and $config->{"preconditions"}[0]{"mount"} eq "/"
not $config->{"preconditions"}[0]{"precondition_type"} eq "image" $config->{"preconditions"}[0]{"mount"} eq "/"
Truth table0%0/3
not(A) and B
A= not $config->{"preconditions"}[0]{"precondition_type"} eq "image"B= $config->{"preconditions"}[0]{"mount"} eq "/"
ABresult
0X0
100
111
136 }
137  
138 0 foreach my $precondition (@{$config->{preconditions}}) {
139 0 ▶ if ($precondition->{precondition_type} eq 'image')
Branch: 10 branches
BranchTrueFalseTotal
if ($precondition->{'precondition_type'} eq 'image') { } 0 0 0
elsif ($precondition->{'precondition_type'} eq 'package') { } 0 0 0
elsif ($precondition->{'precondition_type'} eq 'copyfile') { } 0 0 0
elsif ($precondition->{'precondition_type'} eq 'fstab') { } 0 0 0
elsif ($precondition->{'precondition_type'} eq 'prc') { } 0 0 0
elsif ($precondition->{'precondition_type'} eq 'rawimage') { } 0 0 0
elsif ($precondition->{'precondition_type'} eq 'repository') { } 0 0 0
elsif ($precondition->{'precondition_type'} eq 'exec') { } 0 0 0
elsif ($precondition->{'precondition_type'} eq 'simnow_backend') { } 0 0 0
elsif ($precondition->{'precondition_type'} eq 'kernelbuild') { } 0 0 0
140 {
141 0 $retval = $image->precondition_install($precondition);
142 }
143 elsif ($precondition->{precondition_type} eq 'package')
144 {
145 0 my $package=Tapper::Installer::Precondition::Package->new($config);
146 0 $retval = $package->precondition_install($precondition);
147 }
148 elsif ($precondition->{precondition_type} eq 'copyfile')
149 {
150 0 my $copyfile = Tapper::Installer::Precondition::Copyfile->new($config);
151 0 $retval = $copyfile->precondition_install($precondition);
152 }
153 elsif ($precondition->{precondition_type} eq 'fstab')
154 {
155 0 my $fstab = Tapper::Installer::Precondition::Fstab->new($config);
156 0 $retval = $fstab->precondition_install($precondition);
157 }
158 elsif ($precondition->{precondition_type} eq 'prc')
159 {
160 0 my $prc=Tapper::Installer::Precondition::PRC->new($config);
161 0 $retval = $prc->precondition_install($precondition);
162 }
163 elsif ($precondition->{precondition_type} eq 'rawimage')
164 {
165 0 my $rawimage=Tapper::Installer::Precondition::Rawimage->new($config);
166 0 $retval = $rawimage->precondition_install($precondition);
167 }
168 elsif ($precondition->{precondition_type} eq 'repository')
169 {
170 0 my $repository=Tapper::Installer::Precondition::Repository->new($config);
171 0 $retval = $repository->precondition_install($precondition);
172 }
173 elsif ($precondition->{precondition_type} eq 'exec')
174 {
175 0 my $exec=Tapper::Installer::Precondition::Exec->new($config);
176 0 $retval = $exec->precondition_install($precondition);
177 }
178 elsif ($precondition->{precondition_type} eq 'simnow_backend')
179 {
180 0 my $simnow=Tapper::Installer::Precondition::Simnow->new($config);
181 0 $retval = $simnow->precondition_install($precondition);
182 }
183 elsif ($precondition->{precondition_type} eq 'kernelbuild')
184 {
185 0 my $kernelbuild=Tapper::Installer::Precondition::Kernelbuild->new($config);
186 0 $retval = $kernelbuild->precondition_install($precondition);
187 }
188  
189 0 ▶ if ($retval) {
Branch: 1 branch
BranchTrueFalseTotal
if ($retval) 0 0 0
190 0 ▶ if ($precondition->{continue_on_error}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($precondition->{'continue_on_error'}) { } 0 0 0
191 0 $self->mcp_send({state => 'warn-install', error => $retval});
192 } else {
193 0 $self->logdie($retval);
194 }
195 }
196 }
197  
198 0 ▶ if ($state eq 'standard' and not $config->{no_cleanup}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state eq "standard" and not $config->{"no_cleanup"}) 0 0 0
Condition0%0/3
$state eq "standard" and not $config->{"no_cleanup"}
!ll&&!rl&&r
000
MC/DC0%0/2
$state eq "standard" and not $config->{"no_cleanup"}
$state eq "standard" not $config->{"no_cleanup"}
Truth table0%0/3
A and not(B)
A= $state eq "standard"B= not $config->{"no_cleanup"}
ABresult
0X0
100
111
199 0 $self->cleanup();
200 }
201  
202 0 ▶ if ( $state eq "standard" and not ($config->{skip_prepare_boot})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state eq "standard" and not $config->{"skip_prepare_boot"}) 0 0 0
Condition0%0/3
$state eq "standard" and not $config->{"skip_prepare_boot"}
!ll&&!rl&&r
000
MC/DC0%0/2
$state eq "standard" and not $config->{"skip_prepare_boot"}
$state eq "standard" not $config->{"skip_prepare_boot"}
Truth table0%0/3
A and not(B)
A= $state eq "standard"B= not $config->{"skip_prepare_boot"}
ABresult
0X0
100
111
203 0 ▶ $self->logdie($retval) if $retval = $image->prepare_boot();
Branch: 1 branch
BranchTrueFalseTotal
if $retval = $image->prepare_boot 0 0 0
204  
205 }
206 0 $image->unmount();
207  
208 # no longer send keepalive
209 0 ▶ if ($config->{keep_alive_child}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config->{"keep_alive_child"}) 0 0 0
210 0 kill 15, $config->{keep_alive_child};
211 0 sleep 2;
212 0 kill 9, $config->{keep_alive_child};
213 }
214  
215  
216 0 $self->mcp_inform("end-install");
217 0 $self->log->info("Finished installation of test machine");
218  
219 0 ▶ if ($state eq "standard"){
Branch: 2 branches
BranchTrueFalseTotal
if ($state eq 'standard') { } 0 0 0
elsif ($state eq 'simnow') { } 0 0 0
220 0 ▶ return 0 if $config->{installer_stop};
Branch: 1 branch
BranchTrueFalseTotal
if $config->{"installer_stop"} 0 0 0
221 0 system("sync");
222 0 system("sync");
223 0 system("sync");
224 0 system("reboot");
225 }
226 elsif ($state eq 'simnow'){
227 #FIXME: don't use hardcoded path
228 0 my $simnow_config = $self->cfg->{files}{simnow_config};
229 0 $retval = qx(/opt/tapper/perl/perls/current/bin/perl /opt/tapper/perl/perls/current/bin/tapper-simnow-start --config=$simnow_config);
230 0 ▶ if ($?) {
Branch: 1 branch
BranchTrueFalseTotal
if ($?) 0 0 0
231 0 $self->log->error("Can not start simnow: $retval");
232 0 $self->mcp_send({state => 'error-install',
233 error => "Can not start simnow: $retval",
234 prc_number => 0});
235 }
236  
237 }
238 0 return 0;
239 }
240  
241  
242 4 1;
243  
244 __END__
↑ Summary lib/Tapper/Installer/Precondition/Kernelbuild.pm »