Skip to content

Commit

Permalink
Merge pull request #89 from agrare/bz_1389068_custom_regions
Browse files Browse the repository at this point in the history
Allow additional_regions to be specified in settings
  • Loading branch information
durandom authored Dec 15, 2016
2 parents 07feb3e + 96722e0 commit 771d65a
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/models/manageiq/providers/amazon/regions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ module Regions
}

def self.regions
REGIONS.except(*Array(Settings.ems.ems_amazon.try!(:disabled_regions)))
additional_regions = Hash(Settings.ems.ems_amazon.try!(:additional_regions)).stringify_keys
disabled_regions = Array(Settings.ems.ems_amazon.try!(:disabled_regions))

REGIONS.merge(additional_regions).except(*disabled_regions)
end

def self.regions_by_hostname
Expand Down
60 changes: 60 additions & 0 deletions spec/models/manageiq/providers/amazon/regions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,64 @@
expect(described_class.names).not_to include('us-gov-west-1')
end
end

context "add regions via settings" do
context "with no additional regions set" do
let(:settings) do
{:ems => {:ems_amazon => {:additional_regions => nil}}}
end

it "returns standard regions" do
stub_settings(settings)
expect(described_class.names).to eql(described_class::REGIONS.keys)
end
end

context "with one additional" do
let(:settings) do
{
:ems => {
:ems_amazon => {
:additional_regions => {
:"my-custom-region" => {
:name => "My First Custom Region"
}
}
}
}
}
end

it "returns the custom regions" do
stub_settings(settings)
expect(described_class.names).to include("my-custom-region")
end
end

context "with additional regions and disabled regions" do
let(:settings) do
{
:ems => {
:ems_amazon => {
:disabled_regions => ["my-custom-region-2"],
:additional_regions => {
:"my-custom-region-1" => {
:name => "My First Custom Region"
},
:"my-custom-region-2" => {
:name => "My Second Custom Region"
}
}
}
}
}
end

it "disabled_regions overrides additional_regions" do
stub_settings(settings)
expect(described_class.names).to include("my-custom-region-1")
expect(described_class.names).not_to include("my-custom-region-2")
end
end
end
end

0 comments on commit 771d65a

Please sign in to comment.