lib/Rex/GPU/NVIDIA/Setup/Rpm.pm

filter: Statementstmt 100% 54 / 54 Branchbran 92.8% 13 / 14 Conditioncond 61.5% 8 / 13 MC/DCmcdc 37.5% 3 / 8 Subroutinesub 100% 14 / 14 Podpod 100% 9 / 9 totaltotal 90.1% 101 / 112 CC 15 SCAR 10.4
CC
15
Cov
93%
verify_versioned_package
4.1
installed_fabric_managers
4.1
_rpm_version_in_branch
4.0
CRAP 2.8
« lib/Rex/GPU/NVIDIA/Setup/RHEL.pm ↑ Summary lib/Rex/GPU/NVIDIA/Setup/SUSE.pm »
1 # ABSTRACT: rpm packaging layer of the NVIDIA driver setups (experimental)
2  
3 package Rex::GPU::NVIDIA::Setup::Rpm;
4 36 our $VERSION = '0.005';
5 36 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 36 ▶use Rex::Logger ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 36 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 36 extends 'Rex::GPU::NVIDIA::Setup';
10  
11  
12 503 ▶sub package_manager { 'dnf' }
Subroutine package_manager: called CC=1 SCAR=0.0
Pod documented
13  
14  
15 165 ▶sub package_manager_command {
Subroutine package_manager_command: called CC=1 SCAR=0.0
Pod documented
16 165 my ( $self ) = @_;
17 165 return $self->package_manager;
18 }
19  
20  
21 211 ▶sub install_packages {
Subroutine install_packages: called CC=1 SCAR=0.0
Pod documented
22 211 my ( $self, $plan ) = @_;
23 211 Rex::Logger::info(' Installing: '.join(', ', @{ $plan->{packages} }));
24 211 my $pkg_str = join(' ', @{ $plan->{packages} });
25 211 $self->run_cmd($self->package_manager_command.' install -y '.$pkg_str, auto_die => 0);
26 }
27  
28  
29 297 ▶sub verify_query {
Subroutine verify_query: called CC=1 SCAR=0.0
Pod documented
30 297 my ( $self, $what ) = @_;
31 297 return 'rpm -q '.$what;
32 }
33  
34 308 ▶sub verify_packages {
Subroutine verify_packages: called CC=3 SCAR=11.0
Pod documented
35 308 my ( $self, $plan ) = @_;
36 308 my $pm = $self->package_manager;
37 308 for my $driver_pkg (@{ $plan->{verify} }) {
38 412 my $check = $self->run_cmd($self->verify_query($driver_pkg).' 2>&1', auto_die => 0);
39 412 ▶ die "$driver_pkg not installed after $pm install — check $pm output\n"
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 7 405 412
40 if $? != 0;
41 }
42 }
43  
44  
45 10 ▶sub installed_driver_version {
Subroutine installed_driver_version: called CC=2 SCAR=6.9
Pod documented
46 10 my ( $self, $source ) = @_;
47 10 my $pkg = $self->_with_branch($source->{fabric_manager_match}, $source);
48 10 ▶ die "The driver source names no package to read the driver version from "
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pkg 1 9 10
49 ."(fabric_manager_match); the driver is installed, Fabric Manager is not\n"
50 unless defined $pkg;
51 9 return $self->_rpm_version($pkg);
52 }
53  
54 11 ▶sub install_versioned_package {
Subroutine install_versioned_package: called CC=1 SCAR=0.0
Pod documented
55 11 my ( $self, $pkg, $version ) = @_;
56 11 $self->run_cmd($self->package_manager_command.' install -y '.$pkg.'-'.$version, auto_die => 0);
57 }
58  
59 11 ▶sub verify_versioned_package {
Subroutine verify_versioned_package: called CC=4 SCAR=14.1
Pod documented
60 11 my ( $self, $pkg, $version ) = @_;
61 11 $self->verify_packages({ verify => [ $pkg ] });
62 10 my $installed = $self->_rpm_version($pkg);
63 10 ▶ die "$pkg is ".( $installed // 'unknown' ).' after '.$self->package_manager
Branch: 1 branch
BranchTrueFalseTotal
unless defined $installed and $installed eq $version 1 9 10
Condition60%3/5
defined $installed and $installed eq $version
!ll&&!rl&&r
019
$installed // "unknown"
l!l
10
MC/DC50%1/2
defined $installed and $installed eq $version
defined $installed $installed eq $version
MC/DC0%0/1
$installed // "unknown"
$installed
Truth table66%2/3
A and B
A= defined $installedB= $installed eq $version
ABresult
0X0
100
111
Truth table50%1/2
A
A= $installed
Aresult
11
00
64 ." install, not the driver's $version\n"
65 unless defined $installed && $installed eq $version;
66 }
67  
68  
69 9 ▶sub installed_fabric_managers {
Subroutine installed_fabric_managers: called CC=4 SCAR=14.1
Pod documented
70 9 my ( $self ) = @_;
71 9 my $out = $self->run_cmd(q{rpm -qa --qf '%{NAME} %{VERSION}\n' 'nvidia-fabric*manager*' 2>/dev/null},
72 auto_die => 0);
73 9 my @present;
74 9 ▶ for my $line (split /\n/, $out // '') {
Condition50%1/2
$out // ""
l!l
90
MC/DC0%0/1
$out // ""
$out
Truth table50%1/2
A
A= $out
Aresult
11
00
75 1 my ( $name, $version ) = split ' ', $line;
76 1 ▶ push @present, [ $name, $version ] if $self->_is_fabric_manager_name($name);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_fabric_manager_name($name) 1 0 1
77 }
78 9 return @present;
79 }
80  
81 19 ▶sub _rpm_version {
Subroutine _rpm_version: called CC=3 SCAR=11.0
82 19 my ( $self, $pkg ) = @_;
83 19 my $v = $self->run_cmd("rpm -q --qf '%{VERSION}' $pkg 2>&1", auto_die => 0);
84 19 ▶ return if $? != 0 || !defined $v;
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 or not defined $v 1 18 19
Condition66%2/3
$? != 0 or not defined $v
l!l&&r!l&&!r
1018
MC/DC50%1/2
$? != 0 or not defined $v
$? != 0 not defined $v
Truth table66%2/3
A or not(B)
A= $? != 0B= not defined $v
ABresult
1X1
011
000
85 18 chomp $v;
86 18 return $v;
87 }
88  
89 # Pure (karr #26): is this `rpm -q --qf '%{VERSION}'` output a version of
90 # driver branch $branch ("580.178.04" is branch 580)? Anything else -- another
91 # branch, "package ... is not installed", empty -- is false.
92 49 ▶sub _rpm_version_in_branch {
Subroutine _rpm_version_in_branch: called CC=4 SCAR=13.9
93 49 my ( $self, $version, $branch ) = @_;
94 49 ▶ return 0 unless defined $version && defined $branch;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version and defined $branch 1 48 49
Condition66%2/3
defined $version and defined $branch
!ll&&!rl&&r
1048
MC/DC50%1/2
defined $version and defined $branch
defined $version defined $branch
Truth table66%2/3
A and B
A= defined $versionB= defined $branch
ABresult
0X0
100
111
95 48 ▶ return $version =~ /^\Q$branch\E\./ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$version =~ /^\Q$branch\E\./ ? : 44 4 48
96 }
97  
98 36 1;
99  
100 __END__
« lib/Rex/GPU/NVIDIA/Setup/RHEL.pm ↑ Summary lib/Rex/GPU/NVIDIA/Setup/SUSE.pm »