mirror of
https://github.com/ansible/awx.git
synced 2026-01-09 23:12:08 -03:30
AAP-44233 Create credential types in new migration step (#6969)
* Update database to credential types in new migration file * bump migration * Add assertion * Pre-delete credentials so we test recreation
This commit is contained in:
parent
ee19ee0c10
commit
3d027bafd0
20
awx/main/migrations/0201_create_managed_creds.py
Normal file
20
awx/main/migrations/0201_create_managed_creds.py
Normal file
@ -0,0 +1,20 @@
|
||||
from django.db import migrations
|
||||
|
||||
# AWX
|
||||
from awx.main.models import CredentialType
|
||||
from awx.main.utils.common import set_current_apps
|
||||
|
||||
|
||||
def setup_tower_managed_defaults(apps, schema_editor):
|
||||
set_current_apps(apps)
|
||||
CredentialType.setup_tower_managed_defaults(apps)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('main', '0200_template_name_constraint'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(setup_tower_managed_defaults),
|
||||
]
|
||||
@ -140,3 +140,22 @@ class TestMigrationSmoke:
|
||||
Project = new_state.apps.get_model('main', 'Project')
|
||||
for proj in Project.objects.all():
|
||||
assert proj.org_unique is True
|
||||
|
||||
# Piggyback test for the new credential types
|
||||
validate_exists = ['GitHub App Installation Access Token Lookup', 'Terraform backend configuration']
|
||||
CredentialType = new_state.apps.get_model('main', 'CredentialType')
|
||||
# simulate an upgrade by deleting existing types with these names
|
||||
for expected_name in validate_exists:
|
||||
ct = CredentialType.objects.filter(name=expected_name).first()
|
||||
if ct:
|
||||
ct.delete()
|
||||
|
||||
new_state = migrator.apply_tested_migration(
|
||||
('main', '0201_create_managed_creds'),
|
||||
)
|
||||
|
||||
CredentialType = new_state.apps.get_model('main', 'CredentialType')
|
||||
for expected_name in validate_exists:
|
||||
assert CredentialType.objects.filter(
|
||||
name=expected_name
|
||||
).exists(), f'Could not find {expected_name} credential type name, all names: {list(CredentialType.objects.values_list("name", flat=True))}'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user