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