Skip to content

Commit

Permalink
Revert "Merge pull request #19240 from fdupont-redhat/v2v_state_machi…
Browse files Browse the repository at this point in the history
…ne_restore_vm_attributes"

This reverts commit b752d4e.

https://bugzilla.redhat.com/show_bug.cgi?id=1768524
  • Loading branch information
simaishi committed Dec 3, 2019
1 parent bed579c commit 4b68205
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 143 deletions.
48 changes: 2 additions & 46 deletions app/models/infra_conversion_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,9 @@ def load_transitions
'waiting_for_inventory_refresh' => 'waiting_for_inventory_refresh'
},
:apply_right_sizing => {'waiting_for_inventory_refresh' => 'applying_right_sizing'},
:restore_vm_attributes => {'applying_right_sizing' => 'restoring_vm_attributes'},
:poll_automate_state_machine => {
'restoring_vm_attributes' => 'running_in_automate',
'running_in_automate' => 'running_in_automate'
'applying_right_sizing' => 'running_in_automate',
'running_in_automate' => 'running_in_automate'
},
:finish => {'*' => 'finished'},
:abort_job => {'*' => 'aborting'},
Expand Down Expand Up @@ -103,10 +102,6 @@ def state_settings
:description => "Apply Right-Sizing Recommendation",
:weight => 1
},
:restoring_vm_attributes => {
:description => "Restore VM Attributes",
:weight => 1
},
:running_in_automate => {
:max_retries => 36.hours / state_retry_interval
}
Expand Down Expand Up @@ -454,45 +449,6 @@ def apply_right_sizing
send("apply_right_sizing_#{item}", right_sizing_mode) if right_sizing_mode.present?
end

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

def restore_vm_attributes
update_migration_task_progress(:on_entry)

# Transfer service link to destination VM
if source_vm.service
destination_vm.add_to_service(source_vm.service)
source_vm.direct_service.try(:remove_resource, source_vm)
end

# Copy tags and custom attributes from source VM
source_vm.tags.each do |tag|
next if tag.name =~ /^\/managed\/folder_path_/

tag_as_array = tag.name.split('/')
namespace = tag_as_array.shift
value = tag_as_array.pop
category = tag_as_array.join('/')
destination_vm.tag_add("#{category}/#{value}", :ns => namespace)
end
source_vm.miq_custom_keys.each { |ca| destination_vm.miq_custom_set(ca, source_vm.miq_custom_get(ca)) }

# Copy ownership from source VM
destination_vm.evm_owner = source_vm.evm_owner if source_vm.present?
destination_vm.miq_group = source_vm.miq_group if source_vm.miq_group.present?

# Copy retirement settings from source VM
destination_vm.retires_on = source_vm.retires_on if source_vm.retires_on.present?
destination_vm.retirement_warn = source_vm.retirement_warn if source_vm.retirement_warn.present?

# Save destination_vm in VMDB
destination_vm.save

update_migration_task_progress(:on_exit)
handover_to_automate
queue_signal(:poll_automate_state_machine)
Expand Down
107 changes: 10 additions & 97 deletions spec/models/infra_conversion_job_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
RSpec.describe InfraConversionJob, :v2v do
let(:user) { FactoryBot.create(:user_with_group) }
let(:user_admin) { FactoryBot.create(:user_admin) }
let(:group) { FactoryBot.create(:miq_group) }
let(:zone) { FactoryBot.create(:zone) }

let(:ems_vmware) { FactoryBot.create(:ems_vmware, :zone => zone) }
Expand All @@ -17,14 +15,13 @@
:ems_cluster => ems_cluster_vmware,
:host => host_vmware,
:hardware => hardware_vmware,
:evm_owner => user,
:miq_group => group)
:evm_owner => user)
end

let(:ems_redhat) { FactoryBot.create(:ems_redhat, :zone => zone) }
let(:ems_cluster_redhat) { FactoryBot.create(:ems_cluster, :ext_management_system => ems_redhat) }
let(:host_redhat) { FactoryBot.create(:host, :ext_management_system => ems_redhat, :ems_cluster => ems_cluster_redhat) }
let(:vm_redhat) { FactoryBot.create(:vm_vmware, :ext_management_system => ems_redhat, :ems_cluster => ems_cluster_redhat, :host => host_redhat, :evm_owner => user_admin) }
let(:vm_redhat) { FactoryBot.create(:vm_vmware, :ext_management_system => ems_redhat, :ems_cluster => ems_cluster_redhat, :host => host_redhat, :evm_owner => user) }

