Skip to content

Commit 1cd0072

Browse files
committed
[Bugfix] Fix logic in function are_queues_updated?.
The function was assuming to be called only during cluster update, leading to cluster creation failure if it gets called on cluster creation. The reason is that it was assuming that the file containing the previous cluster config always exists, which is not the case on cluster creation.
1 parent 7ffb589 commit 1cd0072

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

cookbooks/aws-parallelcluster-slurm/libraries/update.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919
require 'timeout'
2020

2121
# Verify if Scheduling section of cluster configuration and compute node bootstrap_timeout have been updated
22+
# If the previous cluster config file does not exists, it assumes that queues have not been updated.
2223
def are_queues_updated?
2324
require 'yaml'
2425
config = YAML.safe_load(File.read(node['cluster']['cluster_config_path']))
25-
previous_config = YAML.safe_load(File.read(node['cluster']['previous_cluster_config_path']))
26+
previous_cluster_config_path = node['cluster']['previous_cluster_config_path']
27+
return false unless File.exist?(previous_cluster_config_path)
28+
previous_config = YAML.safe_load(File.read(previous_cluster_config_path))
2629
config["Scheduling"] != previous_config["Scheduling"] or is_compute_node_bootstrap_timeout_updated?(previous_config, config)
2730
end
2831

cookbooks/aws-parallelcluster-slurm/spec/unit/libraries/update_spec.rb

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,81 @@
5959
}
6060
include_examples "the correct method", changeset, true
6161
end
62+
63+
describe "aws-parallelcluster-slurm:libraries:are_queues_updated" do
64+
CLUSTER_CONFIG_PATH = "/CLUSTER_CONFIG_PATH".freeze
65+
PREVIOUS_CLUSTER_CONFIG_PATH = "/PREVIOUS_CLUSTER_CONFIG_PATH".freeze
66+
67+
let(:node) do
68+
{
69+
"cluster" => {
70+
"cluster_config_path" => CLUSTER_CONFIG_PATH,
71+
"previous_cluster_config_path" => PREVIOUS_CLUSTER_CONFIG_PATH,
72+
},
73+
}
74+
end
75+
76+
shared_examples "the correct result" do |config, previous_config, file_exists, expected_result|
77+
it "returns #{expected_result}" do
78+
allow(File).to receive(:exist?).with(PREVIOUS_CLUSTER_CONFIG_PATH).and_return(file_exists)
79+
allow(File).to receive(:read).with(CLUSTER_CONFIG_PATH).and_return(YAML.dump(config))
80+
if file_exists
81+
allow(File).to receive(:read).with(PREVIOUS_CLUSTER_CONFIG_PATH).and_return(YAML.dump(previous_config))
82+
end
83+
result = are_queues_updated?
84+
expect(result).to eq(expected_result)
85+
end
86+
end
87+
88+
context "when previous cluster config file does not exist" do
89+
config = {
90+
"Scheduling" => { "SlurmQueues" => [] }
91+
}
92+
previous_config = nil
93+
include_examples "the correct result", config, previous_config, false, false
94+
end
95+
96+
context "when Scheduling sections are identical and bootstrap timeout unchanged" do
97+
config = {
98+
"Scheduling" => { "SlurmQueues" => [{ "Name" => "queue1" }] }
99+
}
100+
previous_config = {
101+
"Scheduling" => { "SlurmQueues" => [{ "Name" => "queue1" }] }
102+
}
103+
include_examples "the correct result", config, previous_config, true, false
104+
end
105+
106+
context "when Scheduling sections are identical and bootstrap timeout is updated" do
107+
config = {
108+
"Scheduling" => { "SlurmQueues" => [{ "Name" => "queue1" }] },
109+
"DevSettings" => { "Timeouts" => { "ComputeNodeBootstrapTimeout" => 3600 } }
110+
}
111+
previous_config = {
112+
"Scheduling" => { "SlurmQueues" => [{ "Name" => "queue1" }] },
113+
"DevSettings" => { "Timeouts" => { "ComputeNodeBootstrapTimeout" => 1800 } }
114+
}
115+
include_examples "the correct result", config, previous_config, true, true
116+
end
117+
118+
context "when Scheduling sections are identical and bootstrap timeout changes from default to explicit value" do
119+
config = {
120+
"Scheduling" => { "SlurmQueues" => [{ "Name" => "queue1" }] },
121+
"DevSettings" => { "Timeouts" => { "ComputeNodeBootstrapTimeout" => 3600 } }
122+
}
123+
previous_config = {
124+
"Scheduling" => { "SlurmQueues" => [{ "Name" => "queue1" }] }
125+
}
126+
include_examples "the correct result", config, previous_config, true, true
127+
end
128+
129+
context "when Scheduling sections are different" do
130+
config = {
131+
"Scheduling" => { "SlurmQueues" => [{ "Name" => "queue2" }] }
132+
}
133+
previous_config = {
134+
"Scheduling" => { "SlurmQueues" => [{ "Name" => "queue1" }] }
135+
}
136+
include_examples "the correct result", config, previous_config, true, true
137+
end
138+
end
62139
end

0 commit comments

Comments
 (0)