diff --git a/awx/main/migrations/0038_v320_release.py b/awx/main/migrations/0038_v320_release.py index 8216282e91..6b00103df5 100644 --- a/awx/main/migrations/0038_v320_release.py +++ b/awx/main/migrations/0038_v320_release.py @@ -246,7 +246,7 @@ class Migration(migrations.Migration): migrations.AddField( model_name='inventory', name='insights_credential', - field=models.ForeignKey(related_name='insights_credential', default=None, blank=True, on_delete=models.deletion.SET_NULL, to='main.Credential', help_text='Credentials to be used by hosts belonging to this invtory when accessing Red Hat Insights API.', null=True), + field=models.ForeignKey(related_name='insights_credential', default=None, blank=True, on_delete=models.deletion.SET_NULL, to='main.Credential', help_text='Credentials to be used by hosts belonging to this inventory when accessing Red Hat Insights API.', null=True), ), migrations.AlterField( model_name='inventory', diff --git a/awx/main/migrations/_credentialtypes.py b/awx/main/migrations/_credentialtypes.py index a51a5fc75b..4dd083fa0b 100644 --- a/awx/main/migrations/_credentialtypes.py +++ b/awx/main/migrations/_credentialtypes.py @@ -49,6 +49,10 @@ def _populate_deprecated_cred_types(cred, kind): return cred[kind] +def _get_insights_credential_type(): + return CredentialType.objects.get(kind='insights') + + def _is_insights_scm(apps, cred): return apps.get_model('main', 'Credential').objects.filter(id=cred.id, projects__scm_type='insights').exists() @@ -74,9 +78,10 @@ def migrate_to_v2_credentials(apps, schema_editor): if getattr(cred, 'vault_password', None): data['vault_password'] = cred.vault_password if _is_insights_scm(apps, cred): - data['is_insights'] = True _disassociate_non_insights_projects(apps, cred) - credential_type = _populate_deprecated_cred_types(deprecated_cred, cred.kind) or CredentialType.from_v1_kind(cred.kind, data) + credential_type = _get_insights_credential_type() + else: + credential_type = _populate_deprecated_cred_types(deprecated_cred, cred.kind) or CredentialType.from_v1_kind(cred.kind, data) defined_fields = credential_type.defined_fields cred.credential_type = apps.get_model('main', 'CredentialType').objects.get(pk=credential_type.pk) diff --git a/awx/main/models/credential.py b/awx/main/models/credential.py index 5ff69d6fa3..458635f858 100644 --- a/awx/main/models/credential.py +++ b/awx/main/models/credential.py @@ -469,8 +469,6 @@ class CredentialType(CommonModelNameNotUnique): requirements['kind'] = 'vault' else: requirements['kind'] = 'ssh' - elif kind == 'scm' and data.get('is_insights', False): - requirements['kind'] = 'insights' elif kind in ('net', 'scm'): requirements['kind'] = kind elif kind in kind_choices: diff --git a/awx/main/models/inventory.py b/awx/main/models/inventory.py index f1ddb1b1d3..8785aba6fc 100644 --- a/awx/main/models/inventory.py +++ b/awx/main/models/inventory.py @@ -146,7 +146,7 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin): insights_credential = models.ForeignKey( 'Credential', related_name='insights_credential', - help_text=_('Credentials to be used by hosts belonging to this invtory when accessing Red Hat Insights API.'), + help_text=_('Credentials to be used by hosts belonging to this inventory when accessing Red Hat Insights API.'), on_delete=models.SET_NULL, blank=True, null=True, @@ -357,7 +357,7 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin): def clean_insights_credential(self): if self.insights_credential and self.insights_credential.credential_type.kind != 'insights': - raise ValidationError(_('Invalid CredentialType')) + raise ValidationError(_("Credential kind must be 'insights'.")) return self.insights_credential