mirror of
https://github.com/ansible/awx.git
synced 2026-01-13 02:50:02 -03:30
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:
parent
d4fe60756b
commit
f4a252a331
@ -175,4 +175,4 @@ def migrate_job_credentials(apps, schema_editor):
|
||||
|
||||
|
||||
def create_ovirt4_credtype(apps, schema_editor):
|
||||
CredentialType.defaults['ovirt4']().save()
|
||||
CredentialType.setup_tower_managed_defaults()
|
||||
|
||||
@ -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
|
||||
|
||||
@ -14,6 +14,17 @@ EXAMPLE_PRIVATE_KEY = '-----BEGIN PRIVATE KEY-----\nxyz==\n-----END PRIVATE KEY-
|
||||
EXAMPLE_ENCRYPTED_PRIVATE_KEY = '-----BEGIN PRIVATE KEY-----\nProc-Type: 4,ENCRYPTED\nxyz==\n-----END PRIVATE KEY-----'
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_idempotent_credential_type_setup():
|
||||
assert CredentialType.objects.count() == 0
|
||||
CredentialType.setup_tower_managed_defaults()
|
||||
total = CredentialType.objects.count()
|
||||
assert total > 0
|
||||
|
||||
CredentialType.setup_tower_managed_defaults()
|
||||
assert CredentialType.objects.count() == total
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
@pytest.mark.parametrize('kind, total', [
|
||||
('ssh', 1), ('net', 0)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user