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

Ovirt delete snapshots after x days #45551

Merged
merged 7 commits into from
Oct 5, 2018

Conversation

mnecas
Copy link
Contributor

@mnecas mnecas commented Sep 12, 2018

SUMMARY

Fixes #41500

ISSUE TYPE
  • Bugfix Pull Request
  • Feature Pull Request
COMPONENT NAME

ovirt

ANSIBLE VERSION
ansible 2.6.3
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/mnecas/Desktop/Projects/Redhat/ansible/lib/ansible/modules/cloud/ovirt']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.15 (default, May 16 2018, 17:50:09) [GCC 8.1.1 20180502 (Red Hat 8.1.1-1)]

ADDITIONAL INFORMATION

@ansibot
Copy link
Contributor

ansibot commented Sep 12, 2018

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 bug This issue/PR relates to a bug. cloud community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. virt Virt community (incl. QEMU, KVM, libvirt, ovirt, RHV and Proxmox) support:community This issue/PR relates to code supported by the Ansible community. labels Sep 12, 2018
@ansibot
Copy link
Contributor

ansibot commented Sep 12, 2018

The test ansible-test sanity --test pep8 [explain] failed with 4 errors:

lib/ansible/modules/cloud/ovirt/ovirt_snapshot.py:243:40: E231 missing whitespace after ','
lib/ansible/modules/cloud/ovirt/ovirt_snapshot.py:277:25: E225 missing whitespace around operator
lib/ansible/modules/cloud/ovirt/ovirt_snapshot.py:283:29: E221 multiple spaces before operator
lib/ansible/modules/cloud/ovirt/ovirt_snapshot.py:286:28: E225 missing whitespace around operator

The test ansible-test sanity --test validate-modules [explain] failed with 1 error:

lib/ansible/modules/cloud/ovirt/ovirt_snapshot.py:0:0: E309 version_added for new option (keep_days_old) should be 2.8. Currently 0.0

click here for bot help

@ansibot ansibot added ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Sep 12, 2018
@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Sep 12, 2018
@jborean93 jborean93 removed the needs_triage Needs a first human triage before being processed. label Sep 13, 2018
keep_days_old:
description:
- "Number of days after which should snapshot be deleted."
- "It will check all snapshots of vm and delete them, if they are older."
Copy link
Contributor

Choose a reason for hiding this comment

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

s/vm/virtual machine

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed community_review In order to be merged, this PR must follow the community review workflow. support:community This issue/PR relates to code supported by the Ansible community. labels Sep 17, 2018
except Exception as e:
module.fail_json(msg=str(e), exception=traceback.format_exc())
finally:
if module.params.get('keep_days_old') is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

In this case we wouldn't close the connection. Please create new method something like remove_old_snapshosts and call it from state=='present' branch as it's default state. Also please document what will be returned in case this paramter is used.

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Sep 25, 2018
@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. support:community This issue/PR relates to code supported by the Ansible community. and removed core_review In order to be merged, this PR must follow the core review workflow. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Oct 3, 2018
@@ -112,6 +122,10 @@
at following url: http://ovirt.github.io/ovirt-engine-api-model/master/#types/snapshot."
returned: On success if snapshot is found.
type: dict
snapshots:
description: List of deleted snapshots
Copy link
Contributor

Choose a reason for hiding this comment

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

Please also document that it's returned only in case user specify keep_days_old parameter.

@@ -222,6 +236,23 @@ def restore_snapshot(module, vm_service, snapshots_service):
}


def remove_old_snapshosts(module, snapshots_service):
from datetime import datetime
Copy link
Contributor

Choose a reason for hiding this comment

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

Please do this import at the begging of the file with other imports.

changed = False
date_now = datetime.now()
for snapshot in snapshots_service.list():
if snapshot.vm and snapshot.vm.name == module.params.get('vm_name'):
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should be just fine to check if snapshot.vm is not None because you are already using snapshots_service of that vm, so you don't need to check if names are same.

snapshots_service.snapshot_service(snapshot.id).remove()
deleted_snapshot.append(get_dict_of_struct(snapshot))
changed = True
time.sleep(45)
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to wait until snaphsot is removed and vm ready to remove another snapshot, not any random wait time.

Copy link
Contributor

@machacekondra machacekondra left a comment

Choose a reason for hiding this comment

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

shipit

@ansibot ansibot added automerge This PR was automatically merged by ansibot. shipit This PR is ready to be merged by Core and removed community_review In order to be merged, this PR must follow the community review workflow. labels Oct 5, 2018
@ansibot ansibot merged commit 66b1c83 into ansible:devel Oct 5, 2018
@dagwieers dagwieers added ovirt oVirt and RHV community and removed virt Virt community (incl. QEMU, KVM, libvirt, ovirt, RHV and Proxmox) labels Feb 21, 2019
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 automerge This PR was automatically merged by ansibot. bug This issue/PR relates to a bug. cloud module This issue/PR relates to a module. ovirt oVirt and RHV community shipit This PR is ready to be merged by Core support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow for ovirt_snapshots to be deleted based on date differences
5 participants