Debian Codegraph @

test/units/cli/test_playbook.py

raw
1 # (c) 2016, Adrian Likins <[email protected]>
2 #
3 # This file is part of Ansible
4 #
5 # Ansible is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Ansible is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
17
18 from __future__ import annotations
19
20 import unittest
21
22 import pytest
23
24 from units.mock.loader import DictDataLoader
25
26 from ansible import context
27 from ansible.inventory.manager import InventoryManager
28 from ansible.vars.manager import VariableManager
29
30 from ansible.cli.playbook import PlaybookCLI
31
32
33 class TestPlaybookCLI(unittest.TestCase):
34 def test_flush_cache(self):
35 cli = PlaybookCLI(args=["ansible-playbook", "--flush-cache", "foobar.yml"])
36 cli.parse()
37 self.assertTrue(context.CLIARGS['flush_cache'])
38
39 variable_manager = VariableManager()
40 fake_loader = DictDataLoader({'foobar.yml': ""})
41 inventory = InventoryManager(loader=fake_loader, sources='testhost,')
42
43 variable_manager.set_host_facts('testhost', {'canary': True})
44 variable_manager._fact_cache.get('testhost')
45
46 cli._flush_cache(inventory, variable_manager)
47
48 with pytest.raises(KeyError):
49 variable_manager._fact_cache.get('testhost')