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

Scope ui and api server searches to recently active servers #17670

Merged
merged 2 commits into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
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 @@ -229,7 +229,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
1 change: 1 addition & 0 deletions app/models/miq_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class MiqServer < ApplicationRecord
default_value_for(:zone) { Zone.default_zone }

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) }
delegate :description, :to => :zone, :prefix => true

Expand Down
92 changes: 69 additions & 23 deletions spec/models/miq_region_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,42 +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)
end

it "fetches the url from server" do
expect(region.remote_ws_url).to eq("https://#{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 "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 => hostname, :last_heartbeat => 11.minutes.ago.utc)

expect(region.remote_ws_url).to be_nil
end
end

describe "#remote_ui_url" do
let(:ip) { "1.1.1.94" }
let(:hostname) { "www.manageiq.org" }
let(:url) { "http://localhost:3000" }
let!(:ui_server) do
FactoryGirl.create(:miq_server, :has_active_userinterface => true,
:hostname => hostname,
:ipaddress => ip)

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 "fetches the url from server" do
expect(region.remote_ui_url).to eq("https://#{hostname}")
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

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 "with no recently active servers" do
FactoryGirl.create(:miq_server, :has_active_webservices => true, :hostname => "example.com", :last_heartbeat => 1.month.ago.utc)

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