Skip to content

Commit

Permalink
Revert "Merge pull request #19241 from fdupont-redhat/v2v_state_machi…
Browse files Browse the repository at this point in the history
  • Loading branch information
simaishi committed Dec 3, 2019
1 parent f9ad31a commit bed579c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 176 deletions.
47 changes: 3 additions & 44 deletions app/models/infra_conversion_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ def load_transitions
},
:apply_right_sizing => {'waiting_for_inventory_refresh' => 'applying_right_sizing'},
:restore_vm_attributes => {'applying_right_sizing' => 'restoring_vm_attributes'},
:power_on_vm => {'restoring_vm_attributes' => 'powering_on_vm' },
:poll_power_on_vm_complete => {'powering_on_vm' => 'powering_on_vm'},
:poll_automate_state_machine => {
'powering_on_vm' => 'running_in_automate',
'running_in_automate' => 'running_in_automate'
'restoring_vm_attributes' => 'running_in_automate',
'running_in_automate' => 'running_in_automate'
},
:finish => {'*' => 'finished'},
:abort_job => {'*' => 'aborting'},
Expand Down Expand Up @@ -109,11 +107,6 @@ def state_settings
:description => "Restore VM Attributes",
:weight => 1
},
:powering_on_vm => {
:description => "Power on virtual machine",
:weight => 1,
:max_retries => 15.minutes / state_retry_interval
},
:running_in_automate => {
:max_retries => 36.hours / state_retry_interval
}
Expand Down Expand Up @@ -142,7 +135,7 @@ def destination_vm
end

def target_vm
return @target_vm = source_vm if migration_phase == 'pre' || migration_task.canceling?
return @target_vm = source_vm if migration_phase == 'pre'
return @target_vm = destination_vm if migration_phase == 'post'
end

Expand Down Expand Up @@ -500,22 +493,6 @@ def restore_vm_attributes
# Save destination_vm in VMDB
destination_vm.save

update_migration_task_progress(:on_exit)
queue_signal(:power_on_vm)
rescue StandardError
update_migration_task_progress(:on_error)
queue_signal(:power_on_vm)
end

def power_on_vm
update_migration_task_progress(:on_entry)

if migration_task.options[:source_vm_power_state] == 'on' && target_vm.power_state != 'on'
target_vm.start
update_migration_task_progress(:on_exit)
return queue_signal(:poll_power_on_vm_complete, :deliver_on => Time.now.utc + state_retry_interval)
end

update_migration_task_progress(:on_exit)
handover_to_automate
queue_signal(:poll_automate_state_machine)
Expand All @@ -525,24 +502,6 @@ def power_on_vm
queue_signal(:poll_automate_state_machine)
end

def poll_power_on_vm_complete
update_migration_task_progress(:on_entry)
raise 'Powering on VM timed out' if polling_timeout

if target_vm.power_state == 'on'
update_migration_task_progress(:on_exit)
handover_to_automate
return queue_signal(:poll_automate_state_machine)
end

update_migration_task_progress(:on_retry)
queue_signal(:poll_power_on_vm_complete, :deliver_on => Time.now.utc + state_retry_interval)
rescue StandardError
update_migration_task_progress(:on_error)
handover_to_automate
queue_signal(:poll_automate_state_machine)
end

def poll_automate_state_machine
return abort_conversion('Polling Automate state machine timed out', 'error') if polling_timeout

Expand Down
138 changes: 6 additions & 132 deletions spec/models/infra_conversion_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@
end

context 'state transitions' do
%w[start remove_snapshots poll_remove_snapshots_complete wait_for_ip_address run_migration_playbook poll_run_migration_playbook_complete shutdown_vm poll_shutdown_vm_complete transform_vm poll_transform_vm_complete poll_inventory_refresh_complete apply_right_sizing restore_vm_attributes power_on_vm poll_power_on_vm_complete poll_automate_state_machine finish abort_job cancel error].each do |signal|
%w[start remove_snapshots poll_remove_snapshots_complete wait_for_ip_address run_migration_playbook poll_run_migration_playbook_complete shutdown_vm poll_shutdown_vm_complete transform_vm poll_transform_vm_complete poll_inventory_refresh_complete apply_right_sizing restore_vm_attributes poll_automate_state_machine finish abort_job cancel error].each do |signal|
shared_examples_for "allows #{signal} signal" do
it signal.to_s do
expect(job).to receive(signal.to_sym)
Expand All @@ -361,7 +361,7 @@
end
end

