Skip to content

Commit

Permalink
Add chef spec for kernel module
Browse files Browse the repository at this point in the history
  • Loading branch information
hgreebe committed Jan 16, 2024
1 parent a29b7a0 commit 0d2a6e9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
cwd '/tmp'
code <<-NVIDIA
set -e
#{compiler_version} ./nvidia.run --silent --dkms --disable-nouveau --no-cc-version-check #{kernel_open}
#{compiler_version} ./nvidia.run --silent --dkms --disable-nouveau --no-cc-version-check #{kernel_module}
rm -f /tmp/nvidia.run
NVIDIA
creates '/usr/bin/nvidia-smi'
Expand Down Expand Up @@ -108,9 +108,9 @@ def compiler_version
""
end

def kernel_open
if node['cluster']['nvidia']['kernel-open'] == "false"
""
def kernel_module
if node['cluster']['nvidia']['kernel_module'] == "kernel"
"-m=kernel"
else
"-m=kernel-open"
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,28 @@ def self.setup(chef_run, nvidia_driver_version: nil)
end
end

describe 'nvidia_kernel:kernel_module' do
cached(:chef_run) do
ChefSpec::SoloRunner.new(step_into: ['nvidia_driver'])
end
cached(:resource) do
ConvergeNvidiaDriver.setup(chef_run)
chef_run.find_resource('nvidia_driver', 'setup')
end
context 'when on kernel' do
it 'is kernel' do
allow_any_instance_of(Object).to receive(:kernel_module).and_return("-m=kernel")
expect(resource.kernel_module).to eq('-m=kernel')
end
end
context 'when on kernel-open' do
it 'is kernel-open' do
allow_any_instance_of(Object).to receive(:kernel_module).and_return("-m=kernel-open")
expect(resource.kernel_module).to eq('-m=kernel-open')
end
end
end

describe 'nvidia_driver:nvidia_arch' do
cached(:chef_run) do
ChefSpec::SoloRunner.new(step_into: ['nvidia_driver'])
Expand Down Expand Up @@ -123,6 +145,7 @@ def self.setup(chef_run, nvidia_driver_version: nil)
describe 'nvidia_driver:setup' do
for_all_oses do |platform, version|
cached(:nvidia_arch) { 'nvidia_arch' }
cached(:kernel_module) { 'kernel_module' }
cached(:nvidia_driver_version) { 'nvidia_driver_version' }
cached(:nvidia_driver_url) { "https://us.download.nvidia.com/tesla/#{nvidia_driver_version}/NVIDIA-Linux-#{nvidia_arch}-#{nvidia_driver_version}.run" }

Expand All @@ -143,12 +166,14 @@ def self.setup(chef_run, nvidia_driver_version: nil)
context "on #{platform}#{version} when nvidia_driver enabled" do
cached(:nvidia_arch) { 'nvidia_arch' }
cached(:nvidia_driver_version) { 'nvidia_driver_version' }
cached(:kernel_module) { 'kernel_module' }
cached(:nvidia_driver_url) { "https://us.download.nvidia.com/tesla/#{nvidia_driver_version}/NVIDIA-Linux-#{nvidia_arch}-#{nvidia_driver_version}.run" }

cached(:chef_run) do
stubs_for_resource('nvidia_driver') do |res|
allow(res).to receive(:nvidia_driver_enabled?).and_return(true)
allow(res).to receive(:nvidia_arch).and_return(nvidia_arch)
allow(res).to receive(:kernel_module).and_return(kernel_module)
end

stub_command("lsinitramfs /boot/initrd.img-$(uname -r) | grep nouveau").and_return(true)
Expand Down Expand Up @@ -204,15 +229,27 @@ def self.setup(chef_run, nvidia_driver_version: nil)
)
end
it 'installs nvidia driver' do
is_expected.to run_bash('nvidia.run advanced')
.with(
user: 'root',
group: 'root',
cwd: '/tmp',
creates: '/usr/bin/nvidia-smi'
)
.with_code(%r{CC=/usr/bin/gcc10-gcc ./nvidia.run --silent --dkms --disable-nouveau --no-cc-version-check -m=kernel-open})
.with_code(%r{rm -f /tmp/nvidia.run})
if kernel_module == '-m=kernel'
is_expected.to run_bash('nvidia.run advanced')
.with(
user: 'root',
group: 'root',
cwd: '/tmp',
creates: '/usr/bin/nvidia-smi'
)
.with_code(%r{CC=/usr/bin/gcc10-gcc ./nvidia.run --silent --dkms --disable-nouveau --no-cc-version-check -m=kernel})
.with_code(%r{rm -f /tmp/nvidia.run})
else
is_expected.to run_bash('nvidia.run advanced')
.with(
user: 'root',
group: 'root',
cwd: '/tmp',
creates: '/usr/bin/nvidia-smi'
)
.with_code(%r{CC=/usr/bin/gcc10-gcc ./nvidia.run --silent --dkms --disable-nouveau --no-cc-version-check -m=kernel-open})
.with_code(%r{rm -f /tmp/nvidia.run})
end
end
else
it "doesn't install gcc10" do
Expand Down

0 comments on commit 0d2a6e9

Please sign in to comment.