Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2V - Collect virt-v2v PID from conversion host in kill_virtv2v #18372

Merged
merged 2 commits into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions app/models/service_template_transformation_plan_task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ def get_conversion_state
options[:virtv2v_finished_on] = Time.now.utc.strftime('%Y-%m-%d %H:%M:%S')
if virtv2v_state['failed']
options[:virtv2v_status] = 'failed'
raise "Disks transformation failed."
else
options[:virtv2v_status] = 'succeeded'
updated_disks.each { |d| d[:percent] = 100 }
Expand All @@ -218,8 +217,8 @@ def get_conversion_state
end

def kill_virtv2v(signal = 'TERM')
return false unless options[:virtv2v_wrapper]['pid']
conversion_host.kill_process(options[:virtv2v_wrapper]['pid'], signal)
virtv2v_state = conversion_host.get_conversion_state(options[:virtv2v_wrapper]['state_file'])
conversion_host.kill_process(virtv2v_state['pid'].to_s, signal)
end

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,22 +185,17 @@

describe '#kill_virtv2v' do
before do
task.options = { :virtv2v_wrapper => { 'state_file' => '/tmp/v2v.state' }}
task.conversion_host = conversion_host
task.options = { :virtv2v_wrapper => {}}
end

it "does nothing if pid not present in options[:virtv2v_wrapper]" do
expect(task.kill_virtv2v('KILL')).to eq(false)
allow(conversion_host).to receive(:get_conversion_state).with(task.options[:virtv2v_wrapper]['state_file']).and_return("pid" => 1234)
end

it "returns false if if kill command failed" do
task.options[:virtv2v_wrapper]['pid'] = '1234'
allow(conversion_host).to receive(:kill_process).with('1234', 'KILL').and_return(false)
expect(task.kill_virtv2v('KILL')).to eq(false)
end

it "returns true if if kill command succeeded" do
task.options[:virtv2v_wrapper]['pid'] = '1234'
allow(conversion_host).to receive(:kill_process).with('1234', 'KILL').and_return(true)
expect(task.kill_virtv2v('KILL')).to eq(true)
end
Expand Down