%w[start remove_snapshots poll_remove_snapshots_complete wait_for_ip_address run_migration_playbook poll_run_migration_playbook_complete shutdown_vm poll_shutdown_vm_complete transform_vm poll_transform_vm_complete poll_inventory_refresh_complete apply_right_sizing restore_vm_attributes power_on_vm poll_power_on_vm_complete poll_automate_state_machine].each do |signal|
%w[start remove_snapshots poll_remove_snapshots_complete wait_for_ip_address run_migration_playbook poll_run_migration_playbook_complete shutdown_vm poll_shutdown_vm_complete transform_vm poll_transform_vm_complete poll_inventory_refresh_complete apply_right_sizing restore_vm_attributes poll_automate_state_machine].each do |signal|
shared_examples_for "doesn't allow #{signal} signal" do
it signal.to_s do
expect { job.signal(signal.to_sym) }.to raise_error(RuntimeError, /#{signal} is not permitted at state #{job.state}/)
Expand Down Expand Up @@ -392,8 +392,6 @@
it_behaves_like 'doesn\'t allow poll_inventory_refresh_complete signal'
it_behaves_like 'doesn\'t allow apply_right_sizing signal'
it_behaves_like 'doesn\'t allow restore_vm_attributes signal'
it_behaves_like 'doesn\'t allow power_on_vm signal'
it_behaves_like 'doesn\'t allow poll_power_on_vm_complete signal'
it_behaves_like 'doesn\'t allow poll_automate_state_machine signal'
end

Expand All @@ -420,8 +418,6 @@
it_behaves_like 'doesn\'t allow poll_inventory_refresh_complete signal'
it_behaves_like 'doesn\'t allow apply_right_sizing signal'
it_behaves_like 'doesn\'t allow restore_vm_attributes signal'
it_behaves_like 'doesn\'t allow power_on_vm signal'
it_behaves_like 'doesn\'t allow poll_power_on_vm_complete signal'
it_behaves_like 'doesn\'t allow poll_automate_state_machine signal'
end

Expand All @@ -448,8 +444,6 @@
it_behaves_like 'doesn\'t allow poll_inventory_refresh_complete signal'
it_behaves_like 'doesn\'t allow apply_right_sizing signal'
it_behaves_like 'doesn\'t allow restore_vm_attributes signal'
it_behaves_like 'doesn\'t allow power_on_vm signal'
it_behaves_like 'doesn\'t allow poll_power_on_vm_complete signal'
it_behaves_like 'doesn\'t allow poll_automate_state_machine signal'
end

Expand All @@ -476,8 +470,6 @@
it_behaves_like 'doesn\'t allow poll_inventory_refresh_complete signal'
it_behaves_like 'doesn\'t allow apply_right_sizing signal'
it_behaves_like 'doesn\'t allow restore_vm_attributes signal'
it_behaves_like 'doesn\'t allow power_on_vm signal'
it_behaves_like 'doesn\'t allow poll_power_on_vm_complete signal'
it_behaves_like 'doesn\'t allow poll_automate_state_machine signal'
end

Expand All @@ -504,8 +496,6 @@
it_behaves_like 'doesn\'t allow poll_inventory_refresh_complete signal'
it_behaves_like 'doesn\'t allow apply_right_sizing signal'
it_behaves_like 'doesn\'t allow restore_vm_attributes signal'
it_behaves_like 'doesn\'t allow power_on_vm signal'
it_behaves_like 'doesn\'t allow poll_power_on_vm_complete signal'
it_behaves_like 'doesn\'t allow poll_automate_state_machine signal'
end

Expand All @@ -532,8 +522,6 @@
it_behaves_like 'doesn\'t allow poll_inventory_refresh_complete signal'
it_behaves_like 'doesn\'t allow apply_right_sizing signal'
it_behaves_like 'doesn\'t allow restore_vm_attributes signal'
it_behaves_like 'doesn\'t allow power_on_vm signal'
it_behaves_like 'doesn\'t allow poll_power_on_vm_complete signal'
it_behaves_like 'doesn\'t allow poll_automate_state_machine signal'
end

Expand All @@ -560,8 +548,6 @@
it_behaves_like 'doesn\'t allow transform_vm signal'
it_behaves_like 'doesn\'t allow apply_right_sizing signal'
it_behaves_like 'doesn\'t allow restore_vm_attributes signal'
it_behaves_like 'doesn\'t allow power_on_vm signal'
it_behaves_like 'doesn\'t allow poll_power_on_vm_complete signal'
it_behaves_like 'doesn\'t allow poll_automate_state_machine signal'
end

Expand All @@ -588,9 +574,6 @@
it_behaves_like 'doesn\'t allow transform_vm signal'
it_behaves_like 'doesn\'t allow poll_transform_vm_complete signal'
it_behaves_like 'doesn\'t allow restore_vm_attributes signal'
it_behaves_like 'doesn\'t allow power_on_vm signal'
it_behaves_like 'doesn\'t allow poll_power_on_vm_complete signal'
it_behaves_like 'doesn\'t allow poll_automate_state_machine signal'
end

context 'applying_right_sizing' do
Expand All @@ -616,45 +599,13 @@
it_behaves_like 'doesn\'t allow poll_transform_vm_complete signal'
it_behaves_like 'doesn\'t allow poll_inventory_refresh_complete signal'
it_behaves_like 'doesn\'t allow apply_right_sizing signal'
it_behaves_like 'doesn\'t allow power_on_vm signal'
it_behaves_like 'doesn\'t allow poll_power_on_vm_complete signal'
it_behaves_like 'doesn\'t allow poll_automate_state_machine signal'
end

context 'restoring_vm_attributes' do
before do
job.state = 'restoring_vm_attributes'
end

it_behaves_like 'allows power_on_vm signal'
it_behaves_like 'allows finish signal'
it_behaves_like 'allows abort_job signal'
it_behaves_like 'allows cancel signal'
it_behaves_like 'allows error signal'

it_behaves_like 'doesn\'t allow start signal'
it_behaves_like 'doesn\'t allow remove_snapshots signal'
it_behaves_like 'doesn\'t allow poll_remove_snapshots_complete signal'
it_behaves_like 'doesn\'t allow wait_for_ip_address signal'
it_behaves_like 'doesn\'t allow run_migration_playbook signal'
it_behaves_like 'doesn\'t allow poll_run_migration_playbook_complete signal'
it_behaves_like 'doesn\'t allow shutdown_vm signal'
it_behaves_like 'doesn\'t allow poll_shutdown_vm_complete signal'
it_behaves_like 'doesn\'t allow transform_vm signal'
it_behaves_like 'doesn\'t allow poll_transform_vm_complete signal'
it_behaves_like 'doesn\'t allow poll_inventory_refresh_complete signal'
it_behaves_like 'doesn\'t allow apply_right_sizing signal'
it_behaves_like 'doesn\'t allow restore_vm_attributes signal'
it_behaves_like 'doesn\'t allow poll_power_on_vm_complete signal'
it_behaves_like 'doesn\'t allow poll_automate_state_machine signal'
end

context 'powering_on_vm' do
before do
job.state = 'powering_on_vm'
end

it_behaves_like 'allows poll_power_on_vm_complete signal'
it_behaves_like 'allows poll_automate_state_machine signal'
it_behaves_like 'allows finish signal'
it_behaves_like 'allows abort_job signal'
Expand All @@ -674,7 +625,6 @@
it_behaves_like 'doesn\'t allow poll_inventory_refresh_complete signal'
it_behaves_like 'doesn\'t allow apply_right_sizing signal'
it_behaves_like 'doesn\'t allow restore_vm_attributes signal'
it_behaves_like 'doesn\'t allow power_on_vm signal'
end

context 'running_in_automate' do
Expand All @@ -701,8 +651,6 @@
it_behaves_like 'doesn\'t allow poll_inventory_refresh_complete signal'
it_behaves_like 'doesn\'t allow apply_right_sizing signal'
it_behaves_like 'doesn\'t allow restore_vm_attributes signal'
it_behaves_like 'doesn\'t allow power_on_vm signal'
it_behaves_like 'doesn\'t allow poll_power_on_vm_complete signal'
end
end

Expand Down Expand Up @@ -1172,8 +1120,9 @@
allow(job.migration_task.source).to receive(:service).and_raise('Fake error message')
expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_entry)
expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_error)
expect(job).to receive(:queue_signal).with(:power_on_vm)
expect(job).to receive(:queue_signal).with(:poll_automate_state_machine)
job.signal(:restore_vm_attributes)
expect(task.reload.options[:workflow_runner]).to eq('automate')
end