let(:embedded_ansible_auth) { FactoryBot.create(:embedded_ansible_credential) }
let(:embedded_ansible_catalog_item_options) do
Expand Down Expand Up @@ -352,7 +349,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 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 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 +358,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 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 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 @@ -390,8 +387,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 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_automate_state_machine signal'
end

Expand All @@ -416,8 +411,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 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_automate_state_machine signal'
end

Expand All @@ -442,8 +435,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 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_automate_state_machine signal'
end

Expand All @@ -468,8 +459,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 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_automate_state_machine signal'
end

Expand All @@ -494,8 +483,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 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_automate_state_machine signal'
end

Expand All @@ -520,8 +507,6 @@
it_behaves_like 'doesn\'t allow shutdown_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_automate_state_machine signal'
end

Expand All @@ -546,8 +531,6 @@
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 apply_right_sizing signal'
it_behaves_like 'doesn\'t allow restore_vm_attributes signal'
it_behaves_like 'doesn\'t allow poll_automate_state_machine signal'
end

Expand All @@ -573,39 +556,13 @@
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 restore_vm_attributes signal'
end

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

it_behaves_like 'allows restore_vm_attributes 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'
end

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

it_behaves_like 'allows poll_automate_state_machine signal'
it_behaves_like 'allows finish signal'
it_behaves_like 'allows abort_job signal'
Expand All @@ -624,7 +581,6 @@
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'
end

context 'running_in_automate' do
Expand All @@ -650,7 +606,6 @@
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'
end
end

Expand Down Expand Up @@ -1065,12 +1020,13 @@
task.update!(:destination => vm_redhat)
end

it "exits to next state in case of failure" do
it "exits to next state in case of failed" do
allow(job.migration_task).to receive(:cpu_right_sizing_mode).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(:restore_vm_attributes)
expect(job).to receive(:queue_signal).with(:poll_automate_state_machine)
job.signal(:apply_right_sizing)
expect(task.reload.options[:workflow_runner]).to eq('automate')
end

context 'without right_sizing mode' do
Expand All @@ -1082,8 +1038,9 @@
it 'exits if no right-sizing is requested' 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).to receive(:queue_signal).with(:restore_vm_attributes)
expect(job).to receive(:queue_signal).with(:poll_automate_state_machine)
job.signal(:apply_right_sizing)
expect(task.reload.options[:workflow_runner]).to eq('automate')
end
end

Expand All @@ -1100,52 +1057,8 @@
expect(job.migration_task.destination).to receive(:set_number_of_cpus).with(1)
expect(job.migration_task.destination).to receive(:set_memory).with(1024)
expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_exit)
expect(job).to receive(:queue_signal).with(:restore_vm_attributes)
job.signal(:apply_right_sizing)
end
end
end

context '#restore_vm_attributes' do
let(:service) { FactoryBot.create(:service) }
let(:parent_classification) { FactoryBot.create(:classification, :name => 'environment', :description => 'Environment') }
let(:classification) { FactoryBot.create(:classification, :name => 'prod', :description => 'Production', :parent => parent_classication) }

before do
job.state = 'applying_right_sizing'
task.update!(:destination => vm_redhat)
end

it "exits to next state in case of failure" do
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(:poll_automate_state_machine)
job.signal(:restore_vm_attributes)
expect(task.reload.options[:workflow_runner]).to eq('automate')
end

it 'restore VM attributes' do
Timecop.freeze(2019, 2, 6) do
vm_vmware.add_to_service(service)
vm_vmware.tag_with('test', :ns => '/managed', :cat => 'folder_path_spec')
vm_vmware.tag_with('prod', :ns => '/managed', :cat => 'environment')
vm_vmware.miq_custom_set('attr', 'value')
vm_vmware.update!(:retires_on => Time.now.utc + 1.day)
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(:poll_automate_state_machine)
job.signal(:restore_vm_attributes)
vm_redhat.reload
expect(vm_vmware.service).to be_nil
expect(vm_redhat.service.id).to eq(service.id)
expect(vm_redhat.tags).to eq(['/managed/environment/prod'])
expect(vm_redhat.miq_custom_get('attr')).to eq('value')
expect(vm_redhat.evm_owner.id).to eq(user.id)
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)
job.signal(:apply_right_sizing)
expect(task.reload.options[:workflow_runner]).to eq('automate')
end
end
Expand Down

0 comments on commit 4b68205

Please sign in to comment.