Skip to content

Commit

Permalink
Specify the invalid worker setting key in the error
Browse files Browse the repository at this point in the history
  • Loading branch information
jrafanie committed Jan 6, 2021
1 parent 16019f6 commit b0f62c7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/vmdb/settings/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ def validate_worker_request_limit(worker_class, data)

if cpu_request > cpu_limit
valid = false
errors << [:invalid_value, "#{worker_class.settings_name}: cpu_request_percent: #{cpu_request} cannot exceed cpu_threshold_percent: #{cpu_limit}"]
errors << [:cpu_request_percent, "#{worker_class.settings_name}: cpu_request_percent: #{cpu_request} cannot exceed cpu_threshold_percent: #{cpu_limit}"]
end

if memory_request > memory_limit
valid = false
errors << [:invalid_value, "#{worker_class.settings_name}: memory_request: #{memory_request} cannot exceed memory_threshold: #{memory_limit}"]
errors << [:memory_request, "#{worker_class.settings_name}: memory_request: #{memory_request} cannot exceed memory_threshold: #{memory_limit}"]
end
return valid, errors
end
Expand Down
8 changes: 4 additions & 4 deletions spec/lib/vmdb/settings/validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,31 +83,31 @@
stub_settings_merge(:workers => {:worker_base => {:schedule_worker => {:cpu_request_percent => 50, :cpu_threshold_percent => 40}}})
result, errors = subject.validate
expect(result).to eql(false)
expect(errors.first.first).to eql("workers-invalid_value")
expect(errors.first.first).to eql("workers-cpu_request_percent")
expect(errors.first.last).to include("cannot exceed cpu_threshold_percent")
end

it "is invalid with memory_request > memory_threshold" do
stub_settings_merge(:workers => {:worker_base => {:schedule_worker => {:memory_request => 600.megabytes, :memory_threshold => 500.megabytes}}})
result, errors = subject.validate
expect(result).to eql(false)
expect(errors.first.first).to eql("workers-invalid_value")
expect(errors.first.first).to eql("workers-memory_request")
expect(errors.first.last).to include("cannot exceed memory_threshold")
end

it "is invalid with inherited setting" do
stub_settings_merge(:workers => {:worker_base => {:defaults => {:cpu_request_percent => 15, :cpu_threshold_percent => 10}}})
result, errors = subject.validate
expect(result).to eql(false)
expect(errors.first.first).to eql("workers-invalid_value")
expect(errors.first.first).to eql("workers-cpu_request_percent")
expect(errors.first.last).to include("cannot exceed cpu_threshold_percent")
end

it "is invalid with overridden worker setting" do
stub_settings_merge(:workers => {:worker_base => {:defaults => {:cpu_request_percent => 15, :cpu_threshold_percent => 20}, :schedule_worker => {:cpu_threshold_percent => 10}}})
result, errors = subject.validate
expect(result).to eql(false)
expect(errors.first.first).to eql("workers-invalid_value")
expect(errors.first.first).to eql("workers-cpu_request_percent")
expect(errors.first.last).to include("cannot exceed cpu_threshold_percent")
end

Expand Down

0 comments on commit b0f62c7

Please sign in to comment.