mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-23 12:33:59 -07:00
test/: PEP8 compliancy (#24803)
* test/: PEP8 compliancy - Make PEP8 compliant * Python3 chokes on casting int to bytes (#24952) But if we tell the formatter that the var is a number, it works
This commit is contained in:
parent
31c59ad5f9
commit
4efec414e7
110 changed files with 1702 additions and 1547 deletions
|
@ -20,13 +20,13 @@ from __future__ import (absolute_import, division, print_function)
|
|||
__metaclass__ = type
|
||||
|
||||
import imp
|
||||
import pytest
|
||||
import zipfile
|
||||
|
||||
from collections import namedtuple
|
||||
from functools import partial
|
||||
from io import BytesIO, StringIO
|
||||
|
||||
import pytest
|
||||
|
||||
import ansible.errors
|
||||
|
||||
from ansible.executor.module_common import recursive_finder
|
||||
|
@ -42,12 +42,12 @@ def finder_containers():
|
|||
FinderContainers = namedtuple('FinderContainers', ['py_module_names', 'py_module_cache', 'zf'])
|
||||
|
||||
py_module_names = set()
|
||||
#py_module_cache = {('__init__',): b''}
|
||||
# py_module_cache = {('__init__',): b''}
|
||||
py_module_cache = {}
|
||||
|
||||
zipoutput = BytesIO()
|
||||
zf = zipfile.ZipFile(zipoutput, mode='w', compression=zipfile.ZIP_STORED)
|
||||
#zf.writestr('ansible/__init__.py', b'')
|
||||
# zf.writestr('ansible/__init__.py', b'')
|
||||
|
||||
return FinderContainers(py_module_names, py_module_cache, zf)
|
||||
|
||||
|
@ -79,7 +79,7 @@ class TestRecursiveFinder(object):
|
|||
else:
|
||||
module_utils_data = StringIO(u'# License\ndef do_something():\n pass\n')
|
||||
mocker.patch('imp.find_module', side_effect=partial(find_package_foo, module_utils_data))
|
||||
mocker.patch('ansible.executor.module_common._slurp', side_effect= lambda x: b'# License\ndef do_something():\n pass\n')
|
||||
mocker.patch('ansible.executor.module_common._slurp', side_effect=lambda x: b'# License\ndef do_something():\n pass\n')
|
||||
|
||||
name = 'ping'
|
||||
data = b'#!/usr/bin/python\nfrom ansible.module_utils import foo'
|
||||
|
|
|
@ -57,10 +57,9 @@ class TestPlayIterator(unittest.TestCase):
|
|||
|
||||
new_hs = hs.copy()
|
||||
|
||||
|
||||
@patch('ansible.playbook.role.definition.unfrackpath', mock_unfrackpath_noop)
|
||||
def test_play_iterator(self):
|
||||
#import epdb; epdb.st()
|
||||
# import epdb; epdb.st()
|
||||
fake_loader = DictDataLoader({
|
||||
"test_play.yml": """
|
||||
- hosts: all
|
||||
|
@ -191,11 +190,11 @@ class TestPlayIterator(unittest.TestCase):
|
|||
self.assertEqual(task.name, "role always task")
|
||||
self.assertIsNotNone(task._role)
|
||||
# role include task
|
||||
#(host_state, task) = itr.get_next_task_for_host(hosts[0])
|
||||
#self.assertIsNotNone(task)
|
||||
#self.assertEqual(task.action, 'debug')
|
||||
#self.assertEqual(task.name, "role included task")
|
||||
#self.assertIsNotNone(task._role)
|
||||
# (host_state, task) = itr.get_next_task_for_host(hosts[0])
|
||||
# self.assertIsNotNone(task)
|
||||
# self.assertEqual(task.action, 'debug')
|
||||
# self.assertEqual(task.name, "role included task")
|
||||
# self.assertIsNotNone(task._role)
|
||||
# role task after include
|
||||
(host_state, task) = itr.get_next_task_for_host(hosts[0])
|
||||
self.assertIsNotNone(task)
|
||||
|
@ -427,7 +426,7 @@ class TestPlayIterator(unittest.TestCase):
|
|||
)
|
||||
|
||||
# test the high-level add_tasks() method
|
||||
s = HostState(blocks=[0,1,2])
|
||||
s = HostState(blocks=[0, 1, 2])
|
||||
itr._insert_tasks_into_state = MagicMock(return_value=s)
|
||||
itr.add_tasks(hosts[0], [MagicMock(), MagicMock(), MagicMock()])
|
||||
self.assertEqual(itr._host_states[hosts[0].name], s)
|
||||
|
|
|
@ -21,13 +21,13 @@ __metaclass__ = type
|
|||
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.compat.tests.mock import MagicMock
|
||||
|
||||
from ansible.executor.playbook_executor import PlaybookExecutor
|
||||
from ansible.playbook import Playbook
|
||||
from ansible.template import Templar
|
||||
|
||||
from units.mock.loader import DictDataLoader
|
||||
|
||||
|
||||
class TestPlaybookExecutor(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -96,46 +96,55 @@ class TestPlaybookExecutor(unittest.TestCase):
|
|||
playbook = Playbook.load(pbe._playbooks[0], variable_manager=mock_var_manager, loader=fake_loader)
|
||||
play = playbook.get_plays()[0]
|
||||
play.post_validate(templar)
|
||||
mock_inventory.get_hosts.return_value = ['host0','host1','host2','host3','host4','host5','host6','host7','host8','host9']
|
||||
self.assertEqual(pbe._get_serialized_batches(play), [['host0','host1','host2','host3','host4','host5','host6','host7','host8','host9']])
|
||||
mock_inventory.get_hosts.return_value = ['host0', 'host1', 'host2', 'host3', 'host4', 'host5', 'host6', 'host7', 'host8', 'host9']
|
||||
self.assertEqual(pbe._get_serialized_batches(play), [['host0', 'host1', 'host2', 'host3', 'host4', 'host5', 'host6', 'host7', 'host8', 'host9']])
|
||||
|
||||
playbook = Playbook.load(pbe._playbooks[1], variable_manager=mock_var_manager, loader=fake_loader)
|
||||
play = playbook.get_plays()[0]
|
||||
play.post_validate(templar)
|
||||
mock_inventory.get_hosts.return_value = ['host0','host1','host2','host3','host4','host5','host6','host7','host8','host9']
|
||||
self.assertEqual(pbe._get_serialized_batches(play), [['host0','host1'],['host2','host3'],['host4','host5'],['host6','host7'],['host8','host9']])
|
||||
mock_inventory.get_hosts.return_value = ['host0', 'host1', 'host2', 'host3', 'host4', 'host5', 'host6', 'host7', 'host8', 'host9']
|
||||
self.assertEqual(
|
||||
pbe._get_serialized_batches(play),
|
||||
[['host0', 'host1'], ['host2', 'host3'], ['host4', 'host5'], ['host6', 'host7'], ['host8', 'host9']]
|
||||
)
|
||||
|
||||
playbook = Playbook.load(pbe._playbooks[2], variable_manager=mock_var_manager, loader=fake_loader)
|
||||
play = playbook.get_plays()[0]
|
||||
play.post_validate(templar)
|
||||
mock_inventory.get_hosts.return_value = ['host0','host1','host2','host3','host4','host5','host6','host7','host8','host9']
|
||||
self.assertEqual(pbe._get_serialized_batches(play), [['host0','host1'],['host2','host3'],['host4','host5'],['host6','host7'],['host8','host9']])
|
||||
mock_inventory.get_hosts.return_value = ['host0', 'host1', 'host2', 'host3', 'host4', 'host5', 'host6', 'host7', 'host8', 'host9']
|
||||
self.assertEqual(
|
||||
pbe._get_serialized_batches(play),
|
||||
[['host0', 'host1'], ['host2', 'host3'], ['host4', 'host5'], ['host6', 'host7'], ['host8', 'host9']]
|
||||
)
|
||||
|
||||
playbook = Playbook.load(pbe._playbooks[3], variable_manager=mock_var_manager, loader=fake_loader)
|
||||
play = playbook.get_plays()[0]
|
||||
play.post_validate(templar)
|
||||
mock_inventory.get_hosts.return_value = ['host0','host1','host2','host3','host4','host5','host6','host7','host8','host9']
|
||||
self.assertEqual(pbe._get_serialized_batches(play), [['host0'],['host1','host2'],['host3','host4','host5'],['host6','host7','host8'],['host9']])
|
||||
mock_inventory.get_hosts.return_value = ['host0', 'host1', 'host2', 'host3', 'host4', 'host5', 'host6', 'host7', 'host8', 'host9']
|
||||
self.assertEqual(
|
||||
pbe._get_serialized_batches(play),
|
||||
[['host0'], ['host1', 'host2'], ['host3', 'host4', 'host5'], ['host6', 'host7', 'host8'], ['host9']]
|
||||
)
|
||||
|
||||
playbook = Playbook.load(pbe._playbooks[4], variable_manager=mock_var_manager, loader=fake_loader)
|
||||
play = playbook.get_plays()[0]
|
||||
play.post_validate(templar)
|
||||
mock_inventory.get_hosts.return_value = ['host0','host1','host2','host3','host4','host5','host6','host7','host8','host9']
|
||||
self.assertEqual(pbe._get_serialized_batches(play), [['host0'],['host1','host2'],['host3','host4','host5','host6','host7','host8','host9']])
|
||||
mock_inventory.get_hosts.return_value = ['host0', 'host1', 'host2', 'host3', 'host4', 'host5', 'host6', 'host7', 'host8', 'host9']
|
||||
self.assertEqual(pbe._get_serialized_batches(play), [['host0'], ['host1', 'host2'], ['host3', 'host4', 'host5', 'host6', 'host7', 'host8', 'host9']])
|
||||
|
||||
# Test when serial percent is under 1.0
|
||||
playbook = Playbook.load(pbe._playbooks[2], variable_manager=mock_var_manager, loader=fake_loader)
|
||||
play = playbook.get_plays()[0]
|
||||
play.post_validate(templar)
|
||||
mock_inventory.get_hosts.return_value = ['host0','host1','host2']
|
||||
self.assertEqual(pbe._get_serialized_batches(play), [['host0'],['host1'],['host2']])
|
||||
mock_inventory.get_hosts.return_value = ['host0', 'host1', 'host2']
|
||||
self.assertEqual(pbe._get_serialized_batches(play), [['host0'], ['host1'], ['host2']])
|
||||
|
||||
# Test when there is a remainder for serial as a percent
|
||||
playbook = Playbook.load(pbe._playbooks[2], variable_manager=mock_var_manager, loader=fake_loader)
|
||||
play = playbook.get_plays()[0]
|
||||
play.post_validate(templar)
|
||||
mock_inventory.get_hosts.return_value = ['host0','host1','host2','host3','host4','host5','host6','host7','host8','host9','host10']
|
||||
mock_inventory.get_hosts.return_value = ['host0', 'host1', 'host2', 'host3', 'host4', 'host5', 'host6', 'host7', 'host8', 'host9', 'host10']
|
||||
self.assertEqual(
|
||||
pbe._get_serialized_batches(play),
|
||||
[['host0','host1'],['host2','host3'],['host4','host5'],['host6','host7'],['host8','host9'],['host10']]
|
||||
[['host0', 'host1'], ['host2', 'host3'], ['host4', 'host5'], ['host6', 'host7'], ['host8', 'host9'], ['host10']]
|
||||
)
|
||||
|
|
|
@ -21,7 +21,6 @@ __metaclass__ = type
|
|||
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.compat.tests.mock import patch, MagicMock
|
||||
|
||||
from ansible.errors import AnsibleError, AnsibleParserError
|
||||
from ansible.executor.task_executor import TaskExecutor
|
||||
from ansible.playbook.play_context import PlayContext
|
||||
|
@ -30,6 +29,7 @@ from ansible.parsing.yaml.objects import AnsibleUnicode
|
|||
|
||||
from units.mock.loader import DictDataLoader
|
||||
|
||||
|
||||
class TestTaskExecutor(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -48,14 +48,14 @@ class TestTaskExecutor(unittest.TestCase):
|
|||
job_vars = dict()
|
||||
mock_queue = MagicMock()
|
||||
te = TaskExecutor(
|
||||
host = mock_host,
|
||||
task = mock_task,
|
||||
job_vars = job_vars,
|
||||
play_context = mock_play_context,
|
||||
new_stdin = new_stdin,
|
||||
loader = fake_loader,
|
||||
shared_loader_obj = mock_shared_loader,
|
||||
rslt_q = mock_queue,
|
||||
host=mock_host,
|
||||
task=mock_task,
|
||||
job_vars=job_vars,
|
||||
play_context=mock_play_context,
|
||||
new_stdin=new_stdin,
|
||||
loader=fake_loader,
|
||||
shared_loader_obj=mock_shared_loader,
|
||||
rslt_q=mock_queue,
|
||||
)
|
||||
|
||||
def test_task_executor_run(self):
|
||||
|
@ -75,14 +75,14 @@ class TestTaskExecutor(unittest.TestCase):
|
|||
job_vars = dict()
|
||||
|
||||
te = TaskExecutor(
|
||||
host = mock_host,
|
||||
task = mock_task,
|
||||
job_vars = job_vars,
|
||||
play_context = mock_play_context,
|
||||
new_stdin = new_stdin,
|
||||
loader = fake_loader,
|
||||
shared_loader_obj = mock_shared_loader,
|
||||
rslt_q = mock_queue,
|
||||
host=mock_host,
|
||||
task=mock_task,
|
||||
job_vars=job_vars,
|
||||
play_context=mock_play_context,
|
||||
new_stdin=new_stdin,
|
||||
loader=fake_loader,
|
||||
shared_loader_obj=mock_shared_loader,
|
||||
rslt_q=mock_queue,
|
||||
)
|
||||
|
||||
te._get_loop_items = MagicMock(return_value=None)
|
||||
|
@ -92,7 +92,7 @@ class TestTaskExecutor(unittest.TestCase):
|
|||
te._get_loop_items = MagicMock(return_value=[])
|
||||
res = te.run()
|
||||
|
||||
te._get_loop_items = MagicMock(return_value=['a','b','c'])
|
||||
te._get_loop_items = MagicMock(return_value=['a', 'b', 'c'])
|
||||
te._run_loop = MagicMock(return_value=[dict(item='a', changed=True), dict(item='b', failed=True), dict(item='c')])
|
||||
res = te.run()
|
||||
|
||||
|
@ -119,14 +119,14 @@ class TestTaskExecutor(unittest.TestCase):
|
|||
mock_queue = MagicMock()
|
||||
|
||||
te = TaskExecutor(
|
||||
host = mock_host,
|
||||
task = mock_task,
|
||||
job_vars = job_vars,
|
||||
play_context = mock_play_context,
|
||||
new_stdin = new_stdin,
|
||||
loader = fake_loader,
|
||||
shared_loader_obj = mock_shared_loader,
|
||||
rslt_q = mock_queue,
|
||||
host=mock_host,
|
||||
task=mock_task,
|
||||
job_vars=job_vars,
|
||||
play_context=mock_play_context,
|
||||
new_stdin=new_stdin,
|
||||
loader=fake_loader,
|
||||
shared_loader_obj=mock_shared_loader,
|
||||
rslt_q=mock_queue,
|
||||
)
|
||||
|
||||
items = te._get_loop_items()
|
||||
|
@ -155,14 +155,14 @@ class TestTaskExecutor(unittest.TestCase):
|
|||
job_vars = dict()
|
||||
|
||||
te = TaskExecutor(
|
||||
host = mock_host,
|
||||
task = mock_task,
|
||||
job_vars = job_vars,
|
||||
play_context = mock_play_context,
|
||||
new_stdin = new_stdin,
|
||||
loader = fake_loader,
|
||||
shared_loader_obj = mock_shared_loader,
|
||||
rslt_q = mock_queue,
|
||||
host=mock_host,
|
||||
task=mock_task,
|
||||
job_vars=job_vars,
|
||||
play_context=mock_play_context,
|
||||
new_stdin=new_stdin,
|
||||
loader=fake_loader,
|
||||
shared_loader_obj=mock_shared_loader,
|
||||
rslt_q=mock_queue,
|
||||
)
|
||||
|
||||
def _execute(variables):
|
||||
|
@ -201,51 +201,49 @@ class TestTaskExecutor(unittest.TestCase):
|
|||
job_vars = dict(pkg_mgr='yum')
|
||||
|
||||
te = TaskExecutor(
|
||||
host = mock_host,
|
||||
task = mock_task,
|
||||
job_vars = job_vars,
|
||||
play_context = mock_play_context,
|
||||
new_stdin = new_stdin,
|
||||
loader = fake_loader,
|
||||
shared_loader_obj = mock_shared_loader,
|
||||
rslt_q = mock_queue,
|
||||
host=mock_host,
|
||||
task=mock_task,
|
||||
job_vars=job_vars,
|
||||
play_context=mock_play_context,
|
||||
new_stdin=new_stdin,
|
||||
loader=fake_loader,
|
||||
shared_loader_obj=mock_shared_loader,
|
||||
rslt_q=mock_queue,
|
||||
)
|
||||
|
||||
#
|
||||
# No replacement
|
||||
#
|
||||
mock_task.action = 'yum'
|
||||
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
||||
self.assertEqual(new_items, ['a', 'b', 'c'])
|
||||
self.assertIsInstance(mock_task.args, MagicMock)
|
||||
|
||||
mock_task.action = 'foo'
|
||||
mock_task.args={'name': '{{item}}'}
|
||||
mock_task.args = {'name': '{{item}}'}
|
||||
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
||||
self.assertEqual(new_items, ['a', 'b', 'c'])
|
||||
self.assertEqual(mock_task.args, {'name': '{{item}}'})
|
||||
|
||||
mock_task.action = 'yum'
|
||||
mock_task.args={'name': 'static'}
|
||||
mock_task.args = {'name': 'static'}
|
||||
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
||||
self.assertEqual(new_items, ['a', 'b', 'c'])
|
||||
self.assertEqual(mock_task.args, {'name': 'static'})
|
||||
|
||||
mock_task.action = 'yum'
|
||||
mock_task.args={'name': '{{pkg_mgr}}'}
|
||||
mock_task.args = {'name': '{{pkg_mgr}}'}
|
||||
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
||||
self.assertEqual(new_items, ['a', 'b', 'c'])
|
||||
self.assertEqual(mock_task.args, {'name': '{{pkg_mgr}}'})
|
||||
|
||||
mock_task.action = '{{unknown}}'
|
||||
mock_task.args={'name': '{{item}}'}
|
||||
mock_task.args = {'name': '{{item}}'}
|
||||
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
||||
self.assertEqual(new_items, ['a', 'b', 'c'])
|
||||
self.assertEqual(mock_task.args, {'name': '{{item}}'})
|
||||
|
||||
# Could do something like this to recover from bad deps in a package
|
||||
job_vars = dict(pkg_mgr='yum', packages=['a', 'b'])
|
||||
items = [ 'absent', 'latest' ]
|
||||
items = ['absent', 'latest']
|
||||
mock_task.action = 'yum'
|
||||
mock_task.args = {'name': '{{ packages }}', 'state': '{{ item }}'}
|
||||
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
||||
|
@ -261,7 +259,7 @@ class TestTaskExecutor(unittest.TestCase):
|
|||
# an error later. If so, we can throw it now instead.
|
||||
# Squashing in this case would not be intuitive as the user is being
|
||||
# explicit in using each list entry as a key.
|
||||
job_vars = dict(pkg_mgr='yum', packages={ "a": "foo", "b": "bar", "foo": "baz", "bar": "quux" })
|
||||
job_vars = dict(pkg_mgr='yum', packages={"a": "foo", "b": "bar", "foo": "baz", "bar": "quux"})
|
||||
items = [['a', 'b'], ['foo', 'bar']]
|
||||
mock_task.action = 'yum'
|
||||
mock_task.args = {'name': '{{ packages[item] }}'}
|
||||
|
@ -269,21 +267,19 @@ class TestTaskExecutor(unittest.TestCase):
|
|||
self.assertEqual(new_items, items)
|
||||
self.assertEqual(mock_task.args, {'name': '{{ packages[item] }}'})
|
||||
|
||||
#
|
||||
# Replaces
|
||||
#
|
||||
items = ['a', 'b', 'c']
|
||||
mock_task.action = 'yum'
|
||||
mock_task.args={'name': '{{item}}'}
|
||||
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
||||
self.assertEqual(new_items, [['a','c']])
|
||||
self.assertEqual(mock_task.args, {'name': ['a','c']})
|
||||
|
||||
mock_task.action = '{{pkg_mgr}}'
|
||||
mock_task.args={'name': '{{item}}'}
|
||||
mock_task.args = {'name': '{{item}}'}
|
||||
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
||||
self.assertEqual(new_items, [['a', 'c']])
|
||||
self.assertEqual(mock_task.args, {'name': ['a','c']})
|
||||
self.assertEqual(mock_task.args, {'name': ['a', 'c']})
|
||||
|
||||
mock_task.action = '{{pkg_mgr}}'
|
||||
mock_task.args = {'name': '{{item}}'}
|
||||
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
||||
self.assertEqual(new_items, [['a', 'c']])
|
||||
self.assertEqual(mock_task.args, {'name': ['a', 'c']})
|
||||
|
||||
# New loop_var
|
||||
mock_task.action = 'yum'
|
||||
|
@ -292,7 +288,7 @@ class TestTaskExecutor(unittest.TestCase):
|
|||
loop_var = 'a_loop_var_item'
|
||||
new_items = te._squash_items(items=items, loop_var='a_loop_var_item', variables=job_vars)
|
||||
self.assertEqual(new_items, [['a', 'c']])
|
||||
self.assertEqual(mock_task.args, {'name': ['a','c']})
|
||||
self.assertEqual(mock_task.args, {'name': ['a', 'c']})
|
||||
loop_var = 'item'
|
||||
|
||||
#
|
||||
|
@ -307,8 +303,8 @@ class TestTaskExecutor(unittest.TestCase):
|
|||
mock_task.action = 'yum'
|
||||
mock_task.args = {'name': '{{ item }}'}
|
||||
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
||||
#self.assertEqual(new_items, [['a', 'b', 'foo', 'bar']])
|
||||
#self.assertEqual(mock_task.args, {'name': ['a', 'b', 'foo', 'bar']})
|
||||
# self.assertEqual(new_items, [['a', 'b', 'foo', 'bar']])
|
||||
# self.assertEqual(mock_task.args, {'name': ['a', 'b', 'foo', 'bar']})
|
||||
self.assertEqual(new_items, items)
|
||||
self.assertEqual(mock_task.args, {'name': '{{ item }}'})
|
||||
|
||||
|
@ -317,8 +313,8 @@ class TestTaskExecutor(unittest.TestCase):
|
|||
mock_task.action = 'yum'
|
||||
mock_task.args = {'name': '{{ packages[item] }}'}
|
||||
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
||||
#self.assertEqual(new_items, [['foo', 'baz']])
|
||||
#self.assertEqual(mock_task.args, {'name': ['foo', 'baz']})
|
||||
# self.assertEqual(new_items, [['foo', 'baz']])
|
||||
# self.assertEqual(mock_task.args, {'name': ['foo', 'baz']})
|
||||
self.assertEqual(new_items, items)
|
||||
self.assertEqual(mock_task.args, {'name': '{{ packages[item] }}'})
|
||||
|
||||
|
@ -328,35 +324,38 @@ class TestTaskExecutor(unittest.TestCase):
|
|||
mock_task.action = 'yum'
|
||||
mock_task.args = {'name': '{{ item["package"] }}'}
|
||||
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
||||
#self.assertEqual(new_items, [['foo', 'bar']])
|
||||
#self.assertEqual(mock_task.args, {'name': ['foo', 'bar']})
|
||||
# self.assertEqual(new_items, [['foo', 'bar']])
|
||||
# self.assertEqual(mock_task.args, {'name': ['foo', 'bar']})
|
||||
self.assertEqual(new_items, items)
|
||||
self.assertEqual(mock_task.args, {'name': '{{ item["package"] }}'})
|
||||
|
||||
items = [dict(name='a', state='present'),
|
||||
dict(name='b', state='present'),
|
||||
dict(name='c', state='present')]
|
||||
items = [
|
||||
dict(name='a', state='present'),
|
||||
dict(name='b', state='present'),
|
||||
dict(name='c', state='present'),
|
||||
]
|
||||
mock_task.action = 'yum'
|
||||
mock_task.args={'name': '{{item.name}}', 'state': '{{item.state}}'}
|
||||
mock_task.args = {'name': '{{item.name}}', 'state': '{{item.state}}'}
|
||||
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
||||
#self.assertEqual(new_items, [dict(name=['a', 'b', 'c'], state='present')])
|
||||
#self.assertEqual(mock_task.args, {'name': ['a', 'b', 'c'], 'state': 'present'})
|
||||
# self.assertEqual(new_items, [dict(name=['a', 'b', 'c'], state='present')])
|
||||
# self.assertEqual(mock_task.args, {'name': ['a', 'b', 'c'], 'state': 'present'})
|
||||
self.assertEqual(new_items, items)
|
||||
self.assertEqual(mock_task.args, {'name': '{{item.name}}', 'state': '{{item.state}}'})
|
||||
|
||||
items = [dict(name='a', state='present'),
|
||||
dict(name='b', state='present'),
|
||||
dict(name='c', state='absent')]
|
||||
items = [
|
||||
dict(name='a', state='present'),
|
||||
dict(name='b', state='present'),
|
||||
dict(name='c', state='absent'),
|
||||
]
|
||||
mock_task.action = 'yum'
|
||||
mock_task.args={'name': '{{item.name}}', 'state': '{{item.state}}'}
|
||||
mock_task.args = {'name': '{{item.name}}', 'state': '{{item.state}}'}
|
||||
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
||||
#self.assertEqual(new_items, [dict(name=['a', 'b'], state='present'),
|
||||
# dict(name='c', state='absent')])
|
||||
#self.assertEqual(mock_task.args, {'name': '{{item.name}}', 'state': '{{item.state}}'})
|
||||
# self.assertEqual(new_items, [dict(name=['a', 'b'], state='present'),
|
||||
# dict(name='c', state='absent')])
|
||||
# self.assertEqual(mock_task.args, {'name': '{{item.name}}', 'state': '{{item.state}}'})
|
||||
self.assertEqual(new_items, items)
|
||||
self.assertEqual(mock_task.args, {'name': '{{item.name}}', 'state': '{{item.state}}'})
|
||||
|
||||
|
||||
def test_task_executor_execute(self):
|
||||
fake_loader = DictDataLoader({})
|
||||
|
||||
|
@ -394,14 +393,14 @@ class TestTaskExecutor(unittest.TestCase):
|
|||
job_vars = dict(omit="XXXXXXXXXXXXXXXXXXX")
|
||||
|
||||
te = TaskExecutor(
|
||||
host = mock_host,
|
||||
task = mock_task,
|
||||
job_vars = job_vars,
|
||||
play_context = mock_play_context,
|
||||
new_stdin = new_stdin,
|
||||
loader = fake_loader,
|
||||
shared_loader_obj = shared_loader,
|
||||
rslt_q = mock_queue,
|
||||
host=mock_host,
|
||||
task=mock_task,
|
||||
job_vars=job_vars,
|
||||
play_context=mock_play_context,
|
||||
new_stdin=new_stdin,
|
||||
loader=fake_loader,
|
||||
shared_loader_obj=shared_loader,
|
||||
rslt_q=mock_queue,
|
||||
)
|
||||
|
||||
te._get_connection = MagicMock(return_value=mock_connection)
|
||||
|
@ -433,7 +432,7 @@ class TestTaskExecutor(unittest.TestCase):
|
|||
|
||||
mock_task = MagicMock()
|
||||
mock_task.async = 0.1
|
||||
mock_task.poll = 0.05
|
||||
mock_task.poll = 0.05
|
||||
|
||||
mock_play_context = MagicMock()
|
||||
|
||||
|
@ -449,14 +448,14 @@ class TestTaskExecutor(unittest.TestCase):
|
|||
job_vars = dict(omit="XXXXXXXXXXXXXXXXXXX")
|
||||
|
||||
te = TaskExecutor(
|
||||
host = mock_host,
|
||||
task = mock_task,
|
||||
job_vars = job_vars,
|
||||
play_context = mock_play_context,
|
||||
new_stdin = new_stdin,
|
||||
loader = fake_loader,
|
||||
shared_loader_obj = shared_loader,
|
||||
rslt_q = mock_queue,
|
||||
host=mock_host,
|
||||
task=mock_task,
|
||||
job_vars=job_vars,
|
||||
play_context=mock_play_context,
|
||||
new_stdin=new_stdin,
|
||||
loader=fake_loader,
|
||||
shared_loader_obj=shared_loader,
|
||||
rslt_q=mock_queue,
|
||||
)
|
||||
|
||||
te._connection = MagicMock()
|
||||
|
@ -485,4 +484,3 @@ class TestTaskExecutor(unittest.TestCase):
|
|||
mock_templar = MagicMock()
|
||||
res = te._poll_async_result(result=dict(ansible_job_id=1), templar=mock_templar)
|
||||
self.assertEqual(res, dict(finished=1))
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ from ansible.compat.tests.mock import patch, MagicMock
|
|||
|
||||
from ansible.executor.task_result import TaskResult
|
||||
|
||||
|
||||
class TestTaskResult(unittest.TestCase):
|
||||
def test_task_result_basic(self):
|
||||
mock_host = MagicMock()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue