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

Fix authentication of metrics credentials in RHV #13981

Merged
merged 1 commit into from
Feb 27, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def rhevm_metrics_connect_options(options = {})
server = options[:hostname] || metrics_hostname || hostname
username = options[:user] || authentication_userid(:metrics)
password = options[:pass] || authentication_password(:metrics)
database = options[:database]
database = options[:database] || history_database_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it require a test ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it does, added them.


{
:host => server,
Expand Down Expand Up @@ -184,24 +184,7 @@ def verify_credentials(auth_type = nil, options = {})
end

def history_database_name
@history_database_name = connection_configurations.try(:metrics).try(:endpoint).try(:path)
@history_database_name ||= begin
version = version_3_0? ? '3_0' : '>3_0'
self.class.history_database_name_for(version)
end
end

def version_3_0?
if @version_3_0.nil?
@version_3_0 =
if api_version.nil?
with_provider_connection(&:version_3_0?)
else
api_version.starts_with?("3.0")
end
end

@version_3_0
connection_configurations.try(:metrics).try(:endpoint).try(:path) || self.class.default_history_database_name
end

# Adding disks is supported only by API version 4.0
Expand Down Expand Up @@ -293,14 +276,9 @@ def raw_connect_v3(server, port, path, username, password, service)
const.new(params)
end

def history_database_name_for(api_version)
def default_history_database_name
require 'ovirt_metrics'
case api_version
when '3_0'
OvirtMetrics::DEFAULT_HISTORY_DATABASE_NAME_3_0
else
OvirtMetrics::DEFAULT_HISTORY_DATABASE_NAME
end
OvirtMetrics::DEFAULT_HISTORY_DATABASE_NAME
end

# Calculates an "ems_ref" from the "href" attribute provided by the oVirt REST API, removing the
Expand Down
18 changes: 18 additions & 0 deletions spec/models/manageiq/providers/redhat/infra_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@
expect(ems.rhevm_metrics_connect_options(:hostname => "different.tld")[:host])
.to eq("different.tld")
end

it "rhevm_metrics_connect_options fetches the default database name" do
expect(ems.rhevm_metrics_connect_options[:database])
.to eq(ems.class.default_history_database_name)
end

context "non default metrics database name" do
let(:ems) do
FactoryGirl.create(:ems_redhat,
:hostname => "some.thing.tld",
:connection_configurations => [{:endpoint => {:role => :metrics,
:path => "some.database"}}])
end

it "fetches the set database name" do
expect(ems.rhevm_metrics_connect_options[:database]).to eq("some.database")
end
end
end

context "#vm_reconfigure" do
Expand Down