lib/Tapper/Installer/Precondition/Rawimage.pm

filter: Statementstmt 35.5% 16 / 45 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 27.6% 21 / 76 CC 13 SCAR 49.4
CC
13
Cov
24%
install
182.0
BEGIN
1.0
BEGIN
1.0
CRAP 139.4
« lib/Tapper/Installer/Precondition/Kernelbuild.pm ↑ Summary lib/Tapper/Installer/Precondition/PRC.pm »
1 package Tapper::Installer::Precondition::Rawimage;
2 5 our $AUTHORITY = 'cpan:TAPPER';
3 5 $Tapper::Installer::Precondition::Rawimage::VERSION = '5.0.3';
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 extends 'Tapper::Installer::Precondition';
10  
11  
12  
13  
14 0 ▶sub install {
Subroutine install: not called CC=13 SCAR=52.0
Pod documented
15 0 my ($self, $img) = @_;
16  
17 0 ▶ return "not filename given for rawimage" if not $img->{name};
Branch: 1 branch
BranchTrueFalseTotal
unless $img->{"name"} 0 0 0
18  
19 0 my $img_size = 2048*1024; # 2GByte - size of standard rawimage in kbyte
20  
21 0 my $filename = $img->{name};
22 0 my $path = $self->cfg->{paths}{base_dir}.$img->{path};
23 0 ▶ my $size = $img->{size} || $img_size;
Condition0%0/3
$img->{'size'} || $img_size
l!l&&r!l&&!r
000
MC/DC0%0/2
$img->{'size'} || $img_size
$img->{'size'} $img_size
Truth table0%0/3
A || B
A= $img->{'size'}B= $img_size
ABresult
1X1
011
000
24 0 my ($error, $retval);
25  
26 0 ▶ if (not -d $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $path) 0 0 0
27 0 mkpath($path, {error => \$error});
28 0 foreach my $diag (@$error) {
29 0 my ($file, $message) = each %$diag;
30 0 ▶ return "general error: $message\n" if $file eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $file eq "" 0 0 0
31 0 return "Can't create $file: $message";
32 }
33 }
34  
35 0 $filename = $path."/".$filename;
36  
37 0 ($error, $retval) = $self->log_and_exec("dd if=/dev/zero of=$filename bs=1024 count=$size");
38 0 ▶ return $retval if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
39  
40 0 ($error, $retval) = $self->log_and_exec("/sbin/mkfs.ext3 -F -L tapper $filename");
41 0 ▶ return $retval if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
42  
43 0 ▶ $self->makedir($self->cfg->{paths}{guest_mount_dir}) if not -d $self->cfg->{paths}{guest_mount_dir};
Branch: 1 branch
BranchTrueFalseTotal
unless -d $self->cfg->{"paths"}{"guest_mount_dir"} 0 0 0
44 0 ($error, $retval) = $self->log_and_exec("mount -o loop $filename ".$self->cfg->{paths}{guest_mount_dir});
45 0 ▶ return $retval if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
46 0 my $mountdir = $self->cfg->{paths}{guest_mount_dir};
47  
48 0 ▶ mkdir ("$mountdir/etc") or return ("Can't create /etc in raw image $filename: $!");
Branch: 1 branch
BranchTrueFalseTotal
mkdir "$mountdir/etc" or return "Can't create /etc in raw image ${filename}: $!" 0 0 0
49 0 ▶ open(my $FH,">","$mountdir/etc/tapper-release") or return "Can't open /etc/tapper-release in raw image $filename: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $FH, ">", "$mountdir/etc/tapper-release" or return "Can't open /etc/tapper-release in raw image ${filename}: $!" 0 0 0
50 0 print $FH "Tapper";
51 0 close $FH;
52  
53 0 ($error, $retval) = $self->log_and_exec("umount $mountdir");
54 0 ▶ return $retval if $error;
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
55 0 return 0;
56 }
57 ;
58  
59 5 1;
60  
61 __END__
« lib/Tapper/Installer/Precondition/Kernelbuild.pm ↑ Summary lib/Tapper/Installer/Precondition/PRC.pm »