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

filter: Statementstmt 99.1% 117 / 118 Branchbran 94.2% 49 / 52 Conditioncond 65.2% 15 / 23 MC/DCmcdc 41.6% 5 / 12 Subroutinesub 100% 23 / 23 Podpod 100% 16 / 16 totaltotal 92.2% 225 / 244 CC 39 SCAR 14.8
CC
39
Cov
94%
prepare_source
10.0
verify_packages
6.1
_dnf_list_versions
5.0
CRAP 4.4
« lib/Rex/GPU/NVIDIA/Setup/Apt.pm ↑ Summary lib/Rex/GPU/NVIDIA/Setup/Rpm.pm »
1 # ABSTRACT: NVIDIA driver setup for RHEL, Rocky, AlmaLinux and CentOS Stream (experimental)
2  
3 package Rex::GPU::NVIDIA::Setup::RHEL;
4 36 our $VERSION = '0.005';
5 36 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 36 ▶use Rex::Commands::Gather ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 36 ▶use Rex::Logger ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 36 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 36 extends 'Rex::GPU::NVIDIA::Setup::Rpm';
11  
12  
13 536 ▶sub major {
Subroutine major: called CC=1 SCAR=0.0
Pod documented
14 536 my ( $self ) = @_;
15 536 return $self->_major_version($self->release);
16 }
17  
18  
19 36 has os_release => ( is => 'lazy' );
20  
21 166 ▶sub _build_os_release {
Subroutine _build_os_release: called CC=2 SCAR=6.9
22 166 my ( $self ) = @_;
23 166 my $out = $self->run_cmd('cat /etc/os-release 2>/dev/null', auto_die => 0);
24 166 ▶ return {} if $? != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 1 165 166
25 165 return $self->_parse_os_release($out);
26 }
27  
28 # Pure: KEY=VALUE lines of os-release(5), the value unquoted.
29 166 ▶sub _parse_os_release {
Subroutine _parse_os_release: called CC=4 SCAR=13.9
30 166 my ( $self, $text ) = @_;
31 166 my %kv;
32 166 ▶ for my $line (split /\n/, $text // '') {
Condition50%1/2
$text // ""
l!l
1660
MC/DC0%0/1
$text // ""
$text
Truth table50%1/2
A
A= $text
Aresult
11
00
33 832 ▶ next unless $line =~ /^([A-Z0-9_]+)=(.*?)\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $line =~ /^([A-Z0-9_]+)=(.*?)\s*$/ 2 830 832
34 830 my ( $key, $value ) = ( $1, $2 );
35 830 $value =~ s/^(["'])(.*)\1$/$2/;
36 830 $kv{$key} = $value;
37 }
38 166 return \%kv;
39 }
40  
41 177 ▶sub is_rhel {
Subroutine is_rhel: called CC=3 SCAR=11.0
Pod documented
42 177 my ( $self ) = @_;
43 177 ▶ return ($self->os_release->{ID} // '') eq 'rhel' ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
($self->os_release->{'ID'} // '') eq 'rhel' ? : 32 145 177
Condition100%2/2
$self->os_release->{"ID"} // ""
l!l
1689
MC/DC100%1/1
$self->os_release->{"ID"} // ""
$self->os_release->{"ID"}
Truth table100%2/2
A
A= $self->os_release->{"ID"}
Aresult
11
00
44 }
45  
46 137 ▶sub rex_pkg_works {
Subroutine rex_pkg_works: called CC=2 SCAR=6.9
Pod documented
47 137 my ( $self ) = @_;
48 137 ▶ return Rex::Commands::Gather::is_redhat($self->os) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
Rex::Commands::Gather::is_redhat($self->os) ? : 82 55 137
49 }
50  
51  
52 137 ▶sub install_helpers {
Subroutine install_helpers: called CC=2 SCAR=6.9
Pod documented
53 137 my ( $self, @packages ) = @_;
54 137 ▶ return $self->pkg_cmd([ @packages ], ensure => 'present') if $self->rex_pkg_works;
Branch: 1 branch
BranchTrueFalseTotal
if $self->rex_pkg_works 82 55 137
55 55 $self->run_cmd($self->package_manager.' install -y '.join(' ', @packages), auto_die => 0);
56 55 $self->verify_packages({ verify => [ @packages ] });
57 }
58  
59  
60 176 ▶sub kernel_packages {
Subroutine kernel_packages: called CC=2 SCAR=6.9
Pod documented
61 176 my ( $self ) = @_;
62 176 ▶ return ( ($self->major >= 9 ? 'kernel-devel-matched' : 'kernel-devel-'.$self->kernel),
Branch: 1 branch
BranchTrueFalseTotal
$self->major >= 9 ? : 171 5 176
63 'kernel-headers' );
64 }
65  
66 # branch_at_least 580: every tree carries it. kmod-nvidia-open-dkms in
67 # repos/rhel{8,9}/{x86_64,sbsa} spans 515..615, in repos/rhel10 580..615
68 # (directory listings checked 2026-09-23).
69 #
70 # cuda-580-dkms (karr #26):
71 # * RHEL 8/9: the CUDA repo's module stream nvidia-driver:580-dkms, whose
72 # artifacts are kmod-nvidia-latest-dkms + nvidia-driver(-cuda) 3:580.*
73 # (checked in repos/rhel{8,9}/x86_64 modules.yaml, 2026-09-23).
74 # * RHEL 10: no module streams, so a dnf versionlock on '*nvidia*580*' per
75 # NVIDIA's version-locking guide (docs.nvidia.com/datacenter/tesla/
76 # driver-installation-guide/version-locking.html). repos/rhel10/x86_64
77 # carries kmod-nvidia-latest-dkms, nvidia-driver and nvidia-driver-cuda at
78 # 580.x (checked 2026-09-23).
79 181 ▶sub sources {
Subroutine sources: called CC=3 SCAR=11.0
Pod documented
80 181 my ( $self ) = @_;
81 181 my $major = $self->major;
82 181 ▶ my $open = $major >= 10
Branch: 1 branch
BranchTrueFalseTotal
$major >= 10 ? : 40 141 181
83 ? { packages => [ 'kmod-nvidia-open-dkms', 'nvidia-driver', 'nvidia-driver-cuda' ] }
84 : { packages => [ 'nvidia-open' ], module_stream => 'open-dkms', stream_optional => 1 };
85 # Fabric Manager (karr #23): nvidia-fabricmanager, unversioned from 580 on,
86 # epoch 0 (the driver packages carry epoch 3), no Requires on the driver;
87 # an artifact of every nvidia-driver stream's /fm profile on rhel8/9
88 # (repodata modules.yaml and primary.sqlite, checked 2026-09-24). Pinned
89 # to the installed nvidia-driver's version.
90 181 my %fm = ( fabric_manager => 'nvidia-fabricmanager', fabric_manager_match => 'nvidia-driver' );
91 return (
92 {
93 181 ▶ name => 'cuda-open-dkms',
Branch: 1 branch
BranchTrueFalseTotal
$major >= 10 ? : 40 141 181
94 kernel_module => 'open',
95 branch_at_least => 580,
96 verify => [ 'nvidia-driver' ],
97 %fm,
98 %$open
99 },
100 {
101 %fm,
102 name => 'cuda-580-dkms',
103 kernel_module => 'proprietary',
104 branch => 580,
105 packages => [ 'kmod-nvidia-latest-dkms', 'nvidia-driver', 'nvidia-driver-cuda' ],
106 verify => [ 'nvidia-driver', 'kmod-nvidia-latest-dkms' ],
107 pin_branch => 580,
108 $major >= 10 ? ( versionlock => '*nvidia*580*' ) : ( module_stream => '580-dkms' )
109 }
110 );
111 }
112  
113 # karr #56, research of 2026-09-24 (rhel9 primary.xml): nvidia-fabric-manager
114 # (with the hyphen) for 570/575, nvidia-fabricmanager from 580 on. A fresh
115 # install always takes >= 580.
116 27 ▶sub fabric_manager_package {
Subroutine fabric_manager_package: called CC=4 SCAR=15.6
Pod documented
117 27 my ( $self, $source ) = @_;
118 27 my $pkg = $self->SUPER::fabric_manager_package($source);
119 27 ▶ return $pkg unless defined $pkg && ( $source->{branch} // '' ) =~ /\A57[05]\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pkg and ($source->{"branch"} // "") =~ /\A57[05]\z/ 27 0 27
Condition60%3/5
defined $pkg and ($source->{"branch"} // "") =~ /\A57[05]\z/
!ll&&!rl&&r
0270
$source->{"branch"} // ""
l!l
819
MC/DC50%1/2
defined $pkg and ($source->{"branch"} // "") =~ /\A57[05]\z/
defined $pkg $source->{"branch"}
Truth table66%2/3
A and B
A= defined $pkgB= $source->{"branch"}
ABresult
0X0
100
111
120 0 return 'nvidia-fabric-manager';
121 }
122  
123 # nvlsm: CUDA repos rhel9 and rhel10 (2025.06.5 .. 2025.12.211); rpm Requires
124 # (libibumad or libibumad3). libibumad in BaseOS, infiniband-diags in
125 # AppStream on Rocky 9/10 (research 2026-09-24). NVIDIA's gpu-driver-container
126 # installs `infiniband-diags nvlsm` unversioned.
127 3 ▶sub nvlink_fabric_packages { ( 'nvlsm', 'infiniband-diags', 'libibumad' ) }
Subroutine nvlink_fabric_packages: called CC=1 SCAR=0.0
Pod documented
128  
129 5 ▶sub nvlink_fabric_unavailable {
Subroutine nvlink_fabric_unavailable: called CC=3 SCAR=11.1
Pod documented
130 5 my ( $self ) = @_;
131 5 ▶ return if $self->major >= 9;
Branch: 1 branch
BranchTrueFalseTotal
if $self->major >= 9 4 1 5
132 1 ▶ return "nvlsm was verified in NVIDIA's CUDA repositories for RHEL 9 and 10 only, "
Condition50%1/2
$self->release // ""
l!l
10
MC/DC0%0/1
$self->release // ""
$self->release
Truth table50%1/2
A
A= $self->release
Aresult
11
00
133 .'not for release '.( $self->release // '' );
134 }
135  
136 # NVIDIA's release notes list RHEL 9.6 (B200) and 9.8 (B300) -- kernel 5.14
137 # with backports -- as supported; maintainer decision (karr #56): no kernel
138 # warning on the RHEL family.
139 4 ▶sub nvlink_kernel_backported { 1 }
Subroutine nvlink_kernel_backported: called CC=1 SCAR=0.0
Pod documented
140  
141 216 ▶sub plan {
Subroutine plan: called CC=1 SCAR=0.0
Pod documented
142 216 my ( $self ) = @_;
143 216 my $plan = $self->SUPER::plan;
144 174 $plan->{major} = $self->major;
145 174 $plan->{rhel} = $self->is_rhel;
146 174 return $plan;
147 }
148  
149  
150 31 ▶sub epel_release_url {
Subroutine epel_release_url: called CC=1 SCAR=0.0
Pod documented
151 31 my ( $self, $major ) = @_;
152 31 return 'https://dl.fedoraproject.org/pub/epel/epel-release-latest-'.$major.'.noarch.rpm';
153 }
154  
155 # RHEL (karr #39): per EPEL's getting-started guide and NVIDIA's driver
156 # installation guide (RHEL 8/9/10 pre-installation steps), both checked
157 # 2026-09-24: subscription-manager enables CRB, EPEL comes from its release
158 # RPM URL. dkms: EPEL 8/9/10 carry it, repos/rhel{8,9,10}/x86_64 of the CUDA
159 # repo do not, and kmod-nvidia-{open,latest}-dkms Require it.
160 157 ▶sub prepare_host {
Subroutine prepare_host: called CC=4 SCAR=13.9
Pod documented
161 157 my ( $self, $plan ) = @_;
162 157 Rex::Logger::info(' Enabling EPEL and extra repos...');
163 157 ▶ if ($plan->{rhel}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plan->{"rhel"}) 31 126 157
164 31 my $major = $plan->{major};
165 31 $self->run_cmd($self->package_manager.' install -y '.$self->epel_release_url($major), auto_die => 0);
166 31 $self->verify_packages({ verify => [ 'epel-release' ] });
167 30 my $crb = 'codeready-builder-for-rhel-'.$major.'-'.$self->arch.'-rpms';
168 30 $self->run_cmd('subscription-manager repos --enable '.$crb, auto_die => 0);
169 30 ▶ Rex::Logger::info(' Could not enable '.$crb.' with subscription-manager; '
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 1 29 30
170 .'EPEL packages that need CodeReady Builder will not install', 'warn')
171 if $? != 0;
172 30 return;
173 }
174 126 $self->install_helpers('epel-release');
175 125 ▶ if ($plan->{major} >= 9) {
Branch: 1 branch
BranchTrueFalseTotal
if ($plan->{'major'} >= 9) { } 124 1 125
176 124 $self->run_cmd('dnf config-manager --set-enabled crb 2>/dev/null || true', auto_die => 0);
177 }
178 else {
179 1 $self->run_cmd('dnf config-manager --set-enabled powertools 2>/dev/null || true', auto_die => 0);
180 }
181 }
182  
183  
184 155 ▶sub prepare_source {
Subroutine prepare_source: called CC=10 SCAR=23.0
Pod documented
185 155 my ( $self, $plan ) = @_;
186 155 my $major = $plan->{major};
187  
188 # Arch-aware: aarch64 server/datacenter parts (Grace, Hopper, Blackwell) are
189 # published under the "sbsa" tree, not "x86_64".
190 155 my $distro = "rhel$major";
191 155 my $arch = $self->_cuda_repo_arch($self->arch);
192 155 my $repo_url = "https://developer.download.nvidia.com/compute/cuda/repos/$distro/$arch/cuda-$distro.repo";
193 155 Rex::Logger::info(" Adding NVIDIA CUDA repo ($distro/$arch)...");
194 # karr #47: on an HTTP error --add-repo writes no .repo and exits non-zero;
195 # ignored, that only surfaced as "nvidia-driver not installed" after dnf
196 # install. Die here, naming the URL and dnf's own words.
197 155 my $out = $self->run_cmd("dnf config-manager --add-repo $repo_url 2>&1", auto_die => 0);
198 155 ▶ if ($? != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 3 152 155
199 3 my $exit = $? >> 8;
200 3 ▶ $out //= '';
Condition50%1/2
$out //= ""
l!l
30
MC/DC0%0/1
$out //= ""
$out
Truth table50%1/2
A
A= $out
Aresult
11
00
201 3 $out =~ s/\s+\z//;
202 3 ▶ die "dnf config-manager --add-repo $repo_url failed (exit $exit)"
Branch: 1 branch
BranchTrueFalseTotal
length $out ? : 2 1 3
203 . (length $out ? ": $out" : '')
204 . "; no driver was installed\n";
205 }
206 152 $self->run_cmd('dnf clean expire-cache', auto_die => 0);
207  
208 152 ▶ my $source = $plan->{source} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $source = $plan->{"source"} or return 152 0 152
209 152 ▶ if (my $stream = $source->{module_stream}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $stream = $source->{"module_stream"}) 119 33 152
210 119 ▶ if ($source->{stream_optional}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source->{'stream_optional'}) { } 85 34 119
211 85 $self->run_cmd("dnf module enable nvidia-driver:$stream -y 2>/dev/null || true", auto_die => 0);
212 }
213 else {
214 # Pre-Turing (karr #26): unlike the open stream, a failed enable is NOT
215 # swallowed: without it dnf would resolve the newest branch.
216 34 $self->run_cmd("dnf module enable nvidia-driver:$stream -y", auto_die => 0);
217 34 ▶ die "dnf module enable nvidia-driver:$stream failed — another "
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 1 33 34
218 . "nvidia-driver stream is probably enabled already (`dnf module reset "
219 . "nvidia-driver` switches it); no driver was installed\n"
220 if $? != 0;
221 }
222 }
223 151 ▶ if (my $lock = $source->{versionlock}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $lock = $source->{"versionlock"}) 11 140 151
224 11 $self->install_helpers('python3-dnf-plugin-versionlock');
225 11 $self->run_cmd("dnf versionlock add '$lock'", auto_die => 0);
226 11 ▶ die "dnf versionlock add '$lock' failed; no driver was installed\n"
Branch: 1 branch
BranchTrueFalseTotal
if $? != 0 1 10 11
227 if $? != 0;
228 }
229 }
230  
231  
232 250 ▶sub verify_packages {
Subroutine verify_packages: called CC=6 SCAR=18.0
Pod documented
233 250 my ( $self, $plan ) = @_;
234 250 $self->SUPER::verify_packages($plan);
235 245 ▶ my $branch = $plan->{source} && $plan->{source}{pin_branch} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $branch = $plan->{"source"} && $plan->{"source"}{"pin_branch"} or return 43 202 245
Condition100%3/3
$plan->{'source'} && $plan->{'source'}{'pin_branch'}
!ll&&!rl&&r
9610643
MC/DC100%2/2
$plan->{'source'} && $plan->{'source'}{'pin_branch'}
$plan->{'source'} $plan->{'source'}{'pin_branch'}
Truth table100%3/3
A && B
A= $plan->{'source'}B= $plan->{'source'}{'pin_branch'}
ABresult
0X0
100
111
236 43 my $version = $self->run_cmd("rpm -q --qf '%{VERSION}' nvidia-driver 2>&1", auto_die => 0);
237 43 ▶ chomp $version if defined $version;
Branch: 1 branch
BranchTrueFalseTotal
if defined $version 43 0 43
238 43 ▶ die "nvidia-driver is " . ($version // 'unknown') . ", not branch "
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_rpm_version_in_branch($version, $branch) 1 42 43
Condition50%1/2
$version // "unknown"
l!l
10
MC/DC0%0/1
$version // "unknown"
$version
Truth table50%1/2
A
A= $version
Aresult
11
00
239 . "$branch — this pre-Turing GPU needs $branch\n"
240 unless $self->_rpm_version_in_branch($version, $branch);
241 }
242  
243  
244 4 ▶sub fabric_manager_version_unavailable {
Subroutine fabric_manager_version_unavailable: called CC=2 SCAR=6.9
Pod documented
245 4 my ( $self, $pkg, $version ) = @_;
246 4 my $out = $self->run_cmd("dnf -q list --showduplicates --available $pkg 2>/dev/null", auto_die => 0);
247 return 'dnf list --showduplicates '.$pkg.' lists no version '.$version
248 4 ▶ unless grep { $_ eq $version } $self->_dnf_list_versions($out, $pkg);
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $version;} $self->_dnf_list_versions($out, $pkg) 1 3 4
249 3 return;
250 }
251  
252 # Pure: the upstream versions of $pkg in `dnf list` output
253 # ("nvidia-fabricmanager.x86_64 3:580.95.05-1 cuda-rhel9-x86_64").
254 5 ▶sub _dnf_list_versions {
Subroutine _dnf_list_versions: called CC=5 SCAR=16.2
255 5 my ( $self, $out, $pkg ) = @_;
256 5 my @versions;
257 5 ▶ for my $line (split /\n/, $out // '') {
Condition50%1/2
$out // ""
l!l
50
MC/DC0%0/1
$out // ""
$out
Truth table50%1/2
A
A= $out
Aresult
11
00
258 12 my ( $na, $evr ) = split ' ', $line;
259 12 ▶ next unless defined $evr && $na =~ /\A\Q$pkg\E\.[^.]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $evr and $na =~ /\A\Q$pkg\E\.[^.]+\z/ 5 7 12
Condition66%2/3
defined $evr and $na =~ /\A\Q$pkg\E\.[^.]+\z/
!ll&&!rl&&r
057
MC/DC50%1/2
defined $evr and $na =~ /\A\Q$pkg\E\.[^.]+\z/
defined $evr $na =~ /\A\Q$pkg\E\.[^.]+\z/
Truth table66%2/3
A and B
A= defined $evrB= $na =~ /\A\Q$pkg\E\.[^.]+\z/
ABresult
0X0
100
111
260 7 ( my $v = $evr ) =~ s/^\d+://;
261 7 $v =~ s/-[^-]*$//;
262 7 push @versions, $v;
263 }
264 5 return @versions;
265 }
266  
267 36 1;
268  
269 __END__
« lib/Rex/GPU/NVIDIA/Setup/Apt.pm ↑ Summary lib/Rex/GPU/NVIDIA/Setup/Rpm.pm »