Skip to content

Commit 40203f1

Browse files
committed
[Storage] Delete the shared directory only if the directory exists and it is empty.
We introduce the condition of existence because otherwise, the empty condition may fail when the directory does not exist. Signed-off-by: Giacomo Marciani <mgiacomo@amazon.com>
1 parent ba3e041 commit 40203f1

File tree

6 files changed

+19
-9
lines changed

6 files changed

+19
-9
lines changed

cookbooks/aws-parallelcluster-environment/resources/efs/partial/_mount_umount.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
mode '1777'
121121
recursive false
122122
action :delete
123-
only_if { Dir.empty?(efs_shared_dir.to_s) }
123+
only_if { Dir.exist?(efs_shared_dir.to_s) && Dir.empty?(efs_shared_dir.to_s) }
124124
end
125125
end
126126
end

cookbooks/aws-parallelcluster-environment/resources/lustre/partial/_mount_unmount.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
mode '1777'
9393
recursive false
9494
action :delete
95-
only_if { Dir.empty?(fsx.shared_dir) }
95+
only_if { Dir.exist?(fsx.shared_dir) && Dir.empty?(fsx.shared_dir) }
9696
end
9797
end
9898
end

cookbooks/aws-parallelcluster-environment/resources/volume.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
directory shared_dir do
115115
recursive false
116116
action :delete
117-
only_if { Dir.empty?(shared_dir) }
117+
only_if { Dir.exist?(shared_dir) && Dir.empty?(shared_dir) }
118118
end
119119
end
120120

cookbooks/aws-parallelcluster-environment/spec/unit/resources/efs_spec.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,9 @@ def mock_already_installed(package, expected_version, installed)
355355
before do
356356
stub_command("mount | grep ' /shared_dir_1 '").and_return(false)
357357
stub_command("mount | grep ' /shared_dir_2 '").and_return(true)
358+
allow(Dir).to receive(:exist?).with("/shared_dir_1").and_return(true)
358359
allow(Dir).to receive(:empty?).with("/shared_dir_1").and_return(true)
360+
allow(Dir).to receive(:exist?).with("/shared_dir_2").and_return(true)
359361
allow(Dir).to receive(:empty?).with("/shared_dir_2").and_return(false)
360362
end
361363

@@ -382,7 +384,7 @@ def mock_already_installed(package, expected_version, installed)
382384
end
383385
end
384386

385-
it "deletes shared dir only if empty" do
387+
it "deletes shared dir only if it exists and it is empty" do
386388
is_expected.to delete_directory('/shared_dir_1')
387389
.with(recursive: false)
388390

cookbooks/aws-parallelcluster-environment/spec/unit/resources/lustre_mount_spec.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,9 @@
362362
before do
363363
stub_command("mount | grep ' /shared_dir_1 '").and_return(false)
364364
stub_command("mount | grep ' /shared_dir_2 '").and_return(true)
365+
allow(Dir).to receive(:exist?).with("/shared_dir_1").and_return(true)
365366
allow(Dir).to receive(:empty?).with("/shared_dir_1").and_return(true)
367+
allow(Dir).to receive(:exist?).with("/shared_dir_2").and_return(true)
366368
allow(Dir).to receive(:empty?).with("/shared_dir_2").and_return(false)
367369
end
368370

@@ -386,7 +388,7 @@
386388
.with(pattern: "lustre_id_2.fsx.REGION.amazonaws.com@tcp:/mount_name_2 *")
387389
end
388390

389-
it 'deletes shared dir only if empty' do
391+
it 'deletes shared dir only if it exists and it is empty' do
390392
is_expected.to delete_directory('/shared_dir_1')
391393
.with(recursive: false)
392394
is_expected.not_to delete_directory('/shared_dir_2')
@@ -417,7 +419,9 @@
417419
before do
418420
stub_command("mount | grep ' /shared_dir_1 '").and_return(false)
419421
stub_command("mount | grep ' /shared_dir_2 '").and_return(true)
422+
allow(Dir).to receive(:exist?).with("/shared_dir_1").and_return(true)
420423
allow(Dir).to receive(:empty?).with("/shared_dir_1").and_return(true)
424+
allow(Dir).to receive(:exist?).with("/shared_dir_2").and_return(true)
421425
allow(Dir).to receive(:empty?).with("/shared_dir_2").and_return(false)
422426
end
423427

@@ -441,7 +445,7 @@
441445
.with(pattern: "ontap_id_2.fsx.REGION.amazonaws.com:/junction_path_2 *")
442446
end
443447

444-
it 'deletes shared dir only if empty' do
448+
it 'deletes shared dir only if it exists and it is empty' do
445449
is_expected.to delete_directory('/shared_dir_1')
446450
.with(recursive: false)
447451
is_expected.not_to delete_directory('/shared_dir_2')
@@ -472,7 +476,9 @@
472476
before do
473477
stub_command("mount | grep ' /filecache_dir_1 '").and_return(false)
474478
stub_command("mount | grep ' /filecache_dir_2 '").and_return(true)
479+
allow(Dir).to receive(:exist?).with("/filecache_dir_1").and_return(true)
475480
allow(Dir).to receive(:empty?).with("/filecache_dir_1").and_return(true)
481+
allow(Dir).to receive(:exist?).with("/filecache_dir_2").and_return(true)
476482
allow(Dir).to receive(:empty?).with("/filecache_dir_2").and_return(false)
477483
end
478484

@@ -496,7 +502,7 @@
496502
.with(pattern: "filecache_dns_name_2@tcp:/filecache_mount_name_2 *")
497503
end
498504

499-
it 'deletes shared dir only if empty' do
505+
it 'deletes shared dir only if it exists and it is empty' do
500506
is_expected.to delete_directory('/filecache_dir_1')
501507
.with(recursive: false)
502508
is_expected.not_to delete_directory('/filecache_dir_2')

cookbooks/aws-parallelcluster-environment/spec/unit/resources/volume_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134

135135
before do
136136
stub_command("mount | grep ' /SHARED_DIR '").and_return(false)
137+
allow(Dir).to receive(:exist?).with("/SHARED_DIR").and_return(true)
137138
allow(Dir).to receive(:empty?).with("/SHARED_DIR").and_return(is_dir_empty)
138139
end
139140

@@ -147,7 +148,7 @@
147148
.with(pattern: " /SHARED_DIR ")
148149
end
149150

150-
it "deletes shared dir only if empty" do
151+
it "deletes shared dir only if it exists and it is empty" do
151152
if is_dir_empty
152153
is_expected.to delete_directory('/SHARED_DIR')
153154
.with(recursive: false)
@@ -174,6 +175,7 @@
174175

175176
before do
176177
stub_command("mount | grep ' /SHARED_DIR '").and_return(true)
178+
allow(Dir).to receive(:exist?).with("/SHARED_DIR").and_return(true)
177179
allow(Dir).to receive(:empty?).with("/SHARED_DIR").and_return(is_dir_empty)
178180
end
179181

@@ -189,7 +191,7 @@
189191
.with(pattern: " /SHARED_DIR ")
190192
end
191193

192-
it "deletes shared dir only if empty" do
194+
it "deletes shared dir only if it exists and it is empty" do
193195
if is_dir_empty
194196
is_expected.to delete_directory('/SHARED_DIR')
195197
.with(recursive: false)

0 commit comments

Comments
 (0)