mirror of
https://github.com/ansible/awx.git
synced 2024-11-02 01:21:21 +03:00
Fix some issues syncing playbooks
* Build a list of playbooks and store it in the database at sync time * Fix an issue running playbook sync on jobs for scan jobs * Remove a TODO that was unneeded
This commit is contained in:
parent
0f0d9953b3
commit
7c7d2e37ed
@ -961,12 +961,15 @@ class ProjectSerializer(UnifiedJobTemplateSerializer, ProjectOptionsSerializer):
|
||||
|
||||
class ProjectPlaybooksSerializer(ProjectSerializer):
|
||||
|
||||
playbooks = serializers.ReadOnlyField(help_text='Array of playbooks available within this project.')
|
||||
playbooks = serializers.SerializerMethodField(help_text='Array of playbooks available within this project.')
|
||||
|
||||
class Meta:
|
||||
model = Project
|
||||
fields = ('playbooks',)
|
||||
|
||||
def get_playbooks(self, obj):
|
||||
return obj.playbook_files
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
ret = super(ProjectPlaybooksSerializer, self).data
|
||||
|
20
awx/main/migrations/0044_v310_project_playbook_files.py
Normal file
20
awx/main/migrations/0044_v310_project_playbook_files.py
Normal file
@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import jsonfield.fields
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('main', '0043_v310_scm_revision'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='project',
|
||||
name='playbook_files',
|
||||
field=jsonfield.fields.JSONField(default=[], help_text='List of playbooks found in the project', verbose_name='Playbook Files', editable=False, blank=True),
|
||||
),
|
||||
]
|
@ -7,6 +7,9 @@ import os
|
||||
import re
|
||||
import urlparse
|
||||
|
||||
# JSONField
|
||||
from jsonfield import JSONField
|
||||
|
||||
# Django
|
||||
from django.conf import settings
|
||||
from django.db import models
|
||||
@ -236,6 +239,14 @@ class Project(UnifiedJobTemplate, ProjectOptions, ResourceMixin):
|
||||
help_text=_('The last revision fetched by a project update'),
|
||||
)
|
||||
|
||||
playbook_files = JSONField(
|
||||
blank=True,
|
||||
default=[],
|
||||
editable=False,
|
||||
verbose_name=_('Playbook Files'),
|
||||
help_text=_('List of playbooks found in the project'),
|
||||
)
|
||||
|
||||
admin_role = ImplicitRoleField(parent_role=[
|
||||
'organization.admin_role',
|
||||
'singleton:' + ROLE_SINGLETON_SYSTEM_ADMINISTRATOR,
|
||||
|
@ -160,12 +160,6 @@ def tower_periodic_scheduler(self):
|
||||
logger.debug("Last run was: %s", last_run)
|
||||
write_last_run(run_now)
|
||||
|
||||
# Sanity check: If this is a secondary machine, there is nothing
|
||||
# on the schedule.
|
||||
# TODO: Fix for clustering/ha
|
||||
if Instance.objects.my_role() == 'secondary':
|
||||
return
|
||||
|
||||
old_schedules = Schedule.objects.enabled().before(last_run)
|
||||
for schedule in old_schedules:
|
||||
schedule.save()
|
||||
@ -997,7 +991,7 @@ class RunJob(BaseTask):
|
||||
return getattr(settings, 'AWX_PROOT_ENABLED', False)
|
||||
|
||||
def pre_run_hook(self, job, **kwargs):
|
||||
if job.project.scm_type:
|
||||
if job.project and job.project.scm_type:
|
||||
local_project_sync = job.project.create_project_update()
|
||||
local_project_sync.job_type = 'run'
|
||||
local_project_sync.save()
|
||||
@ -1205,12 +1199,13 @@ class RunProjectUpdate(BaseTask):
|
||||
return kwargs.get('private_data_files', {}).get('scm_credential', '')
|
||||
|
||||
def post_run_hook(self, instance, status, **kwargs):
|
||||
if instance.job_type == 'check':
|
||||
if instance.job_type == 'check' and status not in ('failed', 'canceled',):
|
||||
p = instance.project
|
||||
fd = open('/tmp/_{}_syncrev'.format(instance.id), 'r')
|
||||
lines = fd.readlines()
|
||||
if lines:
|
||||
p.scm_revision = lines[0].strip()
|
||||
p.playbook_files = p.playbooks
|
||||
p.save()
|
||||
else:
|
||||
logger.error("Could not find scm revision in check")
|
||||
|
@ -29,8 +29,8 @@
|
||||
version: "{{scm_branch|quote}}"
|
||||
force: "{{scm_clean}}"
|
||||
accept_hostkey: "{{scm_accept_hostkey}}"
|
||||
clone: "{{ scm_full_checkout }}"
|
||||
update: "{{ scm_full_checkout }}"
|
||||
#clone: "{{ scm_full_checkout }}"
|
||||
#update: "{{ scm_full_checkout }}"
|
||||
when: scm_type == 'git' and scm_accept_hostkey is defined
|
||||
register: scm_result
|
||||
|
||||
@ -45,8 +45,8 @@
|
||||
repo: "{{scm_url|quote}}"
|
||||
version: "{{scm_branch|quote}}"
|
||||
force: "{{scm_clean}}"
|
||||
clone: "{{ scm_full_checkout }}"
|
||||
update: "{{ scm_full_checkout }}"
|
||||
#clone: "{{ scm_full_checkout }}"
|
||||
#update: "{{ scm_full_checkout }}"
|
||||
when: scm_type == 'git' and scm_accept_hostkey is not defined
|
||||
register: scm_result
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user