Skip to content

Commit

Permalink
Modifications per review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
tinaafitz committed Feb 23, 2017
1 parent b394af0 commit 1a0f33f
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@ def main
private

def update_task(message)
return unless service_action == 'Provision'
@handle.root["service_template_provision_task"].tap do |task|
if task.nil?
@handle.log(:error, 'service_template_provision_task is nil')
raise "service_template_provision_task not found"
end
task.miq_request.user_message = message
end
@handle.root['service_template_provision_task'].try { |task| task.miq_request.user_message = message }
end

def service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,7 @@ def main
private

def update_task(message)
return unless service_action == 'Provision'
@handle.root["service_template_provision_task"].tap do |task|
if task.nil?
@handle.log(:error, 'service_template_provision_task is nil')
raise "service_template_provision_task not found"
end
task.miq_request.user_message = message
end
@handle.root['service_template_provision_task'].try { |task| task.miq_request.user_message = message }
end

def service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ def main
private

def update_task(message)
return unless service_action == 'Provision'
@handle.root["service_template_provision_task"].tap do |task|
if task.nil?
@handle.log(:error, 'service_template_provision_task is nil')
raise "service_template_provision_task not found"
end
task.miq_request.user_message = message
end
@handle.root['service_template_provision_task'].try { |task| task.miq_request.user_message = message }
end

def service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,7 @@ def main
private

def update_task(message)
return unless service_action == 'Provision'
@handle.root["service_template_provision_task"].tap do |task|
if task.nil?
@handle.log(:error, 'service_template_provision_task is nil')
raise "service_template_provision_task not found"
end
task.miq_request.user_message = message
end
@handle.root['service_template_provision_task'].try { |task| task.miq_request.user_message = message }
end

def service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,7 @@ def dump_root
end

def update_task(message)
return unless service_action == 'Provision'
@handle.root["service_template_provision_task"].tap do |task|
if task.nil?
@handle.log(:error, 'service_template_provision_task is nil')
raise "service_template_provision_task not found"
end
task.miq_request.user_message = message
end
@handle.root['service_template_provision_task'].try { |task| task.miq_request.user_message = message }
end

def service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ def main
private

def update_task(message)
return unless service_action == 'Provision'
@handle.root["service_template_provision_task"].tap do |task|
if task.nil?
@handle.log(:error, 'service_template_provision_task is nil')
raise "service_template_provision_task not found"
end
task.miq_request.user_message = message
end
@handle.root['service_template_provision_task'].try { |task| task.miq_request.user_message = message }
end

def service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@ def main
private

def update_task(message, status)
return unless service_action == 'Provision'
@handle.root["service_template_provision_task"].tap do |task|
if task.nil?
@handle.log(:error, 'service_template_provision_task is nil')
raise "service_template_provision_task not found"
end
@handle.root['service_template_provision_task'].try do |task|
task.miq_request.user_message = message
task.message = status
end
Expand Down Expand Up @@ -57,7 +52,7 @@ def update_status(service)

updated_message = String.new
updated_message << "Server [#{@handle.root['miq_server'].name}] "
updated_message << "Service [#{service.name}] "
updated_message << "Service [#{service.name}] #{service_action} "
updated_message << "Step [#{@handle.root['ae_state']}] "
updated_message << "Status [#{status}] "
updated_message << "Current Retry Number [#{@handle.root['ae_state_retries']}]"\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,4 @@
end
it_behaves_like "check_completed_error"
end

context "task not found" do
let(:status_and_message) { [true, "error"] }
let(:errormsg) { 'service_template_provision_task not found' }
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service' => svc_service,
'service_action' => 'Provision')
end
it_behaves_like "check_completed_error"
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,4 @@
end
it_behaves_like "check_refreshed_error"
end

context "task not found" do
let(:status_and_message) { [true, "error"] }
let(:errormsg) { 'service_template_provision_task not found' }
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service' => svc_service,
'service_action' => 'Provision')
end
it_behaves_like "check_refreshed_error"
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,7 @@
let(:ae_service) { Spec::Support::MiqAeMockService.new(root_object) }
let(:error_msg) { "failed" }

shared_examples_for "execute_error" do
it "error" do
allow(svc_service).to receive(:destination).and_return(svc_service)
allow(svc_service).to receive(:execute).and_raise(errormsg)

expect { described_class.new(ae_service).main }.to raise_error(errormsg)

expect(ae_service.root['ae_result']).to eq("error")
expect(ae_service.root['ae_reason']).to eq(errormsg)
end
end

context "invalid service_action" do
let(:errormsg) { 'Invalid service_action' }
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service' => svc_service,
'service_action' => 'fred')
end
it_behaves_like "execute_error"
end

context "task not found" do
let(:errormsg) { 'service_template_provision_task not found' }
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service' => svc_service,
'service_action' => 'Provision')
end
it_behaves_like "execute_error"
end

shared_examples_for "execute" do
shared_examples_for "execute_errors" do
it "execute" do
allow(svc_service).to receive(:destination).and_return(svc_service)
allow(svc_service).to receive(:execute).and_return(nil)
Expand All @@ -63,7 +33,18 @@
Spec::Support::MiqAeMockObject.new('service_template_provision_task' => task,
'service_action' => 'Provision')
end
it_behaves_like "execute"
it_behaves_like "execute_errors"
end

