Skip to content

Commit

Permalink
Revert "Merge pull request #575 from fdupont-redhat/v2v_state_machine…
Browse files Browse the repository at this point in the history
  • Loading branch information
simaishi committed Dec 3, 2019
1 parent 4e43e40 commit 33f1d27
Show file tree
Hide file tree
Showing 10 changed files with 254 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
object_type: class
version: 1.0
object:
attributes:
description:
display_name:
name: Common
type:
inherits:
visibility:
owner:
schema:
- field:
aetype: method
name: execute
display_name:
datatype:
priority: 1
owner:
default_value:
substitute: true
message: create
visibility:
collect:
scope:
description:
condition:
on_entry:
on_exit:
on_error:
max_retries:
max_time:
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module ManageIQ
module Automate
module Transformation
module Infrastructure
module VM
module Common
class CheckPoweredOn
def initialize(handle = $evm)
@handle = handle
@task = ManageIQ::Automate::Transformation::Common::Utils.task(@handle)
transformation_phase = ManageIQ::Automate::Transformation::Common::Utils.transformation_phase(@handle)
case transformation_phase
when 'transformation'
@vm = ManageIQ::Automate::Transformation::Common::Utils.destination_vm(@handle)
when 'cleanup'
@vm = ManageIQ::Automate::Transformation::Common::Utils.source_vm(@handle)
end
end

def main
return if @vm.blank?
return if @task.get_option(:source_vm_power_state) != 'on'
if @vm.power_state != 'on'
@handle.root["ae_result"] = "retry"
@handle.root["ae_retry_interval"] = "15.seconds"
end
rescue => e
@handle.set_state_var(:ae_state_progress, 'message' => e.message)
raise
end
end
end
end
end
end
end
end

ManageIQ::Automate::Transformation::Infrastructure::VM::Common::CheckPoweredOn.new.main
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
object_type: method
version: 1.0
object:
attributes:
name: CheckPoweredOn
display_name:
description:
scope: instance
language: ruby
location: inline
embedded_methods:
- "/Transformation/Common/Utils"
options: {}
inputs: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module ManageIQ
module Automate
module Transformation
module Infrastructure
module VM
module Common
class PowerOn
def initialize(handle = $evm)
@handle = handle
@task = ManageIQ::Automate::Transformation::Common::Utils.task(@handle)
transformation_phase = ManageIQ::Automate::Transformation::Common::Utils.transformation_phase(@handle)
case transformation_phase
when 'transformation'
@vm = ManageIQ::Automate::Transformation::Common::Utils.destination_vm(@handle)
when 'cleanup'
@vm = ManageIQ::Automate::Transformation::Common::Utils.source_vm(@handle)
end
end

def main
return if @vm.blank?
@vm.start if @task.get_option(:source_vm_power_state) == 'on'
rescue => e
@handle.set_state_var(:ae_state_progress, 'message' => e.message)
raise
end
end
end
end
end
end
end
end

ManageIQ::Automate::Transformation::Infrastructure::VM::Common::PowerOn.new.main
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
object_type: method
version: 1.0
object:
attributes:
name: PowerOn
display_name:
description:
scope: instance
language: ruby
location: inline
embedded_methods:
- "/Transformation/Common/Utils"
options: {}
inputs: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
object_type: instance
version: 1.0
object:
attributes:
display_name:
name: ".missing"
inherits:
description:
fields:
- execute:
value: "${#_missing_instance}"
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
object_type: namespace
version: 1.0
object:
attributes:
name: VM
description:
display_name:
priority:
enabled:
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
object_type: namespace
version: 1.0
object:
attributes:
name: Infrastructure
description:
display_name:
priority:
enabled:
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@ object:
inherits:
description:
fields:
- State5:
value: "/Transformation/Infrastructure/VM/Common/PowerOn"
on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 5, description
=> "Power-on VM", task_message => "Migrating")
on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 5, description
=> "Power-on VM", task_message => "Migrating")
on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 5, description
=> "Power-on VM", task_message => "Migrating")
- State8:
value: "/Transformation/Infrastructure/VM/Common/CheckPoweredOn"
on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 40, description
=> "Power-on VM", task_message => "Migrating")
on_exit: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 40, description
=> "Power-on VM", task_message => "Migrating")
on_error: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 35, description
=> "Power-on VM", task_message => "Migrating")
max_retries: '200'
- State11:
value: "/Transformation/StateMachines/Ansible/TransformationPlaybook?transformation_hook=post"
on_entry: /System/CommonMethods/MiqAe.WeightedUpdateStatus(weight => 40, description =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
require_domain_file
require File.join(ManageIQ::Content::Engine.root, 'content/automate/ManageIQ/Transformation/Common.class/__methods__/utils.rb')

describe ManageIQ::Automate::Transformation::Infrastructure::VM::Common::CheckPoweredOn do
let(:user) { FactoryBot.create(:user_with_email_and_group) }
let(:group) { FactoryBot.create(:miq_group) }
let(:vm) { FactoryBot.create(:vm) }
let(:task) { FactoryBot.create(:service_template_transformation_plan_task) }

let(:svc_model_user) { MiqAeMethodService::MiqAeServiceUser.find(user.id) }
let(:svc_model_group) { MiqAeMethodService::MiqAeServiceMiqGroup.find(group.id) }
let(:svc_model_vm) { MiqAeMethodService::MiqAeServiceVm.find(vm.id) }
let(:svc_model_task) { MiqAeMethodService::MiqAeServiceServiceTemplateTransformationPlanTask.find(task.id) }

let(:root) do
Spec::Support::MiqAeMockObject.new(
'current' => current_object,
'user' => svc_model_user,
'state_machine_phase' => 'transformation'
)
end

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

before do
ManageIQ::Automate::Transformation::Infrastructure::VM::Common::CheckPoweredOn.instance_variable_set(:@task, nil)
ManageIQ::Automate::Transformation::Infrastructure::VM::Common::CheckPoweredOn.instance_variable_set(:@vm, nil)
allow(ManageIQ::Automate::Transformation::Common::Utils).to receive(:task).and_return(svc_model_task)
allow(ManageIQ::Automate::Transformation::Common::Utils).to receive(:source_vm).and_return(svc_model_vm)
allow(ManageIQ::Automate::Transformation::Common::Utils).to receive(:destination_vm).and_return(svc_model_vm)
allow(svc_model_task).to receive(:get_option).with(:source_vm_power_state).and_return('on')
allow(svc_model_vm).to receive(:power_state).and_return('off')
end

shared_examples_for "#main" do
it "retries if VM is not powered on" do
described_class.new(ae_service).main
expect(ae_service.root['ae_result']).to eq('retry')
expect(ae_service.root['ae_retry_interval']).to eq('15.seconds')
end
end

describe "#main" do
context "handling source vm" do
before { ae_service.root['state_machine_phase'] = 'transformation' }
it_behaves_like "#main"
end

context "handling destination vm" do
before { ae_service.root['state_machine_phase'] = 'cleanup' }
it_behaves_like "#main"
end

it "raises if task preflight check raises" do
errormsg = 'Unexpected error'
allow(svc_model_task).to receive(:get_option).with(:source_vm_power_state).and_raise(errormsg)
expect { described_class.new(ae_service).main }.to raise_error(errormsg)
expect(ae_service.get_state_var(:ae_state_progress)).to eq('message' => errormsg)
end
end
end

0 comments on commit 33f1d27

Please sign in to comment.