-
Notifications
You must be signed in to change notification settings - Fork 897
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 Deleting Snapshot on Smartstate Cancel #16885
Fix Deleting Snapshot on Smartstate Cancel #16885
Conversation
app/models/vm_scan.rb
Outdated
@@ -491,22 +492,26 @@ def call_abort_retry(*args) | |||
end | |||
end | |||
|
|||
def process_delete_evm_snapshot(vm) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems this method is only necessary because of the differences between vm_delete_evm_snapshot
methods of different providers. Ultimately, I think there should be a delete_evm_snapshot
method in the VM object. Then each type of VM can have their own implementation with a common signature. Then all we'd have to do is call vm.delete_evm_snapshot(mor)
without all the if vm.kind_of?
checks.
For now, I think this fix is ok the way it is, but we should consider cleaning it up in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Looks like openstack is the outlier in not accepting the same options, 👍 for unifying the snapshot operations |
app/models/vm_scan.rb
Outdated
@@ -466,7 +466,8 @@ def process_cancel(*args) | |||
_log.info("job canceling, #{options[:message]}") | |||
|
|||
begin | |||
delete_snapshot(context[:snapshot_mor]) | |||
vm = VmOrTemplate.find_by(:id => target_id) | |||
process_delete_evm_snapshot(vm) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The replaced delete_snapshot
method has some logics about user_event and cleaning up snapshot descriptions. They are all missed in your new defined process_delete_evm_snapshot
method. You sure they don't need?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On further review you are correct @hsong-rh. Reworking this PR now and will re-test.
Cancelling a Smartstate Analysis job is supposed to delete the snapshot created if necessary. The code attempted to call an incorrectly named method for the provider in the case of Azure and SCVMM. This resulted in the snapshot being left and consequently the next attempt to run Smartstate on the same VM failed because it seemed as if there was an active analysis job running already. Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1538347
Rubocop caught a redundant assignment of the vm which is already being passed to a method.
Based on review comments the delete_snapshot method was modified to check for the appropriate providers and call the correct methods in the provider rather than totally avoiding the call to delete_snapshot altogether.
0e3c401
to
0277f99
Compare
@hsong-rh I reworked the fix based on your comments. |
@agrare Wondering if, in a future PR, we cannot just have vm.delete_evm_snapshot(mor) if vm.require_snapshot_for_scan? instead of if vm.kind_of?(ManageIQ::Providers::Openstack::CloudManager::Vm)
vm.ext_management_system.vm_delete_evm_snapshot(vm, mor)
elsif vm.kind_of?(ManageIQ::Providers::Microsoft::InfraManager::Vm) || (vm.kind_of?(ManageIQ::Providers::Azure::CloudManager::Vm) && vm.require_snapshot_for_scan?)
vm.ext_management_system.vm_delete_evm_snapshot(vm, :snMor => mor)
else
vm.ext_management_system.vm_remove_snapshot(vm, :snMor => mor, :user_event => user_event)
end |
@chessbyte That's exactly what my comment suggested, before it became "outdated" and hidden :-) |
app/models/vm_scan.rb
Outdated
mor = context[:snapshot_mor] | ||
context[:snapshot_mor] = nil | ||
set_status("Deleting snapshot before aborting job") | ||
if vm.kind_of?(ManageIQ::Providers::Openstack::CloudManager::Vm) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you change this whole conditional block to:
delete_snapshot(mor, vm)
now that delete_snapshot
performs those checks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. YAP (Yet Another Push) coming up.
We are able to simplify process_abort since the lines deleted are performed in the delete_snapshot method now.
app/models/vm_scan.rb
Outdated
else | ||
delete_snapshot(mor) | ||
end | ||
delete_snapshot(mor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass the vm so delete_snapshot
won't have to look it up again:
delete_snapshot(mor, vm)
Review comments requested the above.
Checked commits jerryk55/manageiq@1540f97~...08e8b59 with ruby 2.3.3, rubocop 0.52.0, haml-lint 0.20.0, and yamllint 1.10.0 |
@roliveri waiting on someone to review before merging? |
…a_cancel Fix Deleting Snapshot on Smartstate Cancel
Fix Deleting Snapshot on Smartstate Cancel (cherry picked from commit 4d26ddb) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1539756
Gaprindashvili backport details:
|
Cancelling a Smartstate Analysis job is supposed to delete the
snapshot created if necessary. The code attempted to call an
incorrectly named method for the provider in the case of Azure and SCVMM.
This resulted in the snapshot being left and consequently the next
attempt to run Smartstate on the same VM failed because it seemed as if
there was an active analysis job running already.
@roliveri @hsong-rh please review this blocker fix.
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1538347
Links
Steps for Testing/QA [Optional]
Run Smartstate Analysis on either an Azure or SCVMM VM. Once the snapshot has been taken and scanning has commenced, select the "Cancel Job" button. The job should be cancelled and the snapshot should be deleted.
If you attempt to run another Smartstate Analysis job on the same VM it should not fail because the Snapshot already exists.