Skip to content

Commit

Permalink
Refactor regions spec to not hard-code atypical regions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
agrare committed Oct 26, 2023
1 parent 4e44a00 commit 8c13c5c
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions spec/models/manageiq/providers/amazon/regions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8c13c5c

Please sign in to comment.