lib/Rex/Service.pm

filter: Statementstmt 43.3% 26 / 60 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 29 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 80.0% 8 / 10 Podpod 0.0% 0 / 2 totaltotal 22.3% 34 / 152 CC 27 SCAR 63.4
CC
27
Cov
21%
get
756.0
register_service_provider
2.0
BEGIN
1.0
CRAP 567.3
« lib/Rex/Resource/firewall/Provider/iptables.pm ↑ Summary lib/Rex/Commands/Pkg.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Service;
6  
7 32 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 32 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 32 our $VERSION = '1.16.1'; # VERSION
11  
12 32 ▶use Rex::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 32 ▶use Rex::Commands::Gather;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 32 ▶use Rex::Hardware;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 32 ▶use Rex::Hardware::Host;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 32 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 32 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 32 my %SERVICE_PROVIDER;
20  
21 0 ▶sub register_service_provider {
Subroutine register_service_provider: not called CC=1 SCAR=6.9
Pod undocumented
22 0 my ( $class, $service_name, $service_class ) = @_;
23 0 $SERVICE_PROVIDER{"\L$service_name"} = $service_class;
24 0 return 1;
25 }
26  
27 0 ▶sub get {
Subroutine get: not called CC=27 SCAR=66.3
Pod undocumented
28  
29 0 my $operatingsystem = Rex::Hardware::Host->get_operating_system();
30  
31 0 i_run "systemctl --no-pager > /dev/null", fail_ok => 1;
32 0 ▶ my $can_run_systemctl = $? == 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$? == 0 ? : 0 0 0
33  
34 0 i_run "initctl version | grep upstart", fail_ok => 1;
35 0 ▶ my $running_upstart = $? == 0 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$? == 0 ? : 0 0 0
36  
37 0 my $class;
38  
39 0 $class = "Rex::Service::" . $operatingsystem;
40 0 ▶ if ( is_redhat($operatingsystem) && $can_run_systemctl ) {
Branch: 11 branches
BranchTrueFalseTotal
if (is_redhat($operatingsystem) and $can_run_systemctl) { } 0 0 0
elsif (is_redhat($operatingsystem)) { } 0 0 0
elsif (is_suse($operatingsystem) and $can_run_systemctl) { } 0 0 0
elsif (is_alt($operatingsystem) and $can_run_systemctl) { } 0 0 0
elsif (is_gentoo($operatingsystem) and $can_run_systemctl) { } 0 0 0
elsif (is_gentoo($operatingsystem)) { } 0 0 0
elsif (is_mageia($operatingsystem) and $can_run_systemctl) { } 0 0 0
elsif (is_debian($operatingsystem) and $can_run_systemctl) { } 0 0 0
elsif (is_debian($operatingsystem) and $running_upstart) { } 0 0 0
elsif (is_debian($operatingsystem)) { } 0 0 0
elsif (is_arch($operatingsystem) and $can_run_systemctl) { } 0 0 0
Condition0%0/3
is_redhat($operatingsystem) and $can_run_systemctl
!ll&&!rl&&r
000
MC/DC0%0/2
is_redhat($operatingsystem) and $can_run_systemctl
is_redhat($operatingsystem) $can_run_systemctl
Truth table0%0/3
A and B
A= is_redhat($operatingsystem)B= $can_run_systemctl
ABresult
0X0
100
111
41 0 $class = "Rex::Service::Redhat::systemd";
42 }
43 elsif ( is_redhat($operatingsystem) ) {
44  
45 # this also counts for fedora, centos, ...
46 0 $class = "Rex::Service::Redhat";
47 }
48 ▶ elsif ( is_suse($operatingsystem) && $can_run_systemctl ) {
Condition0%0/3
is_suse($operatingsystem) and $can_run_systemctl
!ll&&!rl&&r
000
MC/DC0%0/2
is_suse($operatingsystem) and $can_run_systemctl
is_suse($operatingsystem) $can_run_systemctl
Truth table0%0/3
A and B
A= is_suse($operatingsystem)B= $can_run_systemctl
ABresult
0X0
100
111
49 0 $class = "Rex::Service::SuSE::systemd";
50 }
51 ▶ elsif ( is_alt($operatingsystem) && $can_run_systemctl ) {
Condition0%0/3
is_alt($operatingsystem) and $can_run_systemctl
!ll&&!rl&&r
000
MC/DC0%0/2
is_alt($operatingsystem) and $can_run_systemctl
is_alt($operatingsystem) $can_run_systemctl
Truth table0%0/3
A and B
A= is_alt($operatingsystem)B= $can_run_systemctl
ABresult
0X0
100
111
52 0 $class = "Rex::Service::ALT::systemd";
53 }
54 ▶ elsif ( is_gentoo($operatingsystem) && $can_run_systemctl ) {
Condition0%0/3
is_gentoo($operatingsystem) and $can_run_systemctl
!ll&&!rl&&r
000
MC/DC0%0/2
is_gentoo($operatingsystem) and $can_run_systemctl
is_gentoo($operatingsystem) $can_run_systemctl
Truth table0%0/3
A and B
A= is_gentoo($operatingsystem)B= $can_run_systemctl
ABresult
0X0
100
111
55 0 $class = "Rex::Service::Gentoo::systemd";
56 }
57 elsif ( is_gentoo($operatingsystem) ) {
58 0 $class = "Rex::Service::Gentoo";
59 }
60 ▶ elsif ( is_mageia($operatingsystem) && $can_run_systemctl ) {
Condition0%0/3
is_mageia($operatingsystem) and $can_run_systemctl
!ll&&!rl&&r
000
MC/DC0%0/2
is_mageia($operatingsystem) and $can_run_systemctl
is_mageia($operatingsystem) $can_run_systemctl
Truth table0%0/3
A and B
A= is_mageia($operatingsystem)B= $can_run_systemctl
ABresult
0X0
100
111
61 0 $class = "Rex::Service::Mageia::systemd";
62 }
63 ▶ elsif ( is_debian($operatingsystem) && $can_run_systemctl ) {
Condition0%0/3
is_debian($operatingsystem) and $can_run_systemctl
!ll&&!rl&&r
000
MC/DC0%0/2
is_debian($operatingsystem) and $can_run_systemctl
is_debian($operatingsystem) $can_run_systemctl
Truth table0%0/3
A and B
A= is_debian($operatingsystem)B= $can_run_systemctl
ABresult
0X0
100
111
64  
65 # this also counts for Ubuntu and LinuxMint
66 0 $class = "Rex::Service::Debian::systemd";
67 }
68 ▶ elsif ( is_debian($operatingsystem) && $running_upstart ) {
Condition0%0/3
is_debian($operatingsystem) and $running_upstart
!ll&&!rl&&r
000
MC/DC0%0/2
is_debian($operatingsystem) and $running_upstart
is_debian($operatingsystem) $running_upstart
Truth table0%0/3
A and B
A= is_debian($operatingsystem)B= $running_upstart
ABresult
0X0
100
111
69  
70 # this is mainly Ubuntu with upstart
71 0 $class = "Rex::Service::Ubuntu";
72 }
73 elsif ( is_debian($operatingsystem) ) {
74 0 $class = "Rex::Service::Debian";
75 }
76 ▶ elsif ( is_arch($operatingsystem) && $can_run_systemctl ) {
Condition0%0/3
is_arch($operatingsystem) and $can_run_systemctl
!ll&&!rl&&r
000
MC/DC0%0/2
is_arch($operatingsystem) and $can_run_systemctl
is_arch($operatingsystem) $can_run_systemctl
Truth table0%0/3
A and B
A= is_arch($operatingsystem)B= $can_run_systemctl
ABresult
0X0
100
111
77 0 $class = "Rex::Service::Arch::systemd";
78 }
79  
80 0 ▶ my $provider_for = Rex::Config->get("service_provider") || {};
Condition0%0/2
'Rex::Config'->get('service_provider') || {}
l!l
00
MC/DC0%0/1
'Rex::Config'->get('service_provider') || {}
'Rex::Config'->get('service_provider')
Truth table0%0/2
A
A= 'Rex::Config'->get('service_provider')
Aresult
11
00
81 0 my $provider;
82  
83 0 ▶ if ( ref($provider_for) && exists $provider_for->{$operatingsystem} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $provider_for and exists $provider_for->{$operatingsystem}) { } 0 0 0
elsif (exists $SERVICE_PROVIDER{$provider_for}) { } 0 0 0
Condition0%0/3
ref $provider_for and exists $provider_for->{$operatingsystem}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $provider_for and exists $provider_for->{$operatingsystem}
ref $provider_for exists $provider_for->{$operatingsystem}
Truth table0%0/3
A and B
A= ref $provider_forB= exists $provider_for->{$operatingsystem}
ABresult
0X0
100
111
84 0 $provider = $provider_for->{$operatingsystem};
85 0 $class .= "::\L$provider";
86 }
87 elsif ( exists $SERVICE_PROVIDER{$provider_for} ) {
88 0 $class = $SERVICE_PROVIDER{$provider_for};
89 }
90  
91 0 Rex::Logger::debug("service using class: $class");
92 0 eval "use $class";
93  
94 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
95  
96 0 Rex::Logger::info("OS ($operatingsystem) not supported");
97 0 exit 1;
98  
99 }
100  
101 0 return $class->new;
102  
103 }
104  
105 32 1;
« lib/Rex/Resource/firewall/Provider/iptables.pm ↑ Summary lib/Rex/Commands/Pkg.pm »