Skip to content

Commit 46c99cd

Browse files
committed
Refactored config recipe for the head node to make it easier to unit test definition of slurm services.
Added spec tests covering the definitions of slurmctld, slurmd and slurmdbd. Signed-off-by: Giacomo Marciani <[email protected]>
1 parent abc0039 commit 46c99cd

6 files changed

+182
-8
lines changed

cookbooks/aws-parallelcluster-slurm/recipes/config/config_head_node.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,7 @@
192192
mode '0644'
193193
end
194194

195-
template '/etc/systemd/system/slurmctld.service' do
196-
source 'slurm/head_node/slurmctld.service.erb'
197-
owner 'root'
198-
group 'root'
199-
mode '0644'
200-
action :create
201-
end
202-
195+
include_recipe 'aws-parallelcluster-slurm::config_slurmctld_systemd_service'
203196
include_recipe 'aws-parallelcluster-slurm::config_health_check'
204197

205198
ruby_block "Configure Slurm Accounting" do
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
#
4+
# Cookbook:: aws-parallelcluster-slurm
5+
# Recipe:: config_slurmctld_systemd_service.rb
6+
#
7+
# Copyright:: 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
8+
#
9+
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the
10+
# License. A copy of the License is located at
11+
#
12+
# http://aws.amazon.com/apache2.0/
13+
#
14+
# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
15+
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
# Create systemd service file for slurmctld
19+
template '/etc/systemd/system/slurmctld.service' do
20+
source 'slurm/head_node/slurmctld.service.erb'
21+
owner 'root'
22+
group 'root'
23+
mode '0644'
24+
action :create
25+
end
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright:: 2024 Amazon.com, Inc. and its affiliates. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the
6+
# License. A copy of the License is located at
7+
#
8+
# http://aws.amazon.com/apache2.0/
9+
#
10+
# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
11+
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
require 'spec_helper'
15+
16+
describe 'aws-parallelcluster-slurm::config_head_node' do
17+
before do
18+
@included_recipes = []
19+
%w(
20+
aws-parallelcluster-slurm::config_head_node_directories
21+
aws-parallelcluster-slurm::config_check_login_stopped_script
22+
aws-parallelcluster-slurm::config_munge_key
23+
aws-parallelcluster-slurm::config_slurm_resume
24+
aws-parallelcluster-slurm::config_slurmctld_systemd_service
25+
aws-parallelcluster-slurm::config_health_check
26+
).each do |recipe_name|
27+
allow_any_instance_of(Chef::Recipe).to receive(:include_recipe).with(recipe_name) do
28+
@included_recipes << recipe_name
29+
end
30+
end
31+
end
32+
33+
for_all_oses do |platform, version|
34+
context "on #{platform}#{version}" do
35+
cached(:chef_run) do
36+
runner = runner(platform: platform, version: version) do |node|
37+
allow_any_instance_of(Object).to receive(:nvidia_installed?).and_return(false)
38+
39+
node.override['cluster']['node_type'] = 'HeadNode'
40+
node.override['cluster']['scheduler'] = 'slurm'
41+
node.override['cluster']['config'] = {}
42+
end
43+
runner.converge(described_recipe)
44+
end
45+
cached(:node) { chef_run.node }
46+
47+
expected_recipes = %w(
48+
aws-parallelcluster-slurm::config_head_node_directories
49+
aws-parallelcluster-slurm::config_check_login_stopped_script
50+
aws-parallelcluster-slurm::config_munge_key
51+
aws-parallelcluster-slurm::config_slurm_resume
52+
aws-parallelcluster-slurm::config_slurmctld_systemd_service
53+
aws-parallelcluster-slurm::config_health_check
54+
)
55+
56+
it "includes the recipes in the right order" do
57+
chef_run
58+
expect(@included_recipes).to eq(expected_recipes)
59+
end
60+
end
61+
end
62+
end

cookbooks/aws-parallelcluster-slurm/spec/unit/recipes/config_slurm_accounting_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@
1313
end
1414
cached(:node) { chef_run.node }
1515

16+
it 'creates the service definition for slurmdbd' do
17+
is_expected.to create_template('/etc/systemd/system/slurmdbd.service').with(
18+
source: 'slurm/head_node/slurmdbd.service.erb',
19+
owner: 'root',
20+
group: 'root',
21+
mode: '0644'
22+
)
23+
end
24+
25+
it 'creates the service definition for slurmdbd with the correct settings' do
26+
is_expected.to render_file('/etc/systemd/system/slurmdbd.service')
27+
.with_content("After=network-online.target munge.service mysql.service mysqld.service mariadb.service remote-fs.target")
28+
end
29+
1630
it 'creates the slurmdbd configuration files' do
1731
slurm_install_dir = "#{node['cluster']['slurm']['install_dir']}"
1832
slurm_user = "#{node['cluster']['slurm']['user']}"
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright:: 2024 Amazon.com, Inc. and its affiliates. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the
6+
# License. A copy of the License is located at
7+
#
8+
# http://aws.amazon.com/apache2.0/
9+
#
10+
# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
11+
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
require 'spec_helper'
15+
16+
describe 'aws-parallelcluster-slurm::config_slurmctld_systemd_service' do
17+
for_all_oses do |platform, version|
18+
context "on #{platform}#{version}" do
19+
cached(:chef_run) do
20+
runner(platform: platform, version: version).converge(described_recipe)
21+
end
22+
23+
it 'creates the service definition for slurmctld' do
24+
is_expected.to create_template('/etc/systemd/system/slurmctld.service').with(
25+
source: 'slurm/head_node/slurmctld.service.erb',
26+
owner: 'root',
27+
group: 'root',
28+
mode: '0644'
29+
)
30+
end
31+
32+
it 'creates the service definition for slurmctld with the correct settings' do
33+
is_expected.to render_file('/etc/systemd/system/slurmctld.service')
34+
.with_content("After=network-online.target munge.service remote-fs.target")
35+
end
36+
end
37+
end
38+
end
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
# Copyright:: 2024 Amazon.com, Inc. and its affiliates. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the
6+
# License. A copy of the License is located at
7+
#
8+
# http://aws.amazon.com/apache2.0/
9+
#
10+
# or in the "LICENSE.txt" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
11+
# OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
require 'spec_helper'
15+
16+
describe 'aws-parallelcluster-slurm::config_slurmd_systemd_service' do
17+
before do
18+
allow_any_instance_of(Object).to receive(:graphic_instance?).and_return(false)
19+
allow_any_instance_of(Object).to receive(:nvidia_installed?).and_return(false)
20+
end
21+
for_all_oses do |platform, version|
22+
context "on #{platform}#{version}" do
23+
cached(:chef_run) do
24+
runner(platform: platform, version: version).converge(described_recipe)
25+
end
26+
27+
it 'creates the service definition for slurmd' do
28+
is_expected.to create_template('/etc/systemd/system/slurmd.service').with(
29+
source: 'slurm/compute/slurmd.service.erb',
30+
owner: 'root',
31+
group: 'root',
32+
mode: '0644'
33+
)
34+
end
35+
36+
it 'creates the service definition for slurmd with the correct settings' do
37+
is_expected.to render_file('/etc/systemd/system/slurmd.service')
38+
.with_content("After=munge.service network-online.target remote-fs.target")
39+
end
40+
end
41+
end
42+
end

0 commit comments

Comments
 (0)