Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring update_serviceprovision_status method #19

Merged
merged 4 commits into from
Jan 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,50 @@
# Description: This method updates the service provision status.
# Required inputs: status
#
module ManageIQ
module Automate
module Cloud
module Orchestration
module Provisioning
module StateMachines
class UpdateServiceProvisionStatus
def initialize(handle = $evm)
@handle = handle
end

prov = $evm.root['service_template_provision_task']
def main
prov = @handle.root['service_template_provision_task']

unless prov
$evm.log(:error, "Service Template Provision Task not provided")
exit(MIQ_STOP)
end
if prov.nil?
@handle.log(:error, "Service Template Provision Task not provided")
raise "Service Template Provision Task not provided"
end

update_status_message(prov, @handle.inputs['status'])
end

# Get status from input field status
status = $evm.inputs['status']
private

# Update Status Message
updated_message = "Server [#{$evm.root['miq_server'].name}] "
updated_message += "Service [#{prov.destination.name}] "
updated_message += "Step [#{$evm.root['ae_state']}] "
updated_message += "Status [#{status}] "
updated_message += "Message [#{prov.message}] "
updated_message += "Current Retry Number [#{$evm.root['ae_state_retries']}]"\
if $evm.root['ae_result'] == 'retry'
prov.miq_request.user_message = updated_message
prov.message = status
def update_status_message(prov, status)
updated_message = "Server [#{@handle.root['miq_server'].name}] "
updated_message += "Service [#{prov.destination.name}] "
updated_message += "Step [#{@handle.root['ae_state']}] "
updated_message += "Status [#{status}] "
updated_message += "Message [#{prov.message}] "
updated_message += "Current Retry Number [#{@handle.root['ae_state_retries']}]"\
if @handle.root['ae_result'] == 'retry'
prov.miq_request.user_message = updated_message
prov.message = status
end
end
end
end
end
end
end
end

if __FILE__ == $PROGRAM_NAME
ManageIQ::Automate::Cloud::Orchestration::Provisioning::
StateMachines::UpdateServiceProvisionStatus.new.main
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,52 @@
# Description: This method updates the service provision status.
# Required inputs: status
#
module ManageIQ
module Automate
module ConfigurationManagement
module AnsibleTower
module Service
module Provisioning
module StateMachines
class UpdateServiceProvisionStatus
def initialize(handle = $evm)
@handle = handle
end

prov = $evm.root['service_template_provision_task']
def main
prov = @handle.root['service_template_provision_task']

unless prov
$evm.log(:error, "Service Template Provision Task not provided")
exit(MIQ_STOP)
end
if prov.nil?
@handle.log(:error, "Service Template Provision Task not provided")
raise "Service Template Provision Task not provided"
end

update_status_message(prov, @handle.inputs['status'])
end

# Get status from input field status
status = $evm.inputs['status']
private

# Update Status Message
updated_message = "Server [#{$evm.root['miq_server'].name}] "
updated_message += "Service [#{prov.destination.name}] "
updated_message += "Step [#{$evm.root['ae_state']}] "
updated_message += "Status [#{status}] "
updated_message += "Message [#{prov.message}] "
updated_message += "Current Retry Number [#{$evm.root['ae_state_retries']}]"\
if $evm.root['ae_result'] == 'retry'
prov.miq_request.user_message = updated_message
prov.message = status
def update_status_message(prov, status)
updated_message = "Server [#{@handle.root['miq_server'].name}] "
updated_message += "Service [#{prov.destination.name}] "
updated_message += "Step [#{@handle.root['ae_state']}] "
updated_message += "Status [#{status}] "
updated_message += "Message [#{prov.message}] "
updated_message += "Current Retry Number [#{@handle.root['ae_state_retries']}]"\
if @handle.root['ae_result'] == 'retry'
prov.miq_request.user_message = updated_message
prov.message = status
end
end
end
end
end
end
end
end
end

if __FILE__ == $PROGRAM_NAME
ManageIQ::Automate::ConfigurationManagement::AnsibleTower::Service::
Provisioning::StateMachines::UpdateServiceProvisionStatus.new.main
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,57 @@
# Description: This method updates the service provision status.
# Required inputs: status
#
module ManageIQ
module Automate
module Service
module Provisioning
module StateMachines
module ServiceProvision_Template
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkomanek can this be module ServiceProvisionTemplate?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pkomanek I am not sure if thats because of an internal naming issue. We might have to leave it as ServiceProvision_Template. @tinaafitz can you comment on this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mkanoor @pkomanek It is an internal naming issue, so we have to leave the name as ServiceProvision_Template.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class UpdateServiceProvisionStatus
def initialize(handle = $evm)
@handle = handle
end

