|
|
@ -1,28 +1,15 @@
|
|
|
|
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
|
|
|
|
# Copyright: (c) Ansible Project
|
|
|
|
#
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
|
|
import unittest
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
|
|
from unittest.mock import patch
|
|
|
|
from unittest.mock import patch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from ansible import errors
|
|
|
|
|
|
|
|
from ansible.parsing.yaml import objects
|
|
|
|
from ansible.playbook.task import Task
|
|
|
|
from ansible.playbook.task import Task
|
|
|
|
from ansible.plugins.loader import init_plugin_loader
|
|
|
|
from ansible.plugins.loader import init_plugin_loader
|
|
|
|
from ansible.parsing.yaml import objects
|
|
|
|
|
|
|
|
from ansible import errors
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
basic_command_task = dict(
|
|
|
|
basic_command_task = dict(
|
|
|
@ -42,7 +29,7 @@ kv_bad_args_ds = {'apk': 'sdfs sf sdf 37'}
|
|
|
|
class TestTask(unittest.TestCase):
|
|
|
|
class TestTask(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
def setUp(self):
|
|
|
|
pass
|
|
|
|
self._task_base = {'name': 'test', 'action': 'debug'}
|
|
|
|
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
def tearDown(self):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
@ -62,7 +49,7 @@ class TestTask(unittest.TestCase):
|
|
|
|
def test_load_task_simple(self):
|
|
|
|
def test_load_task_simple(self):
|
|
|
|
t = Task.load(basic_command_task)
|
|
|
|
t = Task.load(basic_command_task)
|
|
|
|
assert t is not None
|
|
|
|
assert t is not None
|
|
|
|
self.assertEqual(t.name, basic_command_task['name'])
|
|
|
|
self.assertEqual(t.get_name(), basic_command_task['name'])
|
|
|
|
self.assertEqual(t.action, 'command')
|
|
|
|
self.assertEqual(t.action, 'command')
|
|
|
|
self.assertEqual(t.args, dict(_raw_params='echo hi'))
|
|
|
|
self.assertEqual(t.args, dict(_raw_params='echo hi'))
|
|
|
|
|
|
|
|
|
|
|
@ -91,9 +78,41 @@ class TestTask(unittest.TestCase):
|
|
|
|
self.assertEqual(cm.exception.message.count('The error appears to be in'), 1)
|
|
|
|
self.assertEqual(cm.exception.message.count('The error appears to be in'), 1)
|
|
|
|
|
|
|
|
|
|
|
|
def test_task_auto_name(self):
|
|
|
|
def test_task_auto_name(self):
|
|
|
|
assert 'name' not in kv_command_task
|
|
|
|
self.assertNotIn('name', kv_command_task)
|
|
|
|
Task.load(kv_command_task)
|
|
|
|
t = Task.load(kv_command_task)
|
|
|
|
# self.assertEqual(t.name, 'shell echo hi')
|
|
|
|
self.assertEqual(t.get_name(), 'command')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_delay(self):
|
|
|
|
|
|
|
|
good_params = [
|
|
|
|
|
|
|
|
(0, 0),
|
|
|
|
|
|
|
|
(0.1, 0.1),
|
|
|
|
|
|
|
|
('0.3', 0.3),
|
|
|
|
|
|
|
|
('0.03', 0.03),
|
|
|
|
|
|
|
|
('12', 12),
|
|
|
|
|
|
|
|
(12, 12),
|
|
|
|
|
|
|
|
(1.2, 1.2),
|
|
|
|
|
|
|
|
('1.2', 1.2),
|
|
|
|
|
|
|
|
('1.0', 1),
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
for delay, expected in good_params:
|
|
|
|
|
|
|
|
with self.subTest(f'type "{type(delay)}" was not cast to float', delay=delay, expected=expected):
|
|
|
|
|
|
|
|
p = dict(delay=delay)
|
|
|
|
|
|
|
|
p.update(self._task_base)
|
|
|
|
|
|
|
|
t = Task().load_data(p)
|
|
|
|
|
|
|
|
self.assertEqual(t.get_validated_value('delay', t.fattributes.get('delay'), delay, None), expected)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bad_params = [
|
|
|
|
|
|
|
|
('E', ValueError),
|
|
|
|
|
|
|
|
('1.E', ValueError),
|
|
|
|
|
|
|
|
('E.1', ValueError),
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
for delay, expected in bad_params:
|
|
|
|
|
|
|
|
with self.subTest(f'type "{type(delay)} was cast to float w/o error', delay=delay, expected=expected):
|
|
|
|
|
|
|
|
p = dict(delay=delay)
|
|
|
|
|
|
|
|
p.update(self._task_base)
|
|
|
|
|
|
|
|
t = Task().load_data(p)
|
|
|
|
|
|
|
|
with self.assertRaises(expected):
|
|
|
|
|
|
|
|
dummy = t.get_validated_value('delay', t.fattributes.get('delay'), delay, None)
|
|
|
|
|
|
|
|
|
|
|
|
def test_task_auto_name_with_role(self):
|
|
|
|
def test_task_auto_name_with_role(self):
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|