Skip to content

Commit

Permalink
Add unit and kitchen tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hgreebe committed Aug 26, 2024
1 parent 9fe30fb commit 2cdcf4d
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This file is used to list changes made in each version of the AWS ParallelCluste
- Allow custom actions on login nodes.
- Allow DCV connection on login nodes.
- Add new attribute `efs_access_point_ids` to specify optional EFS access points for the mounts
- Install enroot and pyxis in official pcluster AMIs

**BUG FIXES**
- Fix EFA kmod installation with RHEL 8.10 or newer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
default_action :setup

action :setup do
return if on_docker?
action_install_package
end

action :configure do
enroot_installed = ::File.exist?('/usr/bin/enroot')
return if on_docker?
return unless enroot_installed

bash "Configure enroot" do
Expand All @@ -36,14 +37,14 @@
ENROOT_CACHE_PATH=${SHARED_DIR}/enroot envsubst < /tmp/enroot.template.conf > /tmp/enroot.conf
mv /tmp/enroot.conf /etc/enroot/enroot.conf
chmod 0644 /etc/enroot/enroot.conf
mkdir -p /tmp/enroot
chmod 1777 /tmp/enroot
mkdir -p /tmp/enroot/data
chmod 1777 /tmp/enroot/data
chmod 1777 ${SHARED_DIR}/enroot
mkdir -p ${SHARED_DIR}/pyxis/
chown ${NONROOT_USER} ${SHARED_DIR}/pyxis/
sed -i '${s/$/ runtime_path=${SHARED_DIR}\\/pyxis/}' /opt/slurm/etc/plugstack.conf.d/pyxis.conf
Expand All @@ -59,3 +60,7 @@
def package_version
node['cluster']['enroot']['version']
end

def enroot_installed
::File.exist?('/usr/bin/enroot')
end
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
curl -fSsL -O #{enroot_url}
curl -fSsL -O #{enroot_caps_url}
apt install -y ./*.deb
ln -s /usr/share/enroot/hooks.d/50-slurm-pmi.sh /etc/enroot/hooks.d/
ln -s /usr/share/enroot/hooks.d/50-slurm-pytorch.sh /etc/enroot/hooks.d/
mkdir -p /etc/sysconfig
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
require 'spec_helper'

package_version = '3.4.1'
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}" do
let(:chef_run) do
runner(platform: platform, version: version, step_into: ['enroot']) do |node|
node.override['cluster']['enroot']['version'] = package_version
end
end

context 'when nvidia is enabled' do
before do
stubs_for_provider('enroot') do |resource|
allow(resource).to receive(:nvidia_enabled?).and_return(true)
end
end

context 'and enroot is installed' do
before do
ConvergeEnroot.setup(chef_run)
end

it 'installs Enroot' do
is_expected.to run_bash('Install enroot')
end
end
end

context 'when nvidia is not enabled' do
before do
stubs_for_provider('enroot') do |resource|
allow(resource).to receive(:nvidia_enabled?).and_return(false)
end
end

context 'and enroot is installed' do
before do
ConvergeEnroot.setup(chef_run)
end

it 'does not install Enroot' do
is_expected.not_to run_bash('Install enroot')
end
end
end
end
end
end

describe 'enroot:configure' do
for_all_oses do |platform, version|
context "on #{platform}#{version}" do
let(:chef_run) do
runner(platform: platform, version: version, step_into: ['enroot'])
end

context 'when enroot is installed' do
before do
stubs_for_provider('enroot') do |resource|
allow(resource).to receive(:enroot_installed).and_return(true)
end
ConvergeEnroot.configure(chef_run)
end
it 'run configure enroot script' do
is_expected.to run_bash('Configure enroot')
.with(retries: 3)
.with(retry_delay: 5)
.with(user: 'root')
end
end

context 'when enroot is not installed' do
before do
stubs_for_provider('enroot') do |resource|
allow(resource).to receive(:enroot_installed).and_return(false)
end
ConvergeEnroot.configure(chef_run)
end

it 'does not run configure enroot script' do
is_expected.not_to run_bash('Configure enroot')
.with(retries: 3)
.with(retry_delay: 5)
.with(user: 'root')
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright:: 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License. A copy of the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "LICENSE.txt" file accompanying this file.
# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied.
# See the License for the specific language governing permissions and limitations under the License.

control 'tag:install_expected_version_of_enroot_installed' do
only_if { !os_properties.on_docker? && ['yes', true].include?(node['cluster']['nvidia']['enabled']) }

expected_enroot_version = node['cluster']['enroot']['version']

describe "gdrcopy version is expected to be #{expected_enroot_version}" do
subject { command('enroot version').stdout.strip() }
it { should eq expected_enroot_version }
end
end

control 'tag:config_enroot_enabled_on_graphic_instances' do
only_if { !os_properties.on_docker? && ['yes', true].include?(node['cluster']['nvidia']['enabled']) }

describe directory('/usr/bin/enroot') do
it { should exist }
its('owner') { should eq 'root' }
its('group') { should eq 'root' }
end

describe file("/opt/parallelcluster/shared/enroot") do
it { should exist }
its('mode') { should cmp '1777' }
its('owner') { should eq 'root' }
its('group') { should eq 'root' }
end unless os_properties.redhat_on_docker?
end

control 'tag:config_enroot_disabled_on_non_graphic_instances' do
only_if { !os_properties.on_docker? && !['yes', true].include?(node['cluster']['nvidia']['enabled']) }

describe 'enroot service should be disabled' do
subject { command("enroot version") }
its('exit_status') { should eq 127 }
end
end
21 changes: 21 additions & 0 deletions cookbooks/aws-parallelcluster-slurm/test/controls/pyxis_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright:: 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License. A copy of the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "LICENSE.txt" file accompanying this file.
# This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied.
# See the License for the specific language governing permissions and limitations under the License.

control 'tag:install_pyxis_installed' do
title 'Checks Pyxis has been installed'

describe file("/opt/slurm/etc/plugstack.conf.d/pyxis.conf") do
it { should exist }
its('mode') { should cmp '0755' }
its('owner') { should eq 'root' }
its('group') { should eq 'root' }
end unless os_properties.redhat_on_docker?
end

0 comments on commit 2cdcf4d

Please sign in to comment.