Skip to content

Commit

Permalink
Merge pull request #18453 from NickLaMuro/handling_integer_strings_in…
Browse files Browse the repository at this point in the history
…_worker_settings

[MiqWorker::worker_settings] Handle number strings

(cherry picked from commit 2f897c5)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1677409
  • Loading branch information
Fryguy authored and simaishi committed Feb 14, 2019
1 parent 83eb777 commit 4568a21
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/models/miq_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,13 @@ def self.fetch_worker_settings_from_server(miq_server, options = {})
# Clean up the configuration values in a format like "30.seconds"
unless raw
settings.keys.each do |k|
settings[k] = settings[k].to_i_with_method if settings[k].respond_to?(:to_i_with_method) && settings[k].number_with_method?
if settings[k].kind_of?(String)
if settings[k].number_with_method?
settings[k] = settings[k].to_i_with_method
elsif settings[k] =~ /\A\d+(.\d+)?\z/ # case where int/float saved as string
settings[k] = settings[k].to_i
end
end
end
end
end
Expand Down
35 changes: 35 additions & 0 deletions spec/models/miq_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,41 @@ def check_has_required_role(worker_role_names, expected_result)
end
end

context "with mixed memory value types" do
# Same settings from above, just using integers and integers/floats as strings
let(:settings) do
{
:workers => {
:worker_base => {
:defaults => {:memory_threshold => "100.megabytes"},
:queue_worker_base => {
:defaults => {:memory_threshold => 314_572_800}, # 300.megabytes
:ems_refresh_worker => {
:defaults => {:memory_threshold => "524288000"}, # 500.megabytes
:ems_refresh_worker_amazon => {
:memory_threshold => "1181116006.4" # 1.1.gigabtye
}
}
}
}
},
:ems => {:ems_amazon => {}}
}
end

let(:worker_base) { MiqWorker.worker_settings[:memory_threshold] }
let(:queue_worker) { MiqQueueWorkerBase.worker_settings[:memory_threshold] }
let(:ems_worker) { ManageIQ::Providers::BaseManager::RefreshWorker.worker_settings[:memory_threshold] }
let(:aws_worker) { ManageIQ::Providers::Amazon::CloudManager::RefreshWorker.worker_settings[:memory_threshold] }

it "converts everyting to integers properly" do
expect(worker_base).to eq(100.megabytes)
expect(queue_worker).to eq(300.megabytes)
expect(ems_worker).to eq(500.megabytes)
expect(aws_worker).to eq(1_181_116_006)
end
end

it "at the base class" do
actual = MiqWorker.worker_settings[:memory_threshold]
expect(actual).to eq(100.megabytes)
Expand Down

0 comments on commit 4568a21

Please sign in to comment.