From c31d7e0e80dedaac2a273e1656c8cb92baf642c8 Mon Sep 17 00:00:00 2001 From: Giacomo Marciani Date: Fri, 19 Dec 2025 11:50:42 -0500 Subject: [PATCH] [Test] Add retry helper for flaky InSpec controls. Use such retry logic to make the yum repo check more resilient to transient failures. --- .../test/controls/lustre_spec.rb | 20 +++++++++++-------- .../test/libraries/retry_helper.rb | 15 ++++++++++++++ 2 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 cookbooks/aws-parallelcluster-shared/test/libraries/retry_helper.rb diff --git a/cookbooks/aws-parallelcluster-environment/test/controls/lustre_spec.rb b/cookbooks/aws-parallelcluster-environment/test/controls/lustre_spec.rb index 0d1f5b707d..616ed9fc5a 100644 --- a/cookbooks/aws-parallelcluster-environment/test/controls/lustre_spec.rb +++ b/cookbooks/aws-parallelcluster-environment/test/controls/lustre_spec.rb @@ -19,10 +19,12 @@ its('version') { should cmp >= minimal_lustre_client_version } end - describe yum.repo('aws-fsx') do - it { should exist } - it { should be_enabled } - its('baseurl') { should include 'fsx-lustre-client-repo.s3.amazonaws.com' } + with_retry(retries: 3, delay: 5) do + describe yum.repo('aws-fsx') do + it { should exist } + it { should be_enabled } + its('baseurl') { should include 'fsx-lustre-client-repo.s3.amazonaws.com' } + end end end end @@ -47,10 +49,12 @@ its('version') { should cmp >= minimal_lustre_client_version } end - describe yum.repo('aws-fsx') do - it { should exist } - it { should be_enabled } - its('baseurl') { should include 'fsx-lustre-client-repo.s3.amazonaws.com' } + with_retry(retries: 3, delay: 5) do + describe yum.repo('aws-fsx') do + it { should exist } + it { should be_enabled } + its('baseurl') { should include 'fsx-lustre-client-repo.s3.amazonaws.com' } + end end end end diff --git a/cookbooks/aws-parallelcluster-shared/test/libraries/retry_helper.rb b/cookbooks/aws-parallelcluster-shared/test/libraries/retry_helper.rb new file mode 100644 index 0000000000..618c32a550 --- /dev/null +++ b/cookbooks/aws-parallelcluster-shared/test/libraries/retry_helper.rb @@ -0,0 +1,15 @@ +# Helper method to retry flaky InSpec checks +def with_retry(retries: 3, delay: 5) + attempts = 0 + begin + attempts += 1 + yield + rescue => e + if attempts < retries + sleep delay + retry + else + raise e + end + end +end