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

Automatic detection of hawkular endpoint #37

Merged
merged 1 commit into from Jan 3, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/controllers/mixins/ems_common_angular.rb
Expand Up @@ -400,7 +400,10 @@ def set_ems_record_vars(ems, mode = nil)
if ems.kind_of?(ManageIQ::Providers::ContainerManager)
params[:cred_type] = ems.default_authentication_type if params[:cred_type] == "default"
ems.hostname = hostname
hawkular_hostname = hostname if hawkular_hostname.blank?
if hawkular_hostname.blank?
default_key = params[:default_password] || ems.authentication_key
hawkular_hostname = get_hostname_from_routes(ems, hostname, port, default_key)
end

default_endpoint = {:role => :default, :hostname => hostname, :port => port}
hawkular_endpoint = {:role => :hawkular, :hostname => hawkular_hostname, :port => hawkular_api_port}
Expand Down Expand Up @@ -429,6 +432,11 @@ def set_ems_record_vars(ems, mode = nil)
build_connection(ems, endpoints, mode)
end

def get_hostname_from_routes(ems, hostname, port, token)
client = ems.class.raw_connect(hostname, port, :bearer => token)
client.get_routes(:name=>'hawkular-metrics').first.try(:spec).try(:host)
end

def build_connection(ems, endpoints, mode)
authentications = build_credentials(ems, mode)
configurations = []
Expand Down
17 changes: 17 additions & 0 deletions spec/controllers/ems_common_controller_spec.rb
Expand Up @@ -178,7 +178,24 @@
end

describe EmsContainerController do
before :each do
allow(controller).to receive(:get_hostname_from_routes).and_return("myhawkularoute.com")
end
context "::EmsCommon" do
context "#create" do
it "adding new provider without hawkular endpoint" do
controller.instance_variable_set(:@_params,
:name => 'NimiCule',
:default_userid => '_',
:default_hostname => 'mytest.com',
:default_api_port => '8443',
:default_password => 'valid-token',
:emstype => @type)
ems = ManageIQ::Providers::Openshift::ContainerManager.new
controller.send(:set_ems_record_vars, ems)
expect(ems.connection_configurations.hawkular.endpoint.hostname).to eq('myhawkularoute.com')
end
end
context "#update" do
context "updates provider with new token" do
after :each do
Expand Down