From 7123b54921585b715559102a7fcc5ee3c57d2037 Mon Sep 17 00:00:00 2001 From: Giacomo Marciani Date: Thu, 30 May 2024 17:38:37 +0200 Subject: [PATCH] [Storage] Fix method used to get the AWS domain for FSx. In particular, now it does not need anymore to access the undefined node attribute in US ISO regions. Signed-off-by: Giacomo Marciani --- .../libraries/fsx.rb | 8 ++++- .../spec/unit/libraries/fsx_spec.rb | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 cookbooks/aws-parallelcluster-environment/spec/unit/libraries/fsx_spec.rb diff --git a/cookbooks/aws-parallelcluster-environment/libraries/fsx.rb b/cookbooks/aws-parallelcluster-environment/libraries/fsx.rb index 397335aa8..dc5909f41 100644 --- a/cookbooks/aws-parallelcluster-environment/libraries/fsx.rb +++ b/cookbooks/aws-parallelcluster-environment/libraries/fsx.rb @@ -1,4 +1,10 @@ def aws_domain_for_fsx(region) # DNS names have the default AWS domain (amazonaws.com) also in China and GovCloud. - region.start_with?("us-iso") ? aws_domain : CLASSIC_AWS_DOMAIN + if region.start_with?("us-iso-") + US_ISO_AWS_DOMAIN + elsif region.start_with?("us-isob-") + US_ISOB_AWS_DOMAIN + else + CLASSIC_AWS_DOMAIN + end end diff --git a/cookbooks/aws-parallelcluster-environment/spec/unit/libraries/fsx_spec.rb b/cookbooks/aws-parallelcluster-environment/spec/unit/libraries/fsx_spec.rb new file mode 100644 index 000000000..9b4c853f2 --- /dev/null +++ b/cookbooks/aws-parallelcluster-environment/spec/unit/libraries/fsx_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe 'aws-parallelcluster-environment:libraries:aws_domain_for_fsx' do + shared_examples 'a valid aws_domain_for_fsx function' do |region, expected_aws_domain| + it 'returns the correct AWS domain' do + result = aws_domain_for_fsx(region) + expect(result).to eq(expected_aws_domain) + end + end + + context 'when in US-ISO region' do + include_examples 'a valid aws_domain_for_fsx function', 'us-iso-WHATEVER', 'c2s.ic.gov' + end + + context 'when in US-ISOB region' do + include_examples 'a valid aws_domain_for_fsx function', 'us-isob-', 'sc2s.sgov.gov' + end + + context 'when in CN region' do + include_examples 'a valid aws_domain_for_fsx function', 'cn-WHATEVER', 'amazonaws.com' + end + + context 'when in GovCloud region' do + include_examples 'a valid aws_domain_for_fsx function', 'us-gov-WHATEVER', 'amazonaws.com' + end + + context 'when in whatever else region' do + include_examples 'a valid aws_domain_for_fsx function', 'WHATEVER-ELSE', 'amazonaws.com' + end +end