Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Settings hierarchy on Global region #20299

Merged
merged 6 commits into from
Jun 29, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/miq_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ def tenant_identity
end

def miq_region
::MiqRegion.my_region
MiqRegion.find_by(:region => region_id)
end

def self.display_name(number = 1)
Expand Down
41 changes: 41 additions & 0 deletions spec/lib/vmdb/settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,47 @@
settings = Vmdb::Settings.for_resource(MiqServer.new(:zone => server.zone))
expect(settings.api.token_ttl).to eq "4.hour"
end

context "on global region" do
let(:key) { "yuri" }
let(:value_region_remote) { "region_remote" }
let(:value_server_remote) { "server_remote" }

before do
Zone.seed
@region_global = MiqRegion.first
@region_remote = FactoryBot.create(:miq_region, :id => ApplicationRecord.id_in_region(1, @region_global.region + 1))
@zone_remote = FactoryBot.create(:zone, :id => ApplicationRecord.id_in_region(2, @region_remote.region))
@server_remote = FactoryBot.create(:miq_server, :zone => @zone_remote, :id => ApplicationRecord.id_in_region(1, @region_remote.region))
SettingsChange.create!(:id => ApplicationRecord.id_in_region(1, @region_global.region),
:resource_id => @region_global.id,
:resource_type => "MiqRegion",
:key => "/#{key}",
:value => "value from global region")
end

after do
SettingsChange.delete_all
Fryguy marked this conversation as resolved.
Show resolved Hide resolved
end

it "applies settings from remote sever if there are specified" do
SettingsChange.create!(:id => ApplicationRecord.id_in_region(1, @region_remote.region),
:resource_id => @server_remote.id,
:resource_type => "MiqServer",
:key => "/#{key}",
:value => value_server_remote)
expect(Vmdb::Settings.for_resource(@server_remote)[key]).to eq(value_server_remote)
end

it "applies settings from remote region if settings on remote server not specified" do
Fryguy marked this conversation as resolved.
Show resolved Hide resolved
SettingsChange.create!(:id => ApplicationRecord.id_in_region(1, @region_remote.region),
:resource_id => @region_remote.id,
:resource_type => "MiqRegion",
:key => "/#{key}",
:value => value_region_remote)
expect(Vmdb::Settings.for_resource(@server_remote)[key]).to eq(value_region_remote)
end
end
end

describe ".for_resource_yaml" do
Expand Down
17 changes: 17 additions & 0 deletions spec/models/miq_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,23 @@
end
end

describe "#miq_region" do
before do
Zone.seed
@region1 = MiqRegion.first.region
@region2 = FactoryBot.create(:miq_region, :id => MiqRegion.id_in_region(1, @region1 + 1)).region
zone = FactoryBot.create(:zone, :id => Zone.id_in_region(2, @region2))

@server1 = FactoryBot.create(:miq_server)
@server2 = FactoryBot.create(:miq_server, :zone => zone, :id => MiqServer.id_in_region(1, @region2))
end

it "returns region this server belongs to" do
expect(@server1.miq_region.region).to eq(@region1)
expect(@server2.miq_region.region).to eq(@region2)
end
end

describe ".zone_is_modifiable?" do
it "is true when there are multiple zones in the region" do
FactoryBot.create(:miq_server)
Expand Down