From dfa33d0f23670f5a60360c5743ccc4cbca0ec3e9 Mon Sep 17 00:00:00 2001 From: James Cammarata Date: Wed, 30 Sep 2015 08:05:55 -0400 Subject: [PATCH] Tweak variable manager use in role includes to avoid test failures --- lib/ansible/playbook/role/definition.py | 11 +++++++++-- test/units/executor/test_play_iterator.py | 9 +++++---- test/units/playbook/test_play.py | 5 ++++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/ansible/playbook/role/definition.py b/lib/ansible/playbook/role/definition.py index 5941d1554d..3c2661a527 100644 --- a/lib/ansible/playbook/role/definition.py +++ b/lib/ansible/playbook/role/definition.py @@ -159,9 +159,16 @@ class RoleDefinition(Base, Become, Conditional, Taggable): if self._role_basedir: role_search_paths.append(self._role_basedir) - # now iterate through the possible paths and return the first one we find - all_vars = self._variable_manager.get_vars(loader=self._loader, play=self._play) + # create a templar class to template the dependency names, in + # case they contain variables + if self._variable_manager is not None: + all_vars = self._variable_manager.get_vars(loader=self._loader, play=self._play) + else: + all_vars = dict() + templar = Templar(loader=self._loader, variables=all_vars) + + # now iterate through the possible paths and return the first one we find for path in role_search_paths: path = templar.template(path) role_path = unfrackpath(os.path.join(path, role_name)) diff --git a/test/units/executor/test_play_iterator.py b/test/units/executor/test_play_iterator.py index 411b0ed291..b2310fe242 100644 --- a/test/units/executor/test_play_iterator.py +++ b/test/units/executor/test_play_iterator.py @@ -56,7 +56,11 @@ class TestPlayIterator(unittest.TestCase): """, }) - p = Playbook.load('test_play.yml', loader=fake_loader) + mock_var_manager = MagicMock() + mock_var_manager._fact_cache = dict() + mock_var_manager.get_vars.return_value = dict() + + p = Playbook.load('test_play.yml', loader=fake_loader, variable_manager=mock_var_manager) hosts = [] for i in range(0, 10): @@ -68,9 +72,6 @@ class TestPlayIterator(unittest.TestCase): inventory.get_hosts.return_value = hosts inventory.filter_hosts.return_value = hosts - mock_var_manager = MagicMock() - mock_var_manager._fact_cache = dict() - play_context = PlayContext(play=p._entries[0]) itr = PlayIterator( diff --git a/test/units/playbook/test_play.py b/test/units/playbook/test_play.py index f3fe1e0731..fc30d13872 100644 --- a/test/units/playbook/test_play.py +++ b/test/units/playbook/test_play.py @@ -110,12 +110,15 @@ class TestPlay(unittest.TestCase): """, }) + mock_var_manager = MagicMock() + mock_var_manager.get_vars.return_value = dict() + p = Play.load(dict( name="test play", hosts=['foo'], gather_facts=False, roles=['foo'], - ), loader=fake_loader) + ), loader=fake_loader, variable_manager=mock_var_manager) blocks = p.compile()