mirror of
https://github.com/ansible/awx.git
synced 2026-01-16 04:10:44 -03:30
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
This commit is contained in:
parent
0bb7b0700d
commit
a4a17fe14c
@ -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'))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user