|
|
@ -216,26 +216,40 @@ class TestTaskExecutor(unittest.TestCase):
|
|
|
|
mock_task.action = 'yum'
|
|
|
|
mock_task.action = 'yum'
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
self.assertEqual(new_items, ['a', 'b', 'c'])
|
|
|
|
self.assertEqual(new_items, ['a', 'b', 'c'])
|
|
|
|
|
|
|
|
self.assertIsInstance(mock_task.args, MagicMock)
|
|
|
|
|
|
|
|
|
|
|
|
mock_task.action = 'foo'
|
|
|
|
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)
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
self.assertEqual(new_items, ['a', 'b', 'c'])
|
|
|
|
self.assertEqual(new_items, ['a', 'b', 'c'])
|
|
|
|
|
|
|
|
self.assertEqual(mock_task.args, {'name': '{{item}}'})
|
|
|
|
|
|
|
|
|
|
|
|
mock_task.action = 'yum'
|
|
|
|
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)
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
self.assertEqual(new_items, ['a', 'b', 'c'])
|
|
|
|
self.assertEqual(new_items, ['a', 'b', 'c'])
|
|
|
|
|
|
|
|
self.assertEqual(mock_task.args, {'name': 'static'})
|
|
|
|
|
|
|
|
|
|
|
|
mock_task.action = 'yum'
|
|
|
|
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)
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
self.assertEqual(new_items, ['a', 'b', 'c'])
|
|
|
|
self.assertEqual(new_items, ['a', 'b', 'c'])
|
|
|
|
|
|
|
|
self.assertEqual(mock_task.args, {'name': '{{pkg_mgr}}'})
|
|
|
|
|
|
|
|
|
|
|
|
mock_task.action = '{{unknown}}'
|
|
|
|
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)
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
self.assertEqual(new_items, ['a', 'b', 'c'])
|
|
|
|
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' ]
|
|
|
|
|
|
|
|
mock_task.action = 'yum'
|
|
|
|
|
|
|
|
mock_task.args = {'name': '{{ packages }}', 'state': '{{ item }}'}
|
|
|
|
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
|
|
|
|
self.assertEqual(new_items, items)
|
|
|
|
|
|
|
|
self.assertEqual(mock_task.args, {'name': '{{ packages }}', 'state': '{{ item }}'})
|
|
|
|
|
|
|
|
|
|
|
|
# Maybe should raise an error in this case. The user would have to specify:
|
|
|
|
# Maybe should raise an error in this case. The user would have to specify:
|
|
|
|
# - yum: name="{{ packages[item] }}"
|
|
|
|
# - yum: name="{{ packages[item] }}"
|
|
|
@ -252,6 +266,7 @@ class TestTaskExecutor(unittest.TestCase):
|
|
|
|
mock_task.args = {'name': '{{ packages[item] }}'}
|
|
|
|
mock_task.args = {'name': '{{ packages[item] }}'}
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
self.assertEqual(new_items, items)
|
|
|
|
self.assertEqual(new_items, items)
|
|
|
|
|
|
|
|
self.assertEqual(mock_task.args, {'name': '{{ packages[item] }}'})
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# Replaces
|
|
|
|
# Replaces
|
|
|
@ -261,11 +276,13 @@ class TestTaskExecutor(unittest.TestCase):
|
|
|
|
mock_task.args={'name': '{{item}}'}
|
|
|
|
mock_task.args={'name': '{{item}}'}
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
self.assertEqual(new_items, [['a','c']])
|
|
|
|
self.assertEqual(new_items, [['a','c']])
|
|
|
|
|
|
|
|
self.assertEqual(mock_task.args, {'name': ['a','c']})
|
|
|
|
|
|
|
|
|
|
|
|
mock_task.action = '{{pkg_mgr}}'
|
|
|
|
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)
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
self.assertEqual(new_items, [['a', 'c']])
|
|
|
|
self.assertEqual(new_items, [['a', 'c']])
|
|
|
|
|
|
|
|
self.assertEqual(mock_task.args, {'name': ['a','c']})
|
|
|
|
|
|
|
|
|
|
|
|
# New loop_var
|
|
|
|
# New loop_var
|
|
|
|
mock_task.action = 'yum'
|
|
|
|
mock_task.action = 'yum'
|
|
|
@ -274,6 +291,7 @@ class TestTaskExecutor(unittest.TestCase):
|
|
|
|
loop_var = 'a_loop_var_item'
|
|
|
|
loop_var = 'a_loop_var_item'
|
|
|
|
new_items = te._squash_items(items=items, loop_var='a_loop_var_item', variables=job_vars)
|
|
|
|
new_items = te._squash_items(items=items, loop_var='a_loop_var_item', variables=job_vars)
|
|
|
|
self.assertEqual(new_items, [['a', 'c']])
|
|
|
|
self.assertEqual(new_items, [['a', 'c']])
|
|
|
|
|
|
|
|
self.assertEqual(mock_task.args, {'name': ['a','c']})
|
|
|
|
loop_var = 'item'
|
|
|
|
loop_var = 'item'
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
@ -289,7 +307,9 @@ class TestTaskExecutor(unittest.TestCase):
|
|
|
|
mock_task.args = {'name': '{{ item }}'}
|
|
|
|
mock_task.args = {'name': '{{ item }}'}
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
#self.assertEqual(new_items, [['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(new_items, items)
|
|
|
|
|
|
|
|
self.assertEqual(mock_task.args, {'name': '{{ item }}'})
|
|
|
|
|
|
|
|
|
|
|
|
# Retrieving from a dict
|
|
|
|
# Retrieving from a dict
|
|
|
|
items = ['a', 'b', 'foo']
|
|
|
|
items = ['a', 'b', 'foo']
|
|
|
@ -297,7 +317,9 @@ class TestTaskExecutor(unittest.TestCase):
|
|
|
|
mock_task.args = {'name': '{{ packages[item] }}'}
|
|
|
|
mock_task.args = {'name': '{{ packages[item] }}'}
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
#self.assertEqual(new_items, [['foo', 'baz']])
|
|
|
|
#self.assertEqual(new_items, [['foo', 'baz']])
|
|
|
|
|
|
|
|
#self.assertEqual(mock_task.args, {'name': ['foo', 'baz']})
|
|
|
|
self.assertEqual(new_items, items)
|
|
|
|
self.assertEqual(new_items, items)
|
|
|
|
|
|
|
|
self.assertEqual(mock_task.args, {'name': '{{ packages[item] }}'})
|
|
|
|
|
|
|
|
|
|
|
|
# Another way to retrieve from a dict
|
|
|
|
# Another way to retrieve from a dict
|
|
|
|
job_vars = dict(pkg_mgr='yum')
|
|
|
|
job_vars = dict(pkg_mgr='yum')
|
|
|
@ -306,7 +328,9 @@ class TestTaskExecutor(unittest.TestCase):
|
|
|
|
mock_task.args = {'name': '{{ item["package"] }}'}
|
|
|
|
mock_task.args = {'name': '{{ item["package"] }}'}
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
#self.assertEqual(new_items, [['foo', 'bar']])
|
|
|
|
#self.assertEqual(new_items, [['foo', 'bar']])
|
|
|
|
|
|
|
|
#self.assertEqual(mock_task.args, {'name': ['foo', 'bar']})
|
|
|
|
self.assertEqual(new_items, items)
|
|
|
|
self.assertEqual(new_items, items)
|
|
|
|
|
|
|
|
self.assertEqual(mock_task.args, {'name': '{{ item["package"] }}'})
|
|
|
|
|
|
|
|
|
|
|
|
items = [dict(name='a', state='present'),
|
|
|
|
items = [dict(name='a', state='present'),
|
|
|
|
dict(name='b', state='present'),
|
|
|
|
dict(name='b', state='present'),
|
|
|
@ -314,8 +338,10 @@ class TestTaskExecutor(unittest.TestCase):
|
|
|
|
mock_task.action = 'yum'
|
|
|
|
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)
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
self.assertEqual(new_items, items)
|
|
|
|
|
|
|
|
#self.assertEqual(new_items, [dict(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'),
|
|
|
|
items = [dict(name='a', state='present'),
|
|
|
|
dict(name='b', state='present'),
|
|
|
|
dict(name='b', state='present'),
|
|
|
@ -323,17 +349,11 @@ class TestTaskExecutor(unittest.TestCase):
|
|
|
|
mock_task.action = 'yum'
|
|
|
|
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)
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
self.assertEqual(new_items, items)
|
|
|
|
|
|
|
|
#self.assertEqual(new_items, [dict(name=['a', 'b'], state='present'),
|
|
|
|
#self.assertEqual(new_items, [dict(name=['a', 'b'], state='present'),
|
|
|
|
# dict(name='c', state='absent')])
|
|
|
|
# dict(name='c', state='absent')])
|
|
|
|
|
|
|
|
#self.assertEqual(mock_task.args, {'name': '{{item.name}}', 'state': '{{item.state}}'})
|
|
|
|
# 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' ]
|
|
|
|
|
|
|
|
mock_task.action = 'yum'
|
|
|
|
|
|
|
|
mock_task.args = {'name': '{{ packages }}', 'state': '{{ item }}'}
|
|
|
|
|
|
|
|
new_items = te._squash_items(items=items, loop_var='item', variables=job_vars)
|
|
|
|
|
|
|
|
self.assertEqual(new_items, items)
|
|
|
|
self.assertEqual(new_items, items)
|
|
|
|
|
|
|
|
self.assertEqual(mock_task.args, {'name': '{{item.name}}', 'state': '{{item.state}}'})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_task_executor_execute(self):
|
|
|
|
def test_task_executor_execute(self):
|
|
|
|