From 32de2aa2e2b33f813787df79ac0779496fba23d3 Mon Sep 17 00:00:00 2001 From: Boris Odnopozov Date: Wed, 28 Jun 2017 13:18:40 +0300 Subject: [PATCH] Fix unhandled exception in metrics collection when missing credentials When trying to collect C&U data from an Ovirt provider with missing credentials a warning will be shown in the log but no exception will be risen. Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1450644 --- .../providers/redhat/infra_manager/metrics_capture.rb | 7 ++++++- .../providers/redhat/infra_manager/metrics_capture_spec.rb | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/manageiq/providers/redhat/infra_manager/metrics_capture.rb b/app/models/manageiq/providers/redhat/infra_manager/metrics_capture.rb index dc217b35c..11d3213a5 100644 --- a/app/models/manageiq/providers/redhat/infra_manager/metrics_capture.rb +++ b/app/models/manageiq/providers/redhat/infra_manager/metrics_capture.rb @@ -31,8 +31,13 @@ def perf_release_rhevm # def perf_collect_metrics(interval_name, start_time = nil, end_time = nil) - log_header = "[#{interval_name}] for: [#{target.class.name}], [#{target.id}], [#{target.name}]" + target_description = "[#{target.class.name}], [#{target.id}], [#{target.name}]" + unless target.ext_management_system.has_authentication_type?(:metrics) + _log.warn("No C&U credentials defined for: #{target_description} returning empty stats") + return {}, {} + end + log_header = "[#{interval_name}] for: #{target_description}" start_time ||= Metric::Capture.historical_start_time begin diff --git a/spec/models/manageiq/providers/redhat/infra_manager/metrics_capture_spec.rb b/spec/models/manageiq/providers/redhat/infra_manager/metrics_capture_spec.rb index b86b8a1e8..e042863f0 100644 --- a/spec/models/manageiq/providers/redhat/infra_manager/metrics_capture_spec.rb +++ b/spec/models/manageiq/providers/redhat/infra_manager/metrics_capture_spec.rb @@ -12,5 +12,12 @@ expect(OvirtMetrics).to receive(:host_realtime).with(host.uid_ems, start_time, nil) host.perf_collect_metrics("realtime") end + + context 'ems has no metrics authentication' do + let(:ems) { FactoryGirl.create(:ems_redhat) } + it 'returns empty results when no credentials are defined' do + expect(host.perf_collect_metrics("realtime")).to eq([{}, {}]) + end + end end end