add back in support of towervars lost in merge

This commit is contained in:
AlanCoding 2017-12-13 14:28:04 -05:00
parent bd91e8eb54
commit 1b0bca8229
No known key found for this signature in database
GPG Key ID: FD2C3C012A72926B
3 changed files with 29 additions and 2 deletions

View File

@ -2443,7 +2443,8 @@ class InventoryScriptView(RetrieveAPIView):
host = get_object_or_404(obj.hosts, **hosts_q)
return Response(host.variables_dict)
return Response(obj.get_script_data(
hostvars=bool(request.query_params.get('hostvars', '')),
hostvars=hostvars,
towervars=towervars,
show_all=show_all
))

View File

@ -209,7 +209,7 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin):
group_children.add(from_group_id)
return group_children_map
def get_script_data(self, hostvars=False, show_all=False):
def get_script_data(self, hostvars=False, towervars=False, show_all=False):
if show_all:
hosts_q = dict()
else:
@ -271,6 +271,10 @@ class Inventory(CommonModelNameNotUnique, ResourceMixin):
data['_meta'].setdefault('hostvars', dict())
for host in self.hosts.filter(**hosts_q):
data['_meta']['hostvars'][host.name] = host.variables_dict
if towervars:
tower_dict = dict(remote_tower_enabled=str(host.enabled).lower(),
remote_tower_id=host.id)
data['_meta']['hostvars'][host.name].update(tower_dict)
return data

View File

@ -13,6 +13,28 @@ from awx.main.models import (
from awx.main.utils.filters import SmartFilter
@pytest.mark.django_db
class TestInventoryScript:
def test_hostvars(self, inventory):
inventory.hosts.create(name='ahost', variables={"foo": "bar"})
assert inventory.get_script_data(
hostvars=True
)['_meta']['hostvars']['ahost'] == {
'foo': 'bar'
}
def test_towervars(self, inventory):
host = inventory.hosts.create(name='ahost')
assert inventory.get_script_data(
hostvars=True,
towervars=True
)['_meta']['hostvars']['ahost'] == {
'remote_tower_enabled': 'true',
'remote_tower_id': host.id
}
@pytest.mark.django_db
class TestSCMUpdateFeatures: