mirror of https://github.com/ansible/ansible.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.7 KiB
Python
86 lines
2.7 KiB
Python
10 years ago
|
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
|
||
|
#
|
||
|
# This file is part of Ansible
|
||
|
#
|
||
|
# Ansible is free software: you can redistribute it and/or modify
|
||
|
# it under the terms of the GNU General Public License as published by
|
||
|
# the Free Software Foundation, either version 3 of the License, or
|
||
|
# (at your option) any later version.
|
||
|
#
|
||
|
# Ansible is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||
|
|
||
|
# Make coding more python3-ish
|
||
|
from __future__ import (absolute_import, division, print_function)
|
||
|
__metaclass__ = type
|
||
|
|
||
|
from ansible.compat.tests import unittest
|
||
|
from ansible.compat.tests.mock import patch, MagicMock
|
||
|
|
||
|
from ansible.errors import AnsibleError, AnsibleParserError
|
||
10 years ago
|
from ansible.executor.play_iterator import PlayIterator
|
||
10 years ago
|
from ansible.playbook import Playbook
|
||
|
|
||
|
from test.mock.loader import DictDataLoader
|
||
|
|
||
10 years ago
|
class TestPlayIterator(unittest.TestCase):
|
||
10 years ago
|
|
||
|
def setUp(self):
|
||
|
pass
|
||
|
|
||
|
def tearDown(self):
|
||
|
pass
|
||
|
|
||
10 years ago
|
def test_play_iterator(self):
|
||
10 years ago
|
fake_loader = DictDataLoader({
|
||
|
"test_play.yml": """
|
||
|
- hosts: all
|
||
10 years ago
|
gather_facts: false
|
||
10 years ago
|
roles:
|
||
|
- test_role
|
||
|
pre_tasks:
|
||
|
- debug: msg="this is a pre_task"
|
||
|
tasks:
|
||
|
- debug: msg="this is a regular task"
|
||
|
post_tasks:
|
||
|
- debug: msg="this is a post_task"
|
||
|
""",
|
||
|
'/etc/ansible/roles/test_role/tasks/main.yml': """
|
||
|
- debug: msg="this is a role task"
|
||
|
""",
|
||
|
})
|
||
|
|
||
|
p = Playbook.load('test_play.yml', loader=fake_loader)
|
||
|
|
||
|
hosts = []
|
||
|
for i in range(0, 10):
|
||
|
host = MagicMock()
|
||
|
host.get_name.return_value = 'host%02d' % i
|
||
|
hosts.append(host)
|
||
|
|
||
|
inventory = MagicMock()
|
||
|
inventory.get_hosts.return_value = hosts
|
||
10 years ago
|
inventory.filter_hosts.return_value = hosts
|
||
10 years ago
|
|
||
10 years ago
|
itr = PlayIterator(inventory, p._entries[0])
|
||
10 years ago
|
task = itr.get_next_task_for_host(hosts[0])
|
||
|
print(task)
|
||
|
self.assertIsNotNone(task)
|
||
|
task = itr.get_next_task_for_host(hosts[0])
|
||
|
print(task)
|
||
|
self.assertIsNotNone(task)
|
||
|
task = itr.get_next_task_for_host(hosts[0])
|
||
|
print(task)
|
||
|
self.assertIsNotNone(task)
|
||
|
task = itr.get_next_task_for_host(hosts[0])
|
||
|
print(task)
|
||
|
self.assertIsNotNone(task)
|
||
|
task = itr.get_next_task_for_host(hosts[0])
|
||
|
print(task)
|
||
|
self.assertIsNone(task)
|