summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--test/units/vars/test_variable_manager.py147
1 files changed, 0 insertions, 147 deletions
diff --git a/test/units/vars/test_variable_manager.py b/test/units/vars/test_variable_manager.py
index d3cdf0de08..7ffd44b81f 100644
--- a/test/units/vars/test_variable_manager.py
+++ b/test/units/vars/test_variable_manager.py
@@ -21,7 +21,6 @@ import os
import unittest
from unittest.mock import MagicMock, patch
-from ansible.inventory.manager import InventoryManager
from ansible.playbook.play import Play
@@ -101,152 +100,6 @@ class TestVariableManager(unittest.TestCase):
v = VariableManager(inventory=mock_inventory, loader=fake_loader)
self.assertEqual(v.get_vars(play=mock_play, use_cache=False).get("foo"), "bar")
- def test_variable_manager_task_vars(self):
- # FIXME: BCS make this work
- return
-
- # pylint: disable=unreachable
- fake_loader = DictDataLoader({})
-
- mock_task = MagicMock()
- mock_task._role = None
- mock_task.loop = None
- mock_task.get_vars.return_value = dict(foo="bar")
- mock_task.get_include_params.return_value = dict()
-
- mock_all = MagicMock()
- mock_all.get_vars.return_value = {}
- mock_all.get_file_vars.return_value = {}
-
- mock_host = MagicMock()
- mock_host.get.name.return_value = 'test01'
- mock_host.get_vars.return_value = {}
- mock_host.get_host_vars.return_value = {}
-
- mock_inventory = MagicMock()
- mock_inventory.hosts.get.return_value = mock_host
- mock_inventory.hosts.get.name.return_value = 'test01'
- mock_inventory.get_host.return_value = mock_host
- mock_inventory.groups.__getitem__.return_value = mock_all
-
- v = VariableManager(loader=fake_loader, inventory=mock_inventory)
- self.assertEqual(v.get_vars(task=mock_task, use_cache=False).get("foo"), "bar")
-
- @patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
- def test_variable_manager_precedence(self):
- # FIXME: this needs to be redone as dataloader is not the automatic source of data anymore
- return
-
- # pylint: disable=unreachable
- # Tests complex variations and combinations of get_vars() with different
- # objects to modify the context under which variables are merged.
- # FIXME: BCS makethiswork
- # return True
-
- mock_inventory = MagicMock()
-
- inventory1_filedata = """
- [group2:children]
- group1
-
- [group1]
- host1 host_var=host_var_from_inventory_host1
-
- [group1:vars]
- group_var = group_var_from_inventory_group1
-
- [group2:vars]
- group_var = group_var_from_inventory_group2
- """
-
- fake_loader = DictDataLoader({
- # inventory1
- '/etc/ansible/inventory1': inventory1_filedata,
- # role defaults_only1
- '/etc/ansible/roles/defaults_only1/defaults/main.yml': """
- default_var: "default_var_from_defaults_only1"
- host_var: "host_var_from_defaults_only1"
- group_var: "group_var_from_defaults_only1"
- group_var_all: "group_var_all_from_defaults_only1"
- extra_var: "extra_var_from_defaults_only1"
- """,
- '/etc/ansible/roles/defaults_only1/tasks/main.yml': """
- - debug: msg="here i am"
- """,
-
- # role defaults_only2
- '/etc/ansible/roles/defaults_only2/defaults/main.yml': """
- default_var: "default_var_from_defaults_only2"
- host_var: "host_var_from_defaults_only2"
- group_var: "group_var_from_defaults_only2"
- group_var_all: "group_var_all_from_defaults_only2"
- extra_var: "extra_var_from_defaults_only2"
- """,
- })
-
- inv1 = InventoryManager(loader=fake_loader, sources=['/etc/ansible/inventory1'])
- v = VariableManager(inventory=mock_inventory, loader=fake_loader)
-
- play1 = Play.load(dict(
- hosts=['all'],
- roles=['defaults_only1', 'defaults_only2'],
- ), loader=fake_loader, variable_manager=v)
-
- # first we assert that the defaults as viewed as a whole are the merged results
- # of the defaults from each role, with the last role defined "winning" when
- # there is a variable naming conflict
- res = v.get_vars(play=play1)
- self.assertEqual(res['default_var'], 'default_var_from_defaults_only2')
-
- # next, we assert that when vars are viewed from the context of a task within a
- # role, that task will see its own role defaults before any other role's
- blocks = play1.compile()
- task = blocks[1].block[0]
- res = v.get_vars(play=play1, task=task)
- self.assertEqual(res['default_var'], 'default_var_from_defaults_only1')
-
- # next we assert the precedence of inventory variables
- v.set_inventory(inv1)
- h1 = inv1.get_host('host1')
-
- res = v.get_vars(play=play1, host=h1)
- self.assertEqual(res['group_var'], 'group_var_from_inventory_group1')
- self.assertEqual(res['host_var'], 'host_var_from_inventory_host1')
-
- # next we test with group_vars/ files loaded
- fake_loader.push("/etc/ansible/group_vars/all", """
- group_var_all: group_var_all_from_group_vars_all
- """)
- fake_loader.push("/etc/ansible/group_vars/group1", """
- group_var: group_var_from_group_vars_group1
- """)
- fake_loader.push("/etc/ansible/group_vars/group3", """
- # this is a dummy, which should not be used anywhere
- group_var: group_var_from_group_vars_group3
- """)
- fake_loader.push("/etc/ansible/host_vars/host1", """
- host_var: host_var_from_host_vars_host1
- """)
- fake_loader.push("group_vars/group1", """
- playbook_group_var: playbook_group_var
- """)
- fake_loader.push("host_vars/host1", """
- playbook_host_var: playbook_host_var
- """)
-
- res = v.get_vars(play=play1, host=h1)
- # self.assertEqual(res['group_var'], 'group_var_from_group_vars_group1')
- # self.assertEqual(res['group_var_all'], 'group_var_all_from_group_vars_all')
- # self.assertEqual(res['playbook_group_var'], 'playbook_group_var')
- # self.assertEqual(res['host_var'], 'host_var_from_host_vars_host1')
- # self.assertEqual(res['playbook_host_var'], 'playbook_host_var')
-
- # add in the fact cache
- v._fact_cache['host1'] = dict(fact_cache_var="fact_cache_var_from_fact_cache")
-
- res = v.get_vars(play=play1, host=h1)
- self.assertEqual(res['fact_cache_var'], 'fact_cache_var_from_fact_cache')
-
@patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
def test_variable_manager_role_vars_dependencies(self):
"""