-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Merge pull request #575 from fdupont-redhat/v2v_state_machine…
…_power_on" This reverts commit b55b85a. https://bugzilla.redhat.com/show_bug.cgi?id=1768539
- Loading branch information
Showing
10 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__class__.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
39 changes: 39 additions & 0 deletions
39
...mate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/checkpoweredon.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
15 changes: 15 additions & 0 deletions
15
...te/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/checkpoweredon.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [] |
35 changes: 35 additions & 0 deletions
35
...nt/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweron.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
15 changes: 15 additions & 0 deletions
15
.../automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/poweron.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: [] |
12 changes: 12 additions & 0 deletions
12
content/automate/ManageIQ/Transformation/Infrastructure/VM/Common.class/_missing.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
10 changes: 10 additions & 0 deletions
10
content/automate/ManageIQ/Transformation/Infrastructure/VM/__namespace__.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
10 changes: 10 additions & 0 deletions
10
content/automate/ManageIQ/Transformation/Infrastructure/__namespace__.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...ManageIQ/Transformation/Infrastructure/VM/Common.class/__methods__/checkpoweredon_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |