Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cookbooks/aws-parallelcluster-slurm/libraries/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
require 'timeout'

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,81 @@
}
include_examples "the correct method", changeset, true
end

describe "aws-parallelcluster-slurm:libraries:are_queues_updated" do
CLUSTER_CONFIG_PATH = "/CLUSTER_CONFIG_PATH".freeze
PREVIOUS_CLUSTER_CONFIG_PATH = "/PREVIOUS_CLUSTER_CONFIG_PATH".freeze

let(:node) do
{
"cluster" => {
"cluster_config_path" => CLUSTER_CONFIG_PATH,
"previous_cluster_config_path" => PREVIOUS_CLUSTER_CONFIG_PATH,
},
}
end

shared_examples "the correct result" do |config, previous_config, file_exists, expected_result|
it "returns #{expected_result}" do
allow(File).to receive(:exist?).with(PREVIOUS_CLUSTER_CONFIG_PATH).and_return(file_exists)
allow(File).to receive(:read).with(CLUSTER_CONFIG_PATH).and_return(YAML.dump(config))
if file_exists
allow(File).to receive(:read).with(PREVIOUS_CLUSTER_CONFIG_PATH).and_return(YAML.dump(previous_config))
end
result = are_queues_updated?
expect(result).to eq(expected_result)
end
end

context "when previous cluster config file does not exist" do
config = {
"Scheduling" => { "SlurmQueues" => [] },
}
previous_config = nil
include_examples "the correct result", config, previous_config, false, false
end

context "when Scheduling sections are identical and bootstrap timeout unchanged" do
config = {
"Scheduling" => { "SlurmQueues" => [{ "Name" => "queue1" }] },
}
previous_config = {
"Scheduling" => { "SlurmQueues" => [{ "Name" => "queue1" }] },
}
include_examples "the correct result", config, previous_config, true, false
end

context "when Scheduling sections are identical and bootstrap timeout is updated" do
config = {
"Scheduling" => { "SlurmQueues" => [{ "Name" => "queue1" }] },
"DevSettings" => { "Timeouts" => { "ComputeNodeBootstrapTimeout" => 3600 } },
}
previous_config = {
"Scheduling" => { "SlurmQueues" => [{ "Name" => "queue1" }] },
"DevSettings" => { "Timeouts" => { "ComputeNodeBootstrapTimeout" => 1800 } },
}
include_examples "the correct result", config, previous_config, true, true
end

context "when Scheduling sections are identical and bootstrap timeout changes from default to explicit value" do
config = {
"Scheduling" => { "SlurmQueues" => [{ "Name" => "queue1" }] },
"DevSettings" => { "Timeouts" => { "ComputeNodeBootstrapTimeout" => 3600 } },
}
previous_config = {
"Scheduling" => { "SlurmQueues" => [{ "Name" => "queue1" }] },
}
include_examples "the correct result", config, previous_config, true, true
end

context "when Scheduling sections are different" do
config = {
"Scheduling" => { "SlurmQueues" => [{ "Name" => "queue2" }] },
}
previous_config = {
"Scheduling" => { "SlurmQueues" => [{ "Name" => "queue1" }] },
}
include_examples "the correct result", config, previous_config, true, true
end
end
end
Loading