lib/Rex/Virtualization/LibVirt/destroy.pm

filter: Statementstmt 52.0% 13 / 25 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 4 / 5 Podpod 0.0% 0 / 1 totaltotal 38.6% 17 / 44 CC 6 SCAR 32.4
CC
6
Cov
36%
execute
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 25.6
« lib/Rex/Virtualization/Docker/list.pm ↑ Summary lib/Rex/Virtualization/LibVirt/option.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Virtualization::LibVirt::destroy;
6  
7 1 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '1.16.1'; # VERSION
11  
12 1 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 0 ▶sub execute {
Subroutine execute: not called CC=6 SCAR=37.4
Pod undocumented
16 0 my ( $class, $arg1, %opt ) = @_;
17 0 my $virt_settings = Rex::Config->get("virtualization");
18 chomp( my $uri =
19 0 ▶ ref($virt_settings) ? $virt_settings->{connect} : i_run "virsh uri" );
Branch: 1 branch
BranchTrueFalseTotal
ref $virt_settings ? : 0 0 0
20  
21 0 ▶ unless ($arg1) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($arg1) 0 0 0
22 0 die("You have to define the vm name!");
23 }
24  
25 0 my $dom = $arg1;
26 0 Rex::Logger::debug("destroying domain: $dom");
27  
28 0 ▶ unless ($dom) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dom) 0 0 0
29 0 die("VM $dom not found.");
30 }
31  
32 # virsh must distinguish between a not-running VM and failed to destroy via exit code!
33 0 my $out = i_run "virsh -c $uri destroy '$dom' 2>&1", fail_ok => 1;
34 0 ▶ if ( $? != 0 && $out !~ /domain is not running/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0 and not $out =~ /domain is not running/u) 0 0 0
Condition0%0/3
$? != 0 and not $out =~ /domain is not running/u
!ll&&!rl&&r
000
MC/DC0%0/2
$? != 0 and not $out =~ /domain is not running/u
$? != 0 not $out =~ /domain is not running/u
Truth table0%0/3
A and not(B)
A= $? != 0B= not $out =~ /domain is not running/u
ABresult
0X0
100
111
35 0 die("Error destroying vm $dom");
36 }
37  
38 }
39  
40 1 1;
« lib/Rex/Virtualization/Docker/list.pm ↑ Summary lib/Rex/Virtualization/LibVirt/option.pm »