Skip to content

Commit d7a8aea

Browse files
committed
Add unit test to cover systemd timer logic for updates
1 parent 61ff8e4 commit d7a8aea

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
require 'spec_helper'
2+
3+
describe 'aws-parallelcluster-computefleet::config_check_update_systemd_service' do
4+
for_all_oses do |platform, version|
5+
context "on #{platform}#{version}" do
6+
cached(:chef_run) do
7+
runner = runner(platform: platform, version: version) do |node|
8+
node.override['cluster']['node_type'] = 'ComputeFleet'
9+
end
10+
runner.converge(described_recipe)
11+
end
12+
cached(:node) { chef_run.node }
13+
14+
it 'creates the check-update.service template' do
15+
is_expected.to create_template('/etc/systemd/system/check-update.service')
16+
.with(source: 'check_update/check-update.service.erb')
17+
.with(owner: 'root')
18+
.with(group: 'root')
19+
.with(mode: '0644')
20+
end
21+
22+
it 'creates the check-update.timer file' do
23+
is_expected.to create_cookbook_file('/etc/systemd/system/check-update.timer')
24+
.with(source: 'check_update/check-update.timer')
25+
.with(owner: 'root')
26+
.with(group: 'root')
27+
.with(mode: '0644')
28+
end
29+
30+
it 'creates the shared update path file if missing' do
31+
is_expected.to create_file_if_missing(node['cluster']['shared_update_path'])
32+
.with(content: '')
33+
.with(owner: 'root')
34+
.with(group: 'root')
35+
.with(mode: '0644')
36+
end
37+
38+
it 'creates the local update checkpoint file if missing' do
39+
is_expected.to create_file_if_missing(node['cluster']['update_checkpoint'])
40+
.with(content: '')
41+
.with(owner: 'root')
42+
.with(group: 'root')
43+
.with(mode: '0644')
44+
end
45+
46+
it 'enables and starts the check-update.timer service' do
47+
is_expected.to enable_service('check-update.timer')
48+
is_expected.to start_service('check-update.timer')
49+
end
50+
51+
describe 'check-update.service template content' do
52+
it 'has Type=oneshot to prevent concurrent executions' do
53+
is_expected.to render_file('/etc/systemd/system/check-update.service')
54+
.with_content('Type=oneshot')
55+
end
56+
57+
it 'has TimeoutStartSec=30 to handle NFS hangs' do
58+
is_expected.to render_file('/etc/systemd/system/check-update.service')
59+
.with_content('TimeoutStartSec=30')
60+
end
61+
62+
it 'exits gracefully if shared file does not exist' do
63+
is_expected.to render_file('/etc/systemd/system/check-update.service')
64+
.with_content('[ ! -f "$SHARED_FILE" ] && exit 0')
65+
end
66+
67+
it 'exits gracefully if cat fails' do
68+
is_expected.to render_file('/etc/systemd/system/check-update.service')
69+
.with_content('CURRENT_UPDATE=$(cat "$SHARED_FILE") || exit 0')
70+
end
71+
72+
it 'writes checkpoint before running update action' do
73+
is_expected.to render_file('/etc/systemd/system/check-update.service')
74+
.with_content('echo "$CURRENT_UPDATE" > "$LOCAL_CHECKPOINT" && ')
75+
end
76+
77+
it 'references the correct shared update path' do
78+
is_expected.to render_file('/etc/systemd/system/check-update.service')
79+
.with_content("SHARED_FILE=\"#{node['cluster']['shared_update_path']}\"")
80+
end
81+
82+
it 'references the correct local checkpoint path' do
83+
is_expected.to render_file('/etc/systemd/system/check-update.service')
84+
.with_content("LOCAL_CHECKPOINT=\"#{node['cluster']['update_checkpoint']}\"")
85+
end
86+
87+
it 'calls cfn-hup-update-action.sh when update is needed' do
88+
is_expected.to render_file('/etc/systemd/system/check-update.service')
89+
.with_content("#{node['cluster']['scripts_dir']}/cfn-hup-update-action.sh")
90+
end
91+
end
92+
end
93+
end
94+
end

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@
3434
)
3535
end
3636

37+
it 'writes the config version to shared update file' do
38+
is_expected.to create_file(chef_run.node['cluster']['shared_update_path']).with(
39+
content: cluster_config_version,
40+
owner: 'root',
41+
group: 'root',
42+
mode: '0644'
43+
)
44+
end
45+
3746
if are_mount_or_unmount_required
3847
it 'updates the shared storage' do
3948
is_expected.to run_ruby_block("update_shared_storages")

0 commit comments

Comments
 (0)