From 0bc5665e92f5a807b133fe90b9865e4e44730d0f Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Wed, 25 Apr 2018 14:20:19 -0400 Subject: [PATCH] remove the legacy fact cleanup system template see: https://github.com/ansible/tower/issues/1021 --- .../api/system_job_template_launch.md | 7 ------- .../0037_v330_remove_legacy_fact_cleanup.py | 18 ++++++++++++++++++ awx/main/migrations/_scan_jobs.py | 8 ++++++++ awx/main/tasks.py | 9 ++------- 4 files changed, 28 insertions(+), 14 deletions(-) create mode 100644 awx/main/migrations/0037_v330_remove_legacy_fact_cleanup.py diff --git a/awx/api/templates/api/system_job_template_launch.md b/awx/api/templates/api/system_job_template_launch.md index 95d0f6b378..ee05d38cb9 100644 --- a/awx/api/templates/api/system_job_template_launch.md +++ b/awx/api/templates/api/system_job_template_launch.md @@ -12,12 +12,6 @@ For example on `cleanup_jobs` and `cleanup_activitystream`: Which will act on data older than 30 days. -For `cleanup_facts`: - -`{"extra_vars": {"older_than": "4w", "granularity": "3d"}}` - -Which will reduce the granularity of scan data to one scan per 3 days when the data is older than 4w. - For `cleanup_activitystream` and `cleanup_jobs` commands, providing `"dry_run": true` inside of `extra_vars` will show items that will be removed without deleting them. @@ -27,7 +21,6 @@ applicable either when running it from the command line or launching its system job template with empty `extra_vars`. - Defaults for `cleanup_activitystream`: days=90 - - Defaults for `cleanup_facts`: older_than="30d", granularity="1w" - Defaults for `cleanup_jobs`: days=90 If successful, the response status code will be 202. If the job cannot be diff --git a/awx/main/migrations/0037_v330_remove_legacy_fact_cleanup.py b/awx/main/migrations/0037_v330_remove_legacy_fact_cleanup.py new file mode 100644 index 0000000000..da2423bdcf --- /dev/null +++ b/awx/main/migrations/0037_v330_remove_legacy_fact_cleanup.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +# AWX +from awx.main.migrations._scan_jobs import remove_legacy_fact_cleanup + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('main', '0036_v330_credtype_remove_become_methods'), + ] + + operations = [ + migrations.RunPython(remove_legacy_fact_cleanup), + ] diff --git a/awx/main/migrations/_scan_jobs.py b/awx/main/migrations/_scan_jobs.py index 0d91e3ef23..993b28c5d1 100644 --- a/awx/main/migrations/_scan_jobs.py +++ b/awx/main/migrations/_scan_jobs.py @@ -102,3 +102,11 @@ def remove_scan_type_nodes(apps, schema_editor): prompts.pop('job_type') node.char_prompts = prompts node.save() + + +def remove_legacy_fact_cleanup(apps, schema_editor): + SystemJobTemplate = apps.get_model('main', 'SystemJobTemplate') + for job in SystemJobTemplate.objects.filter(job_type='cleanup_facts').all(): + for sched in job.schedules.all(): + sched.delete() + job.delete() diff --git a/awx/main/tasks.py b/awx/main/tasks.py index cb42464462..470da6f1f2 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -2278,19 +2278,14 @@ class RunSystemJob(BaseTask): json_vars = {} else: json_vars = json.loads(system_job.extra_vars) - if 'days' in json_vars and system_job.job_type != 'cleanup_facts': + if 'days' in json_vars: args.extend(['--days', str(json_vars.get('days', 60))]) - if 'dry_run' in json_vars and json_vars['dry_run'] and system_job.job_type != 'cleanup_facts': + if 'dry_run' in json_vars and json_vars['dry_run']: args.extend(['--dry-run']) if system_job.job_type == 'cleanup_jobs': args.extend(['--jobs', '--project-updates', '--inventory-updates', '--management-jobs', '--ad-hoc-commands', '--workflow-jobs', '--notifications']) - if system_job.job_type == 'cleanup_facts': - if 'older_than' in json_vars: - args.extend(['--older_than', str(json_vars['older_than'])]) - if 'granularity' in json_vars: - args.extend(['--granularity', str(json_vars['granularity'])]) except Exception: logger.exception(six.text_type("{} Failed to parse system job").format(system_job.log_format)) return args