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

filter: Statementstmt 100% 99 / 99 Branchbran 94.1% 32 / 34 Conditioncond 57.1% 20 / 35 MC/DCmcdc 35.0% 7 / 20 Subroutinesub 100% 23 / 23 Podpod 100% 15 / 15 totaltotal 86.7% 196 / 226 CC 34 SCAR 14.8
CC
34
Cov
90%
installed_fabric_managers
9.0
_madison_version_for
7.8
fabric_manager_version_unavailable
6.0
CRAP 4.4
« lib/Rex/GPU/NVIDIA/VGPU.pm ↑ Summary lib/Rex/GPU/NVIDIA/Setup/RHEL.pm »
1 # ABSTRACT: apt/dpkg packaging layer of the NVIDIA driver setups (experimental)
2  
3 package Rex::GPU::NVIDIA::Setup::Apt;
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 36 has apt_lock_timeout => ( is => 'ro', default => 120 );
13  
14 197 ▶sub _build_arch {
Subroutine _build_arch: called CC=1 SCAR=0.0
15 197 my ( $self ) = @_;
16 197 my $arch = $self->run_cmd('dpkg --print-architecture', auto_die => 0);
17 197 chomp $arch;
18 197 return $arch;
19 }
20  
21  
22 501 ▶sub apt_get {
Subroutine apt_get: called CC=1 SCAR=0.0
Pod documented
23 501 my ( $self ) = @_;
24 501 return 'apt-get -o DPkg::Lock::Timeout='.$self->apt_lock_timeout;
25 }
26  
27  
28 243 ▶sub kernel_packages {
Subroutine kernel_packages: called CC=1 SCAR=0.0
Pod documented
29 243 my ( $self ) = @_;
30 243 $self->arch;
31 243 return 'linux-headers-'.$self->kernel;
32 }
33  
34  
35 203 ▶sub prepare_host {
Subroutine prepare_host: called CC=1 SCAR=0.0
Pod documented
36 203 my ( $self, $plan ) = @_;
37 203 $self->run_cmd('systemctl stop unattended-upgrades apt-daily.service apt-daily-upgrade.service 2>/dev/null || true',
38 auto_die => 0);
39 }
40  
41  
42 198 ▶sub prepare_source {
Subroutine prepare_source: called CC=1 SCAR=0.0
Pod documented
43 198 my ( $self, $plan ) = @_;
44 198 $self->refresh_package_index;
45 }
46  
47  
48 215 ▶sub refresh_package_index {
Subroutine refresh_package_index: called CC=1 SCAR=0.0
Pod documented
49 215 my ( $self ) = @_;
50 215 $self->run_cmd($self->apt_get.' update -q', auto_die => 0);
51 }
52  
53  
54 15 ▶sub installed_fabric_managers {
Subroutine installed_fabric_managers: called CC=8 SCAR=22.0
Pod documented
55 15 my ( $self ) = @_;
56 15 my $out = $self->run_cmd(q{dpkg-query -W -f='${Package} ${db:Status-Abbrev} ${Version}\n' 'nvidia-fabric*manager*' 2>/dev/null},
57 auto_die => 0);
58 15 my @present;
59 15 ▶ for my $line (split /\n/, $out // '') {
Condition50%1/2
$out // ""
l!l
150
MC/DC0%0/1
$out // ""
$out
Truth table50%1/2
A
A= $out
Aresult
11
00
60 8 my ( $name, $status, $version ) = split ' ', $line;
61 8 ▶ next unless $self->_is_fabric_manager_name($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_fabric_manager_name($name) 1 7 8
62 7 ▶ next unless defined $status && $status =~ /\A[a-z]([a-zA-Z])/ && $1 ne 'n' && $1 ne 'c';
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status and $status =~ /\A[a-z]([a-zA-Z])/ and $1 ne "n" and $1 ne "c" 1 6 7
Condition44%4/9
defined $status and $status =~ /\A[a-z]([a-zA-Z])/ and $1 ne "n" and $1 ne "c"
!ll&&!rl&&r
016
defined $status and $status =~ /\A[a-z]([a-zA-Z])/ and $1 ne "n"
!ll&&!rl&&r
007
defined $status and $status =~ /\A[a-z]([a-zA-Z])/
!ll&&!rl&&r
007
MC/DC25%1/4
defined $status and $status =~ /\A[a-z]([a-zA-Z])/ and $1 ne "n" and $1 ne "c"
defined $status $status =~ /\A[a-z]([a-zA-Z])/ $1 ne "n" $1 ne "c"
Truth table40%2/5
A and B and C and D
A= defined $statusB= $status =~ /\A[a-z]([a-zA-Z])/C= $1 ne "n"D= $1 ne "c"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
63 6 push @present, [ $name, $self->_dpkg_upstream_version($version) ];
64 }
65 15 return @present;
66 }
67  
68 9 ▶sub fabric_manager_version_unavailable {
Subroutine fabric_manager_version_unavailable: called CC=6 SCAR=17.9
Pod documented
69 9 my ( $self, $pkg, $version ) = @_;
70 9 my $madison = $self->run_cmd("apt-cache madison $pkg 2>/dev/null", auto_die => 0);
71 9 my $full = $self->_madison_version_for($madison, $version);
72 9 ▶ return 'apt-cache madison '.$pkg.' lists no version '.$version unless defined $full;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $full 3 6 9
73 6 my $sim = $self->run_cmd('LC_ALL=C '.$self->apt_get.' -s install '.$pkg.'='.$full.' 2>&1',
74 auto_die => 0);
75 6 ▶ return 'apt-get -s install '.$pkg.'='.$full.' fails' if $? != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 1 5 6
76 5 ▶ my @removed = map { /^Remv (\S+)/ ? $1 : () } split /\n/, $sim // '';
Branch: 1 branch
BranchTrueFalseTotal
/^Remv (\S+)/ ? : 1 1 2
Condition50%1/2
$sim // ""
l!l
50
MC/DC0%0/1
$sim // ""
$sim
Truth table50%1/2
A
A= $sim
Aresult
11
00
77 5 ▶ return 'installing '.$pkg.'='.$full.' would remove '.join(', ', @removed) if @removed;
Branch: 1 branch
BranchTrueFalseTotal
if @removed 1 4 5
78 4 return;
79 }
80  
81  
82 199 ▶sub install_packages {
Subroutine install_packages: called CC=1 SCAR=0.0
Pod documented
83 199 my ( $self, $plan ) = @_;
84 199 Rex::Logger::info(' Installing: '.join(', ', @{ $plan->{packages} }));
85 199 my $pkg_str = join(' ', @{ $plan->{packages} });
86 199 $self->run_cmd('DEBIAN_FRONTEND=noninteractive '.$self->apt_get.' install -y '.$pkg_str, auto_die => 0);
87 }
88  
89  
90 261 ▶sub verify_packages {
Subroutine verify_packages: called CC=3 SCAR=11.0
Pod documented
91 261 my ( $self, $plan ) = @_;
92 261 for my $driver_pkg (@{ $plan->{verify} }) {
93 390 my $check = $self->run_cmd("dpkg -l $driver_pkg 2>/dev/null | grep -q '^ii'", auto_die => 0);
94 390 ▶ die "$driver_pkg not installed after apt-get install — check apt output\n"
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 5 385 390
95 if $? != 0;
96 }
97 }
98  
99  
100 15 ▶sub fabric_manager_unavailable {
Subroutine fabric_manager_unavailable: called CC=2 SCAR=6.9
Pod documented
101 15 my ( $self, $pkg ) = @_;
102 15 my $policy = $self->run_cmd("LC_ALL=C apt-cache policy $pkg 2>/dev/null", auto_die => 0);
103 15 ▶ return if $self->_apt_candidate_present($policy);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_apt_candidate_present($policy) 14 1 15
104 1 return $pkg.' has no installation candidate after apt-get update';
105 }
106  
107 14 ▶sub installed_driver_version {
Subroutine installed_driver_version: called CC=2 SCAR=6.9
Pod documented
108 14 my ( $self, $source ) = @_;
109 14 my $pkg = $self->_with_branch($source->{fabric_manager_match}, $source);
110 14 ▶ die "The driver source names no package to read the driver version from "
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pkg 1 13 14
111 ."(fabric_manager_match); the driver is installed, Fabric Manager is not\n"
112 unless defined $pkg;
113 13 return $self->_dpkg_upstream_version($self->_dpkg_version($pkg));
114 }
115  
116 17 ▶sub install_versioned_package {
Subroutine install_versioned_package: called CC=2 SCAR=6.9
Pod documented
117 17 my ( $self, $pkg, $version ) = @_;
118 17 my $madison = $self->run_cmd("apt-cache madison $pkg 2>/dev/null", auto_die => 0);
119 17 my $full = $self->_madison_version_for($madison, $version);
120 17 ▶ die "apt has no $pkg of driver version $version (apt-cache madison $pkg); Fabric "
Branch: 1 branch
BranchTrueFalseTotal
unless defined $full 1 16 17
121 ."Manager must match the driver exactly, so none was installed. The driver is "
122 ."installed, Fabric Manager is not\n" unless defined $full;
123 16 $self->run_cmd('DEBIAN_FRONTEND=noninteractive '.$self->apt_get.' install -y '.$pkg.'='.$full,
124 auto_die => 0);
125 }
126  
127 16 ▶sub verify_versioned_package {
Subroutine verify_versioned_package: called CC=4 SCAR=14.1
Pod documented
128 16 my ( $self, $pkg, $version ) = @_;
129 16 $self->verify_packages({ verify => [ $pkg ] });
130 16 my $installed = $self->_dpkg_upstream_version($self->_dpkg_version($pkg));
131 16 ▶ die "$pkg is ".( $installed // 'unknown' )." after apt-get install, not the driver's "
Branch: 1 branch
BranchTrueFalseTotal
unless defined $installed and $installed eq $version 1 15 16
Condition60%3/5
defined $installed and $installed eq $version
!ll&&!rl&&r
0115
$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
132 ."$version\n" unless defined $installed && $installed eq $version;
133 }
134  
135 29 ▶sub _dpkg_version {
Subroutine _dpkg_version: called CC=3 SCAR=11.8
136 29 my ( $self, $pkg ) = @_;
137 29 my $v = $self->run_cmd("dpkg-query -W -f='\${Version}' $pkg 2>/dev/null", auto_die => 0);
138 29 ▶ return if $? != 0 || !defined $v;
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 or not defined $v 0 29 29
Condition33%1/3
$? != 0 or not defined $v
l!l&&r!l&&!r
0029
MC/DC0%0/2
$? != 0 or not defined $v
$? != 0 not defined $v
Truth table33%1/3
A or not(B)
A= $? != 0B= not defined $v
ABresult
1X1
011
000
139 29 chomp $v;
140 29 return $v;
141 }
142  
143 # Pure: "1:580.95.05-0ubuntu1" -> "580.95.05". undef/empty -> undef.
144 72 ▶sub _dpkg_upstream_version {
Subroutine _dpkg_upstream_version: called CC=3 SCAR=11.0
145 72 my ( $self, $version ) = @_;
146 72 ▶ return unless defined $version && length $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version and length $version 2 70 72
Condition100%3/3
defined $version and length $version
!ll&&!rl&&r
1170
MC/DC100%2/2
defined $version and length $version
defined $version length $version
Truth table100%3/3
A and B
A= defined $versionB= length $version
ABresult
0X0
100
111
147 70 ( my $up = $version ) =~ s/^\d+://;
148 70 $up =~ s/-[^-]*$//;
149 70 return $up;
150 }
151  
152 # Pure: the first `apt-cache madison` version (madison lists newest first)
153 # whose upstream part is $upstream; undef if none.
154 26 ▶sub _madison_version_for {
Subroutine _madison_version_for: called CC=7 SCAR=20.5
155 26 my ( $self, $madison, $upstream ) = @_;
156 26 ▶ for my $line (split /\n/, $madison // '') {
Condition50%1/2
$madison // ""
l!l
260
MC/DC0%0/1
$madison // ""
$madison
Truth table50%1/2
A
A= $madison
Aresult
11
00
157 35 my ( undef, $full ) = map { s/^\s+|\s+$//gr } split /\|/, $line;
158 35 ▶ next unless defined $full && length $full;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $full and length $full 0 35 35
Condition33%1/3
defined $full and length $full
!ll&&!rl&&r
0035
MC/DC0%0/2
defined $full and length $full
defined $full length $full
Truth table33%1/3
A and B
A= defined $fullB= length $full
ABresult
0X0
100
111
159 35 my $up = $self->_dpkg_upstream_version($full);
160 35 ▶ return $full if defined $up && $up eq $upstream;
Branch: 1 branch
BranchTrueFalseTotal
if defined $up and $up eq $upstream 22 13 35
Condition66%2/3
defined $up and $up eq $upstream
!ll&&!rl&&r
01322
MC/DC50%1/2
defined $up and $up eq $upstream
defined $up $up eq $upstream
Truth table66%2/3
A and B
A= defined $upB= $up eq $upstream
ABresult
0X0
100
111
161 }
162 4 return;
163 }
164  
165  
166 # karr #56, research of 2026-09-24: the nvlsm .deb (CUDA repo, 2025.12.211)
167 # Depends on libibumad3; NVIDIA's gpu-driver-container installs
168 # `nvlsm infiniband-diags` unversioned; the Fabric Manager start script
169 # needs ibstat (infiniband-diags).
170 11 ▶sub nvlink_fabric_packages { ( 'nvlsm', 'infiniband-diags', 'libibumad3' ) }
Subroutine nvlink_fabric_packages: called CC=1 SCAR=0.0
Pod documented
171  
172  
173 159 ▶sub initramfs_command { 'update-initramfs -u 2>/dev/null' }
Subroutine initramfs_command: called CC=1 SCAR=0.0
Pod documented
174  
175 # Pure (karr #26): does `apt-cache policy PKG` output (LC_ALL=C) show an
176 # installation candidate? An unknown package prints nothing; a known one with
177 # nothing installable prints "Candidate: (none)".
178 42 ▶sub _apt_candidate_present {
Subroutine _apt_candidate_present: called CC=4 SCAR=13.9
179 42 my ( $self, $policy ) = @_;
180 42 ▶ return 0 unless defined $policy;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $policy 1 41 42
181 41 my ($candidate) = $policy =~ /^\s*Candidate:\s*(\S+)/m;
182 41 ▶ return (defined $candidate && $candidate ne '(none)') ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $candidate && $candidate ne '(none)' ? : 37 4 41
Condition100%3/3
defined $candidate and $candidate ne "(none)"
!ll&&!rl&&r
2237
MC/DC100%2/2
defined $candidate and $candidate ne "(none)"
defined $candidate $candidate ne "(none)"
Truth table100%3/3
A and B
A= defined $candidateB= $candidate ne "(none)"
ABresult
0X0
100
111
183 }
184  
185 36 1;
186  
187 __END__
« lib/Rex/GPU/NVIDIA/VGPU.pm ↑ Summary lib/Rex/GPU/NVIDIA/Setup/RHEL.pm »