mirror of
https://github.com/ZwareBear/awx.git
synced 2026-05-17 05:48:36 -05:00
Fix for AC-284. Delete groups when they are disassociated and have no more parents. Remove all group and host associations from a group when it is marked inactive.
This commit is contained in:
@@ -333,7 +333,7 @@ class InventoryTest(BaseTest):
|
||||
self.post(url5, data=remove_me, expect=204, auth=self.get_other_credentials())
|
||||
got = self.get(url5, expect=200, auth=self.get_other_credentials())
|
||||
self.assertEquals(got['count'], 3)
|
||||
|
||||
|
||||
###################################################
|
||||
# VARIABLES
|
||||
|
||||
@@ -566,6 +566,17 @@ class InventoryTest(BaseTest):
|
||||
# try to double disassociate to see what happens (should no-op)
|
||||
self.post(subgroups_url3, data=result, expect=204, auth=self.get_other_credentials())
|
||||
|
||||
# removed group should be automatically marked inactive once it no longer has any parents.
|
||||
removed_group = Group.objects.get(pk=result['id'])
|
||||
self.assertTrue(removed_group.parents.count())
|
||||
self.assertTrue(removed_group.active)
|
||||
for parent in removed_group.parents.all():
|
||||
parent_children_url = reverse('main:group_children_list', args=(parent.pk,))
|
||||
data = {'id': removed_group.pk, 'disassociate': 1}
|
||||
self.post(parent_children_url, data, expect=204, auth=self.get_super_credentials())
|
||||
removed_group = Group.objects.get(pk=result['id'])
|
||||
self.assertFalse(removed_group.active)
|
||||
|
||||
#########################################################
|
||||
# FIXME: TAGS
|
||||
|
||||
@@ -628,11 +639,15 @@ class InventoryTest(BaseTest):
|
||||
self.assertFalse(h_d in g_c.hosts.all())
|
||||
|
||||
# Mark group C inactive. Its child groups and hosts should now also be
|
||||
# attached to group A. Group D hosts should be unchanged.
|
||||
# attached to group A. Group D hosts should be unchanged. Group C
|
||||
# should also no longer have any group or host relationships.
|
||||
g_c.mark_inactive()
|
||||
self.assertTrue(g_d in g_a.children.all())
|
||||
self.assertTrue(h_c in g_a.hosts.all())
|
||||
self.assertFalse(h_d in g_a.hosts.all())
|
||||
self.assertFalse(g_c.parents.all())
|
||||
self.assertFalse(g_c.children.all())
|
||||
self.assertFalse(g_c.hosts.all())
|
||||
|
||||
def test_group_parents_and_children(self):
|
||||
# Test for various levels of group parent/child relations, with hosts,
|
||||
|
||||
@@ -377,11 +377,13 @@ class RunJobTest(BaseCeleryTest):
|
||||
self.assertFalse(self.group.has_active_failures)
|
||||
self.inventory = Inventory.objects.get(pk=self.inventory.pk)
|
||||
self.assertFalse(self.inventory.has_active_failures)
|
||||
# Un-mark host as inactive (should set flag on group and inventory)
|
||||
# Un-mark host as inactive (need to force update of flag on group and
|
||||
# inventory)
|
||||
host = self.host
|
||||
host.name = '_'.join(host.name.split('_')[3:]) or 'undeleted host'
|
||||
host.active = True
|
||||
host.save()
|
||||
host.update_has_active_failures()
|
||||
self.group = Group.objects.get(pk=self.group.pk)
|
||||
self.assertTrue(self.group.has_active_failures)
|
||||
self.inventory = Inventory.objects.get(pk=self.inventory.pk)
|
||||
@@ -404,10 +406,11 @@ class RunJobTest(BaseCeleryTest):
|
||||
self.assertFalse(self.group.has_active_failures)
|
||||
self.inventory = Inventory.objects.get(pk=self.inventory.pk)
|
||||
self.assertFalse(self.inventory.has_active_failures)
|
||||
# Un-mark job as inactive (should set flag on host, group and inventory)
|
||||
# Un-mark job as inactive (need to force update of flag)
|
||||
job.name = '_'.join(job.name.split('_')[3:]) or 'undeleted job'
|
||||
job.active = True
|
||||
job.save()
|
||||
job.inventory.update_has_active_failures()
|
||||
self.host = Host.objects.get(pk=self.host.pk)
|
||||
self.assertTrue(self.host.has_active_failures)
|
||||
self.group = Group.objects.get(pk=self.group.pk)
|
||||
|
||||
Reference in New Issue
Block a user