Skip to content

Commit 481141c

Browse files
committed
[Test] Add retry helper for flaky InSpec controls. Use such retry logic to make the yum repo check more resilient to transient failures.
1 parent 695ff9a commit 481141c

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

cookbooks/aws-parallelcluster-environment/test/controls/lustre_spec.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@
1919
its('version') { should cmp >= minimal_lustre_client_version }
2020
end
2121

22-
describe yum.repo('aws-fsx') do
23-
it { should exist }
24-
it { should be_enabled }
25-
its('baseurl') { should include 'fsx-lustre-client-repo.s3.amazonaws.com' }
22+
with_retry(retries: 3, delay: 10) do
23+
describe yum.repo('aws-fsx') do
24+
it { should exist }
25+
it { should be_enabled }
26+
its('baseurl') { should include 'fsx-lustre-client-repo.s3.amazonaws.com' }
27+
end
2628
end
2729
end
2830
end
@@ -47,10 +49,12 @@
4749
its('version') { should cmp >= minimal_lustre_client_version }
4850
end
4951

50-
describe yum.repo('aws-fsx') do
51-
it { should exist }
52-
it { should be_enabled }
53-
its('baseurl') { should include 'fsx-lustre-client-repo.s3.amazonaws.com' }
52+
with_retry(retries: 3, delay: 5) do
53+
describe yum.repo('aws-fsx') do
54+
it { should exist }
55+
it { should be_enabled }
56+
its('baseurl') { should include 'fsx-lustre-client-repo.s3.amazonaws.com' }
57+
end
5458
end
5559
end
5660
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Helper method to retry flaky InSpec checks
2+
def with_retry(retries: 3, delay: 5)
3+
attempts = 0
4+
begin
5+
attempts += 1
6+
yield
7+
rescue => e
8+
if attempts < retries
9+
sleep delay
10+
retry
11+
else
12+
raise e
13+
end
14+
end
15+
end

0 commit comments

Comments
 (0)