context "Invalid service action" do
let(:msg) { 'Invalid service_action' }
let(:rc) { 'error' }
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service' => svc_service,
'service_template_provision_task' => task,
'service_action' => 'fred')
end
it_behaves_like "execute_errors"
end

context "execute" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,6 @@
let(:errormsg) { "simple error" }

shared_examples_for "postprocess_error" do
it "error" do
allow(svc_service).to receive(:destination).and_return(svc_service)
allow(svc_service).to receive(:postprocess).and_raise(errormsg)

expect { described_class.new(ae_service).main }.to raise_error(errormsg)

expect(ae_service.root['ae_result']).to eq("error")
expect(ae_service.root['ae_reason']).to eq(errormsg)
end
end

context "invalid service_action" do
let(:errormsg) { 'Invalid service_action' }
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service' => svc_service,
'service_action' => 'fred')
end
it_behaves_like "postprocess_error"
end

context "task not found" do
let(:errormsg) { 'service_template_provision_task not found' }
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service' => svc_service,
'service_action' => 'Provision')
end
it_behaves_like "postprocess_error"
end

shared_examples_for "postprocess" do
it "postprocess" do
allow(svc_service).to receive(:destination).and_return(svc_service)
allow(svc_service).to receive(:postprocess).and_return(nil)
Expand All @@ -63,7 +33,18 @@
Spec::Support::MiqAeMockObject.new('service_template_provision_task' => task,
'service_action' => 'Provision')
end
it_behaves_like "postprocess"
it_behaves_like "postprocess_error"
end

context "invalid service_action" do
let(:msg) { 'Invalid service_action' }
let(:rc) { 'error' }
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service' => svc_service,
'service_template_provision_task' => task,
'service_action' => 'fred')
end
it_behaves_like "postprocess_error"
end

context "postprocess" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,6 @@
let(:errormsg) { "error" }

shared_examples_for "preprocess_error" do
it "error" do
allow(svc_service).to receive(:destination).and_return(svc_service)
allow(svc_service).to receive(:preprocess).and_raise(errormsg)

expect { described_class.new(ae_service).main }.to raise_error(errormsg)

expect(ae_service.root['ae_result']).to eq("error")
expect(ae_service.root['ae_reason']).to eq(errormsg)
end
end

context "invalid service_action" do
let(:errormsg) { 'Invalid service_action' }
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service' => svc_service,
'service_action' => 'fred')
end
it_behaves_like "preprocess_error"
end

context "task not found" do
let(:errormsg) { 'service_template_provision_task not found' }
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service' => svc_service,
'service_action' => 'Provision')
end
it_behaves_like "preprocess_error"
end

shared_examples_for "preprocess" do
it "preprocess" do
allow(svc_service).to receive(:destination).and_return(svc_service)
allow(svc_service).to receive(:preprocess).and_return(nil)
Expand All @@ -63,7 +33,18 @@
Spec::Support::MiqAeMockObject.new('service_template_provision_task' => task,
'service_action' => 'Provision')
end
it_behaves_like "preprocess"
it_behaves_like "preprocess_error"
end

context "invalid service_action" do
let(:msg) { 'Invalid service_action' }
let(:rc) { 'error' }
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service' => svc_service,
'service_template_provision_task' => task,
'service_action' => 'fred')
end
it_behaves_like "preprocess_error"
end

context "preprocess" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,8 @@
let(:svc_service) { MiqAeMethodService::MiqAeServiceServiceAnsibleTower.find(service_ansible_tower.id) }
let(:root_object) { Spec::Support::MiqAeMockObject.new('service' => svc_service, 'service_action' => 'Provision') }
let(:ae_service) { Spec::Support::MiqAeMockService.new(root_object) }
let(:errormsg) { "simple error" }

shared_examples_for "refresh_error" do
it "error" do
allow(svc_service).to receive(:destination).and_return(svc_service)
allow(svc_service).to receive(:refresh).and_raise(errormsg)

expect { described_class.new(ae_service).main }.to raise_error(errormsg)

expect(ae_service.root['ae_result']).to eq("error")
expect(ae_service.root['ae_reason']).to eq(errormsg)
end
end

context "invalid service_action" do
let(:errormsg) { 'Invalid service_action' }
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service' => svc_service,
'service_action' => 'fred')
end
it_behaves_like "refresh_error"
end

context "task not found" do
let(:errormsg) { 'service_template_provision_task not found' }
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service' => svc_service,
'service_action' => 'Provision')
end
it_behaves_like "refresh_error"
end

shared_examples_for "refresh" do
it "refresh" do
allow(svc_service).to receive(:destination).and_return(svc_service)
allow(svc_service).to receive(:refresh).and_return(nil)
Expand All @@ -63,7 +32,18 @@
Spec::Support::MiqAeMockObject.new('service_template_provision_task' => task,
'service_action' => 'Provision')
end
it_behaves_like "refresh"
it_behaves_like "refresh_error"
end

context "invalid service_action" do
let(:msg) { 'Invalid service_action' }
let(:rc) { 'error' }
let(:root_object) do
Spec::Support::MiqAeMockObject.new('service' => svc_service,
'service_template_provision_task' => task,
'service_action' => 'fred')
end
it_behaves_like "refresh_error"
end

context "refresh" do
Expand Down
Loading

0 comments on commit 1a0f33f

Please sign in to comment.