prov = $evm.root['service_template_provision_task']
def main
prov = @handle.root['service_template_provision_task']

unless prov
$evm.log(:error, "service_template_provision_task object not provided")
exit(MIQ_STOP)
end
if prov.nil?
@handle.log(:error, "service_template_provision_task object not provided")
raise "service_template_provision_task object not provided"
end

updated_message = update_status_message(prov, @handle.inputs['status'])

# Get status from input field status
status = $evm.inputs['status']
if @handle.root['ae_result'] == "error"
@handle.create_notification(:level => "error",
:subject => prov.miq_request,
:message => "Service Provision Error: #{updated_message}")
end
end

# Update Status Message
updated_message = "Server [#{$evm.root['miq_server'].name}] "
updated_message += "Service [#{prov.destination.name}] "
updated_message += "Step [#{$evm.root['ae_state']}] "
updated_message += "Status [#{status}] "
updated_message += "Message [#{prov.message}] "
updated_message += "Current Retry Number [#{$evm.root['ae_state_retries']}]" if $evm.root['ae_result'] == 'retry'
prov.miq_request.user_message = updated_message
prov.message = status
private

if $evm.root['ae_result'] == "error"
$evm.create_notification(:level => "error", :subject => prov.miq_request, \
:message => "Service Provision Error: #{updated_message}")
def update_status_message(prov, status)
updated_message = "Server [#{@handle.root['miq_server'].name}] "
updated_message += "Service [#{prov.destination.name}] "
updated_message += "Step [#{@handle.root['ae_state']}] "
updated_message += "Status [#{status}] "
updated_message += "Message [#{prov.message}] "
updated_message += "Current Retry Number [#{@handle.root['ae_state_retries']}]"\
if @handle.root['ae_result'] == 'retry'
prov.miq_request.user_message = updated_message
prov.message = status

updated_message
end
end
end
end
end
end
end
end
if __FILE__ == $PROGRAM_NAME
ManageIQ::Automate::Service::Provisioning::StateMachines::
ServiceProvision_Template::UpdateServiceProvisionStatus.new.main
end

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
require_domain_file

describe ManageIQ::Automate::Cloud::Orchestration::Provisioning::StateMachines::UpdateServiceProvisionStatus do
let(:user) { FactoryGirl.create(:user_with_group) }
let(:miq_server) { EvmSpecHelper.local_miq_server }
let(:service_orchestration) { FactoryGirl.create(:service_orchestration) }

let(:miq_request_task) do
FactoryGirl.create(:miq_request_task, :destination => service_orchestration,
:miq_request => request, :state => 'fred')
end

let(:request) do
FactoryGirl.create(:service_template_provision_request, :requester => user)
end

let(:ae_service) do
Spec::Support::MiqAeMockService.new(root_object).tap do |service|
current_object = Spec::Support::MiqAeMockObject.new
current_object.parent = root_object
service.object = current_object
end
end

let(:svc_model_miq_server) { MiqAeMethodService::MiqAeServiceMiqServer.find(miq_server.id) }
let(:svc_model_miq_request_task) { MiqAeMethodService::MiqAeServiceMiqRequestTask.find(miq_request_task.id) }
let(:svc_model_service) { MiqAeMethodService::MiqAeServiceService.find(service_orchestration.id) }
let(:svc_model_request) do
MiqAeMethodService::MiqAeServiceServiceTemplateProvisionRequest.find(request.id)
end

context "with a stp request object" do
let(:root_hash) do
{ 'service_template' => MiqAeMethodService::MiqAeServiceService.find(service_orchestration.id) }
end

let(:root_object) do
obj = Spec::Support::MiqAeMockObject.new(root_hash)
obj["service_template_provision_task"] = svc_model_miq_request_task
obj["miq_server"] = svc_model_miq_server
obj
end

before do
allow(ae_service).to receive(:inputs) { {'status' => "fred"} }
allow(svc_model_miq_request_task).to receive(:destination) { svc_model_service }
ae_service.root['ae_result'] = 'ok'
end

it "method succeeds" do
described_class.new(ae_service).main
expect(svc_model_request.reload.status).to eq('Ok')
end

it "request message set properly" do
described_class.new(ae_service).main
msg = "Server [#{miq_server.name}] Service [#{service_orchestration.name}] Step [] Status [fred] Message [] "
expect(svc_model_request.reload.message).to eq(msg)
end
end

context "without a stp request object" do
let(:root_hash) { {} }
let(:root_object) { Spec::Support::MiqAeMockObject.new(root_hash) }

it "method fails" do
expect { described_class.new(ae_service).main }.to raise_error(
"Service Template Provision Task not provided"
)
end
end
end
Loading