From 50dde45a0ab3b2b8c91b43fa72dda4b1bf4c2858 Mon Sep 17 00:00:00 2001 From: Satoe Imaishi Date: Tue, 3 Dec 2019 12:44:51 -0500 Subject: [PATCH] Revert "Merge pull request #19238 from fdupont-redhat/v2v_state_machine_apply_right_size" This reverts commit bf502643dd759b65da14163a86f5cda96771e521. https://bugzilla.redhat.com/show_bug.cgi?id=1768522 --- app/models/infra_conversion_job.rb | 84 ++------ .../validate_config_info.rb | 2 - ...rvice_template_transformation_plan_task.rb | 8 - spec/models/infra_conversion_job_spec.rb | 186 +++--------------- 4 files changed, 37 insertions(+), 243 deletions(-) diff --git a/app/models/infra_conversion_job.rb b/app/models/infra_conversion_job.rb index 566804eb822..2ee70bd7ade 100644 --- a/app/models/infra_conversion_job.rb +++ b/app/models/infra_conversion_job.rb @@ -44,14 +44,9 @@ def load_transitions :poll_shutdown_vm_complete => {'shutting_down_vm' => 'shutting_down_vm'}, :transform_vm => {'shutting_down_vm' => 'transforming_vm'}, :poll_transform_vm_complete => {'transforming_vm' => 'transforming_vm'}, - :poll_inventory_refresh_complete => { - 'transforming_vm' => 'waiting_for_inventory_refresh', - 'waiting_for_inventory_refresh' => 'waiting_for_inventory_refresh' - }, - :apply_right_sizing => {'waiting_for_inventory_refresh' => 'applying_right_sizing'}, :poll_automate_state_machine => { - 'applying_right_sizing' => 'running_in_automate', - 'running_in_automate' => 'running_in_automate' + 'transforming_vm' => 'running_in_automate', + 'running_in_automate' => 'running_in_automate' }, :finish => {'*' => 'finished'}, :abort_job => {'*' => 'aborting'}, @@ -68,41 +63,32 @@ def load_transitions # } def state_settings @state_settings ||= { - :removing_snapshots => { + :removing_snapshots => { :description => 'Remove snapshosts', :weight => 5, :max_retries => 4.hours / state_retry_interval }, - :waiting_for_ip_address => { + :waiting_for_ip_address => { :description => 'Waiting for VM IP address', :weight => 1, :max_retries => 1.hour / state_retry_interval }, - :running_migration_playbook => { + :running_migration_playbook => { :description => "Running #{migration_phase}-migration playbook", :weight => 10, :max_retries => 6.hours / state_retry_interval }, - :shutting_down_vm => { + :shutting_down_vm => { :description => "Shutting down virtual machine", :weight => 1, :max_retries => 15.minutes / state_retry_interval }, - :transforming_vm => { + :transforming_vm => { :description => "Converting disks", :weight => 60, :max_retries => 1.day / state_retry_interval }, - :waiting_for_inventory_refresh => { - :description => "Identify destination VM", - :weight => 4, - :max_retries => 1.hour / state_retry_interval - }, - :applying_right_sizing => { - :description => "Apply Right-Sizing Recommendation", - :weight => 1 - }, - :running_in_automate => { + :running_in_automate => { :max_retries => 36.hours / state_retry_interval } } @@ -126,7 +112,11 @@ def source_vm end def destination_vm - @destination_vm ||= migration_task.destination + return nil if migration_task.options[:destination_vm_id].nil? + + @destination_vm ||= Vm.find(migration_task.options[:destination_vm_id]).tap do |vm| + raise "No Vm in VMDB with id #{migration_task.options[:destination_vm_id]}" if vm.nil? + end end def target_vm @@ -224,14 +214,6 @@ def order_ansible_playbook_service service_template.provision_request(migration_task.userid.to_i, service_dialog_options) end - def apply_right_sizing_cpu(mode) - destination_vm.set_number_of_cpus(source_vm.send("#{mode}_recommended_vcpus")) - end - - def apply_right_sizing_memory(mode) - destination_vm.set_memory(source_vm.send("#{mode}_recommended_mem")) - end - # --- Methods that implement the state machine transitions --- # # This transition simply allows to officially mark the task as migrating. @@ -412,6 +394,7 @@ def poll_transform_vm_complete raise migration_task.options[:virtv2v_message] when 'succeeded' update_migration_task_progress(:on_exit) + handover_to_automate queue_signal(:poll_automate_state_machine) end rescue StandardError => error @@ -419,45 +402,6 @@ def poll_transform_vm_complete abort_conversion(error.message, 'error') end - # This methods waits for the destination EMS inventory to refresh. - # It updates the migration_task.destination relationship with the create VM. - # We don't force the EMS refresh and rather allow 1 hour to get it. - def poll_inventory_refresh_complete - update_migration_task_progress(:on_entry) - return abort_conversion('Identify destination VM timed out', 'error') if polling_timeout - - destination_vm = Vm.find_by(:name => migration_task.source.name, :ems_id => migration_task.destination_ems.id) - if destination_vm.nil? - update_migration_task_progress(:on_retry) - return queue_signal(:poll_inventory_refresh_complete, :deliver_on => Time.now.utc + state_retry_interval) - end - - migration_task.update!(:destination => destination_vm) - migration_task.update_options(:migration_phase => 'post') - update_migration_task_progress(:on_exit) - queue_signal(:apply_right_sizing) - rescue StandardError => error - update_migration_task_progress(:on_error) - abort_conversion(error.message, 'error') - end - - def apply_right_sizing - update_migration_task_progress(:on_entry) - - %i[cpu memory].each do |item| - right_sizing_mode = migration_task.send("#{item}_right_sizing_mode") - send("apply_right_sizing_#{item}", right_sizing_mode) if right_sizing_mode.present? - end - - update_migration_task_progress(:on_exit) - handover_to_automate - queue_signal(:poll_automate_state_machine) - 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 diff --git a/app/models/service_template_transformation_plan/validate_config_info.rb b/app/models/service_template_transformation_plan/validate_config_info.rb index 922633978b9..4ce859e1121 100644 --- a/app/models/service_template_transformation_plan/validate_config_info.rb +++ b/app/models/service_template_transformation_plan/validate_config_info.rb @@ -32,8 +32,6 @@ def validate_config_info(options) vm_options[:post_ansible_playbook_service_template_id] = post_service_id if vm_hash[:post_service] vm_options[:osp_security_group_id] = vm_hash[:osp_security_group_id] if vm_hash[:osp_security_group_id].present? vm_options[:osp_flavor_id] = vm_hash[:osp_flavor_id] if vm_hash[:osp_flavor_id].present? - vm_options[:cpu_right_sizing_mode] = vm_hash[:cpu_right_sizing_mode] if vm_hash[:cpu_right_sizing_mode].present? - vm_options[:memory_right_sizing_mode] = vm_hash[:memory_right_sizing_mode] if vm_hash[:memory_right_sizing_mode].present? vms << {:vm => vm_obj, :options => vm_options} end end diff --git a/app/models/service_template_transformation_plan_task.rb b/app/models/service_template_transformation_plan_task.rb index 61ec823315f..c801a5677ef 100644 --- a/app/models/service_template_transformation_plan_task.rb +++ b/app/models/service_template_transformation_plan_task.rb @@ -31,14 +31,6 @@ def post_ansible_playbook_service_template ServiceTemplate.find_by(:id => vm_resource.options["post_ansible_playbook_service_template_id"]) end - def cpu_right_sizing_mode - vm_resource.options["cpu_right_sizing_mode"] - end - - def memory_right_sizing_mode - vm_resource.options["memory_right_sizing_mode"] - end - def update_transformation_progress(progress) update_options(:progress => (options[:progress] || {}).merge(progress)) end diff --git a/spec/models/infra_conversion_job_spec.rb b/spec/models/infra_conversion_job_spec.rb index d04bca4245f..8c24e488073 100644 --- a/spec/models/infra_conversion_job_spec.rb +++ b/spec/models/infra_conversion_job_spec.rb @@ -93,8 +93,7 @@ end it 'returns vm_redhat if migration phase is "post"' do - task.update_options(:migration_phase => 'post') - task.update!(:destination => vm_redhat) + task.update_options(:migration_phase => 'post', :destination_vm_id => vm_redhat.id) task.reload expect(job.target_vm.id).to eq(vm_redhat.id) end @@ -349,7 +348,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 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_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) @@ -358,7 +357,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 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_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}/) @@ -386,7 +385,6 @@ 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 poll_automate_state_machine signal' end @@ -410,7 +408,6 @@ 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 poll_automate_state_machine signal' end @@ -434,7 +431,6 @@ 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 poll_automate_state_machine signal' end @@ -458,7 +454,6 @@ 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 poll_automate_state_machine signal' end @@ -482,7 +477,6 @@ 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 poll_automate_state_machine signal' end @@ -506,7 +500,6 @@ 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_transform_vm_complete signal' - it_behaves_like 'doesn\'t allow poll_inventory_refresh_complete signal' it_behaves_like 'doesn\'t allow poll_automate_state_machine signal' end @@ -516,53 +509,6 @@ end it_behaves_like 'allows poll_transform_vm_complete signal' - it_behaves_like 'allows poll_inventory_refresh_complete 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_automate_state_machine signal' - end - - context 'waiting_for_inventory_refresh' do - before do - job.state = 'waiting_for_inventory_refresh' - end - - it_behaves_like 'allows poll_inventory_refresh_complete signal' - it_behaves_like 'allows apply_right_sizing 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' - end - - context 'applying_right_sizing' do - before do - job.state = 'applying_right_sizing' - end - it_behaves_like 'allows poll_automate_state_machine signal' it_behaves_like 'allows finish signal' it_behaves_like 'allows abort_job signal' @@ -578,9 +524,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 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 'running_in_automate' do @@ -604,8 +547,6 @@ 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 end @@ -977,118 +918,37 @@ expect(job).to receive(:queue_signal).with(:poll_automate_state_machine) job.signal(:poll_transform_vm_complete) expect(task.reload.options[:progress][:states][job.state.to_sym]).to include(:percent => 100.0) + expect(task.options[:workflow_runner]).to eq('automate') end end end - end - - context '#poll_inventory_refresh_complete' do - before do - job.state = 'waiting_for_inventory_refresh' - end - - it 'abort_conversion when waiting_for_inventory_refresh times out' do - job.context[:retries_waiting_for_inventory_refresh] = 240 - expect(job).to receive(:abort_conversion).with('Identify destination VM timed out', 'error') - job.signal(:poll_inventory_refresh_complete) - end - - it 'retry when destination VM is not in the inventory' do - 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_inventory_refresh_complete, :deliver_on => Time.now.utc + job.state_retry_interval) - job.signal(:poll_inventory_refresh_complete) - end - end - - it 'to finish when migration_task.state is finished' do - allow(Vm).to receive(:find_by).with(:name => task.source.name, :ems_id => task.destination_ems.id).and_return(vm_redhat) - Timecop.freeze(2019, 2, 6) do - expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_entry).and_call_original - expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_exit).and_call_original - expect(job).to receive(:queue_signal).with(:apply_right_sizing) - job.signal(:poll_inventory_refresh_complete) - expect(job.migration_task.destination.id).to eq(vm_redhat.id) - end - end - end - context '#apply_right_sizing' do - before do - job.state = 'waiting_for_inventory_refresh' - task.update!(:destination => vm_redhat) - end - - 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(: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 + context '#poll_automate_state_machine' do before do - allow(job.migration_task).to receive(:cpu_right_sizing_mode).and_return(nil) - allow(job.migration_task).to receive(:memory_right_sizing_mode).and_return(nil) - end - - 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(:poll_automate_state_machine) - job.signal(:apply_right_sizing) - expect(task.reload.options[:workflow_runner]).to eq('automate') - end - end - - context 'with right_sizing_mode' do - before do - allow(job.migration_task).to receive(:cpu_right_sizing_mode).and_return(:aggressive) - allow(job.migration_task).to receive(:memory_right_sizing_mode).and_return(:conservative) - allow(job.migration_task.source).to receive(:aggressive_recommended_vcpus).and_return(1) - allow(job.migration_task.source).to receive(:conservative_recommended_mem).and_return(1024) + job.state = 'running_in_automate' end - it 'applies right-sizing if mode is set' do - expect(job).to receive(:update_migration_task_progress).once.ordered.with(:on_entry) - 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(:poll_automate_state_machine) - job.signal(:apply_right_sizing) - expect(task.reload.options[:workflow_runner]).to eq('automate') + it 'abort_conversion when running_in_automate times out' do + job.context[:retries_running_in_automate] = 8640 + expect(job).to receive(:abort_conversion).with('Polling Automate state machine timed out', 'error') + job.signal(:poll_automate_state_machine) end - end - end - - context '#poll_automate_state_machine' do - before do - job.state = 'running_in_automate' - end - - it 'abort_conversion when running_in_automate times out' do - job.context[:retries_running_in_automate] = 8640 - expect(job).to receive(:abort_conversion).with('Polling Automate state machine timed out', 'error') - job.signal(:poll_automate_state_machine) - end - it 'to poll_automate_state_machine when migration_task.state is not finished' do - task.update!(:state => 'migrate') - Timecop.freeze(2019, 2, 6) do - expect(job).to receive(:queue_signal).with(:poll_automate_state_machine, :deliver_on => Time.now.utc + job.state_retry_interval) - job.signal(:poll_automate_state_machine) + it 'to poll_automate_state_machine when migration_task.state is not finished' do + task.update!(:state => 'migrate') + Timecop.freeze(2019, 2, 6) do + expect(job).to receive(:queue_signal).with(:poll_automate_state_machine, :deliver_on => Time.now.utc + job.state_retry_interval) + job.signal(:poll_automate_state_machine) + end end - end - it 'to finish when migration_task.state is finished' do - task.update!(:state => 'finished', :status => 'Ok') - Timecop.freeze(2019, 2, 6) do - expect(job).to receive(:queue_signal).with(:finish) - job.signal(:poll_automate_state_machine) - expect(job.status).to eq(task.status) + it 'to finish when migration_task.state is finished' do + task.update!(:state => 'finished', :status => 'Ok') + Timecop.freeze(2019, 2, 6) do + expect(job).to receive(:queue_signal).with(:finish) + job.signal(:poll_automate_state_machine) + expect(job.status).to eq(task.status) + end end end end