Esempio n. 1
0
def test_process_include_diff_files(mock_iterator, mock_variable_manager):
    hostname = "testhost1"
    hostname2 = "testhost2"

    parent_task_ds = {'debug': 'msg=foo'}
    parent_task = Task.load(parent_task_ds)
    parent_task._play = None

    task_ds = {'include': 'include_test.yml'}
    loaded_task = TaskInclude.load(task_ds, task_include=parent_task)
    loaded_task._play = None

    child_task_ds = {'include': 'other_include_test.yml'}
    loaded_child_task = TaskInclude.load(child_task_ds,
                                         task_include=loaded_task)
    loaded_child_task._play = None

    return_data = {'include': 'include_test.yml'}
    # The task in the TaskResult has to be a TaskInclude so it has a .static attr
    result1 = task_result.TaskResult(host=hostname,
                                     task=loaded_task,
                                     return_data=return_data)

    return_data = {'include': 'other_include_test.yml'}
    result2 = task_result.TaskResult(host=hostname2,
                                     task=loaded_child_task,
                                     return_data=return_data)
    results = [result1, result2]

    fake_loader = DictDataLoader({
        'include_test.yml': "",
        'other_include_test.yml': ""
    })

    res = IncludedFile.process_include_results(results, mock_iterator,
                                               fake_loader,
                                               mock_variable_manager)
    assert isinstance(res, list)
    assert res[0]._filename == os.path.join(os.getcwd(), 'include_test.yml')
    assert res[1]._filename == os.path.join(os.getcwd(),
                                            'other_include_test.yml')

    assert res[0]._hosts == ['testhost1']
    assert res[1]._hosts == ['testhost2']

    assert res[0]._args == {}
    assert res[1]._args == {}

    assert res[0]._vars == {}
    assert res[1]._vars == {}
Esempio n. 2
0
def test_empty_raw_params():
    parent_task_ds = {'debug': 'msg=foo'}
    parent_task = Task.load(parent_task_ds)
    parent_task._play = None

    task_ds_list = [{
        'include': ''
    }, {
        'include_tasks': ''
    }, {
        'import_tasks': ''
    }]
    for task_ds in task_ds_list:
        with pytest.raises(AssibleParserError):
            TaskInclude.load(task_ds, task_include=parent_task)
Esempio n. 3
0
 def test_one_include_not_static(self):
     ds = [{
         'include': '/dev/null/includes/static_test_include.yml',
         'static': False
     }]
     # a_block = Block()
     ti_ds = {'include': '/dev/null/includes/ssdftatic_test_include.yml'}
     a_task_include = TaskInclude()
     ti = a_task_include.load(ti_ds)
     res = helpers.load_list_of_tasks(
         ds,
         play=self.mock_play,
         block=ti,
         variable_manager=self.mock_variable_manager,
         loader=self.fake_include_loader)
     self._assert_is_task_list_or_blocks(res)
     self.assertIsInstance(res[0], Task)
     self.assertEqual(res[0].args['_raw_params'],
                      '/dev/null/includes/static_test_include.yml')