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

Fix virt-v2v kill #433

Closed
wants to merge 3 commits into from
Closed

Conversation

ghost
Copy link

@ghost ghost commented Sep 27, 2018

In the course of a discussion with Richard W.M. Jones, he said that:

It's not too nice to send kill -9 to virt-v2v because it means none of the at-exit handlers get to run, so it will leave temporary files all over the place. It's better to send an ordinary kill signal (eg. SIGTERM). If virt-v2v doesn't exit after some grace period, eg. 30 seconds, then it's a bug, but maybe you could then send SIGKILL.

This PR aims at fixing this by first using SIGTERM to kill virt-v2v with a grace period of 30 seconds, using retry. After that grace period, virt-v2v is sent SIGKILL, as it was the case before.

While I was at it, I added the specs for this method.

Associated RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=1633526

@ghost
Copy link
Author

ghost commented Sep 27, 2018

@miq-bot add-label transformation, bug, technical debt, hammer/yes

@ghost ghost force-pushed the v2v_fix_virtv2v_kill branch from 48a4b49 to 137858c Compare September 27, 2018 08:47
end

it "when virtv2v is finished" do
allow(svc_model_task).to receive(:get_option).with(:virtv2v_started_on).and_return(Time.now.utc - 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fdupont-redhat There is a lot of shared setup between these tests. I recommend creating context so you can share the setup between tests.

For example,
The allow(svc_model_task).to receive(:get_option).with(:virtv2v_started_on).and_return(Time.now.utc - 1) could define one context. with several tests.

Inside of that context would be another that does a before block for allow(svc_model_task).to receive(:get_option).with(:virtv2v_finished_on).and_return(nil) and list the tests under it.

Can you take a shot at reorganizing these and let me know if you need help.

@gmcculloug gmcculloug self-assigned this Sep 28, 2018
end

before(:each) do
ManageIQ::Automate::Transformation::TransformationHosts::Common::KillVirtV2V.instance_variable_set(:@task, nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before(:each) is the default action so it is the same as the before block above. This line can just move up in to the previous block.

before { allow(svc_model_task).to receive(:get_option).with(:virtv2v_started_on).and_return(Time.now.utc - 1) }

context "when virtv2v is finished" do
before { allow(svc_model_task).to receive(:get_option).with(:virtv2v_finished_on).and_return(Time.now.utc) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, move the allow to the test block.


context "#task_virtv2v_state" do
context "when virtv2v is not started" do
before { allow(svc_model_task).to receive(:get_option).with(:virtv2v_started_on).and_return(nil) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the before block if there is only one test. Just include the allow line in the test block.

@handle.root['ae_result'] = 'retry'
@handle.root['ae_retry_interval'] = '30.seconds'
end
ManageIQ::Automate::Transformation::TransformationHosts::Common::Utils.remote_command(@task, transformation_host, "kill -s #{signal} #{pid}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about how to write this without using unless since we normally only use that for simple one-line conditions.

My suggestion would be to move the kill_signal logic into a separate method.

def kill_virtv2v(transformation_host, pid)
  ManageIQ::Automate::Transformation::TransformationHosts::Common::Utils.remote_command(@task, transformation_host, "kill -s #{kill_signal} #{pid}")
end

def kill_signal
  if @handle.get_state_var('virtv2v_graceful_kill')
    'KILL'
  else
    @handle.set_state_var('virtv2v_graceful_kill', true)
    @handle.root['ae_result'] = 'retry'
    @handle.root['ae_retry_interval'] = '30.seconds'
    'TERM'
  end
end

@miq-bot
Copy link
Member

miq-bot commented Oct 1, 2018

Checked commits fabiendupont/manageiq-content@137858c~...03be4ae with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
2 files checked, 0 offenses detected
Everything looks fine. 🍰

@ghost
Copy link
Author

ghost commented Oct 5, 2018

@gmcculloug Do you want more changes ?

@miq-bot
Copy link
Member

miq-bot commented Oct 19, 2018

This pull request is not mergeable. Please rebase and repush.

@ghost
Copy link
Author

ghost commented Oct 19, 2018

This change has been implemented in #441. Closing this PR.

@ghost ghost closed this Oct 19, 2018
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants