From 1422bb20434f4c0de4957ef3afc274f95832d9e7 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Mon, 21 Jun 2021 14:43:40 -0400 Subject: [PATCH] Fix tower upgrade (#5114) * Hack to avoid creating both tower and controller CredentialType * Remove line used for testing --- .../migrations/0150_rename_inv_sources_inv_updates.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/awx/main/migrations/0150_rename_inv_sources_inv_updates.py b/awx/main/migrations/0150_rename_inv_sources_inv_updates.py index 2f557350bf..11c4b1b3f9 100644 --- a/awx/main/migrations/0150_rename_inv_sources_inv_updates.py +++ b/awx/main/migrations/0150_rename_inv_sources_inv_updates.py @@ -23,11 +23,16 @@ def forwards(apps, schema_editor): CredentialType = apps.get_model('main', 'CredentialType') tower_type = CredentialType.objects.filter(managed_by_tower=True, namespace='tower').first() - if tower_type is not None and not CredentialType.objects.filter(managed_by_tower=True, namespace='controller', kind='cloud').exists(): + if tower_type is not None: + controller_type = CredentialType.objects.filter(managed_by_tower=True, namespace='controller', kind='cloud').first() + if controller_type: + # this gets created by prior migrations in upgrade scenarios + controller_type.delete() + registry_type = ManagedCredentialType.registry.get('controller') if not registry_type: raise RuntimeError('Excpected to find controller credential, this may need to be edited in the future!') - logger.info('Renaming the Ansible Tower credential type for existing install') + logger.warn('Renaming the Ansible Tower credential type for existing install') tower_type.name = registry_type.name # sensitive to translations tower_type.namespace = 'controller' # if not done, will error setup_tower_managed_defaults tower_type.save(update_fields=['name', 'namespace'])