From e1b1a4ef003026103ac38defc53427aab8806614 Mon Sep 17 00:00:00 2001 From: Giacomo Marciani Date: Fri, 24 May 2024 11:57:27 +0200 Subject: [PATCH] [Storage][IsolatedRegions] Adapt FSxLustre DNS domain for US isolated regions. Signed-off-by: Giacomo Marciani --- .../libraries/fsx.rb | 4 ++++ .../lustre/partial/_mount_unmount.rb | 4 ++-- .../spec/unit/resources/lustre_mount_spec.rb | 21 ++++++++++++------- 3 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 cookbooks/aws-parallelcluster-environment/libraries/fsx.rb diff --git a/cookbooks/aws-parallelcluster-environment/libraries/fsx.rb b/cookbooks/aws-parallelcluster-environment/libraries/fsx.rb new file mode 100644 index 000000000..397335aa8 --- /dev/null +++ b/cookbooks/aws-parallelcluster-environment/libraries/fsx.rb @@ -0,0 +1,4 @@ +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 +end diff --git a/cookbooks/aws-parallelcluster-environment/resources/lustre/partial/_mount_unmount.rb b/cookbooks/aws-parallelcluster-environment/resources/lustre/partial/_mount_unmount.rb index 58ee34ee8..7745329e7 100644 --- a/cookbooks/aws-parallelcluster-environment/resources/lustre/partial/_mount_unmount.rb +++ b/cookbooks/aws-parallelcluster-environment/resources/lustre/partial/_mount_unmount.rb @@ -109,8 +109,8 @@ def initialize(node, resource, index) @volume_junction_path = self.class.make_absolute(resource.fsx_volume_junction_path_array[index]) if @dns_name.blank? - # Region Building Note: DNS names have the default AWS domain (amazonaws.com) also in China and GovCloud. - @dns_name = "#{@id}.fsx.#{node['cluster']['region']}.amazonaws.com" + region = node['cluster']['region'] + @dns_name = "#{@id}.fsx.#{region}.#{aws_domain_for_fsx(region)}" end @mount_name = resource.fsx_mount_name_array[index] diff --git a/cookbooks/aws-parallelcluster-environment/spec/unit/resources/lustre_mount_spec.rb b/cookbooks/aws-parallelcluster-environment/spec/unit/resources/lustre_mount_spec.rb index 75db5fa1e..6e3a52f79 100644 --- a/cookbooks/aws-parallelcluster-environment/spec/unit/resources/lustre_mount_spec.rb +++ b/cookbooks/aws-parallelcluster-environment/spec/unit/resources/lustre_mount_spec.rb @@ -29,6 +29,7 @@ before do stub_command("mount | grep ' /lustre_shared_dir_with_no_mount '").and_return(false) stub_command("mount | grep ' /lustre_shared_dir_with_mount '").and_return(true) + allow_any_instance_of(Object).to receive(:aws_domain_for_fsx).and_return("AWS_DOMAIN_FOR_FSX") end it 'creates_shared_dir' do @@ -58,7 +59,7 @@ it 'enables shared dir mount if already mounted' do is_expected.to enable_mount('/lustre_shared_dir_with_mount') - .with(device: 'lustre_id_2.fsx.REGION.amazonaws.com@tcp:/lustre_mount_name_2') + .with(device: 'lustre_id_2.fsx.REGION.AWS_DOMAIN_FOR_FSX@tcp:/lustre_mount_name_2') .with(fstype: 'lustre') .with(dump: 0) .with(pass: 0) @@ -113,6 +114,7 @@ before do stub_command("mount | grep ' /filecache_shared_dir_1 '").and_return(false) stub_command("mount | grep ' /filecache_shared_dir_2 '").and_return(true) + allow_any_instance_of(Object).to receive(:aws_domain_for_fsx).and_return("AWS_DOMAIN_FOR_FSX") end it 'creates_shared_dir' do @@ -196,6 +198,7 @@ before do stub_command("mount | grep ' /openzfs_shared_dir_1 '").and_return(false) stub_command("mount | grep ' /openzfs_shared_dir_2 '").and_return(true) + allow_any_instance_of(Object).to receive(:aws_domain_for_fsx).and_return("AWS_DOMAIN_FOR_FSX") end it 'creates_shared_dir' do @@ -225,7 +228,7 @@ it 'enables shared dir mount if already mounted' do is_expected.to enable_mount('/openzfs_shared_dir_2') - .with(device: 'openzfs_id_2.fsx.REGION.amazonaws.com:/junction_path_2') + .with(device: 'openzfs_id_2.fsx.REGION.AWS_DOMAIN_FOR_FSX:/junction_path_2') .with(fstype: 'nfs') .with(dump: 0) .with(pass: 0) @@ -272,6 +275,7 @@ before do stub_command("mount | grep ' /ontap_shared_dir_1 '").and_return(false) stub_command("mount | grep ' /ontap_shared_dir_2 '").and_return(true) + allow_any_instance_of(Object).to receive(:aws_domain_for_fsx).and_return("AWS_DOMAIN_FOR_FSX") end it 'creates_shared_dir' do @@ -301,7 +305,7 @@ it 'enables shared dir mount if already mounted' do is_expected.to enable_mount('/ontap_shared_dir_2') - .with(device: 'ontap_id_2.fsx.REGION.amazonaws.com:/junction_path_2') + .with(device: 'ontap_id_2.fsx.REGION.AWS_DOMAIN_FOR_FSX:/junction_path_2') .with(fstype: 'nfs') .with(dump: 0) .with(pass: 0) @@ -366,6 +370,7 @@ allow(Dir).to receive(:empty?).with("/shared_dir_1").and_return(true) allow(Dir).to receive(:exist?).with("/shared_dir_2").and_return(true) allow(Dir).to receive(:empty?).with("/shared_dir_2").and_return(false) + allow_any_instance_of(Object).to receive(:aws_domain_for_fsx).and_return("AWS_DOMAIN_FOR_FSX") end it 'unmounts fsx only if mounted' do @@ -383,9 +388,9 @@ .with(path: "/etc/fstab") .with(pattern: "dns_name@tcp:/mount_name_1 *") - is_expected.to edit_delete_lines('remove volume lustre_id_2.fsx.REGION.amazonaws.com@tcp:/mount_name_2 from /etc/fstab') + is_expected.to edit_delete_lines('remove volume lustre_id_2.fsx.REGION.AWS_DOMAIN_FOR_FSX@tcp:/mount_name_2 from /etc/fstab') .with(path: "/etc/fstab") - .with(pattern: "lustre_id_2.fsx.REGION.amazonaws.com@tcp:/mount_name_2 *") + .with(pattern: "lustre_id_2.fsx.REGION.AWS_DOMAIN_FOR_FSX@tcp:/mount_name_2 *") end it 'deletes shared dir only if it exists and it is empty' do @@ -423,6 +428,7 @@ allow(Dir).to receive(:empty?).with("/shared_dir_1").and_return(true) allow(Dir).to receive(:exist?).with("/shared_dir_2").and_return(true) allow(Dir).to receive(:empty?).with("/shared_dir_2").and_return(false) + allow_any_instance_of(Object).to receive(:aws_domain_for_fsx).and_return("AWS_DOMAIN_FOR_FSX") end it 'unmounts fsx only if mounted' do @@ -440,9 +446,9 @@ .with(path: "/etc/fstab") .with(pattern: "dns_name:/junction_path_1 *") - is_expected.to edit_delete_lines('remove volume ontap_id_2.fsx.REGION.amazonaws.com:/junction_path_2 from /etc/fstab') + is_expected.to edit_delete_lines('remove volume ontap_id_2.fsx.REGION.AWS_DOMAIN_FOR_FSX:/junction_path_2 from /etc/fstab') .with(path: "/etc/fstab") - .with(pattern: "ontap_id_2.fsx.REGION.amazonaws.com:/junction_path_2 *") + .with(pattern: "ontap_id_2.fsx.REGION.AWS_DOMAIN_FOR_FSX:/junction_path_2 *") end it 'deletes shared dir only if it exists and it is empty' do @@ -480,6 +486,7 @@ allow(Dir).to receive(:empty?).with("/filecache_dir_1").and_return(true) allow(Dir).to receive(:exist?).with("/filecache_dir_2").and_return(true) allow(Dir).to receive(:empty?).with("/filecache_dir_2").and_return(false) + allow_any_instance_of(Object).to receive(:aws_domain_for_fsx).and_return("AWS_DOMAIN_FOR_FSX") end it 'unmounts fsx only if mounted' do