Skip to content

Commit

Permalink
Merge pull request #73 from jelkosz/vm_import_fix_issues_causing_time…
Browse files Browse the repository at this point in the history
…outs

Fixed cases causing waiting on timeout in vm_import
  • Loading branch information
oourfali authored Aug 7, 2017
2 parents eec8484 + 330a356 commit f4f79f9
Show file tree
Hide file tree
Showing 4 changed files with 35 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
15 changes: 15 additions & 0 deletions spec/models/manageiq/providers/redhat/infra_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@

ems.api_version = "4.2.0_master"
expect(ems.version_higher_than?("4.1")).to be_truthy

ems.api_version = "4.2.1_master"
expect(ems.version_higher_than?("4.2.0")).to be_truthy
end
end

Expand All @@ -351,6 +354,18 @@

ems.api_version = "4.0.0_master"
expect(ems.version_higher_than?("4.1")).to be_falsey

ems.api_version = "4.0.1_master"
expect(ems.version_higher_than?("4.0.2")).to be_falsey
end
end

context "api version not set" do
let(:api_version) { nil }
it 'always return false' do
expect(ems.version_higher_than?("10.1")).to be_falsey

expect(ems.version_higher_than?("0")).to be_falsey
end
end
end
Expand Down

0 comments on commit f4f79f9

Please sign in to comment.