mirror of
https://github.com/ansible/awx.git
synced 2026-01-09 23:12:08 -03:30
Create system_administrator rbac role in migration
* We had race conditions with the system_administrator role being created just-in-time. Instead of fixing the race condition(s), dodge them by ensuring the role always exists
This commit is contained in:
parent
622f6ea166
commit
f51af03424
@ -10,6 +10,11 @@ def setup_tower_managed_defaults(apps, schema_editor):
|
|||||||
CredentialType.setup_tower_managed_defaults(apps)
|
CredentialType.setup_tower_managed_defaults(apps)
|
||||||
|
|
||||||
|
|
||||||
|
def setup_rbac_role_system_administrator(apps, schema_editor):
|
||||||
|
Role = apps.get_model('main', 'Role')
|
||||||
|
Role.objects.get_or_create(singleton_name='system_administrator', role_field='system_administrator')
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('main', '0200_template_name_constraint'),
|
('main', '0200_template_name_constraint'),
|
||||||
@ -17,4 +22,5 @@ class Migration(migrations.Migration):
|
|||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.RunPython(setup_tower_managed_defaults),
|
migrations.RunPython(setup_tower_managed_defaults),
|
||||||
|
migrations.RunPython(setup_rbac_role_system_administrator),
|
||||||
]
|
]
|
||||||
|
|||||||
@ -167,3 +167,9 @@ class TestMigrationSmoke:
|
|||||||
assert CredentialType.objects.filter(
|
assert CredentialType.objects.filter(
|
||||||
name=expected_name
|
name=expected_name
|
||||||
).exists(), f'Could not find {expected_name} credential type name, all names: {list(CredentialType.objects.values_list("name", flat=True))}'
|
).exists(), f'Could not find {expected_name} credential type name, all names: {list(CredentialType.objects.values_list("name", flat=True))}'
|
||||||
|
|
||||||
|
# Verify the system_administrator role exists
|
||||||
|
Role = new_state.apps.get_model('main', 'Role')
|
||||||
|
assert Role.objects.filter(
|
||||||
|
singleton_name='system_administrator', role_field='system_administrator'
|
||||||
|
).exists(), "expected to find a system_administrator singleton role"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user