Skip to content

Commit

Permalink
Fix up sensible default values when nil.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrafanie committed Jan 6, 2021
1 parent 0849e5a commit 16019f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/vmdb/settings/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ def validate_worker_request_limit(worker_class, data)
errors = []
worker_settings = worker_class.fetch_worker_settings_from_server(true, data)

cpu_request = worker_settings.fetch(:cpu_request_percent, 0)
cpu_limit = worker_settings.fetch(:cpu_threshold_percent, Float::INFINITY)
memory_request = worker_settings.fetch(:memory_request, 0.bytes)
memory_limit = worker_settings.fetch(:memory_threshold, Float::INFINITY.megabytes)
cpu_request = worker_settings[:cpu_request_percent] || 0
cpu_limit = worker_settings[:cpu_threshold_percent] || Float::INFINITY
memory_request = worker_settings[:memory_request] || 0.bytes
memory_limit = worker_settings[:memory_threshold] || Float::INFINITY.megabytes

if cpu_request > cpu_limit
valid = false
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/vmdb/settings/validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@
end

[:memory_request, 500.megabytes, :memory_threshold, 500.megabytes, :cpu_request, 50, :cpu_threshold_percent, 50].each_slice(2) do |key, value|
it "is valid when specifying only: #{key}" do
stub_settings_merge(:workers => {:worker_base => {:schedule_worker => {key => value}}})
it "is valid with nil values replaced with default values, when specifying only: #{key}" do
stub_settings_merge(:workers => {:worker_base => {:defaults => {:cpu_request_percent => nil, :cpu_threshold_percent => nil}, :schedule_worker => {key => value}}})
result, errors = subject.validate
expect(result).to eql(true)
expect(errors.empty?).to eql(true)
Expand Down

0 comments on commit 16019f6

Please sign in to comment.