From 3c8c1858d493c7dbbaaf95d0fa3ac86a34f1a51e Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Thu, 14 May 2020 16:05:21 -0400 Subject: [PATCH] Fix migration through manual testing --- awx/main/migrations/_inventory_source.py | 10 ++++++++-- awx/main/tasks.py | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/awx/main/migrations/_inventory_source.py b/awx/main/migrations/_inventory_source.py index 22e5ff0ce3..ed79606587 100644 --- a/awx/main/migrations/_inventory_source.py +++ b/awx/main/migrations/_inventory_source.py @@ -3,6 +3,7 @@ import logging from uuid import uuid4 from django.utils.encoding import smart_text +from django.utils.timezone import now from awx.main.utils.common import parse_yaml_or_json @@ -99,20 +100,25 @@ def create_scm_script_substitute(apps, source): # it can still be updated manually later (but staying within 2.9 branch), if desired ansible_rev = '6f83b9aff42331e15c55a171de0a8b001208c18c' InventorySource = apps.get_model('main', 'InventorySource') + ContentType = apps.get_model('contenttypes', 'ContentType') Project = apps.get_model('main', 'Project') if not InventorySource.objects.filter(source=source).exists(): logger.debug('No sources of type {} to migrate'.format(source)) return proj_name = 'Replacement project for {} type sources - {}'.format(source, uuid4()) - project = Project( + right_now = now() + project = Project.objects.create( name=proj_name, + created=right_now, + modified=right_now, description='Created by migration', + polymorphic_ctype=ContentType.objects.get(model='project'), + # project-specific fields scm_type='git', scm_url='https://github.com/ansible/ansible.git', scm_branch='stable-2.9', scm_revision=ansible_rev ) - project.save(skip_update=True) ct = 0 for inv_src in InventorySource.objects.filter(source=source).iterator(): inv_src.source = 'scm' diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 9fd3753440..7873ee4b84 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -2281,7 +2281,11 @@ class RunProjectUpdate(BaseTask): def acquire_lock(self, instance, blocking=True): lock_path = instance.get_lock_file() if lock_path is None: - raise RuntimeError(u'Invalid lock file path') + # If from migration or someone blanked local_path for any other reason, recoverable by save + instance.save() + lock_path = instance.get_lock_file() + if lock_path is None: + raise RuntimeError(u'Invalid lock file path') try: self.lock_fd = os.open(lock_path, os.O_RDWR | os.O_CREAT)