Skip to content

Commit

Permalink
Fix validate_quota method to properly set the request.message for quota
Browse files Browse the repository at this point in the history
exceeded and modified tests to check request.message.

https://bugzilla.redhat.com/show_bug.cgi?id=1333698
  • Loading branch information
tinaafitz committed Jun 3, 2016
1 parent 3c3daca commit df1a627
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,24 +76,21 @@ def check_quotas
end

def check_quota_results
message = ""
unless @max_exceeded.empty?
max_message = message_text(nil, "Request exceeds maximum allowed for the following: ", @max_exceeded)
message = set_exceeded_results(message, max_message, :quota_max_exceeded, "error")
@miq_request.set_message(set_exceeded_results(max_message, :quota_max_exceeded, "error"))
return
end
unless @warn_exceeded.empty?
warn_message = message_text('warn_', "Request exceeds warning limits for the following: ", @warn_exceeded)
message = set_exceeded_results(message, warn_message, :quota_warn_exceeded, "ok")
@miq_request.set_message(set_exceeded_results(warn_message, :quota_warn_exceeded, "ok"))
end
@miq_request.set_message(message[0..250])
end

def set_exceeded_results(request_message, new_message, request_option, ae_result_text)
request_message += new_message
@miq_request.set_option(request_option, request_message)
def set_exceeded_results(new_message, request_option, ae_result_text)
@miq_request.set_option(request_option, new_message)
$evm.root['ae_result'] = ae_result_text
request_message
new_message
end

def message_text(type, msg, exceeded_hash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def approvers
association :approvers

def set_message(value)
object_send(:update_attributes, :message => value)
object_send(:update_attributes, :message => value.try!(:truncate, 255))
end

def description=(new_description)
Expand Down
8 changes: 8 additions & 0 deletions spec/automation/unit/method_validation/validate_quota_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def run_automate_method(provision_request)
expect(ws.root['ae_result']).to eql('error')
@miq_request.reload
expect(@miq_request.options[:quota_max_exceeded]).to eql(err_msg)
expect(@miq_request.message).to eql(err_msg)
end

it "failure warn memory" do
Expand All @@ -50,6 +51,7 @@ def run_automate_method(provision_request)
expect(ws.root['ae_result']).to eql('ok')
@miq_request.reload
expect(@miq_request.options[:quota_warn_exceeded]).to eql(err_msg)
expect(@miq_request.message).to eql(err_msg)
end

it "failure max vms" do
Expand All @@ -61,6 +63,7 @@ def run_automate_method(provision_request)
expect(ws.root['ae_result']).to eql('error')
@miq_request.reload
expect(@miq_request.options[:quota_max_exceeded]).to eql(err_msg)
expect(@miq_request.message).to eql(err_msg)
end

it "failure warn vms" do
Expand All @@ -72,6 +75,7 @@ def run_automate_method(provision_request)
expect(ws.root['ae_result']).to eql('ok')
@miq_request.reload
expect(@miq_request.options[:quota_warn_exceeded]).to eql(err_msg)
expect(@miq_request.message).to eql(err_msg)
end

it "failure max cpu" do
Expand All @@ -83,6 +87,7 @@ def run_automate_method(provision_request)
expect(ws.root['ae_result']).to eql('error')
@miq_request.reload
expect(@miq_request.options[:quota_max_exceeded]).to eql(err_msg)
expect(@miq_request.message).to eql(err_msg)
end

it "failure warn cpu" do
Expand All @@ -94,6 +99,7 @@ def run_automate_method(provision_request)
expect(ws.root['ae_result']).to eql('ok')
@miq_request.reload
expect(@miq_request.options[:quota_warn_exceeded]).to eql(err_msg)
expect(@miq_request.message).to eql(err_msg)
end

it "failure max storage" do
Expand All @@ -105,6 +111,7 @@ def run_automate_method(provision_request)
expect(ws.root['ae_result']).to eql('error')
@miq_request.reload
expect(@miq_request.options[:quota_max_exceeded]).to eql(err_msg)
expect(@miq_request.message).to eql(err_msg)
end

it "failure warn storage" do
Expand All @@ -116,6 +123,7 @@ def run_automate_method(provision_request)
expect(ws.root['ae_result']).to eql('ok')
@miq_request.reload
expect(@miq_request.options[:quota_warn_exceeded]).to eql(err_msg)
expect(@miq_request.message).to eql(err_msg)
end
end
end

0 comments on commit df1a627

Please sign in to comment.