From a4a17fe14c077549ccf3cd1ec469053d2a7d9051 Mon Sep 17 00:00:00 2001 From: AlanCoding Date: Mon, 25 Sep 2017 11:22:06 -0400 Subject: [PATCH] always ignore deprecated_group if in groups If overwrite=True for an inventory source import, then this matters creating a new inventory source through v1 API will not include deprecated_group inside of the InventorySource groups m2m related connection, but migrations from 3.1 will In those migrated cases, this code will leave the deprecated_group untouched, so as to not trigger its cascade delete --- awx/main/management/commands/inventory_import.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/awx/main/management/commands/inventory_import.py b/awx/main/management/commands/inventory_import.py index 59853874a2..aa1fe65c2b 100644 --- a/awx/main/management/commands/inventory_import.py +++ b/awx/main/management/commands/inventory_import.py @@ -503,6 +503,12 @@ class Command(NoArgsCommand): group_names = all_group_names[offset:(offset + self._batch_size)] for group_pk in groups_qs.filter(name__in=group_names).values_list('pk', flat=True): del_group_pks.discard(group_pk) + if self.inventory_source.deprecated_group_id in del_group_pks: # TODO: remove in 3.3 + logger.warning( + 'Group "%s" from v1 API is not deleted by overwrite', + self.inventory_source.deprecated_group.name + ) + del_group_pks.discard(self.inventory_source.deprecated_group_id) # Now delete all remaining groups in batches. all_del_pks = sorted(list(del_group_pks)) for offset in xrange(0, len(all_del_pks), self._batch_size): @@ -531,6 +537,12 @@ class Command(NoArgsCommand): group_host_count = 0 db_groups = self.inventory_source.groups for db_group in db_groups.all(): + if self.inventory_source.deprecated_group_id == db_group.id: # TODO: remove in 3.3 + logger.info( + 'Group "%s" from v1 API child group/host connections preserved', + db_group.name + ) + continue # Delete child group relationships not present in imported data. db_children = db_group.children db_children_name_pk_map = dict(db_children.values_list('name', 'pk'))