Exemple #1
0
    def test_module_exec_with_become(self, use_task, o_b, o_bmethod, o_buser,
                                     e_b, e_bmethod, e_buser):
        def mock_execute_module(self, **kwargs):
            pc = self._play_context
            return {"become": pc.become, "become_method": pc.become_method,
                    "become_user": pc.become_user}

        task = MagicMock(Task)
        task.args = {}

        connection = MagicMock()
        connection.module_implementation_preferences = ('.ps1', '.exe', '')

        play_context = MagicMock()
        play_context.check_mode = False
        play_context.become = o_b
        play_context.become_method = o_bmethod
        play_context.become_user = o_buser

        plugin = ActionModule(task, connection, play_context, loader=None,
                              templar=None, shared_loader_obj=None)
        with patch('ansible.plugins.action.ActionBase._execute_module',
                   new=mock_execute_module):
            actual = plugin._execute_module_with_become('win_updates', {}, {},
                                                        True, use_task)

        # always make sure we reset back to the defaults
        assert play_context.become == o_b
        assert play_context.become_method == o_bmethod
        assert play_context.become_user == o_buser

        # verify what was set when _execute_module was called
        assert actual['become'] == e_b
        assert actual['become_method'] == e_bmethod
        assert actual['become_user'] == e_buser
Exemple #2
0
    def test_invalid_options(self, task_args, async_val, expected):
        task = MagicMock(Task)
        task.args = task_args
        task.async_val = async_val

        connection = MagicMock()
        play_context = MagicMock()
        play_context.check_mode = False

        plugin = ActionModule(task, connection, play_context, loader=None,
                              templar=None, shared_loader_obj=None)
        res = plugin.run()
        assert res['failed']
        assert expected in res['msg']
Exemple #3
0
    def test_module_exec_async_result(self, monkeypatch):
        return_val = {
            "ansible_async_watchdog_pid": 7584,
            "ansible_job_id": "545519115287.9620",
            "changed": True,
            "finished": 0,
            "results_file": r"C:\.ansible_async\545519115287.9620",
            "started": 1
        }
        mock_execute = MagicMock(return_value=return_val)
        monkeypatch.setattr(ActionModule, '_execute_module', mock_execute)

        task = MagicMock(Task)
        task.args = {}
        task.async_val = 10

        connection = MagicMock()
        connection.module_implementation_preferences = ('.ps1', '.exe', '')

        play_context = MagicMock()
        play_context.check_mode = False
        play_context.become = True
        play_context.become_method = 'runas'
        play_context.become_user = '******'

        plugin = ActionModule(task,
                              connection,
                              play_context,
                              loader=None,
                              templar=None,
                              shared_loader_obj=None)
        actual = plugin.run(None, {})

        assert actual.get('failed') is None
        assert actual['ansible_async_watchdog_pid'] == 7584
        assert actual['ansible_job_id'] == "545519115287.9620"
        assert actual['changed'] is True
        assert actual['finished'] == 0
        assert actual['results_file'] == r"C:\.ansible_async\545519115287.9620"
        assert actual['started'] == 1
Exemple #4
0
def test_win_updates():
    task = MagicMock(Task)
    task.args = {}

    connection = MagicMock()
    connection.module_implementation_preferences = ('.ps1', '.exe', '')

    play_context = MagicMock()
    play_context.check_mode = False

    plugin = ActionModule(task,
                          connection,
                          play_context,
                          loader=None,
                          templar=None,
                          shared_loader_obj=None)
    return plugin