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 Deleting Snapshot on Smartstate Cancel #16885

Merged
merged 5 commits into from
Jan 27, 2018

Conversation

jerryk55
Copy link
Member

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.

@@ -491,22 +492,26 @@ def call_abort_retry(*args)
end
end

def process_delete_evm_snapshot(vm)
Copy link
Member

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.

Copy link
Member

@agrare agrare left a comment

Choose a reason for hiding this comment

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

👍

@agrare
Copy link
Member

agrare commented Jan 25, 2018

Looks like openstack is the outlier in not accepting the same options, 👍 for unifying the snapshot operations

@@ -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)
Copy link
Contributor

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?

Copy link
Member Author

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.
@jerryk55 jerryk55 force-pushed the fix_delete_snap_on_ssa_cancel branch from 0e3c401 to 0277f99 Compare January 25, 2018 20:06
@jerryk55
Copy link
Member Author

@hsong-rh I reworked the fix based on your comments.

@chessbyte
Copy link
Member

chessbyte commented Jan 25, 2018

@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

@roliveri
Copy link
Member

@chessbyte That's exactly what my comment suggested, before it became "outdated" and hidden :-)

mor = context[:snapshot_mor]
context[:snapshot_mor] = nil
set_status("Deleting snapshot before aborting job")
if vm.kind_of?(ManageIQ::Providers::Openstack::CloudManager::Vm)
Copy link
Member

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?

Copy link
Member Author

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.
else
delete_snapshot(mor)
end
delete_snapshot(mor)
Copy link
Member

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.
@miq-bot
Copy link
Member

miq-bot commented Jan 25, 2018

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
1 file checked, 0 offenses detected
Everything looks fine. 🍰

@chessbyte
Copy link
Member

@roliveri waiting on someone to review before merging?

@roliveri roliveri merged commit 4d26ddb into ManageIQ:master Jan 27, 2018
@roliveri roliveri added this to the Sprint 78 Ending Jan 29, 2018 milestone Jan 27, 2018
paulslaby pushed a commit to paulslaby/manageiq that referenced this pull request Jan 29, 2018
…a_cancel

Fix Deleting Snapshot on Smartstate Cancel
simaishi pushed a commit that referenced this pull request Jan 29, 2018
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit bc0a80d8e77aee7b1f1f14de2c0d60efa6a147ae
Author: Richard Oliveri <[email protected]>
Date:   Sat Jan 27 15:57:30 2018 -0500

    Merge pull request #16885 from jerryk55/fix_delete_snap_on_ssa_cancel
    
    Fix Deleting Snapshot on Smartstate Cancel
    (cherry picked from commit 4d26ddb64ad31361a19ce75def14f8b9decc296d)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1539756

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.

8 participants