add new credential types in a more stable way in migrations

instead of writing individual migrations for new built-in credential
types, this change makes the "setup_tower_managed_defaults" function
idempotent so that it only adds the credential types you're missing
This commit is contained in:
Ryan Petrello
2017-09-26 14:14:46 -04:00
committed by Matthew Jones
parent d4fe60756b
commit f4a252a331
3 changed files with 20 additions and 1 deletions

View File

@@ -3,6 +3,7 @@
from collections import OrderedDict
import functools
import json
import logging
import operator
import os
import stat
@@ -35,6 +36,8 @@ from awx.main.utils import encrypt_field
__all__ = ['Credential', 'CredentialType', 'V1Credential']
logger = logging.getLogger('awx.main.models.credential')
class V1Credential(object):
@@ -468,6 +471,11 @@ class CredentialType(CommonModelNameNotUnique):
for default in cls.defaults.values():
default_ = default()
if persisted:
if CredentialType.objects.filter(name=default_.name, kind=default_.kind).count():
continue
logger.debug(_(
"adding %s credential type" % default_.name
))
default_.save()
@classmethod