it 'restore VM attributes' do
Expand All @@ -1186,7 +1135,7 @@
vm_vmware.update!(:retirement_warn => 7)
expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_entry)
expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_exit)
expect(job).to receive(:queue_signal).with(:power_on_vm)
expect(job).to receive(:queue_signal).with(:poll_automate_state_machine)
job.signal(:restore_vm_attributes)
vm_redhat.reload
expect(vm_vmware.service).to be_nil
Expand All @@ -1197,86 +1146,11 @@
expect(vm_redhat.miq_group.id).to eq(group.id)
expect(vm_redhat.retires_on).to eq(Time.now.utc + 1.day)
expect(vm_redhat.retirement_warn).to eq(7)
expect(task.reload.options[:workflow_runner]).to eq('automate')
end
end
end

context '#power_on_vm' do
before do
job.state = 'restoring_vm_attributes'
task.update_options(:migration_phase => 'post')
task.update!(:destination => vm_redhat)
end

it 'exits if VM is already on' do
vm_redhat.update!(:raw_power_state => 'poweredOn')
task.update_options(:source_vm_power_state => 'on')
expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_entry)
expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_exit)
expect(job).to receive(:queue_signal).with(:poll_automate_state_machine)
job.signal(:power_on_vm)
expect(task.reload.options[:workflow_runner]).to eq('automate')
end

