mirror of
https://github.com/ansible/awx.git
synced 2026-01-14 19:30:39 -03:30
Merge pull request #2614 from stokkie90/devel
Fixed bug where all group variables are not included Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
commit
eec7d7199b
@ -294,6 +294,8 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin, RelatedJobsMixin):
|
||||
|
||||
# Remove any empty groups
|
||||
for group_name in list(data.keys()):
|
||||
if group_name == 'all':
|
||||
continue
|
||||
if not (data.get(group_name, {}).get('hosts', []) or data.get(group_name, {}).get('children', [])):
|
||||
data.pop(group_name)
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@ def test_empty_inventory(post, get, admin_user, organization, group_factory):
|
||||
inventory.save()
|
||||
resp = get(reverse('api:inventory_script_view', kwargs={'version': 'v2', 'pk': inventory.pk}), admin_user)
|
||||
jdata = json.loads(resp.content)
|
||||
jdata.pop('all')
|
||||
|
||||
assert inventory.hosts.count() == 0
|
||||
assert jdata == {}
|
||||
|
||||
@ -38,6 +38,19 @@ class TestInventoryScript:
|
||||
'remote_tower_id': host.id
|
||||
}
|
||||
|
||||
def test_all_group(self, inventory):
|
||||
inventory.groups.create(name='all', variables={'a1': 'a1'})
|
||||
# make sure we return a1 details in output
|
||||
data = inventory.get_script_data()
|
||||
assert 'all' in data
|
||||
assert data['all'] == {
|
||||
'hosts': [],
|
||||
'children': [],
|
||||
'vars': {
|
||||
'a1': 'a1'
|
||||
}
|
||||
}
|
||||
|
||||
def test_grandparent_group(self, inventory):
|
||||
g1 = inventory.groups.create(name='g1', variables={'v1': 'v1'})
|
||||
g2 = inventory.groups.create(name='g2', variables={'v2': 'v2'})
|
||||
@ -85,7 +98,9 @@ class TestInventoryScript:
|
||||
}
|
||||
if i < 2:
|
||||
expected_data['contains_two_hosts'] = {'hosts': ['host{}'.format(i)], 'children': [], 'vars': {}}
|
||||
assert inventory.get_script_data(slice_number=i + 1, slice_count=3) == expected_data
|
||||
data = inventory.get_script_data(slice_number=i + 1, slice_count=3)
|
||||
data.pop('all')
|
||||
assert data == expected_data
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user