« lib/Tapper/Installer/Precondition/PRC.pm
↑ Summary
lib/Tapper/Installer/Precondition/Repository.pm »
| 1 | package Tapper::Installer::Precondition::Image; | ||||||||||||||||||||||||||||
| 2 | 6 | our $AUTHORITY = 'cpan:TAPPER'; | |||||||||||||||||||||||||||
| 3 | 6 | $Tapper::Installer::Precondition::Image::VERSION = '5.0.3'; | |||||||||||||||||||||||||||
| 4 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 6 | extends 'Tapper::Installer::Precondition'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | has images => ( isa => 'ArrayRef', | ||||||||||||||||||||||||||||
| 11 | is => 'rw', | ||||||||||||||||||||||||||||
| 12 | 3 | ▶ | default => sub {[]}, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 6 | ); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | sub get_partition_number | ||||||||||||||||||||||||||||
| 19 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_partition_number: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 0 | my ($self, $device_file) = @_; | |||||||||||||||||||||||||||
| 21 | 0 | my ($partition_number) = $device_file =~ m/(\d+)/; | |||||||||||||||||||||||||||
| 22 | 0 | $partition_number--; | |||||||||||||||||||||||||||
| 23 | 0 | return $partition_number; | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | sub get_grub_device | ||||||||||||||||||||||||||||
| 28 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_grub_device: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 29 | 0 | my ($self, $device_file) = @_; | |||||||||||||||||||||||||||
| 30 | 0 | my $basedir = $self->cfg->{paths}{base_dir}; | |||||||||||||||||||||||||||
| 31 | 0 | my $error = $self->log_and_exec("/usr/sbin/grub-install","--recheck", | |||||||||||||||||||||||||||
| 32 | "--root-directory=$basedir","--no-floppy","$device_file"); | ||||||||||||||||||||||||||||
| 33 | 0 | my ($grub_device) = $device_file =~ m/[hs]d([a-z])/; | |||||||||||||||||||||||||||
| 34 | 0 | $grub_device =~ tr/[a-j]/[0-9]/; | |||||||||||||||||||||||||||
| 35 | 0 | ▶ | if ($grub_device eq "") { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 0 | $self->log->warn( "Grub device not found, took '0'"); | |||||||||||||||||||||||||||
| 37 | 0 | $grub_device = 0; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 0 | return (0, $grub_device); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | sub configure_fstab | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
configure_fstab: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 48 | # Creates fstab-entry for the final partition | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | $self->log->debug("Configuring fstab to contain installed images"); | |||||||||||||||||||||||||||
| 51 | 0 | ▶ | open (my $FSTAB, ">", $self->cfg->{paths}{base_dir}."/etc/fstab") or return "Can't open fstab for appending: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | # write defaults for fstab | ||||||||||||||||||||||||||||
| 54 | 0 | print $FSTAB "proc\t/proc\tproc\tdefaults\t0 0\n","sysfs\t/sys\tsysfs\tauto\t0 0\n"; | |||||||||||||||||||||||||||
| 55 | 0 | print $FSTAB "tapper:/data/tapper /data/tapper nfs vers=3 0 0\n"; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # put swap in fstab | ||||||||||||||||||||||||||||
| 58 | 0 | foreach my $line (grep {$_ =~ m/swap/i} qx(fdisk -l)) { | |||||||||||||||||||||||||||
| 59 | 0 | my ($file_name) = split / +/, $line; | |||||||||||||||||||||||||||
| 60 | 0 | print $FSTAB "$file_name\tnone\tswap\tsw\t0\t0\n"; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | foreach my $image (@{$self->images}) { | |||||||||||||||||||||||||||
| 65 | 0 | print $FSTAB $image->{partition},"\t",$image->{mount},"\text3\tdefaults\t1 1\n"; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | close $FSTAB or return "Can't write fstab: $!"; # well, cases when close fails are rare but still exist | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | return 0; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | sub generate_user_grub_conf | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
generate_user_grub_conf: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 0 | my ($self, $device_file) = @_; | |||||||||||||||||||||||||||
| 77 | 0 | my $mount_point=$self->cfg->{paths}{base_dir}; | |||||||||||||||||||||||||||
| 78 | 0 | my $conf_string=$self->cfg->{grub}; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | my $partition_number = $self->get_partition_number($device_file); | |||||||||||||||||||||||||||
| 81 | 0 | my ($error, $grub_device) = $self->get_grub_device( $device_file); | |||||||||||||||||||||||||||
| 82 | 0 | ▶ | return $grub_device if $error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | my $initrd_options = ''; | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | $initrd_options = "initrd /boot/initrd" if -e $self->cfg->{paths}{base_dir}."/boot/initrd"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | $conf_string =~ s/\$root/$device_file/g; | |||||||||||||||||||||||||||
| 88 | 0 | $conf_string =~ s/\$grubroot/(hd$grub_device,$partition_number)/g; | |||||||||||||||||||||||||||
| 89 | 0 | $conf_string =~ s/\$initrd_options/$initrd_options/g; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | return $self->write_menu_lst($conf_string, "truncate"); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | sub generate_grub_menu_lst | ||||||||||||||||||||||||||||
| 97 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
generate_grub_menu_lst: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 98 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 99 | 0 | my $retval; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | my $partition = $self->images->[0]->{partition}; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | return $retval if $retval = $self->generate_user_grub_conf($partition); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | return 0; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | sub prepare_boot | ||||||||||||||||||||||||||||
| 110 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
prepare_boot: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 111 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 112 | 0 | my $retval = 0; | |||||||||||||||||||||||||||
| 113 | 0 | ▶ | return $retval if $retval = $self->configure_fstab(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | return $retval if $retval = $self->generate_grub_menu_lst( ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | return $retval if $retval = $self->generate_pxe_grub(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | # return $retval if $retval = $self->copy_menu_lst(); | ||||||||||||||||||||||||||||
| 117 | 0 | return 0; | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | sub get_device | ||||||||||||||||||||||||||||
| 123 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_device: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||
| 124 | 0 | my ($self, $devices, $basedir) = @_; | |||||||||||||||||||||||||||
| 125 | 0 | ▶ | $basedir ||= '/'; # basedir is only supposed for unit testing | ||||||||||||||||||||||||||
|
Condition0%0/2
$basedir ||= "/"
MC/DC0%0/1
$basedir ||= "/"
$basedir
Truth table0%0/2
A
A= $basedir
| |||||||||||||||||||||||||||||
| 126 | 0 | my @device_alternatives; | |||||||||||||||||||||||||||
| 127 | 0 | ▶ | if (ref($devices) eq 'ARRAY') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | @device_alternatives = @$devices; | |||||||||||||||||||||||||||
| 129 | } else { | ||||||||||||||||||||||||||||
| 130 | 0 | @device_alternatives = ($devices); | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 0 | my $dev_symlink; | |||||||||||||||||||||||||||
| 134 | ALTERNATIVE: | ||||||||||||||||||||||||||||
| 135 | 0 | foreach my $device_id (@device_alternatives) { | |||||||||||||||||||||||||||
| 136 | 0 | ▶ | if (-e "$basedir/dev/disk/by-label/".$device_id) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 137 | 0 | $dev_symlink=readlink("$basedir/dev/disk/by-label/$device_id"); | |||||||||||||||||||||||||||
| 138 | 0 | last ALTERNATIVE; | |||||||||||||||||||||||||||
| 139 | } elsif (-e "$basedir/dev/disk/by-uuid/".$device_id) { | ||||||||||||||||||||||||||||
| 140 | 0 | $dev_symlink = readlink("$basedir/dev/disk/by-uuid/$device_id"); | |||||||||||||||||||||||||||
| 141 | 0 | last ALTERNATIVE; | |||||||||||||||||||||||||||
| 142 | ▶ | } elsif (-e "$basedir/dev/".$device_id or -e "$basedir/$device_id") { | |||||||||||||||||||||||||||
|
Condition0%0/3
-e "$basedir/dev/" . $device_id or -e "$basedir/$device_id"
MC/DC0%0/2
-e "$basedir/dev/" . $device_id or -e "$basedir/$device_id"
-e "$basedir/dev/" . $device_id
-e "$basedir/$device_id"
Truth table0%0/3
A or B
A= -e "$basedir/dev/" . $device_idB= -e "$basedir/$device_id"
| |||||||||||||||||||||||||||||
| 143 | 0 | $dev_symlink = $device_id; | |||||||||||||||||||||||||||
| 144 | 0 | last ALTERNATIVE; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | 0 | my $error_string = "No device named "; | |||||||||||||||||||||||||||
| 149 | 0 | $error_string .= join ", ", @device_alternatives; | |||||||||||||||||||||||||||
| 150 | 0 | $error_string .= " could be found"; | |||||||||||||||||||||||||||
| 151 | 0 | ▶ | return(1, $error_string) if not $dev_symlink; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 0 | my @linkpath=split("/", $dev_symlink); # split link to avoid /dev/disk/by-xyz/../../hda1, is way faster than regexp | |||||||||||||||||||||||||||
| 154 | 0 | my $partition = $linkpath[-1]; | |||||||||||||||||||||||||||
| 155 | 0 | return (0,"/dev/$partition"); | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | sub get_partition_label | ||||||||||||||||||||||||||||
| 162 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_partition_label: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 163 | 0 | my ($self, $device_file) = @_; | |||||||||||||||||||||||||||
| 164 | 0 | return $self->log_and_exec("e2label $device_file"); | |||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | sub generate_pxe_grub | ||||||||||||||||||||||||||||
| 171 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
generate_pxe_grub: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 172 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 0 | my $partition = $self->cfg->{preconditions}->[0]->{partition}; | |||||||||||||||||||||||||||
| 175 | 0 | my $hostname = $self->gethostname(); | |||||||||||||||||||||||||||
| 176 | 0 | my $partition_number = $self->get_partition_number( $partition ); | |||||||||||||||||||||||||||
| 177 | 0 | my ($error, $grub_device) = $self->get_grub_device( $partition ); | |||||||||||||||||||||||||||
| 178 | 0 | ▶ | return $grub_device if $error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | my $filename = $self->cfg->{paths}{grubpath}."/$hostname.lst"; | |||||||||||||||||||||||||||
| 183 | 0 | ▶ | open my $fh, ">", $filename or return "Can not open PXE grub file $filename: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 0 | print $fh | |||||||||||||||||||||||||||
| 185 | "serial --unit=0 --speed=115200\n", | ||||||||||||||||||||||||||||
| 186 | "terminal serial\n", | ||||||||||||||||||||||||||||
| 187 | "timeout 2\n\n", | ||||||||||||||||||||||||||||
| 188 | "title Boot from first hard disc\n", | ||||||||||||||||||||||||||||
| 189 | "chainloader (hd$grub_device,$partition_number)+1"; | ||||||||||||||||||||||||||||
| 190 | 0 | ▶ | close $fh or return "Closing PXE grub file $filename of NFS failed: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | 0 | return 0; | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | sub copy_menu_lst | ||||||||||||||||||||||||||||
| 198 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
copy_menu_lst: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 199 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | my $hostname = $self->gethostname(); | |||||||||||||||||||||||||||
| 202 | 0 | my $menu_lst_file = $self->cfg->{paths}{base_dir}."/boot/grub/menu.lst"; | |||||||||||||||||||||||||||
| 203 | 0 | my $tapper_conf = $self->cfg->{paths}{grubpath}; | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 0 | return $self->log_and_exec("cp $menu_lst_file $tapper_conf/$hostname.lst"); | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | sub write_menu_lst | ||||||||||||||||||||||||||||
| 211 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
write_menu_lst: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 212 | 0 | my ($self, $content, $truncate) = @_; | |||||||||||||||||||||||||||
| 213 | 0 | $self->makedir($self->cfg->{paths}{base_dir}."/boot/grub/"); | |||||||||||||||||||||||||||
| 214 | 0 | my $menu_lst_file = $self->cfg->{paths}{base_dir}."/boot/grub/menu.lst"; | |||||||||||||||||||||||||||
| 215 | 0 | my $mode = '>>'; | |||||||||||||||||||||||||||
| 216 | 0 | ▶ | if ($truncate) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | 0 | $mode = '>'; | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 0 | ▶ | open (my $FILE, $mode,$menu_lst_file) or return "Can't open $menu_lst_file for writing: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 221 | 0 | print $FILE $content; | |||||||||||||||||||||||||||
| 222 | 0 | ▶ | close $FILE or return "Can't write $menu_lst_file: $!"; # well, cases when close fails are rare but still exist; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | 0 | return 0; | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | ; | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | sub install | ||||||||||||||||||||||||||||
| 229 | 5 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
install: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 230 | 5 | my ($self, $image) = @_; | |||||||||||||||||||||||||||
| 231 | 5 | my $retval; | |||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | # set partition name to the normalized value /dev/* | ||||||||||||||||||||||||||||
| 234 | 5 | my $partition=$image->{partition}; | |||||||||||||||||||||||||||
| 235 | 5 | my $error; | |||||||||||||||||||||||||||
| 236 | 5 | ($error, $partition) = $self->get_device($partition); | |||||||||||||||||||||||||||
| 237 | 5 | ▶ | if ($error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 0 | return $partition; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 5 | $image->{partition}=$partition; | |||||||||||||||||||||||||||
| 242 | 5 | $self->log->debug("partition = $partition"); | |||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | # mount points in image precondition are relative to test system root | ||||||||||||||||||||||||||||
| 245 | # installation needs it relative to current root | ||||||||||||||||||||||||||||
| 246 | 5 | my $mount_point = $self->cfg->{paths}{base_dir}.$image->{mount}; | |||||||||||||||||||||||||||
| 247 | 5 | $error = $self->makedir($mount_point); | |||||||||||||||||||||||||||
| 248 | 5 | ▶ | return $error if $error; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | 4 | ▶ | if ($image->{image}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 251 | 1 | $retval = $self->copy_image( $partition, $image->{image}, $mount_point); | |||||||||||||||||||||||||||
| 252 | 1 | ▶ | return $retval if $retval; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 253 | } else { | ||||||||||||||||||||||||||||
| 254 | 3 | $self->log->debug("No image to install on $partition, mounting old image to $mount_point"); | |||||||||||||||||||||||||||
| 255 | 3 | $retval = $self->log_and_exec("mount","$partition","$mount_point"); | |||||||||||||||||||||||||||
| 256 | 3 | ▶ | return $retval if $retval; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | 3 | $self->images([ @{$self->images}, $image ]); | |||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 3 | $self->log->debug("Image copied successfully"); | |||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 3 | return 0; | |||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | sub install_image | ||||||||||||||||||||||||||||
| 269 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
install_image: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 270 | 0 | my ($self, $image_file, $device_file, $mount_point) = @_; | |||||||||||||||||||||||||||
| 271 | 0 | my ($error, $partition_size)=$self->log_and_exec("/sbin/blockdev --getsize64 $device_file"); | |||||||||||||||||||||||||||
| 272 | 0 | ▶ | if ($error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 273 | 0 | $self->log->warn("Can't get size of partition $device_file: $partition_size. Won't check if images fits."); | |||||||||||||||||||||||||||
| 274 | 0 | $partition_size = 0; | |||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 0 | my ($partition_label, $image_type); | |||||||||||||||||||||||||||
| 278 | 0 | ($error, $image_type)=$self->get_file_type($image_file); | |||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 0 | ($error, $partition_label) = $self->get_partition_label($device_file); | |||||||||||||||||||||||||||
| 281 | 0 | ▶ | if ($error) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 282 | 0 | $self->log->info("Can't get partition label of $device_file: $partition_label"); | |||||||||||||||||||||||||||
| 283 | 0 | $partition_label=''; | |||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||
| 285 | 0 | ▶ | $partition_label ||= "testing"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$partition_label ||= "testing"
MC/DC0%0/1
$partition_label ||= "testing"
$partition_label
Truth table0%0/2
A
A= $partition_label
| |||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | 0 | ▶ | if ($image_type eq "iso") { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 288 | # ISO images are preformatted and thus bring their own | ||||||||||||||||||||||||||||
| 289 | # partition label | ||||||||||||||||||||||||||||
| 290 | 0 | return $self->install_image_iso($image_file, $partition_size, $device_file, $mount_point); | |||||||||||||||||||||||||||
| 291 | } elsif ($image_type eq "tar") { | ||||||||||||||||||||||||||||
| 292 | 0 | return $self->install_image_tar($image_file, $partition_size, $device_file, $mount_point, $partition_label); | |||||||||||||||||||||||||||
| 293 | } elsif ($image_type eq "gzip"){ | ||||||||||||||||||||||||||||
| 294 | 0 | return $self->install_image_gz($image_file, $partition_size, $device_file, $mount_point, $partition_label); | |||||||||||||||||||||||||||
| 295 | } elsif ($image_type eq "bz2") { | ||||||||||||||||||||||||||||
| 296 | 0 | return $self->install_image_bz2($image_file, $partition_size, $device_file, $mount_point, $partition_label); | |||||||||||||||||||||||||||
| 297 | } else { | ||||||||||||||||||||||||||||
| 298 | 0 | return("Imagetype could not be detected"); | |||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||
| 300 | 0 | return 0; | |||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | sub install_image_iso | ||||||||||||||||||||||||||||
| 306 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
install_image_iso: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 307 | 0 | my ($self, $image_file, $partition_size, $device_file, $mount_point) = @_; | |||||||||||||||||||||||||||
| 308 | # -s return the size in byte | ||||||||||||||||||||||||||||
| 309 | 0 | ▶ | if ( $partition_size and (-s $image_file) > $partition_size) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$partition_size and -s $image_file > $partition_size
MC/DC0%0/2
$partition_size and -s $image_file > $partition_size
$partition_size
-s $image_file > $partition_size
Truth table0%0/3
A and B
A= $partition_sizeB= -s $image_file > $partition_size
| |||||||||||||||||||||||||||||
| 310 | 0 | return("Image $image_file is to big for device $device_file"); | |||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||
| 312 | 0 | $self->log->info( "Using image type iso" ); | |||||||||||||||||||||||||||
| 313 | 0 | my $retval; | |||||||||||||||||||||||||||
| 314 | 0 | ▶ | return $retval if $retval=$self->log_and_exec("dd if=$image_file of=$device_file"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 315 | 0 | ▶ | return $retval if $retval=$self->log_and_exec("mount $device_file $mount_point"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 0 | return(0); | |||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | sub install_image_tar | ||||||||||||||||||||||||||||
| 323 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
install_image_tar: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 324 | 0 | my ($self, $image_file, $partition_size, $device_file, $mount_point, $partition_label) = @_; | |||||||||||||||||||||||||||
| 325 | # -s return the size in byte | ||||||||||||||||||||||||||||
| 326 | 0 | ▶ | if ( $partition_size and (-s $image_file) > $partition_size) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$partition_size and -s $image_file > $partition_size
MC/DC0%0/2
$partition_size and -s $image_file > $partition_size
$partition_size
-s $image_file > $partition_size
Truth table0%0/3
A and B
A= $partition_sizeB= -s $image_file > $partition_size
| |||||||||||||||||||||||||||||
| 327 | 0 | return("Image $image_file is to big for device $device_file"); | |||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||
| 329 | 0 | $self->log->info( "Using image type tar" ); | |||||||||||||||||||||||||||
| 330 | 0 | my $retval; | |||||||||||||||||||||||||||
| 331 | 0 | ▶ | return $retval if $retval=$self->log_and_exec("mkfs.ext3 -q -L $partition_label $device_file"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 332 | 0 | ▶ | return $retval if $retval=$self->log_and_exec("mount $device_file $mount_point"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | 0 | ▶ | return $retval if $retval=$self->log_and_exec("tar xf $image_file -C $mount_point"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 335 | 0 | return 0; | |||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | sub install_image_gz | ||||||||||||||||||||||||||||
| 340 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
install_image_gz: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 341 | 0 | my ($self, $image_file, $partition_size, $device_file, $mount_point, $partition_label) = @_; | |||||||||||||||||||||||||||
| 342 | 0 | my $gz_factor=3.82; | |||||||||||||||||||||||||||
| 343 | 0 | ▶ | if ( $partition_size and (-s $image_file)*$gz_factor > $partition_size) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$partition_size and (-s $image_file) * $gz_factor > $partition_size
MC/DC0%0/2
$partition_size and (-s $image_file) * $gz_factor > $partition_size
$partition_size
(-s $image_file) * $gz_factor > $partition_size
Truth table0%0/3
A and B
A= $partition_sizeB= (-s $image_file) * $gz_factor > $partition_size
| |||||||||||||||||||||||||||||
| 344 | 0 | return("Image $image_file is to big for device $device_file"); | |||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||
| 346 | 0 | $self->log->info( "Using image type gzip" ); | |||||||||||||||||||||||||||
| 347 | 0 | my $retval; | |||||||||||||||||||||||||||
| 348 | 0 | ▶ | return $retval if $retval=$self->log_and_exec("mkfs.ext3 -q -L $partition_label $device_file"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 349 | 0 | ▶ | return $retval if $retval=$self->log_and_exec("mount $device_file $mount_point"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | 0 | ▶ | return $retval if $retval=$self->log_and_exec("tar xfz $image_file -C $mount_point"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 352 | 0 | return 0; | |||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | sub install_image_bz2 | ||||||||||||||||||||||||||||
| 357 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
install_image_bz2: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 358 | 0 | my ($self, $image_file, $partition_size, $device_file, $mount_point, $partition_label) = @_; | |||||||||||||||||||||||||||
| 359 | 0 | my $bz2_factor=4.30; | |||||||||||||||||||||||||||
| 360 | 0 | ▶ | if ( $partition_size and (-s $image_file)*$bz2_factor > $partition_size) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$partition_size and (-s $image_file) * $bz2_factor > $partition_size
MC/DC0%0/2
$partition_size and (-s $image_file) * $bz2_factor > $partition_size
$partition_size
(-s $image_file) * $bz2_factor > $partition_size
Truth table0%0/3
A and B
A= $partition_sizeB= (-s $image_file) * $bz2_factor > $partition_size
| |||||||||||||||||||||||||||||
| 361 | 0 | return("Image $image_file is to big for device $device_file"); | |||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||
| 363 | 0 | $self->log->info( "Using image type bzip2" ); | |||||||||||||||||||||||||||
| 364 | 0 | my $retval; | |||||||||||||||||||||||||||
| 365 | 0 | ▶ | return $retval if $retval=$self->log_and_exec("mkfs.ext3 -q -L $partition_label $device_file"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 366 | 0 | ▶ | return $retval if $retval=$self->log_and_exec("mount $device_file $mount_point"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | 0 | ▶ | return $retval if $retval=$self->log_and_exec("tar xfj $image_file -C $mount_point"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 369 | 0 | return 0; | |||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | sub copy_image | ||||||||||||||||||||||||||||
| 375 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
copy_image: called CC=3 SCAR=12.0
Pod
documented
| |||||||||||||||||||||||||||||
| 376 | 1 | my ($self, $device_file, $image_file, $mount_point) = @_; | |||||||||||||||||||||||||||
| 377 | 1 | ▶ | $image_file = $self->cfg->{paths}{image_dir}.$image_file unless $image_file =~m(^/); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | # Image exists? | ||||||||||||||||||||||||||||
| 380 | 1 | ▶ | if (not -e $image_file) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 381 | 1 | return("Image $image_file could not be found"); | |||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||
| 383 | 0 | return $self->install_image($image_file, $device_file, $mount_point); | |||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | sub unmount | ||||||||||||||||||||||||||||
| 388 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
unmount: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 389 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 390 | 1 | my $basedir = $self->cfg->{paths}{base_dir}; | |||||||||||||||||||||||||||
| 391 | 1 | foreach my $image (reverse @{$self->images}) { | |||||||||||||||||||||||||||
| 392 | 3 | my $mount = $basedir.$image->{mount}; | |||||||||||||||||||||||||||
| 393 | 3 | ▶ | next unless -d $mount; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 394 | 3 | $self->log_and_exec('umount', $mount); | |||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||
| 396 | 1 | return 0; | |||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | 6 | 1; | |||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||
| 401 | __END__ | ||||||||||||||||||||||||||||