From 1ca9689fbf26713721ac13a636f1e05af571f0d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Z=C3=A1zrivec?= Date: Fri, 29 Mar 2019 15:36:10 +0100 Subject: [PATCH] Merge pull request #5394 from h-kataria/workers_default_settings_fixed Fixed display of default memory threshold correctly on new appliance (cherry picked from commit 4b913ce70afb0a070801f796e30606cd51bc86f3) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1686902 --- app/controllers/ops_controller/settings/common.rb | 12 ++++++------ .../ops_controller/settings/common_spec.rb | 8 ++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/controllers/ops_controller/settings/common.rb b/app/controllers/ops_controller/settings/common.rb index f269c89492b..df7d1aca599 100644 --- a/app/controllers/ops_controller/settings/common.rb +++ b/app/controllers/ops_controller/settings/common.rb @@ -1023,9 +1023,8 @@ def settings_set_form_vars_workers qwb[:ems_metrics_collector_worker] ||= {} qwb[:ems_metrics_collector_worker][:defaults] ||= {} w = qwb[:ems_metrics_collector_worker][:defaults] - raw = get_worker_setting(@edit[:current], MiqEmsMetricsCollectorWorker) - w[:count] = raw[:defaults][:count] || 2 - w[:memory_threshold] = raw[:defaults][:memory_threshold] || 400.megabytes + w[:count] = get_worker_setting(@edit[:current], MiqEmsMetricsCollectorWorker, :defaults, :count) || 2 + w[:memory_threshold] = get_worker_setting(@edit[:current], MiqEmsMetricsCollectorWorker, :defaults, :memory_threshold) || 400.megabytes @sb[:ems_metrics_collector_threshold] = [] @sb[:ems_metrics_collector_threshold] = copy_array(@sb[:threshold]) @@ -1040,6 +1039,7 @@ def settings_set_form_vars_workers w[:memory_threshold] = get_worker_setting(@edit[:current], MiqSmartProxyWorker, :memory_threshold) || 400.megabytes @sb[:smart_proxy_threshold] = [] @sb[:smart_proxy_threshold] = copy_array(@sb[:threshold]) + (1.gigabytes..2.9.gigabytes).step(0.1.gigabyte) { |x| @sb[:smart_proxy_threshold] << [number_to_human_size(x, :significant => false), x.to_i] } qwb[:ems_refresh_worker] ||= {} qwb[:ems_refresh_worker][:defaults] ||= {} @@ -1048,7 +1048,7 @@ def settings_set_form_vars_workers @sb[:ems_refresh_threshold] = [] (200.megabytes...550.megabytes).step(50.megabytes) { |x| @sb[:ems_refresh_threshold] << [number_to_human_size(x, :significant => false), x] } (600.megabytes..900.megabytes).step(100.megabytes) { |x| @sb[:ems_refresh_threshold] << [number_to_human_size(x, :significant => false), x] } - (1.gigabytes..2.9.gigabytes).step(1.gigabyte / 10) { |x| @sb[:ems_refresh_threshold] << [number_to_human_size(x, :significant => false), x.to_i] } + (1.gigabytes..2.9.gigabytes).step(0.1.gigabyte) { |x| @sb[:ems_refresh_threshold] << [number_to_human_size(x, :significant => false), x.to_i] } (3.gigabytes..10.gigabytes).step(512.megabytes) { |x| @sb[:ems_refresh_threshold] << [number_to_human_size(x, :significant => false), x.to_i] } wb = @edit[:current].config[:workers][:worker_base] @@ -1056,14 +1056,14 @@ def settings_set_form_vars_workers w[:memory_threshold] = get_worker_setting(@edit[:current], MiqEventCatcher, :memory_threshold) || 1.gigabytes @sb[:event_catcher_threshold] = [] (500.megabytes...1000.megabytes).step(100.megabytes) { |x| @sb[:event_catcher_threshold] << [number_to_human_size(x, :significant => false), x] } - (1.gigabytes..2.9.gigabytes).step(1.gigabyte / 10) { |x| @sb[:event_catcher_threshold] << [number_to_human_size(x, :significant => false), x.to_i] } + (1.gigabytes..2.9.gigabytes).step(0.1.gigabyte) { |x| @sb[:event_catcher_threshold] << [number_to_human_size(x, :significant => false), x.to_i] } (3.gigabytes..10.gigabytes).step(512.megabytes) { |x| @sb[:event_catcher_threshold] << [number_to_human_size(x, :significant => false), x.to_i] } w = (wb[:vim_broker_worker] ||= {}) w[:memory_threshold] = get_worker_setting(@edit[:current], MiqVimBrokerWorker, :memory_threshold) || 1.gigabytes @sb[:vim_broker_threshold] = [] (500.megabytes..900.megabytes).step(100.megabytes) { |x| @sb[:vim_broker_threshold] << [number_to_human_size(x, :significant => false), x] } - (1.gigabytes..2.9.gigabytes).step(1.gigabyte / 10) { |x| @sb[:vim_broker_threshold] << [number_to_human_size(x, :significant => false), x.to_i] } + (1.gigabytes..2.9.gigabytes).step(0.1.gigabyte) { |x| @sb[:vim_broker_threshold] << [number_to_human_size(x, :significant => false), x.to_i] } (3.gigabytes..10.gigabytes).step(512.megabytes) { |x| @sb[:vim_broker_threshold] << [number_to_human_size(x, :significant => false), x.to_i] } w = (wb[:ui_worker] ||= {}) diff --git a/spec/controllers/ops_controller/settings/common_spec.rb b/spec/controllers/ops_controller/settings/common_spec.rb index b5d513f5bdf..3e4c4ee8f29 100644 --- a/spec/controllers/ops_controller/settings/common_spec.rb +++ b/spec/controllers/ops_controller/settings/common_spec.rb @@ -441,6 +441,7 @@ end describe '#settings_set_form_vars_workers' do + include ActionView::Helpers::NumberHelper context "set worker settings for selected server" do before do @miq_server = FactoryBot.create(:miq_server) @@ -474,6 +475,13 @@ expect(ui_worker_threshold).to eq(600.megabytes) expect(ui_worker_count).to eq(2) end + + it "gets worker setting and makes sure it exists in threshold array so correct value can be selected in drop down" do + controller.send(:settings_set_form_vars_workers) + proxy_worker_threshold = controller.send(:get_worker_setting, assigns(:edit)[:current], MiqSmartProxyWorker, :memory_threshold) + proxy_worker_threshold_human_size = number_to_human_size(proxy_worker_threshold, :significant => false) + expect(assigns(:sb)[:smart_proxy_threshold]).to include([proxy_worker_threshold_human_size, proxy_worker_threshold]) + end end end end