Skip to content

Commit

Permalink
Fixed cases causing waiting on timeout in vm_import
Browse files Browse the repository at this point in the history
2 problems fixed:
- allow to import only using 4.1.5+ provider.
  The reason is that the required fix (https://bugzilla.redhat.com/1477375) is
  present in 4.1.5+ and without this fix manageiq will wait until timeout
  reached.
- check if submit to the provider succeeded.
  The reason is that if the result is not checked, this state will always
  succeed and the import will again wait until timeout.
  • Loading branch information
Tomas Jelinek committed Aug 7, 2017
1 parent 484a6a5 commit ee7858a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 3 additions & 1 deletion app/models/manageiq/providers/redhat/infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ def supports_migrate_for_all?(vms)
end

def version_higher_than?(version)
ems_version = api_version[/\d+\.\d+/x]
return false if api_version.nil?

ems_version = api_version[/\d+\.\d+\.?\d*/x]
Gem::Version.new(ems_version) >= Gem::Version.new(version)
end
end
13 changes: 11 additions & 2 deletions app/models/manageiq/providers/redhat/infra_manager/vm_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,30 @@ def configure_imported_vm_networks(vm_id)
end
end

def check_task!(t, msg)
raise msg if t.nil? || MiqTask.status_error?(t.status) || MiqTask.status_timeout?(t.status)
end

def submit_import_vm(userid, source_vm_id, target_params)
task_id = queue_self_method_call(userid, 'Import VM', 'import_vm', source_vm_id, target_params)
task = MiqTask.wait_for_taskid(task_id)

check_task!(task, _('Error while importing the VM.'))

task.task_results
end

def validate_import_vm
Gem::Version.new(api_version) >= Gem::Version.new('4')
# The version of the RHV needs to be at least 4.1.5 due to https://bugzilla.redhat.com/1477375
version_higher_than?('4.1.5')
end

def submit_configure_imported_vm_networks(userid, vm_id)
task_id = queue_self_method_call(userid, "Configure imported VM's networks", 'configure_imported_vm_networks', vm_id)
task = MiqTask.wait_for_taskid(task_id)

check_task!(task, _('Error while configuring VM network.'))

task.task_results
end

Expand All @@ -68,7 +77,7 @@ def submit_configure_imported_vm_networks(userid, vm_id)
def check_import_supported!(source_provider)
raise _('Cannot import archived VMs') if source_provider.nil?

raise _('Cannot import to a RHEV provider of version < 4.0') unless api_version >= '4.0'
raise _('Cannot import to a RHEV provider of version < 4.1.5') unless validate_import_vm
unless source_provider.type == ManageIQ::Providers::Vmware::InfraManager.name
raise _('Source provider must be of type Vmware')
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,15 @@ def expect_import(params, expected_request)
let(:ems) { FactoryGirl.create(:ems_redhat) }

it 'validates successfully' do
allow(ems).to receive(:api_version).and_return('4')
allow(ems).to receive(:api_version).and_return('4.1.5')
expect(ems.validate_import_vm).to be_truthy
end

it 'fails validation on old api version' do
allow(ems).to receive(:api_version).and_return('4.1.4')
expect(ems.validate_import_vm).to be_falsey
end

it 'validates before connecting' do
allow(ems).to receive(:api_version).and_return(nil)
expect(ems.validate_import_vm).to be_falsey
Expand Down

0 comments on commit ee7858a

Please sign in to comment.