-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
164 additions
and
0 deletions.
There are no files selected for viewing
164 changes: 164 additions & 0 deletions
164
cookbooks/aws-parallelcluster-platform/spec/unit/resources/enroot_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
require 'spec_helper' | ||
|
||
class ConvergeEnroot | ||
def self.setup(chef_run) | ||
chef_run.converge_dsl('aws-parallelcluster-platform') do | ||
enroot 'setup' do | ||
action :setup | ||
end | ||
end | ||
end | ||
|
||
def self.configure(chef_run) | ||
chef_run.converge_dsl('aws-parallelcluster-platform') do | ||
enroot 'configure' do | ||
action :configure | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe 'enroot:package_version' do | ||
for_all_oses do |platform, version| | ||
context "on #{platform}#{version}" do | ||
cached(:chef_run) do | ||
allow_any_instance_of(Object).to receive(:nvidia_enabled?).and_return(false) | ||
runner = runner(platform: platform, version: version, step_into: ['enroot']) | ||
ConvergeEnroot.setup(runner) | ||
end | ||
cached(:resource) do | ||
chef_run.find_resource('enroot', 'setup') | ||
end | ||
|
||
it 'returns the expected enroot version' do | ||
expected_enroot_version = "3.4.1" | ||
expect(resource.package_version).to eq(expected_enroot_version) | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe 'enroot:arch_suffix' do | ||
for_all_oses do |platform, version| | ||
context "on #{platform}#{version} - arm" do | ||
cached(:chef_run) do | ||
allow_any_instance_of(Object).to receive(:nvidia_enabled?).and_return(false) | ||
runner = runner(platform: platform, version: version, step_into: ['enroot']) | ||
ConvergeEnroot.setup(runner) | ||
end | ||
cached(:resource) do | ||
chef_run.find_resource('enroot', 'setup') | ||
end | ||
|
||
context 'on arm instance' do | ||
cached(:expected_arch) do | ||
case platform | ||
when 'amazon', 'redhat', 'rocky' | ||
'aarch64' | ||
else | ||
'arm64' | ||
end | ||
end | ||
|
||
it 'returns arch value for arm architecture' do | ||
allow_any_instance_of(Object).to receive(:arm_instance?).and_return(true) | ||
expect(resource.arch_suffix).to eq(expected_arch) | ||
end | ||
end | ||
|
||
context 'not on arm instance' do | ||
cached(:expected_arch) do | ||
platform == 'ubuntu' ? 'amd64' : 'x86_64' | ||
end | ||
|
||
it 'returns arch value for arm architecture' do | ||
allow_any_instance_of(Object).to receive(:arm_instance?).and_return(false) | ||
expect(resource.arch_suffix).to eq(expected_arch) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe 'enroot:setup' do | ||
for_all_oses do |platform, version| | ||
context "on #{platform}#{version} when enroot not enabled" do | ||
cached(:chef_run) do | ||
stubs_for_resource('enroot') do |res| | ||
allow(res).to receive(:nvidia_enabled?).and_return(false) | ||
end | ||
runner = runner(platform: platform, version: version, step_into: ['enroot']) | ||
ConvergeEnroot.setup(runner) | ||
end | ||
|
||
it 'does not install enroot' do | ||
is_expected.not_to run_bash('Install enroot') | ||
end | ||
end | ||
|
||
context "on #{platform}#{version} when enroot enabled" do | ||
cached(:sources_dir) { 'sources_dir' } | ||
cached(:package_version) { '3.4.1' } | ||
cached(:enroot_arch) { 'enroot_arch' } | ||
cached(:enroot_url) do | ||
case platform | ||
when 'ubuntu' | ||
"https://github.com/NVIDIA/enroot/releases/download/v#{package_version}/enroot_#{package_version}-1_#{arch_suffix}.deb" | ||
else | ||
"https://github.com/NVIDIA/enroot/releases/download/v#{package_version}/enroot-#{package_version}-1.el8.#{arch_suffix}.rpm" | ||
end | ||
end | ||
cached(:chef_run) do | ||
stubs_for_resource('enroot') do |res| | ||
allow(res).to receive(:nvidia_enabled?).and_return(true) | ||
allow(res).to receive(:enroot_arch).and_return(enroot_arch) | ||
end | ||
runner = runner(platform: platform, version: version, step_into: ['enroot']) do |node| | ||
node.override['cluster']['sources_dir'] = sources_dir | ||
end | ||
ConvergeEnroot.setup(runner) | ||
end | ||
cached(:node) { chef_run.node } | ||
|
||
it 'sets up enroot' do | ||
is_expected.to setup_enroot('setup') | ||
end | ||
|
||
if platform == 'ubuntu' | ||
it 'installs enroot for ubuntu' do | ||
is_expected.to run_bash('Install enroot') | ||
.with_code(%r{apt install -y ./*.deb}) | ||
.with_code(%r{ln -s /usr/share/enroot/hooks.d/50-slurm-pmi.sh /etc/enroot/hooks.d/}) | ||
.with_code(%r{ln -s /usr/share/enroot/hooks.d/50-slurm-pytorch.sh /etc/enroot/hooks.d/}) | ||
.with_code(%r{mkdir -p /etc/sysconfig}) | ||
end | ||
else | ||
it 'installs enroot for rhel' do | ||
is_expected.to run_bash('Install enroot') | ||
.with_code(%r{yum install -y #{enroot_url}}) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
describe 'enroot:configure' do | ||
for_all_oses do |platform, version| | ||
context "on #{platform}#{version} when enroot has been installed" do | ||
cached(:chef_run) do | ||
stubs_for_resource('enroot') do |res| | ||
allow(res).to receive(:enroot_installed).and_return(true) | ||
end | ||
runner = runner(platform: platform, version: version, step_into: ['enroot']) | ||
ConvergeEnroot.setup(runner) | ||
end | ||
|
||
it 'configures enroot' do | ||
is_expected.to configure_enroot('configure') | ||
is_expected.to run_bash('Configure enroot') | ||
.with_code(%r{mv /tmp/enroot.conf /etc/enroot/enroot.conf}) | ||
.with_code(%r{chmod 0644 /etc/enroot/enroot.conf}) | ||
end | ||
end | ||
end | ||
end |