Skip to content

Commit

Permalink
[MiqWorker::worker_settings] Handle number strings
Browse files Browse the repository at this point in the history
Due to some UI specific issues, settings in the config can be set as
"integer strings", or a string that is just a integer (floats are also
possible).  This doesn't work booting workers as it initializes them
with incorrect values.

This does some extra checking to avoid that.
  • Loading branch information
NickLaMuro committed Feb 13, 2019
1 parent d4e8a96 commit eee01fb
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 @@ -209,7 +209,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 eee01fb

Please sign in to comment.