From 1a0f33fa7915f4b504cfe6948418d109524f3d71 Mon Sep 17 00:00:00 2001 From: Tina Fitzgerald Date: Thu, 23 Feb 2017 17:27:21 -0500 Subject: [PATCH] Modifications per review comments. --- .../__methods__/check_completed.rb | 9 +--- .../__methods__/check_refreshed.rb | 9 +--- .../__methods__/execute.rb | 9 +--- .../__methods__/postprocess.rb | 9 +--- .../__methods__/preprocess.rb | 9 +--- .../__methods__/refresh.rb | 9 +--- .../__methods__/update_status.rb | 9 +--- .../__methods__/check_completed_spec.rb | 10 ----- .../__methods__/check_refreshed_spec.rb | 10 ----- .../__methods__/execute_spec.rb | 45 ++++++------------- .../__methods__/postprocess_spec.rb | 43 +++++------------- .../__methods__/preprocess_spec.rb | 43 +++++------------- .../__methods__/refresh_spec.rb | 44 +++++------------- .../__methods__/update_status_spec.rb | 12 +---- 14 files changed, 58 insertions(+), 212 deletions(-) diff --git a/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/check_completed.rb b/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/check_completed.rb index 4a4af2ec3..83cdba617 100644 --- a/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/check_completed.rb +++ b/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/check_completed.rb @@ -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 diff --git a/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/check_refreshed.rb b/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/check_refreshed.rb index ffe7a1631..4831d0b61 100644 --- a/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/check_refreshed.rb +++ b/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/check_refreshed.rb @@ -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 diff --git a/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/execute.rb b/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/execute.rb index aac6cbf5c..bc0586a23 100644 --- a/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/execute.rb +++ b/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/execute.rb @@ -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 diff --git a/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/postprocess.rb b/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/postprocess.rb index f86170a47..4a7477b23 100644 --- a/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/postprocess.rb +++ b/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/postprocess.rb @@ -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 diff --git a/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/preprocess.rb b/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/preprocess.rb index 04477275b..291c1bb21 100644 --- a/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/preprocess.rb +++ b/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/preprocess.rb @@ -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 diff --git a/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/refresh.rb b/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/refresh.rb index 41a2ff405..574f15e2a 100644 --- a/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/refresh.rb +++ b/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/refresh.rb @@ -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 diff --git a/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/update_status.rb b/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/update_status.rb index 87b9e30f3..db5401b84 100644 --- a/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/update_status.rb +++ b/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/update_status.rb @@ -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 @@ -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']}]"\ diff --git a/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/check_completed_spec.rb b/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/check_completed_spec.rb index 94fafc17c..5e1561001 100644 --- a/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/check_completed_spec.rb +++ b/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/check_completed_spec.rb @@ -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 diff --git a/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/check_refreshed_spec.rb b/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/check_refreshed_spec.rb index 79fbde95e..9d8f3e951 100644 --- a/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/check_refreshed_spec.rb +++ b/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/check_refreshed_spec.rb @@ -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 diff --git a/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/execute_spec.rb b/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/execute_spec.rb index 4b8f23530..83c4ffa8b 100644 --- a/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/execute_spec.rb +++ b/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/execute_spec.rb @@ -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) @@ -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 diff --git a/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/postprocess_spec.rb b/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/postprocess_spec.rb index bf951aa90..614b0f0b5 100644 --- a/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/postprocess_spec.rb +++ b/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/postprocess_spec.rb @@ -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) @@ -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 diff --git a/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/preprocess_spec.rb b/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/preprocess_spec.rb index 2f7fc7c18..c313cf836 100644 --- a/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/preprocess_spec.rb +++ b/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/preprocess_spec.rb @@ -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) @@ -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 diff --git a/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/refresh_spec.rb b/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/refresh_spec.rb index 943380929..0aedb43e9 100644 --- a/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/refresh_spec.rb +++ b/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/refresh_spec.rb @@ -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) @@ -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 diff --git a/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/update_status_spec.rb b/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/update_status_spec.rb index 209893970..fbd324c19 100644 --- a/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/update_status_spec.rb +++ b/spec/content/automate/ManageIQ/Service/Generic/StateMachines/GenericLifecycle.class/__methods__/update_status_spec.rb @@ -39,16 +39,6 @@ it_behaves_like "update_status_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', - 'miq_server' => svc_model_miq_server) - end - it_behaves_like "update_status_error" - end - context "service not found" do let(:errormsg) { 'Service not found' } let(:root_object) do @@ -73,7 +63,7 @@ described_class.new(ae_service).main - msg = "Server [#{miq_server.name}] Service [#{svc_service.name}] Step [] Status [fred] " + msg = "Server [#{miq_server.name}] Service [#{svc_service.name}] Provision Step [] Status [fred] " expect(svc_model_request.reload.message).to eq(msg) end end