From 80b367fcf66e6ad1e24b2c167c30685c1807ac34 Mon Sep 17 00:00:00 2001 From: thearifismail Date: Tue, 15 Oct 2019 16:53:40 -0400 Subject: [PATCH 01/11] add VM validation for warm migration eligibilty and updated specs to deal with warm migration --- .../validate_config_info.rb | 1 + ...rvice_template_transformation_plan_spec.rb | 24 +++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) 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 d08e56a71bd..6413cddc9fe 100644 --- a/app/models/service_template_transformation_plan/validate_config_info.rb +++ b/app/models/service_template_transformation_plan/validate_config_info.rb @@ -63,6 +63,7 @@ def validate_config_info(options) raise _("Invalid VM found #{vm_obj.name}") if vm_obj.invalid? vm_options = {} + vm_options[:warm_migration_incompatible] = vm_obj.snapshots.present? vm_options[:pre_ansible_playbook_service_template_id] = pre_service_id if vm_hash[:pre_service] vm_options[:post_ansible_playbook_service_template_id] = post_service_id if vm_hash[:post_service] vm_options[:cpu_right_sizing_mode] = vm_hash[:cpu_right_sizing_mode] if vm_hash[:cpu_right_sizing_mode].present? diff --git a/spec/models/service_template_transformation_plan_spec.rb b/spec/models/service_template_transformation_plan_spec.rb index 0d0388537fc..c10044c659a 100644 --- a/spec/models/service_template_transformation_plan_spec.rb +++ b/spec/models/service_template_transformation_plan_spec.rb @@ -277,9 +277,9 @@ expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_incompatible" => false) expect(service_template.vm_resources.find_by(:resource_id => vm2.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_incompatible" => false) expect(service_template.config_info).to eq(catalog_item_options[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -355,11 +355,11 @@ expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2, vm3]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_incompatible" => false) expect(service_template.vm_resources.find_by(:resource_id => vm2.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_incompatible" => false) expect(service_template.vm_resources.find_by(:resource_id => vm3.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group2.id, "osp_flavor_id" => flavor2.id) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group2.id, "osp_flavor_id" => flavor2.id, "warm_migration_incompatible" => false) expect(service_template.config_info).to eq(updated_catalog_item_options_with_vms_added[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -377,7 +377,7 @@ expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED]) expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "warm_migration_incompatible" => false) expect(service_template.config_info).to eq(updated_catalog_item_options_with_vms_removed[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -395,9 +395,9 @@ expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm3]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "warm_migration_incompatible" => false) expect(service_template.vm_resources.find_by(:resource_id => vm3.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "warm_migration_incompatible" => false) expect(service_template.config_info).to eq(updated_catalog_item_options_with_vms_added_and_removed[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -416,9 +416,9 @@ expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_incompatible" => false) expect(service_template.vm_resources.find_by(:resource_id => vm2.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_incompatible" => false) expect(service_template.config_info).to eq(catalog_item_options[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -436,9 +436,9 @@ expect(service_template.transformation_mapping).to eq(transformation_mapping) expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2]) expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_incompatible" => false) expect(service_template.vm_resources.find_by(:resource_id => vm2.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_incompatible" => false) expect(service_template.config_info).to eq(catalog_item_options[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', From 3a115c7e0094ba6eeb54789d4a27da427cc80c98 Mon Sep 17 00:00:00 2001 From: thearifismail Date: Tue, 15 Oct 2019 17:57:15 -0400 Subject: [PATCH 02/11] removed :warm_migration_incompatible with :warm_migration_compatible --- .../validate_config_info.rb | 2 +- ...rvice_template_transformation_plan_spec.rb | 24 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) 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 6413cddc9fe..5c62fc5a3a2 100644 --- a/app/models/service_template_transformation_plan/validate_config_info.rb +++ b/app/models/service_template_transformation_plan/validate_config_info.rb @@ -63,7 +63,7 @@ def validate_config_info(options) raise _("Invalid VM found #{vm_obj.name}") if vm_obj.invalid? vm_options = {} - vm_options[:warm_migration_incompatible] = vm_obj.snapshots.present? + vm_options[:warm_migration_compatible] = !vm_obj.snapshots.present? vm_options[:pre_ansible_playbook_service_template_id] = pre_service_id if vm_hash[:pre_service] vm_options[:post_ansible_playbook_service_template_id] = post_service_id if vm_hash[:post_service] vm_options[:cpu_right_sizing_mode] = vm_hash[:cpu_right_sizing_mode] if vm_hash[:cpu_right_sizing_mode].present? diff --git a/spec/models/service_template_transformation_plan_spec.rb b/spec/models/service_template_transformation_plan_spec.rb index c10044c659a..5d18b2caf81 100644 --- a/spec/models/service_template_transformation_plan_spec.rb +++ b/spec/models/service_template_transformation_plan_spec.rb @@ -277,9 +277,9 @@ expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_incompatible" => false) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) expect(service_template.vm_resources.find_by(:resource_id => vm2.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_incompatible" => false) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) expect(service_template.config_info).to eq(catalog_item_options[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -355,11 +355,11 @@ expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2, vm3]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_incompatible" => false) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) expect(service_template.vm_resources.find_by(:resource_id => vm2.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_incompatible" => false) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) expect(service_template.vm_resources.find_by(:resource_id => vm3.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group2.id, "osp_flavor_id" => flavor2.id, "warm_migration_incompatible" => false) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group2.id, "osp_flavor_id" => flavor2.id, "warm_migration_compatible" => true) expect(service_template.config_info).to eq(updated_catalog_item_options_with_vms_added[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -377,7 +377,7 @@ expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED]) expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "warm_migration_incompatible" => false) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "warm_migration_compatible" => true) expect(service_template.config_info).to eq(updated_catalog_item_options_with_vms_removed[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -395,9 +395,9 @@ expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm3]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "warm_migration_incompatible" => false) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "warm_migration_compatible" => true) expect(service_template.vm_resources.find_by(:resource_id => vm3.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "warm_migration_incompatible" => false) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "warm_migration_compatible" => true) expect(service_template.config_info).to eq(updated_catalog_item_options_with_vms_added_and_removed[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -416,9 +416,9 @@ expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_incompatible" => false) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) expect(service_template.vm_resources.find_by(:resource_id => vm2.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_incompatible" => false) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) expect(service_template.config_info).to eq(catalog_item_options[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -436,9 +436,9 @@ expect(service_template.transformation_mapping).to eq(transformation_mapping) expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2]) expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_incompatible" => false) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) expect(service_template.vm_resources.find_by(:resource_id => vm2.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_incompatible" => false) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) expect(service_template.config_info).to eq(catalog_item_options[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', From c94efed5a9131b5c61e3cfb0671418dbbc82ffa7 Mon Sep 17 00:00:00 2001 From: thearifismail Date: Wed, 16 Oct 2019 09:13:08 -0400 Subject: [PATCH 03/11] replaced snapshots not_present with snapshots blank --- .../validate_config_info.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5c62fc5a3a2..2304aad0324 100644 --- a/app/models/service_template_transformation_plan/validate_config_info.rb +++ b/app/models/service_template_transformation_plan/validate_config_info.rb @@ -63,7 +63,7 @@ def validate_config_info(options) raise _("Invalid VM found #{vm_obj.name}") if vm_obj.invalid? vm_options = {} - vm_options[:warm_migration_compatible] = !vm_obj.snapshots.present? + vm_options[:warm_migration_compatible] = vm_obj.snapshots.blank? vm_options[:pre_ansible_playbook_service_template_id] = pre_service_id if vm_hash[:pre_service] vm_options[:post_ansible_playbook_service_template_id] = post_service_id if vm_hash[:post_service] vm_options[:cpu_right_sizing_mode] = vm_hash[:cpu_right_sizing_mode] if vm_hash[:cpu_right_sizing_mode].present? From ee67e3b91a78e700b6fd4fea8137041e783fab48 Mon Sep 17 00:00:00 2001 From: thearifismail Date: Wed, 16 Oct 2019 13:00:30 -0400 Subject: [PATCH 04/11] added test using snapshots in a migration plan --- .byebug_history | 6 ++++++ .../service_template_transformation_plan_spec.rb | 13 +++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 .byebug_history diff --git a/.byebug_history b/.byebug_history new file mode 100644 index 00000000000..905093a53ce --- /dev/null +++ b/.byebug_history @@ -0,0 +1,6 @@ +c +vm.snapshots.first.name +vm.snapshots.count +vm.v_total_snapshots +vm.v_total_snapshots.count +n diff --git a/spec/models/service_template_transformation_plan_spec.rb b/spec/models/service_template_transformation_plan_spec.rb index 5d18b2caf81..e16f82526e3 100644 --- a/spec/models/service_template_transformation_plan_spec.rb +++ b/spec/models/service_template_transformation_plan_spec.rb @@ -1,4 +1,5 @@ RSpec.describe ServiceTemplateTransformationPlan, :v2v do + before { EvmSpecHelper.local_miq_server } # required for creating snapshots needed for warm migration testing subject { FactoryBot.create(:service_template_transformation_plan) } describe '#request_class' do @@ -287,6 +288,18 @@ ) end + it 'creates and returns a transformation plan with VMs containing snapshots' do + FactoryBot.create_list(:snapshot, 2, :create_time => 1.minute.ago, :vm_or_template => vm1) + FactoryBot.create_list(:snapshot, 2, :create_time => 1.minute.ago, :vm_or_template => vm2) + + service_template = described_class.create_catalog_item(catalog_item_options) + + expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => false) + expect(service_template.vm_resources.find_by(:resource_id => vm2.id).options) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => false) + end + it 'requires a transformation mapping' do catalog_item_options[:config_info].delete(:transformation_mapping_id) From 5fc0e1b6f885b21f990c3d0fc826a95c1d3bf7fc Mon Sep 17 00:00:00 2001 From: thearifismail Date: Wed, 16 Oct 2019 13:12:08 -0400 Subject: [PATCH 05/11] removed .byebug_history --- .byebug_history | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .byebug_history diff --git a/.byebug_history b/.byebug_history deleted file mode 100644 index 905093a53ce..00000000000 --- a/.byebug_history +++ /dev/null @@ -1,6 +0,0 @@ -c -vm.snapshots.first.name -vm.snapshots.count -vm.v_total_snapshots -vm.v_total_snapshots.count -n From 60e98b284d0343c23449f4ffc1d406d9ca012b69 Mon Sep 17 00:00:00 2001 From: thearifismail Date: Tue, 22 Oct 2019 10:30:03 -0400 Subject: [PATCH 06/11] added VM validations for warm migration --- app/models/mixins/supports_feature_mixin.rb | 1 + .../validate_config_info.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/mixins/supports_feature_mixin.rb b/app/models/mixins/supports_feature_mixin.rb index c222d043632..19121ba0682 100644 --- a/app/models/mixins/supports_feature_mixin.rb +++ b/app/models/mixins/supports_feature_mixin.rb @@ -96,6 +96,7 @@ module SupportsFeatureMixin :launch_vmrc_console => 'Launch VMRC Console', :admin_ui => 'Open Admin UI for a Provider', :live_migrate => 'Live Migration', + :warm_migrate => 'Warm Migration', :migrate => 'Migration', :capture => 'Capture of Capacity & Utilization Metrics', :openscap_scan => 'OpenSCAP security scan', 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 2304aad0324..2f9b80b0d3d 100644 --- a/app/models/service_template_transformation_plan/validate_config_info.rb +++ b/app/models/service_template_transformation_plan/validate_config_info.rb @@ -63,7 +63,7 @@ def validate_config_info(options) raise _("Invalid VM found #{vm_obj.name}") if vm_obj.invalid? vm_options = {} - vm_options[:warm_migration_compatible] = vm_obj.snapshots.blank? + vm_options[:warm_migration_compatible] = vm_obj.supports_warm_migrate? vm_options[:pre_ansible_playbook_service_template_id] = pre_service_id if vm_hash[:pre_service] vm_options[:post_ansible_playbook_service_template_id] = post_service_id if vm_hash[:post_service] vm_options[:cpu_right_sizing_mode] = vm_hash[:cpu_right_sizing_mode] if vm_hash[:cpu_right_sizing_mode].present? From 4b8e090f61cec8cebb96c0dafa808a02a94c5ca5 Mon Sep 17 00:00:00 2001 From: thearifismail Date: Tue, 22 Oct 2019 13:42:35 -0400 Subject: [PATCH 07/11] changed VMs factory to vmware from vm_or_template --- spec/models/service_template_transformation_plan_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/models/service_template_transformation_plan_spec.rb b/spec/models/service_template_transformation_plan_spec.rb index e16f82526e3..89f7da8cad8 100644 --- a/spec/models/service_template_transformation_plan_spec.rb +++ b/spec/models/service_template_transformation_plan_spec.rb @@ -11,9 +11,9 @@ end let(:apst) { FactoryBot.create(:service_template_ansible_playbook) } - let(:vm1) { FactoryBot.create(:vm_or_template) } - let(:vm2) { FactoryBot.create(:vm_or_template) } - let(:vm3) { FactoryBot.create(:vm_or_template) } + let(:vm1) { FactoryBot.create(:vm_vmware) } + let(:vm2) { FactoryBot.create(:vm_vmware) } + let(:vm3) { FactoryBot.create(:vm_vmware) } let(:security_group1) { FactoryBot.create(:security_group, :name => "default") } let(:flavor1) { FactoryBot.create(:flavor, :name => "large") } let(:security_group2) { FactoryBot.create(:security_group, :name => "default") } From 92654880000fd9882fe2696a1ab6757317c179fd Mon Sep 17 00:00:00 2001 From: thearifismail Date: Sat, 26 Oct 2019 13:38:29 -0400 Subject: [PATCH 08/11] added stub_consts to work around vendor specific VMs --- ...rvice_template_transformation_plan_spec.rb | 120 ++++++++++++++---- 1 file changed, 93 insertions(+), 27 deletions(-) diff --git a/spec/models/service_template_transformation_plan_spec.rb b/spec/models/service_template_transformation_plan_spec.rb index 89f7da8cad8..b4d05f0d8a4 100644 --- a/spec/models/service_template_transformation_plan_spec.rb +++ b/spec/models/service_template_transformation_plan_spec.rb @@ -11,9 +11,9 @@ end let(:apst) { FactoryBot.create(:service_template_ansible_playbook) } - let(:vm1) { FactoryBot.create(:vm_vmware) } - let(:vm2) { FactoryBot.create(:vm_vmware) } - let(:vm3) { FactoryBot.create(:vm_vmware) } + let(:vm1) { FactoryBot.create(:vm_or_template) } + let(:vm2) { FactoryBot.create(:vm_or_template) } + let(:vm3) { FactoryBot.create(:vm_or_template) } let(:security_group1) { FactoryBot.create(:security_group, :name => "default") } let(:flavor1) { FactoryBot.create(:flavor, :name => "large") } let(:security_group2) { FactoryBot.create(:security_group, :name => "default") } @@ -277,10 +277,21 @@ expect(service_template.transformation_mapping).to eq(transformation_mapping) expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) - expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) - expect(service_template.vm_resources.find_by(:resource_id => vm2.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) + + stub_const("VirtualMachine", Class.new(ManageIQ::Providers::InfraManager::Vm) do + supports :warm_migrate do + unsupported_reason_add(:warm_migrate, _('Warm migratiobn can not migrate a VM with snapshots')) if snapshots.present? + end + end) + + vm1_options = service_template.vm_resources.find_by(:resource_id => vm1.id).options + vm1_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm1.snapshots).supports_warm_migrate? + expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) + + vm2_options = service_template.vm_resources.find_by(:resource_id => vm2.id).options + vm2_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm1.snapshots).supports_warm_migrate? + expect(vm2_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) + expect(service_template.config_info).to eq(catalog_item_options[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -367,12 +378,25 @@ expect(service_template.transformation_mapping).to eq(transformation_mapping) expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2, vm3]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) - expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) - expect(service_template.vm_resources.find_by(:resource_id => vm2.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) - expect(service_template.vm_resources.find_by(:resource_id => vm3.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group2.id, "osp_flavor_id" => flavor2.id, "warm_migration_compatible" => true) + + stub_const("VirtualMachine", Class.new(ManageIQ::Providers::InfraManager::Vm) do + supports :warm_migrate do + unsupported_reason_add(:warm_migrate, _('Warm migratiobn can not migrate a VM with snapshots')) if snapshots.present? + end + end) + + vm1_options = service_template.vm_resources.find_by(:resource_id => vm1.id).options + vm1_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm1.snapshots).supports_warm_migrate? + expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) + + vm2_options = service_template.vm_resources.find_by(:resource_id => vm2.id).options + vm2_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm2.snapshots).supports_warm_migrate? + expect(vm2_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) + + vm3_options = service_template.vm_resources.find_by(:resource_id => vm3.id).options + vm3_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm3.snapshots).supports_warm_migrate? + expect(vm3_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group2.id, "osp_flavor_id" => flavor2.id, "warm_migration_compatible" => true) + expect(service_template.config_info).to eq(updated_catalog_item_options_with_vms_added[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -389,8 +413,17 @@ expect(service_template.transformation_mapping).to eq(transformation_mapping) expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED]) - expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "warm_migration_compatible" => true) + + stub_const("VirtualMachine", Class.new(ManageIQ::Providers::InfraManager::Vm) do + supports :warm_migrate do + unsupported_reason_add(:warm_migrate, _('Warm migratiobn can not migrate a VM with snapshots')) if snapshots.present? + end + end) + + vm1_options = service_template.vm_resources.find_by(:resource_id => vm1.id).options + vm1_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm1.snapshots).supports_warm_migrate? + expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "warm_migration_compatible" => true) # Arif: returns false + expect(service_template.config_info).to eq(updated_catalog_item_options_with_vms_removed[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -407,10 +440,21 @@ expect(service_template.transformation_mapping).to eq(transformation_mapping) expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm3]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) - expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "warm_migration_compatible" => true) - expect(service_template.vm_resources.find_by(:resource_id => vm3.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "warm_migration_compatible" => true) + + stub_const("VirtualMachine", Class.new(ManageIQ::Providers::InfraManager::Vm) do + supports :warm_migrate do + unsupported_reason_add(:warm_migrate, _('Warm migratiobn can not migrate a VM with snapshots')) if snapshots.present? + end + end) + + vm1_options = service_template.vm_resources.find_by(:resource_id => vm1.id).options + vm1_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm1.snapshots).supports_warm_migrate? + expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "warm_migration_compatible" => true) + + vm3_options = service_template.vm_resources.find_by(:resource_id => vm3.id).options + vm3_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm3.snapshots).supports_warm_migrate? + expect(vm3_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "warm_migration_compatible" => true) + expect(service_template.config_info).to eq(updated_catalog_item_options_with_vms_added_and_removed[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -428,10 +472,21 @@ expect(service_template.transformation_mapping).to eq(transformation_mapping) expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) - expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) - expect(service_template.vm_resources.find_by(:resource_id => vm2.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) + + stub_const("VirtualMachine", Class.new(ManageIQ::Providers::InfraManager::Vm) do + supports :warm_migrate do + unsupported_reason_add(:warm_migrate, _('Warm migratiobn can not migrate a VM with snapshots')) if snapshots.present? + end + end) + + vm1_options = service_template.vm_resources.find_by(:resource_id => vm1.id).options + vm1_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm1.snapshots).supports_warm_migrate? + expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) # Arif: returns false + + vm2_options = service_template.vm_resources.find_by(:resource_id => vm2.id).options + vm2_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm2.snapshots).supports_warm_migrate? + expect(vm2_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) + expect(service_template.config_info).to eq(catalog_item_options[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -448,10 +503,21 @@ expect(service_template.description).to eq('an updated description') expect(service_template.transformation_mapping).to eq(transformation_mapping) expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2]) - expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) - expect(service_template.vm_resources.find_by(:resource_id => vm2.id).options) - .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) + + stub_const("VirtualMachine", Class.new(ManageIQ::Providers::InfraManager::Vm) do + supports :warm_migrate do + unsupported_reason_add(:warm_migrate, _('Warm migratiobn can not migrate a VM with snapshots')) if snapshots.present? + end + end) + + vm1_options = service_template.vm_resources.find_by(:resource_id => vm1.id).options + vm1_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm1.snapshots).supports_warm_migrate? + expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) + + vm2_options = service_template.vm_resources.find_by(:resource_id => vm2.id).options + vm2_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm2.snapshots).supports_warm_migrate? + expect(vm2_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) + expect(service_template.config_info).to eq(catalog_item_options[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', From 860a76d6c08eefb0893e881df35808d51d3ecf7b Mon Sep 17 00:00:00 2001 From: thearifismail Date: Mon, 28 Oct 2019 12:28:42 -0400 Subject: [PATCH 09/11] moved stub_const to before-do-end block and changed VirtualMachine to WarmMigrationVM --- ...rvice_template_transformation_plan_spec.rb | 72 ++++++------------- 1 file changed, 22 insertions(+), 50 deletions(-) diff --git a/spec/models/service_template_transformation_plan_spec.rb b/spec/models/service_template_transformation_plan_spec.rb index b4d05f0d8a4..5bfad7ed601 100644 --- a/spec/models/service_template_transformation_plan_spec.rb +++ b/spec/models/service_template_transformation_plan_spec.rb @@ -241,6 +241,14 @@ let(:miq_requests) { [FactoryBot.create(:service_template_transformation_plan_request, :request_state => "finished")] } let(:miq_requests_with_in_progress_request) { [FactoryBot.create(:service_template_transformation_plan_request, :request_state => "active")] } + before do + stub_const("ManageIQ::Providers::InfraManager::WarmMigrationVm", Class.new(ManageIQ::Providers::InfraManager::Vm) do + supports :warm_migrate do + unsupported_reason_add(:warm_migrate, _('Warm migratiobn can not migrate a VM with snapshots')) if snapshots.present? + end + end) + end + describe '#validate_order' do let(:service_template) { described_class.create_catalog_item(catalog_item_options) } @@ -278,18 +286,12 @@ expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) - stub_const("VirtualMachine", Class.new(ManageIQ::Providers::InfraManager::Vm) do - supports :warm_migrate do - unsupported_reason_add(:warm_migrate, _('Warm migratiobn can not migrate a VM with snapshots')) if snapshots.present? - end - end) - vm1_options = service_template.vm_resources.find_by(:resource_id => vm1.id).options - vm1_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm1.snapshots).supports_warm_migrate? + vm1_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm1.snapshots).supports_warm_migrate? expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) vm2_options = service_template.vm_resources.find_by(:resource_id => vm2.id).options - vm2_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm1.snapshots).supports_warm_migrate? + vm2_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm2.snapshots).supports_warm_migrate? expect(vm2_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) expect(service_template.config_info).to eq(catalog_item_options[:config_info]) @@ -379,22 +381,16 @@ expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2, vm3]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) - stub_const("VirtualMachine", Class.new(ManageIQ::Providers::InfraManager::Vm) do - supports :warm_migrate do - unsupported_reason_add(:warm_migrate, _('Warm migratiobn can not migrate a VM with snapshots')) if snapshots.present? - end - end) - vm1_options = service_template.vm_resources.find_by(:resource_id => vm1.id).options - vm1_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm1.snapshots).supports_warm_migrate? + vm1_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm1.snapshots).supports_warm_migrate? expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) vm2_options = service_template.vm_resources.find_by(:resource_id => vm2.id).options - vm2_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm2.snapshots).supports_warm_migrate? + vm2_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm2.snapshots).supports_warm_migrate? expect(vm2_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) vm3_options = service_template.vm_resources.find_by(:resource_id => vm3.id).options - vm3_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm3.snapshots).supports_warm_migrate? + vm3_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm3.snapshots).supports_warm_migrate? expect(vm3_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group2.id, "osp_flavor_id" => flavor2.id, "warm_migration_compatible" => true) expect(service_template.config_info).to eq(updated_catalog_item_options_with_vms_added[:config_info]) @@ -414,15 +410,9 @@ expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED]) - stub_const("VirtualMachine", Class.new(ManageIQ::Providers::InfraManager::Vm) do - supports :warm_migrate do - unsupported_reason_add(:warm_migrate, _('Warm migratiobn can not migrate a VM with snapshots')) if snapshots.present? - end - end) - vm1_options = service_template.vm_resources.find_by(:resource_id => vm1.id).options - vm1_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm1.snapshots).supports_warm_migrate? - expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "warm_migration_compatible" => true) # Arif: returns false + vm1_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm1.snapshots).supports_warm_migrate? + expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "warm_migration_compatible" => true) expect(service_template.config_info).to eq(updated_catalog_item_options_with_vms_removed[:config_info]) expect(service_template.resource_actions.first).to have_attributes( @@ -441,18 +431,12 @@ expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm3]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) - stub_const("VirtualMachine", Class.new(ManageIQ::Providers::InfraManager::Vm) do - supports :warm_migrate do - unsupported_reason_add(:warm_migrate, _('Warm migratiobn can not migrate a VM with snapshots')) if snapshots.present? - end - end) - vm1_options = service_template.vm_resources.find_by(:resource_id => vm1.id).options - vm1_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm1.snapshots).supports_warm_migrate? + vm1_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm1.snapshots).supports_warm_migrate? expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "warm_migration_compatible" => true) vm3_options = service_template.vm_resources.find_by(:resource_id => vm3.id).options - vm3_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm3.snapshots).supports_warm_migrate? + vm3_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm3.snapshots).supports_warm_migrate? expect(vm3_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "warm_migration_compatible" => true) expect(service_template.config_info).to eq(updated_catalog_item_options_with_vms_added_and_removed[:config_info]) @@ -473,18 +457,12 @@ expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) - stub_const("VirtualMachine", Class.new(ManageIQ::Providers::InfraManager::Vm) do - supports :warm_migrate do - unsupported_reason_add(:warm_migrate, _('Warm migratiobn can not migrate a VM with snapshots')) if snapshots.present? - end - end) - vm1_options = service_template.vm_resources.find_by(:resource_id => vm1.id).options - vm1_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm1.snapshots).supports_warm_migrate? - expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) # Arif: returns false + vm1_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm1.snapshots).supports_warm_migrate? + expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) vm2_options = service_template.vm_resources.find_by(:resource_id => vm2.id).options - vm2_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm2.snapshots).supports_warm_migrate? + vm2_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm2.snapshots).supports_warm_migrate? expect(vm2_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) expect(service_template.config_info).to eq(catalog_item_options[:config_info]) @@ -504,18 +482,12 @@ expect(service_template.transformation_mapping).to eq(transformation_mapping) expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2]) - stub_const("VirtualMachine", Class.new(ManageIQ::Providers::InfraManager::Vm) do - supports :warm_migrate do - unsupported_reason_add(:warm_migrate, _('Warm migratiobn can not migrate a VM with snapshots')) if snapshots.present? - end - end) - vm1_options = service_template.vm_resources.find_by(:resource_id => vm1.id).options - vm1_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm1.snapshots).supports_warm_migrate? + vm1_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm1.snapshots).supports_warm_migrate? expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) vm2_options = service_template.vm_resources.find_by(:resource_id => vm2.id).options - vm2_options["warm_migration_compatible"] = VirtualMachine.new(:snapshots => vm2.snapshots).supports_warm_migrate? + vm2_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm2.snapshots).supports_warm_migrate? expect(vm2_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) expect(service_template.config_info).to eq(catalog_item_options[:config_info]) From 8f4ba69747155f4f8db11106639717fb7a633e42 Mon Sep 17 00:00:00 2001 From: thearifismail Date: Mon, 28 Oct 2019 12:40:06 -0400 Subject: [PATCH 10/11] fixed the spelling of migratiobn --- spec/models/service_template_transformation_plan_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/service_template_transformation_plan_spec.rb b/spec/models/service_template_transformation_plan_spec.rb index 5bfad7ed601..534f61ac4e1 100644 --- a/spec/models/service_template_transformation_plan_spec.rb +++ b/spec/models/service_template_transformation_plan_spec.rb @@ -244,7 +244,7 @@ before do stub_const("ManageIQ::Providers::InfraManager::WarmMigrationVm", Class.new(ManageIQ::Providers::InfraManager::Vm) do supports :warm_migrate do - unsupported_reason_add(:warm_migrate, _('Warm migratiobn can not migrate a VM with snapshots')) if snapshots.present? + unsupported_reason_add(:warm_migrate, _('Warm migration can not migrate a VM with snapshots')) if snapshots.present? end end) end From e43f670e1fc97a37d5173448dd26003b1857eb0a Mon Sep 17 00:00:00 2001 From: thearifismail Date: Tue, 29 Oct 2019 14:21:12 -0400 Subject: [PATCH 11/11] changed VM type to vm_vmware from vm_or_template --- ...rvice_template_transformation_plan_spec.rb | 92 ++++++------------- 1 file changed, 27 insertions(+), 65 deletions(-) diff --git a/spec/models/service_template_transformation_plan_spec.rb b/spec/models/service_template_transformation_plan_spec.rb index 534f61ac4e1..89f7da8cad8 100644 --- a/spec/models/service_template_transformation_plan_spec.rb +++ b/spec/models/service_template_transformation_plan_spec.rb @@ -11,9 +11,9 @@ end let(:apst) { FactoryBot.create(:service_template_ansible_playbook) } - let(:vm1) { FactoryBot.create(:vm_or_template) } - let(:vm2) { FactoryBot.create(:vm_or_template) } - let(:vm3) { FactoryBot.create(:vm_or_template) } + let(:vm1) { FactoryBot.create(:vm_vmware) } + let(:vm2) { FactoryBot.create(:vm_vmware) } + let(:vm3) { FactoryBot.create(:vm_vmware) } let(:security_group1) { FactoryBot.create(:security_group, :name => "default") } let(:flavor1) { FactoryBot.create(:flavor, :name => "large") } let(:security_group2) { FactoryBot.create(:security_group, :name => "default") } @@ -241,14 +241,6 @@ let(:miq_requests) { [FactoryBot.create(:service_template_transformation_plan_request, :request_state => "finished")] } let(:miq_requests_with_in_progress_request) { [FactoryBot.create(:service_template_transformation_plan_request, :request_state => "active")] } - before do - stub_const("ManageIQ::Providers::InfraManager::WarmMigrationVm", Class.new(ManageIQ::Providers::InfraManager::Vm) do - supports :warm_migrate do - unsupported_reason_add(:warm_migrate, _('Warm migration can not migrate a VM with snapshots')) if snapshots.present? - end - end) - end - describe '#validate_order' do let(:service_template) { described_class.create_catalog_item(catalog_item_options) } @@ -285,15 +277,10 @@ expect(service_template.transformation_mapping).to eq(transformation_mapping) expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) - - vm1_options = service_template.vm_resources.find_by(:resource_id => vm1.id).options - vm1_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm1.snapshots).supports_warm_migrate? - expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) - - vm2_options = service_template.vm_resources.find_by(:resource_id => vm2.id).options - vm2_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm2.snapshots).supports_warm_migrate? - expect(vm2_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) - + expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) + expect(service_template.vm_resources.find_by(:resource_id => vm2.id).options) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) expect(service_template.config_info).to eq(catalog_item_options[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -380,19 +367,12 @@ expect(service_template.transformation_mapping).to eq(transformation_mapping) expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2, vm3]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) - - vm1_options = service_template.vm_resources.find_by(:resource_id => vm1.id).options - vm1_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm1.snapshots).supports_warm_migrate? - expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) - - vm2_options = service_template.vm_resources.find_by(:resource_id => vm2.id).options - vm2_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm2.snapshots).supports_warm_migrate? - expect(vm2_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) - - vm3_options = service_template.vm_resources.find_by(:resource_id => vm3.id).options - vm3_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm3.snapshots).supports_warm_migrate? - expect(vm3_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group2.id, "osp_flavor_id" => flavor2.id, "warm_migration_compatible" => true) - + expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) + expect(service_template.vm_resources.find_by(:resource_id => vm2.id).options) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) + expect(service_template.vm_resources.find_by(:resource_id => vm3.id).options) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group2.id, "osp_flavor_id" => flavor2.id, "warm_migration_compatible" => true) expect(service_template.config_info).to eq(updated_catalog_item_options_with_vms_added[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -409,11 +389,8 @@ expect(service_template.transformation_mapping).to eq(transformation_mapping) expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED]) - - vm1_options = service_template.vm_resources.find_by(:resource_id => vm1.id).options - vm1_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm1.snapshots).supports_warm_migrate? - expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "warm_migration_compatible" => true) - + expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "warm_migration_compatible" => true) expect(service_template.config_info).to eq(updated_catalog_item_options_with_vms_removed[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -430,15 +407,10 @@ expect(service_template.transformation_mapping).to eq(transformation_mapping) expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm3]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) - - vm1_options = service_template.vm_resources.find_by(:resource_id => vm1.id).options - vm1_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm1.snapshots).supports_warm_migrate? - expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "warm_migration_compatible" => true) - - vm3_options = service_template.vm_resources.find_by(:resource_id => vm3.id).options - vm3_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm3.snapshots).supports_warm_migrate? - expect(vm3_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "warm_migration_compatible" => true) - + expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "warm_migration_compatible" => true) + expect(service_template.vm_resources.find_by(:resource_id => vm3.id).options) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "warm_migration_compatible" => true) expect(service_template.config_info).to eq(updated_catalog_item_options_with_vms_added_and_removed[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -456,15 +428,10 @@ expect(service_template.transformation_mapping).to eq(transformation_mapping) expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2]) expect(service_template.vm_resources.collect(&:status)).to eq([ServiceResource::STATUS_QUEUED, ServiceResource::STATUS_QUEUED]) - - vm1_options = service_template.vm_resources.find_by(:resource_id => vm1.id).options - vm1_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm1.snapshots).supports_warm_migrate? - expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) - - vm2_options = service_template.vm_resources.find_by(:resource_id => vm2.id).options - vm2_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm2.snapshots).supports_warm_migrate? - expect(vm2_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) - + expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) + expect(service_template.vm_resources.find_by(:resource_id => vm2.id).options) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) expect(service_template.config_info).to eq(catalog_item_options[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision', @@ -481,15 +448,10 @@ expect(service_template.description).to eq('an updated description') expect(service_template.transformation_mapping).to eq(transformation_mapping) expect(service_template.vm_resources.collect(&:resource)).to match_array([vm1, vm2]) - - vm1_options = service_template.vm_resources.find_by(:resource_id => vm1.id).options - vm1_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm1.snapshots).supports_warm_migrate? - expect(vm1_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) - - vm2_options = service_template.vm_resources.find_by(:resource_id => vm2.id).options - vm2_options["warm_migration_compatible"] = ManageIQ::Providers::InfraManager::WarmMigrationVm.new(:snapshots => vm2.snapshots).supports_warm_migrate? - expect(vm2_options).to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) - + expect(service_template.vm_resources.find_by(:resource_id => vm1.id).options) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) + expect(service_template.vm_resources.find_by(:resource_id => vm2.id).options) + .to eq("pre_ansible_playbook_service_template_id" => apst.id, "post_ansible_playbook_service_template_id" => apst.id, "osp_security_group_id" => security_group1.id, "osp_flavor_id" => flavor1.id, "warm_migration_compatible" => true) expect(service_template.config_info).to eq(catalog_item_options[:config_info]) expect(service_template.resource_actions.first).to have_attributes( :action => 'Provision',