Cmd/Cobbler.pm

filter: Statementstmt 38.5% 27 / 70 Branchbran 5.0% 1 / 20 Conditioncond 12.5% 1 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 61.5% 8 / 13 Podpod 100% 6 / 6 totaltotal 35.2% 43 / 122 CC 16 SCAR 28.9
CC
16
Cov
30%
cobbler_execute
42.0
host_new
21.2
host_list
20.0
CRAP 18.1
« Cmd/Host.pm ↑ Summary Cmd/Testrun.pm »
1 package Tapper::Cmd::Cobbler;
2 3 our $AUTHORITY = 'cpan:TAPPER';
3 3 $Tapper::Cmd::Cobbler::VERSION = '5.0.14';
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Tapper::Model 'model';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Tapper::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Net::OpenSSH;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 ▶use parent 'Tapper::Cmd';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14  
15  
16  
17 sub get_mac_address
18 0 ▶{
Subroutine get_mac_address: not called CC=1 SCAR=6.9
Pod documented
19 0 my ($self, $host) = @_;
20 0 my ($retval) = map{$_->value} grep{ $_->entry eq 'mac_address'} $host->features->all;
21 0 return $retval;
22 }
23  
24  
25 sub cobbler_execute
26 0 ▶{
Subroutine cobbler_execute: not called CC=6 SCAR=37.4
Pod documented
27 0 my ($self, @command) = @_;
28  
29 0 my $cfg = Tapper::Config->subconfig;
30 0 my $cobbler_host = $cfg->{cobbler}->{host};
31  
32 0 my $output;
33 0 ▶ if ($cobbler_host) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cobbler_host) { } 0 0 0
34 0 my $user = $cfg->{cobbler}->{user};
35 0 my $ssh = Net::OpenSSH->new("$user\@$cobbler_host");
36 0 ▶ $ssh->error and die "ssh $user\@$cobbler_host failed: ".$ssh->error;
Branch: 1 branch
BranchTrueFalseTotal
$ssh->error and die "ssh $user\@$cobbler_host failed: " . $ssh->error 0 0 0
37 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
38 0 my @output = $ssh->capture({ quote_args => 1 }, @command);
39 0 ▶ $ssh->error and die "Calling ".(join (" ",@command))." on $cobbler_host failed: ".$ssh->error;
Branch: 1 branch
BranchTrueFalseTotal
$ssh->error and die 'Calling ' . join(" ", @command) . " on $cobbler_host failed: " . $ssh->error 0 0 0
40 0 return @output;
41 } else {
42 0 my $output = $ssh->capture({ quote_args => 1 }, @command);
43 0 ▶ $ssh->error and die "Calling ".(join (" ",@command))." on $cobbler_host failed: ".$ssh->error;
Branch: 1 branch
BranchTrueFalseTotal
$ssh->error and die 'Calling ' . join(" ", @command) . " on $cobbler_host failed: " . $ssh->error 0 0 0
44 0 return $output;
45 }
46 } else {
47 0 return qx( @command );
48 }
49 }
50  
51  
52 sub host_new
53 1 ▶{
Subroutine host_new: called CC=6 SCAR=30.5
Pod documented
54 1 my ($self, $name, $options) = @_;
55 1 ▶ my $default = $options->{default} || 'default';
Condition50%1/2
$options->{'default'} || 'default'
l!l
01
MC/DC0%0/1
$options->{'default'} || 'default'
$options->{'default'}
Truth table50%1/2
A
A= $options->{'default'}
Aresult
11
00
56  
57 1 ▶ return (join "",("Need a string as first argument in ",
Branch: 1 branch
BranchTrueFalseTotal
if ref $name 1 0 1
58 __FILE__,
59 ", line ",
60 __LINE__,
61 ". You provided a ",
62 ref $name))
63 if ref $name;
64  
65 0 my $host = model('TestrunDB')->resultset('Host')->find({name => $name});
66 0 ▶ return "Host '$name' does not exist in the database" if not $host;
Branch: 1 branch
BranchTrueFalseTotal
unless $host 0 0 0
67  
68 0 ▶ my $mac = $options->{mac} || $self->get_mac_address($host);
Condition0%0/3
$options->{'mac'} || $self->get_mac_address($host)
l!l&&r!l&&!r
000
MC/DC0%0/2
$options->{'mac'} || $self->get_mac_address($host)
$options->{'mac'} $self->get_mac_address($host)
Truth table0%0/3
A || B
A= $options->{'mac'}B= $self->get_mac_address($host)
ABresult
1X1
011
000
69 0 ▶ return "Missing mac address for host '$name'" if not $mac;
Branch: 1 branch
BranchTrueFalseTotal
unless $mac 0 0 0
70  
71 0 my @command = split(" ","cobbler system copy --name $default --newname $name --mac-address $mac");
72  
73 0 return $self->cobbler_execute(@command);
74 }
75  
76  
77  
78 sub host_del
79 0 ▶{
Subroutine host_del: not called CC=1 SCAR=6.9
Pod documented
80 0 my ($self, $name) = @_;
81  
82 0 my @command = split(" ", "cobbler system remove --name $name");
83 0 return $self->cobbler_execute(@command);
84 }
85  
86  
87 sub host_list
88 0 ▶{
Subroutine host_list: not called CC=4 SCAR=30.0
Pod documented
89 0 my ($self, $search) = @_;
90  
91 0 my @command = qw/cobbler system find/;
92 0 ▶ if ($search and ref($search) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($search and ref $search eq "HASH") 0 0 0
Condition0%0/3
$search and ref $search eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$search and ref $search eq "HASH"
$search ref $search eq "HASH"
Truth table0%0/3
A and B
A= $searchB= ref $search eq "HASH"
ABresult
0X0
100
111
93 KEY:
94 0 foreach my $key (keys %$search) {
95 0 push @command, "--$key", $search->{$key};
96 }
97 }
98 0 return $self->cobbler_execute(@command);
99 }
100  
101  
102  
103 sub host_update
104 0 ▶{
Subroutine host_update: not called CC=3 SCAR=24.8
Pod documented
105 0 my ($self, $name, $options) = @_;
106  
107 0 ▶ return (join "",("Need a string as first argument in ",
Branch: 1 branch
BranchTrueFalseTotal
if ref $name 0 0 0
108 __FILE__,
109 ", line ",
110 __LINE__,
111 ". You provided a ",
112 ref $name))
113 if ref $name;
114  
115 0 my @command = qw/cobbler system edit --name/;
116 0 push @command, $name;
117 0 foreach my $key (keys %$options) {
118 0 push @command, "--$key", $options->{$key};
119 }
120 0 return $self->cobbler_execute(@command);
121 }
122  
123  
124  
125  
126  
127 3 1; # End of Tapper::Cmd::Cobbler
128  
129 __END__
« Cmd/Host.pm ↑ Summary Cmd/Testrun.pm »