Skip to content

Commit

Permalink
Merge pull request #17670 from bdunne/only_contact_active_ws_servers
Browse files Browse the repository at this point in the history
Scope ui and api server searches to recently active servers

(cherry picked from commit ebfcf7c)
https://bugzilla.redhat.com/show_bug.cgi?id=1607409
  • Loading branch information
gtanzillo authored and bdunne committed Sep 12, 2018
1 parent b28bb84 commit f3f54de
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/models/miq_region.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def role_assigned?(role_name)
end

def remote_ui_miq_server
MiqServer.in_region(region).find_by(:has_active_userinterface => true)
MiqServer.in_region(region).recently_active.find_by(:has_active_userinterface => true)
end

def remote_ui_ipaddress
Expand All @@ -225,7 +225,7 @@ def remote_ui_url(contact_with = :hostname)
end

def remote_ws_miq_server
MiqServer.in_region(region).find_by(:has_active_webservices => true)
MiqServer.in_region(region).recently_active.find_by(:has_active_webservices => true)
end

def remote_ws_address
Expand Down
2 changes: 2 additions & 0 deletions app/models/miq_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class MiqServer < ApplicationRecord

virtual_column :zone_description, :type => :string

scope :active_miq_servers, -> { where(:status => STATUSES_ACTIVE) }
scope :recently_active, -> { where(:last_heartbeat => 10.minutes.ago.utc...Time.now.utc) }
scope :with_zone_id, ->(zone_id) { where(:zone_id => zone_id) }

STATUS_STARTING = 'starting'.freeze
Expand Down
88 changes: 77 additions & 11 deletions spec/models/miq_region_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,22 +191,88 @@
end

describe "#remote_ws_url" do
let(:ip) { "1.1.1.94" }
let(:hostname) { "www.manageiq.org" }
let(:url) { "https://www.manageiq.org" }
let!(:web_server) do
FactoryGirl.create(:miq_server, :has_active_webservices => true,
:hostname => hostname,
:ipaddress => ip)

context "with a recently active server" do
let(:ip) { "1.1.1.94" }
let(:url) { "https://www.manageiq.org" }
let!(:web_server) do
FactoryGirl.create(:miq_server, :has_active_webservices => true,
:hostname => hostname,
:ipaddress => ip)
end

it "fetches the url from server" do
expect(region.remote_ws_url).to eq("https://#{ip}")
end

it "fetches the url from the setting" do
Vmdb::Settings.save!(web_server, :webservices => {:url => url})
expect(region.remote_ws_url).to eq(url)
end
end

it "with no recently active servers" do
FactoryGirl.create(:miq_server, :has_active_webservices => true, :hostname => hostname, :last_heartbeat => 11.minutes.ago.utc)

expect(region.remote_ws_url).to be_nil
end
end

describe "#remote_ui_url" do
let(:hostname) { "www.manageiq.org" }

context "with a recently active server" do
let(:ip) { "1.1.1.94" }
let(:url) { "http://localhost:3000" }
let!(:ui_server) do
FactoryGirl.create(:miq_server, :has_active_userinterface => true,
:hostname => hostname,
:ipaddress => ip)
end

it "fetches the url from server" do
expect(region.remote_ui_url).to eq("https://#{hostname}")
end

it "fetches the url from the setting" do
Vmdb::Settings.save!(ui_server, :ui => {:url => url})
expect(region.remote_ui_url).to eq(url)
end
end

it "with no recently active servers" do
FactoryGirl.create(:miq_server, :has_active_userinterface => true, :hostname => hostname, :last_heartbeat => 11.minutes.ago.utc)

expect(region.remote_ws_url).to be_nil
end
end

describe "#remote_ui_miq_server" do
it "with no recently active servers" do
server = FactoryGirl.create(:miq_server, :has_active_userinterface => true, :hostname => "example.com")

expect(region.remote_ui_miq_server).to eq(server)
end

it "with no recently active servers" do
FactoryGirl.create(:miq_server, :has_active_userinterface => true, :hostname => "example.com", :last_heartbeat => 1.month.ago.utc)

expect(region.remote_ui_miq_server).to be_nil
end
end

it "fetches the url from server" do
expect(region.remote_ws_url).to eq("https://#{ip}")
describe "#remote_ws_miq_server" do
it "with no recently active servers" do
server = FactoryGirl.create(:miq_server, :has_active_webservices => true, :hostname => "example.com")

expect(region.remote_ws_miq_server).to eq(server)
end

it "fetches the url from the setting" do
Vmdb::Settings.save!(web_server, :webservices => {:url => url})
expect(region.remote_ws_url).to eq(url)
it "with no recently active servers" do
FactoryGirl.create(:miq_server, :has_active_webservices => true, :hostname => "example.com", :last_heartbeat => 1.month.ago.utc)

expect(region.remote_ws_miq_server).to be_nil
end
end
end

0 comments on commit f3f54de

Please sign in to comment.