Skip to content

Commit a177b5d

Browse files
committed
[DFSM] Make the check 'are_mount_or_unmount_required?' resilient to the lack of the changeset file.
In particular, we consider mount/unmount not required if the change-set file is missing. Signed-off-by: Giacomo Marciani <[email protected]>
1 parent 34340ba commit a177b5d

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ def are_bulk_custom_slurm_settings_updated?
3636

3737
def are_mount_or_unmount_required?
3838
require 'json'
39-
change_set = JSON.load_file("#{node['cluster']['shared_dir']}/change-set.json")
39+
40+
change_set_path = node["cluster"]["change_set_path"]
41+
42+
return false unless ::File.exist?(change_set_path)
43+
44+
change_set = JSON.load_file(change_set_path)
4045
change_set["changeSet"].each do |change|
4146
next unless change["updatePolicy"] == "SHARED_STORAGE_UPDATE_POLICY"
4247

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11
require 'spec_helper'
22

33
describe "aws-parallelcluster-slurm:libraries:are_mount_unmount_required" do
4+
CHANGE_SET_PATH = "/CHANGE_SET_PATH"
5+
46
let(:node) do
57
{
6-
"cluster" => { "shared_dir" => "/SHARED_DIR" },
8+
"cluster" => { "change_set_path" => CHANGE_SET_PATH },
79
}
810
end
911

1012
shared_examples "the correct method" do |changeset, expected_result|
1113
it "returns #{expected_result}" do
12-
allow(File).to receive(:read).with("/SHARED_DIR/change-set.json").and_return(JSON.dump(changeset))
14+
if changeset.nil?
15+
allow(File).to receive(:exist?).with(CHANGE_SET_PATH).and_return(false)
16+
allow(File).to receive(:read).with(CHANGE_SET_PATH).and_call_original
17+
else
18+
allow(File).to receive(:exist?).with(CHANGE_SET_PATH).and_return(true)
19+
allow(File).to receive(:read).with(CHANGE_SET_PATH).and_return(JSON.dump(changeset))
20+
end
1321
result = are_mount_or_unmount_required?
1422
expect(result).to eq(expected_result)
1523
end
1624
end
1725

26+
context "when changeset does not exist" do
27+
changeset = nil
28+
include_examples "the correct method", changeset, false
29+
end
30+
1831
context "when changeset is empty" do
1932
changeset = {
2033
"changeSet" => [],

0 commit comments

Comments
 (0)