Skip to content

Commit

Permalink
Add install drivers option to V2V
Browse files Browse the repository at this point in the history
  • Loading branch information
matobet committed Jun 1, 2017
1 parent 99ccb8e commit db41e8d
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 23 deletions.
Expand Up @@ -10,6 +10,7 @@ module ManageIQ::Providers::Redhat::InfraManager::VmImport
# cluster_id
# storage_id
# sparse
# drivers_iso
# }
def import_vm(source_vm_id, target_params)
vm = Vm.includes(:ext_management_system).find(source_vm_id)
Expand All @@ -26,7 +27,8 @@ def import_vm(source_vm_id, target_params)
:url => vmware_import_url(source_provider, vm),
:cluster_id => EmsCluster.find(target_params[:cluster_id]).uid_ems,
:storage_domain_id => Storage.find(target_params[:storage_id]).ems_ref_obj.split('/').last,
:sparse => target_params[:sparse]
:sparse => target_params[:sparse],
:drivers_iso => target_params[:drivers_iso]
)
end

Expand Down Expand Up @@ -87,6 +89,7 @@ def perform_vmware_to_ovirt_import(params)
:cluster => { :id => params[:cluster_id] },
:storage_domain => { :id => params[:storage_domain_id] },
:sparse => params[:sparse],
:drivers_iso => params[:drivers_iso].try { |iso| OvirtSDK4::File.new(:id => iso) }
)
)
self.class.make_ems_ref(import.vm.href)
Expand Down
76 changes: 76 additions & 0 deletions content/service_dialogs/transform-vm.yml
Expand Up @@ -208,6 +208,82 @@
ae_instance:
ae_message:
ae_attributes: {}
- name: install_drivers
description: Install necessary drivers as a part of the conversion process
data_type:
notes:
notes_display:
display: edit
display_method:
display_method_options: {}
required: false
required_method:
required_method_options: {}
default_value: f
values:
values_method:
values_method_options: {}
options: {}
label: Install Drivers
position: 5
validator_type:
validator_rule:
reconfigurable:
dynamic: false
show_refresh_button:
load_values_on_init:
read_only: false
auto_refresh:
trigger_auto_refresh: true
visible: true
type: DialogFieldCheckBox
resource_action:
action:
resource_type: DialogField
ae_namespace:
ae_class:
ae_instance:
ae_message:
ae_attributes: {}
- name: drivers_iso
description: ISO where the drivers are located
data_type: string
notes:
notes_display:
display: edit
display_method:
display_method_options: {}
required: true
required_method:
required_method_options: {}
default_value:
values:
values_method:
values_method_options: {}
options:
:force_multi_value: false
:sort_by: :description
label: Drivers ISO
position: 6
validator_type:
validator_rule:
reconfigurable:
dynamic: true
show_refresh_button:
load_values_on_init:
read_only: false
auto_refresh: true
trigger_auto_refresh:
visible:
type: DialogFieldDropDownList
resource_action:
action:
resource_type: DialogField
ae_namespace: Infrastructure/VM/Transform
ae_class: Import
ae_instance: list_driver_isos
ae_message:
ae_attributes: {}
resource_actions:
- action:
ae_namespace: SYSTEM
Expand Down
Expand Up @@ -10,8 +10,14 @@
let(:cluster_path) { 'Folder1/Folder @#$*2/Compute 3/Folder4/Cluster 5' }
let(:cluster_path_escaped) { 'Folder1%2FFolder%20%40%23%24*2%2FCompute%203%2FFolder4%2FCluster%205' }

let(:cluster_guid) { cluster.uid_ems }
let(:storage_guid) { storage.ems_ref_obj.split('/').last }

let(:new_name) { 'created-vm' }
let(:new_vm_id) { '6820ad2a-a8c0-4b4e-baf2-3482357ba352' }
let(:vcenter) { source_ems.endpoints.first.hostname }
let(:url) { "vpx://testuser@#{vcenter}/#{cluster_path_escaped}/#{source_host.ipaddress}?no_verify=1" }
let(:iso_name) { 'RHEV-toolsSetup_4.1_5.iso' }

let(:vm_import_response) do
OvirtSDK4::ExternalVmImport.new(
Expand Down Expand Up @@ -40,30 +46,59 @@
allow(OvirtSDK4::Probe).to receive(:probe).and_return([OvirtSDK4::ProbeResult.new(:version => '4')])
end

it 'passes the proper params to oVirt API' do
vcenter = source_ems.endpoints.first.hostname
url = "vpx://testuser@#{vcenter}/#{cluster_path_escaped}/#{source_host.ipaddress}?no_verify=1"
import_params = OvirtSDK4::ExternalVmImport.new(
:name => source_vm.name,
:vm => { :name => new_name },
:provider => OvirtSDK4::ExternalVmProviderType::VMWARE,
:username => 'testuser',
:password => 'secret',
:url => url,
:cluster => { :id => cluster.uid_ems },
:storage_domain => { :id => storage.ems_ref_obj.split('/').last },
:sparse => true
)
expect_any_instance_of(OvirtSDK4::ExternalVmImportsService).to receive(:add).with(eq(import_params)).and_return(vm_import_response)
new_ems_ref = target_ems.import_vm(
source_vm.id,
:name => new_name,
:cluster_id => cluster.id,
:storage_id => storage.id,
:sparse => true
)
def expect_import(params, expected_request)
expect_any_instance_of(OvirtSDK4::ExternalVmImportsService).to receive(:add).with(eq(expected_request)).and_return(vm_import_response)
new_ems_ref = target_ems.import_vm(source_vm.id, params)
expect(new_ems_ref).to eq("/api/vms/#{new_vm_id}")
end

context 'when called without ISO drivers' do
it 'passes the proper params to oVirt API' do
params = {
:name => new_name,
:cluster_id => cluster.id,
:storage_id => storage.id,
:sparse => true
}
import = OvirtSDK4::ExternalVmImport.new(
:name => source_vm.name,
:vm => { :name => new_name },
:provider => OvirtSDK4::ExternalVmProviderType::VMWARE,
:username => 'testuser',
:password => 'secret',
:url => url,
:cluster => { :id => cluster_guid },
:storage_domain => { :id => storage_guid },
:sparse => true
)
expect_import(params, import)
end
end

context 'when called with ISO drivers' do
it 'passes the proper params to oVirt API' do
params = {
:name => new_name,
:cluster_id => cluster.id,
:storage_id => storage.id,
:sparse => true,
:drivers_iso => iso_name
}
import = OvirtSDK4::ExternalVmImport.new(
:name => source_vm.name,
:vm => { :name => new_name },
:provider => OvirtSDK4::ExternalVmProviderType::VMWARE,
:username => 'testuser',
:password => 'secret',
:url => url,
:cluster => { :id => cluster_guid },
:storage_domain => { :id => storage_guid },
:sparse => true,
:drivers_iso => OvirtSDK4::File.new(:id => iso_name)
)
expect_import(params, import)
end
end
end

context 'checks version during validation' do
Expand Down

0 comments on commit db41e8d

Please sign in to comment.