Skip to content

Commit

Permalink
changed VM type to vm_vmware from vm_or_template
Browse files Browse the repository at this point in the history
  • Loading branch information
thearifismail committed Oct 29, 2019
1 parent 8f4ba69 commit e43f670
Showing 1 changed file with 27 additions and 65 deletions.
92 changes: 27 additions & 65 deletions spec/models/service_template_transformation_plan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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") }
Expand Down Expand Up @@ -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) }

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit e43f670

Please sign in to comment.