diff options
Diffstat (limited to 'test/units/playbook')
-rw-r--r-- | test/units/playbook/role/test_role.py | 1 | ||||
-rw-r--r-- | test/units/playbook/test_attribute.py | 1 | ||||
-rw-r--r-- | test/units/playbook/test_base.py | 5 | ||||
-rw-r--r-- | test/units/playbook/test_block.py | 34 | ||||
-rw-r--r-- | test/units/playbook/test_conditional.py | 6 | ||||
-rw-r--r-- | test/units/playbook/test_helpers.py | 4 | ||||
-rw-r--r-- | test/units/playbook/test_play_context.py | 268 | ||||
-rw-r--r-- | test/units/playbook/test_playbook.py | 4 | ||||
-rw-r--r-- | test/units/playbook/test_taggable.py | 1 | ||||
-rw-r--r-- | test/units/playbook/test_task.py | 12 |
10 files changed, 181 insertions, 155 deletions
diff --git a/test/units/playbook/role/test_role.py b/test/units/playbook/role/test_role.py index 1e93ec535f..5cce8f7aa1 100644 --- a/test/units/playbook/role/test_role.py +++ b/test/units/playbook/role/test_role.py @@ -274,4 +274,3 @@ class TestRole(unittest.TestCase): r = Role.load(i, play=mock_play) self.assertEqual(r.get_name(), "foo_complex") - diff --git a/test/units/playbook/test_attribute.py b/test/units/playbook/test_attribute.py index 10217a7ce9..216966c15c 100644 --- a/test/units/playbook/test_attribute.py +++ b/test/units/playbook/test_attribute.py @@ -52,4 +52,3 @@ class TestAttribute(unittest.TestCase): self.assertTrue(self.one >= self.one) self.assertFalse(self.one >= self.two) self.assertTrue(self.two >= self.one) - diff --git a/test/units/playbook/test_base.py b/test/units/playbook/test_base.py index 78d5e34e25..76b2114aab 100644 --- a/test/units/playbook/test_base.py +++ b/test/units/playbook/test_base.py @@ -114,7 +114,7 @@ class TestBase(unittest.TestCase): data = {'no_log': False, 'remote_user': None, 'vars': self.assorted_vars, - #'check_mode': False, + # 'check_mode': False, 'always_run': False, 'environment': [], 'run_once': False, @@ -340,8 +340,7 @@ class BaseSubClass(base.Base): _test_attr_unknown_isa = FieldAttribute(isa='not_a_real_isa', always_post_validate=True) _test_attr_example = FieldAttribute(isa='string', default='the_default', always_post_validate=True) - _test_attr_none = FieldAttribute(isa='string', - always_post_validate=True) + _test_attr_none = FieldAttribute(isa='string', always_post_validate=True) _test_attr_preprocess = FieldAttribute(isa='string', default='the default for preprocess') _test_attr_method = FieldAttribute(isa='string', default='some attr with a getter', always_post_validate=True) diff --git a/test/units/playbook/test_block.py b/test/units/playbook/test_block.py index 2fec92ef04..4d191a287a 100644 --- a/test/units/playbook/test_block.py +++ b/test/units/playbook/test_block.py @@ -19,9 +19,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +from ansible.compat.tests import unittest from ansible.playbook.block import Block from ansible.playbook.task import Task -from ansible.compat.tests import unittest + class TestBlock(unittest.TestCase): @@ -39,24 +40,24 @@ class TestBlock(unittest.TestCase): def test_load_block_simple(self): ds = dict( - block = [], - rescue = [], - always = [], - #otherwise = [], + block=[], + rescue=[], + always=[], + # otherwise=[], ) b = Block.load(ds) self.assertEqual(b.block, []) self.assertEqual(b.rescue, []) self.assertEqual(b.always, []) # not currently used - #self.assertEqual(b.otherwise, []) + # self.assertEqual(b.otherwise, []) def test_load_block_with_tasks(self): ds = dict( - block = [dict(action='block')], - rescue = [dict(action='rescue')], - always = [dict(action='always')], - #otherwise = [dict(action='otherwise')], + block=[dict(action='block')], + rescue=[dict(action='rescue')], + always=[dict(action='always')], + # otherwise=[dict(action='otherwise')], ) b = Block.load(ds) self.assertEqual(len(b.block), 1) @@ -66,8 +67,8 @@ class TestBlock(unittest.TestCase): self.assertEqual(len(b.always), 1) self.assertIsInstance(b.always[0], Task) # not currently used - #self.assertEqual(len(b.otherwise), 1) - #self.assertIsInstance(b.otherwise[0], Task) + # self.assertEqual(len(b.otherwise), 1) + # self.assertIsInstance(b.otherwise[0], Task) def test_load_implicit_block(self): ds = [dict(action='foo')] @@ -77,12 +78,11 @@ class TestBlock(unittest.TestCase): def test_deserialize(self): ds = dict( - block = [dict(action='block')], - rescue = [dict(action='rescue')], - always = [dict(action='always')], + block=[dict(action='block')], + rescue=[dict(action='rescue')], + always=[dict(action='always')], ) b = Block.load(ds) - data = dict(parent = ds, parent_type = 'Block') + data = dict(parent=ds, parent_type='Block') b.deserialize(data) self.assertIsInstance(b._parent, Block) - diff --git a/test/units/playbook/test_conditional.py b/test/units/playbook/test_conditional.py index a375a19e5c..5184186104 100644 --- a/test/units/playbook/test_conditional.py +++ b/test/units/playbook/test_conditional.py @@ -97,11 +97,11 @@ class TestConditional(unittest.TestCase): } when = [u"some_dict.some_dict_key1 == hostvars['host3']"] - #self._eval_con(when, variables) + # self._eval_con(when, variables) self.assertRaisesRegexp(errors.AnsibleError, "The conditional check 'some_dict.some_dict_key1 == hostvars\['host3'\]' failed", - #"The conditional check 'some_dict.some_dict_key1 == hostvars['host3']' failed", - #"The conditional check 'some_dict.some_dict_key1 == hostvars['host3']' failed.", + # "The conditional check 'some_dict.some_dict_key1 == hostvars['host3']' failed", + # "The conditional check 'some_dict.some_dict_key1 == hostvars['host3']' failed.", self._eval_con, when, variables) diff --git a/test/units/playbook/test_helpers.py b/test/units/playbook/test_helpers.py index 25261cd86a..65e0f8291d 100644 --- a/test/units/playbook/test_helpers.py +++ b/test/units/playbook/test_helpers.py @@ -222,7 +222,7 @@ class TestLoadListOfTasks(unittest.TestCase, MixinForMocks): # TODO/FIXME: do this non deprecated way def test_one_parent_include_tags(self): ds = [{'include': '/dev/null/includes/test_include.yml', - #'vars': {'tags': ['test_one_parent_include_tags_tag1', 'and_another_tag2']} + # 'vars': {'tags': ['test_one_parent_include_tags_tag1', 'and_another_tag2']} 'tags': ['test_one_parent_include_tags_tag1', 'and_another_tag2'] } ] @@ -281,7 +281,7 @@ class TestLoadListOfTasks(unittest.TestCase, MixinForMocks): 'include': '/dev/null/includes/static_test_include.yml', 'static': False }] - #a_block = Block() + # a_block = Block() ti_ds = {'include': '/dev/null/includes/ssdftatic_test_include.yml'} a_task_include = TaskInclude() ti = a_task_include.load(ti_ds) diff --git a/test/units/playbook/test_play_context.py b/test/units/playbook/test_play_context.py index 7889a8347d..56cab943e1 100644 --- a/test/units/playbook/test_play_context.py +++ b/test/units/playbook/test_play_context.py @@ -21,30 +21,30 @@ __metaclass__ = type import os -from ansible.compat.tests import unittest -from ansible.compat.tests.mock import patch, MagicMock - from ansible import constants as C from ansible.cli import CLI +from ansible.compat.tests import unittest +from ansible.compat.tests.mock import patch, MagicMock from ansible.errors import AnsibleError, AnsibleParserError from ansible.module_utils.six.moves import shlex_quote from ansible.playbook.play_context import PlayContext from units.mock.loader import DictDataLoader + class TestPlayContext(unittest.TestCase): def setUp(self): self._parser = CLI.base_parser( - runas_opts = True, - meta_opts = True, - runtask_opts = True, - vault_opts = True, - async_opts = True, - connect_opts = True, - subset_opts = True, - check_opts = True, - inventory_opts = True, + runas_opts=True, + meta_opts=True, + runtask_opts=True, + vault_opts=True, + async_opts=True, + connect_opts=True, + subset_opts=True, + check_opts=True, + inventory_opts=True, ) def tearDown(self): @@ -66,13 +66,13 @@ class TestPlayContext(unittest.TestCase): self.assertEqual(play_context.no_log, None) mock_play = MagicMock() - mock_play.connection = 'mock' - mock_play.remote_user = 'mock' - mock_play.port = 1234 - mock_play.become = True + mock_play.connection = 'mock' + mock_play.remote_user = 'mock' + mock_play.port = 1234 + mock_play.become = True mock_play.become_method = 'mock' - mock_play.become_user = 'mockroot' - mock_play.no_log = True + mock_play.become_user = 'mockroot' + mock_play.no_log = True play_context = PlayContext(play=mock_play, options=options) self.assertEqual(play_context.connection, 'mock') @@ -84,19 +84,19 @@ class TestPlayContext(unittest.TestCase): self.assertEqual(play_context.become_user, "mockroot") mock_task = MagicMock() - mock_task.connection = 'mocktask' - mock_task.remote_user = 'mocktask' - mock_task.no_log = mock_play.no_log - mock_task.become = True + mock_task.connection = 'mocktask' + mock_task.remote_user = 'mocktask' + mock_task.no_log = mock_play.no_log + mock_task.become = True mock_task.become_method = 'mocktask' - mock_task.become_user = 'mocktaskroot' - mock_task.become_pass = 'mocktaskpass' + mock_task.become_user = 'mocktaskroot' + mock_task.become_pass = 'mocktaskpass' mock_task._local_action = False - mock_task.delegate_to = None + mock_task.delegate_to = None all_vars = dict( - ansible_connection = 'mock_inventory', - ansible_ssh_port = 4321, + ansible_connection='mock_inventory', + ansible_ssh_port=4321, ) mock_templar = MagicMock() @@ -112,7 +112,7 @@ class TestPlayContext(unittest.TestCase): self.assertEqual(play_context.become_user, "mocktaskroot") self.assertEqual(play_context.become_pass, "mocktaskpass") - mock_task.no_log = False + mock_task.no_log = False play_context = play_context.set_task_and_variable_override(task=mock_task, variables=all_vars, templar=mock_templar) self.assertEqual(play_context.no_log, False) @@ -122,19 +122,19 @@ class TestPlayContext(unittest.TestCase): default_cmd = "/bin/foo" default_exe = "/bin/bash" - sudo_exe = C.DEFAULT_SUDO_EXE or 'sudo' - sudo_flags = C.DEFAULT_SUDO_FLAGS - su_exe = C.DEFAULT_SU_EXE or 'su' - su_flags = C.DEFAULT_SU_FLAGS or '' - pbrun_exe = 'pbrun' + sudo_exe = C.DEFAULT_SUDO_EXE or 'sudo' + sudo_flags = C.DEFAULT_SUDO_FLAGS + su_exe = C.DEFAULT_SU_EXE or 'su' + su_flags = C.DEFAULT_SU_FLAGS or '' + pbrun_exe = 'pbrun' pbrun_flags = '' - pfexec_exe = 'pfexec' + pfexec_exe = 'pfexec' pfexec_flags = '' - doas_exe = 'doas' - doas_flags = ' -n -u foo ' + doas_exe = 'doas' + doas_flags = ' -n -u foo ' ksu_exe = 'ksu' ksu_flags = '' - dzdo_exe = 'dzdo' + dzdo_exe = 'dzdo' cmd = play_context.make_become_cmd(cmd=default_cmd, executable=default_exe) self.assertEqual(cmd, default_cmd) @@ -152,7 +152,7 @@ class TestPlayContext(unittest.TestCase): cmd = play_context.make_become_cmd(cmd=default_cmd, executable=default_exe) self.assertEqual( cmd, - """%s %s -p "%s" -u %s %s -c 'echo %s; %s'""" % (sudo_exe, sudo_flags.replace('-n',''), play_context.prompt, play_context.become_user, default_exe, + """%s %s -p "%s" -u %s %s -c 'echo %s; %s'""" % (sudo_exe, sudo_flags.replace('-n', ''), play_context.prompt, play_context.become_user, default_exe, play_context.success_key, default_cmd) ) @@ -207,103 +207,129 @@ class TestPlayContext(unittest.TestCase): class TestTaskAndVariableOverrride(unittest.TestCase): inventory_vars = ( - ('preferred_names', - dict(ansible_connection='local', - ansible_user='ansibull', - ansible_become_user='ansibull', - ansible_become_method='su', - ansible_become_pass='ansibullwuzhere',), - dict(connection='local', - remote_user='ansibull', - become_user='ansibull', - become_method='su', - become_pass='ansibullwuzhere',) - ), - ('alternate_names', - dict(ansible_become_password='ansibullwuzhere',), - dict(become_pass='ansibullwuzhere',) - ), - ('deprecated_names', - dict(ansible_ssh_user='ansibull', - ansible_sudo_user='ansibull', - ansible_sudo_pass='ansibullwuzhere',), - dict(remote_user='ansibull', - become_method='sudo', - become_user='ansibull', - become_pass='ansibullwuzhere',) - ), - ('deprecated_names2', - dict(ansible_ssh_user='ansibull', - ansible_su_user='ansibull', - ansible_su_pass='ansibullwuzhere',), - dict(remote_user='ansibull', - become_method='su', - become_user='ansibull', - become_pass='ansibullwuzhere',) + ( + 'preferred_names', + dict( + ansible_connection='local', + ansible_user='ansibull', + ansible_become_user='ansibull', + ansible_become_method='su', + ansible_become_pass='ansibullwuzhere', ), - ('deprecated_alt_names', - dict(ansible_sudo_password='ansibullwuzhere',), - dict(become_method='sudo', - become_pass='ansibullwuzhere',) + dict( + connection='local', + remote_user='ansibull', + become_user='ansibull', + become_method='su', + become_pass='ansibullwuzhere', + ) + ), + ( + 'alternate_names', + dict(ansible_become_password='ansibullwuzhere',), + dict(become_pass='ansibullwuzhere',) + ), + ( + 'deprecated_names', + dict( + ansible_ssh_user='ansibull', + ansible_sudo_user='ansibull', + ansible_sudo_pass='ansibullwuzhere', ), - ('deprecated_alt_names2', - dict(ansible_su_password='ansibullwuzhere',), - dict(become_method='su', - become_pass='ansibullwuzhere',) + dict( + remote_user='ansibull', + become_method='sudo', + become_user='ansibull', + become_pass='ansibullwuzhere', + ) + ), + ( + 'deprecated_names2', + dict( + ansible_ssh_user='ansibull', + ansible_su_user='ansibull', + ansible_su_pass='ansibullwuzhere', ), - ('deprecated_and_preferred_names', - dict(ansible_user='ansibull', - ansible_ssh_user='badbull', - ansible_become_user='ansibull', - ansible_sudo_user='badbull', - ansible_become_method='su', - ansible_become_pass='ansibullwuzhere', - ansible_sudo_pass='badbull', - ), - dict(connection='local', - remote_user='ansibull', - become_user='ansibull', - become_method='su', - become_pass='ansibullwuzhere',) + dict( + remote_user='ansibull', + become_method='su', + become_user='ansibull', + become_pass='ansibullwuzhere', + ) + ), + ( + 'deprecated_alt_names', + dict(ansible_sudo_password='ansibullwuzhere',), + dict( + become_method='sudo', + become_pass='ansibullwuzhere', + ) + ), + ( + 'deprecated_alt_names2', + dict(ansible_su_password='ansibullwuzhere',), + dict( + become_method='su', + become_pass='ansibullwuzhere', + ) + ), + ( + 'deprecated_and_preferred_names', + dict( + ansible_user='ansibull', + ansible_ssh_user='badbull', + ansible_become_user='ansibull', + ansible_sudo_user='badbull', + ansible_become_method='su', + ansible_become_pass='ansibullwuzhere', + ansible_sudo_pass='badbull', ), + dict( + connection='local', + remote_user='ansibull', + become_user='ansibull', + become_method='su', + become_pass='ansibullwuzhere', + ) + ), ) def setUp(self): parser = CLI.base_parser( - runas_opts = True, - meta_opts = True, - runtask_opts = True, - vault_opts = True, - async_opts = True, - connect_opts = True, - subset_opts = True, - check_opts = True, - inventory_opts = True, + runas_opts=True, + meta_opts=True, + runtask_opts=True, + vault_opts=True, + async_opts=True, + connect_opts=True, + subset_opts=True, + check_opts=True, + inventory_opts=True, ) (options, args) = parser.parse_args(['-vv', '--check']) mock_play = MagicMock() - mock_play.connection = 'mock' - mock_play.remote_user = 'mock' - mock_play.port = 1234 - mock_play.become = True + mock_play.connection = 'mock' + mock_play.remote_user = 'mock' + mock_play.port = 1234 + mock_play.become = True mock_play.become_method = 'mock' - mock_play.become_user = 'mockroot' - mock_play.no_log = True + mock_play.become_user = 'mockroot' + mock_play.no_log = True self.play_context = PlayContext(play=mock_play, options=options) mock_task = MagicMock() - mock_task.connection = mock_play.connection - mock_task.remote_user = mock_play.remote_user - mock_task.no_log = mock_play.no_log - mock_task.become = mock_play.become + mock_task.connection = mock_play.connection + mock_task.remote_user = mock_play.remote_user + mock_task.no_log = mock_play.no_log + mock_task.become = mock_play.become mock_task.become_method = mock_play.becom_method - mock_task.become_user = mock_play.become_user - mock_task.become_pass = 'mocktaskpass' + mock_task.become_user = mock_play.become_user + mock_task.become_pass = 'mocktaskpass' mock_task._local_action = False - mock_task.delegate_to = None + mock_task.delegate_to = None self.mock_task = mock_task @@ -322,19 +348,19 @@ class TestTaskAndVariableOverrride(unittest.TestCase): self.assertEqual(play_context.become_user, "mocktaskroot") self.assertEqual(play_context.become_pass, "mocktaskpass") - mock_task.no_log = False + mock_task.no_log = False play_context = play_context.set_task_and_variable_override(task=mock_task, variables=all_vars, templar=mock_templar) self.assertEqual(play_context.no_log, False) def test_override_magic_variables(self): play_context = play_context.set_task_and_variable_override(task=self.mock_task, variables=all_vars, templar=self.mock_templar) - mock_play.connection = 'mock' - mock_play.remote_user = 'mock' - mock_play.port = 1234 + mock_play.connection = 'mock' + mock_play.remote_user = 'mock' + mock_play.port = 1234 mock_play.become_method = 'mock' - mock_play.become_user = 'mockroot' - mock_task.become_pass = 'mocktaskpass' + mock_play.become_user = 'mockroot' + mock_task.become_pass = 'mocktaskpass' # Inventory vars override things set from cli vars (--become, -user, # etc... [notably, not --extravars]) for test_name, all_vars, expected in self.inventory_vars: diff --git a/test/units/playbook/test_playbook.py b/test/units/playbook/test_playbook.py index caf85e7733..75db3025e8 100644 --- a/test/units/playbook/test_playbook.py +++ b/test/units/playbook/test_playbook.py @@ -21,13 +21,13 @@ __metaclass__ = type from ansible.compat.tests import unittest from ansible.compat.tests.mock import patch, MagicMock - from ansible.errors import AnsibleError, AnsibleParserError from ansible.playbook import Playbook from ansible.vars.manager import VariableManager from units.mock.loader import DictDataLoader + class TestPlaybook(unittest.TestCase): def setUp(self): @@ -42,7 +42,7 @@ class TestPlaybook(unittest.TestCase): def test_basic_playbook(self): fake_loader = DictDataLoader({ - "test_file.yml":""" + "test_file.yml": """ - hosts: all """, }) diff --git a/test/units/playbook/test_taggable.py b/test/units/playbook/test_taggable.py index 501136741a..f10a89e1d8 100644 --- a/test/units/playbook/test_taggable.py +++ b/test/units/playbook/test_taggable.py @@ -23,6 +23,7 @@ from ansible.compat.tests import unittest from ansible.playbook.taggable import Taggable from units.mock.loader import DictDataLoader + class TaggableTestObj(Taggable): def __init__(self): diff --git a/test/units/playbook/test_task.py b/test/units/playbook/test_task.py index 3995c4fd55..662c6b7931 100644 --- a/test/units/playbook/test_task.py +++ b/test/units/playbook/test_task.py @@ -19,18 +19,20 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -from ansible.playbook.task import Task from ansible.compat.tests import unittest +from ansible.playbook.task import Task + basic_shell_task = dict( - name = 'Test Task', - shell = 'echo hi' + name='Test Task', + shell='echo hi' ) kv_shell_task = dict( - action = 'shell echo hi' + action='shell echo hi' ) + class TestTask(unittest.TestCase): def setUp(self): @@ -66,7 +68,7 @@ class TestTask(unittest.TestCase): def test_task_auto_name(self): assert 'name' not in kv_shell_task t = Task.load(kv_shell_task) - #self.assertEqual(t.name, 'shell echo hi') + # self.assertEqual(t.name, 'shell echo hi') def test_task_auto_name_with_role(self): pass |