it "exits if source VM power state was not 'on'" do
vm_redhat.update!(:raw_power_state => 'poweredOff')
task.update_options(:source_vm_power_state => 'off')
expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_entry)
expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_exit)
expect(job).to receive(:queue_signal).with(:poll_automate_state_machine)
job.signal(:power_on_vm)
expect(task.reload.options[:workflow_runner]).to eq('automate')
end

it 'sends start request to VM if VM is off' do
vm_redhat.update!(:raw_power_state => 'poweredOff')
task.update_options(:source_vm_power_state => 'on')
Timecop.freeze(2019, 2, 6) do
expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_entry)
expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_exit)
expect(job.migration_task.destination).to receive(:start)
expect(job).to receive(:queue_signal).with(:poll_power_on_vm_complete, :deliver_on => Time.now.utc + job.state_retry_interval)
job.signal(:power_on_vm)
end
end
end

context '#poll_power_on_vm_complete' do
before do
job.state = 'powering_on_vm'
task.update_options(:migration_phase => 'post')
task.update!(:destination => vm_redhat)
end

it "exits to next state in case of failure" do
job.context[:retries_powering_on_vm] = 60
expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_entry)
expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_error)
expect(job).to receive(:queue_signal).with(:poll_automate_state_machine)
job.signal(:poll_power_on_vm_complete)
expect(task.reload.options[:workflow_runner]).to eq('automate')
end

it 'retries if VM is not on' do
vm_redhat.update!(:raw_power_state => 'poweredOff')
Timecop.freeze(2019, 2, 6) do
expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_entry)
expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_retry)
expect(job).to receive(:queue_signal).with(:poll_power_on_vm_complete, :deliver_on => Time.now.utc + job.state_retry_interval)
job.signal(:poll_power_on_vm_complete)
end
end

it 'exits if VM is on' do
vm_redhat.update!(:raw_power_state => 'poweredOn')
expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_entry)
expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_exit)
expect(job).to receive(:queue_signal).with(:poll_automate_state_machine)
job.signal(:poll_power_on_vm_complete)
expect(task.reload.options[:workflow_runner]).to eq('automate')
end
end

context '#poll_automate_state_machine' do
before do
job.state = 'running_in_automate'
Expand Down

0 comments on commit bed579c

Please sign in to comment.