Fix edge case in inventory import that would cause a group to become its own parent.

This commit is contained in:
Chris Church 2014-03-31 17:37:35 -04:00
parent 2913ce21d2
commit d7f31f9777
2 changed files with 18 additions and 2 deletions

View File

@ -649,7 +649,7 @@ class Command(NoArgsCommand):
self.logger.info('Group "%s" variables updated', k)
else:
self.logger.info('Group "%s" variables unmodified', k)
if self.inventory_source.group:
if self.inventory_source.group and self.inventory_source.group != group:
self.inventory_source.group.children.add(group)
group.inventory_sources.add(self.inventory_source)

View File

@ -1270,6 +1270,11 @@ class InventoryUpdatesTest(BaseTransactionTest):
user=self.super_django_user,
username=source_username,
password=source_password)
# Set parent group name to one that might be created by the sync.
group = self.group
group.name = 'ec2'
group.save()
self.group = group
inventory_source = self.update_inventory_source(self.group,
source='ec2', credential=credential, source_regions=source_regions,
source_vars='---')
@ -1279,7 +1284,10 @@ class InventoryUpdatesTest(BaseTransactionTest):
host.enabled = False
host.save()
self.check_inventory_source(inventory_source, initial=False)
# Verify that main group is in top level groups (hasn't been added as
# its own child).
self.assertTrue(self.group in self.inventory.root_groups)
def test_update_from_rax(self):
source_username = getattr(settings, 'TEST_RACKSPACE_USERNAME', '')
source_password = getattr(settings, 'TEST_RACKSPACE_API_KEY', '')
@ -1290,6 +1298,11 @@ class InventoryUpdatesTest(BaseTransactionTest):
user=self.super_django_user,
username=source_username,
password=source_password)
# Set parent group name to one that might be created by the sync.
group = self.group
group.name = 'DFW'
group.save()
self.group = group
inventory_source = self.update_inventory_source(self.group,
source='rax', credential=credential, source_regions=source_regions)
self.check_inventory_source(inventory_source)
@ -1303,3 +1316,6 @@ class InventoryUpdatesTest(BaseTransactionTest):
inventory_source2 = self.update_inventory_source(self.group2,
source='rax', credential=credential, source_regions='')
self.check_inventory_source(inventory_source2)
# Verify that main group is in top level groups (hasn't been added as
# its own child).
self.assertTrue(self.group in self.inventory.root_groups)