From 8c13c5ca322046029a74e5d7d72f2e93c5c65675 Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Thu, 26 Oct 2023 13:24:31 -0400 Subject: [PATCH] Refactor regions spec to not hard-code atypical regions The regions spec has a hard-coded list of "atypical regions" which really just means regions which exist but are not available to us via the aws-sdk `describe_regions` API call. It would be simpler to just check that all of the regions that we do have access to are in the regions list. This would allow us to update the `config/regions.yml` list in an automated way. --- .../manageiq/providers/amazon/regions_spec.rb | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/spec/models/manageiq/providers/amazon/regions_spec.rb b/spec/models/manageiq/providers/amazon/regions_spec.rb index ad95f603..d68e1686 100644 --- a/spec/models/manageiq/providers/amazon/regions_spec.rb +++ b/spec/models/manageiq/providers/amazon/regions_spec.rb @@ -5,36 +5,23 @@ # https://github.com/aws/aws-sdk-ruby/blob/5fe5795e8910bb667996dfc75e4f16b7e69e3980/gems/aws-partitions/partitions.json#L11 ordinary_regions_regexp = /^(us|eu|ap|sa|ca)\-\w+\-\d+$/ - # https://docs.aws.amazon.com/general/latest/gr/rande.html - see quotes below - atypical_regions = [ - 'ap-east-1', # "you must manually enable before you can use..." - 'ap-south-2', - 'ap-southeast-3', - 'ap-southeast-4', - 'eu-central-2', - 'eu-south-1', - 'eu-south-2' - ] - current_regions = described_class.regions.reject do |name, _config| - atypical_regions.include?(name) || name !~ ordinary_regions_regexp + name !~ ordinary_regions_regexp end.map do |_name, config| {:region_name => config[:name], :endpoint => config[:hostname]} end online_regions = VCR.use_cassette(described_class.name.underscore) do - ems.connect.client.describe_regions.to_h[:regions] + ems.connect.client.describe_regions.to_h[:regions].map { |r| r.slice(:region_name, :endpoint) } end - online_regions.each { |r| r.delete(:opt_in_status) } - # sort for better diff [current_regions, online_regions].each do |regions| regions.map! { |r| r.sort.to_h } regions.sort_by! { |r| r[:region_name] } end - expect(online_regions).to eq(current_regions) + expect(current_regions).to include(*online_regions) end context "disable regions via Settings" do