diff --git a/awx/main/migrations/0006_v320_release.py b/awx/main/migrations/0006_v320_release.py index e9af9962c5..45eabbebc5 100644 --- a/awx/main/migrations/0006_v320_release.py +++ b/awx/main/migrations/0006_v320_release.py @@ -145,12 +145,12 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='inventorysource', name='source', - field=models.CharField(default=b'', max_length=32, blank=True, choices=[(b'', 'Manual'), (b'file', 'File, Directory or Script'), (b'scm', 'Sourced from a Project'), (b'ec2', 'Amazon EC2'), (b'gce', 'Google Compute Engine'), (b'azure', 'Microsoft Azure Classic (deprecated)'), (b'azure_rm', 'Microsoft Azure Resource Manager'), (b'vmware', 'VMware vCenter'), (b'satellite6', 'Red Hat Satellite 6'), (b'cloudforms', 'Red Hat CloudForms'), (b'openstack', 'OpenStack'), (b'custom', 'Custom Script')]), + field=models.CharField(default=b'', max_length=32, blank=True, choices=[(b'', 'Manual'), (b'file', 'File, Directory or Script'), (b'scm', 'Sourced from a Project'), (b'ec2', 'Amazon EC2'), (b'gce', 'Google Compute Engine'), (b'azure_rm', 'Microsoft Azure Resource Manager'), (b'vmware', 'VMware vCenter'), (b'satellite6', 'Red Hat Satellite 6'), (b'cloudforms', 'Red Hat CloudForms'), (b'openstack', 'OpenStack'), (b'custom', 'Custom Script')]), ), migrations.AlterField( model_name='inventoryupdate', name='source', - field=models.CharField(default=b'', max_length=32, blank=True, choices=[(b'', 'Manual'), (b'file', 'File, Directory or Script'), (b'scm', 'Sourced from a Project'), (b'ec2', 'Amazon EC2'), (b'gce', 'Google Compute Engine'), (b'azure', 'Microsoft Azure Classic (deprecated)'), (b'azure_rm', 'Microsoft Azure Resource Manager'), (b'vmware', 'VMware vCenter'), (b'satellite6', 'Red Hat Satellite 6'), (b'cloudforms', 'Red Hat CloudForms'), (b'openstack', 'OpenStack'), (b'custom', 'Custom Script')]), + field=models.CharField(default=b'', max_length=32, blank=True, choices=[(b'', 'Manual'), (b'file', 'File, Directory or Script'), (b'scm', 'Sourced from a Project'), (b'ec2', 'Amazon EC2'), (b'gce', 'Google Compute Engine'), (b'azure_rm', 'Microsoft Azure Resource Manager'), (b'vmware', 'VMware vCenter'), (b'satellite6', 'Red Hat Satellite 6'), (b'cloudforms', 'Red Hat CloudForms'), (b'openstack', 'OpenStack'), (b'custom', 'Custom Script')]), ), migrations.AlterField( model_name='inventorysource', diff --git a/awx/main/migrations/0007_v320_data_migrations.py b/awx/main/migrations/0007_v320_data_migrations.py index 2971dba213..9461e81bcb 100644 --- a/awx/main/migrations/0007_v320_data_migrations.py +++ b/awx/main/migrations/0007_v320_data_migrations.py @@ -11,6 +11,7 @@ from awx.main.migrations import _migration_utils as migration_utils from awx.main.migrations import _reencrypt as reencrypt from awx.main.migrations import _scan_jobs as scan_jobs from awx.main.migrations import _credentialtypes as credentialtypes +from awx.main.migrations import _azure_credentials as azurecreds import awx.main.fields @@ -24,6 +25,8 @@ class Migration(migrations.Migration): # Inventory Refresh migrations.RunPython(migration_utils.set_current_apps_for_migrations), migrations.RunPython(invsrc.remove_rax_inventory_sources), + migrations.RunPython(azurecreds.remove_azure_credentials), + migrations.RunPython(invsrc.remove_azure_inventory_sources), migrations.RunPython(invsrc.remove_inventory_source_with_no_inventory_link), migrations.RunPython(invsrc.rename_inventory_sources), migrations.RunPython(reencrypt.replace_aesecb_fernet), diff --git a/awx/main/migrations/_azure_credentials.py b/awx/main/migrations/_azure_credentials.py new file mode 100644 index 0000000000..93981ea8f9 --- /dev/null +++ b/awx/main/migrations/_azure_credentials.py @@ -0,0 +1,15 @@ +import logging + +from django.db.models import Q + +logger = logging.getLogger('awx.main.migrations') + + +def remove_azure_credentials(apps, schema_editor): + '''Azure is not supported as of 3.2 and greater. Instead, azure_rm is + supported. + ''' + Credential = apps.get_model('main', 'Credential') + logger.debug("Removing all Azure Credentials from database.") + Credential.objects.filter(kind='azure').delete() + diff --git a/awx/main/migrations/_inventory_source.py b/awx/main/migrations/_inventory_source.py index baf5576e90..e2401ee3ae 100644 --- a/awx/main/migrations/_inventory_source.py +++ b/awx/main/migrations/_inventory_source.py @@ -51,3 +51,12 @@ def remove_inventory_source_with_no_inventory_link(apps, schema_editor): InventorySource = apps.get_model('main', 'InventorySource') logger.debug("Removing all InventorySource that have no link to an Inventory from database.") InventorySource.objects.filter(Q(inventory__organization=None) & Q(deprecated_group__inventory=None)).delete() + + +def remove_azure_inventory_sources(apps, schema_editor): + '''Azure inventory sources are not supported since 3.2, remove them. + ''' + InventorySource = apps.get_model('main', 'InventorySource') + logger.debug("Removing all Azure InventorySource from database.") + InventorySource.objects.filter(source='azure').delete() + diff --git a/awx/main/tests/functional/test_inventory_source_migration.py b/awx/main/tests/functional/test_inventory_source_migration.py index 75d7a15704..9752a65579 100644 --- a/awx/main/tests/functional/test_inventory_source_migration.py +++ b/awx/main/tests/functional/test_inventory_source_migration.py @@ -35,3 +35,13 @@ def test_inv_src_rename(inventory_source_factory): inv_src01.refresh_from_db() # inv-is-t1 is generated in the inventory_source_factory assert inv_src01.name == 't1 - inv-is-t1 - 0' + + +@pytest.mark.django_db +def test_azure_inv_src_removal(inventory_source): + inventory_source.source = 'azure' + inventory_source.save() + + assert InventorySource.objects.filter(pk=inventory_source.pk).exists() + invsrc.remove_azure_inventory_sources(apps, None) + assert not InventorySource.objects.filter(pk=inventory_source.pk).exists()