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 == {}
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)
def deserialize(self, data): # import is here to avoid import loops from assible.playbook.task_include import TaskInclude from assible.playbook.handler_task_include import HandlerTaskInclude parent_data = data.get('parent', None) if parent_data: parent_type = data.get('parent_type') if parent_type == 'Block': p = Block() elif parent_type == 'TaskInclude': p = TaskInclude() elif parent_type == 'HandlerTaskInclude': p = HandlerTaskInclude() p.deserialize(parent_data) self._parent = p del data['parent'] role_data = data.get('role') if role_data: r = Role() r.deserialize(role_data) self._role = r del data['role'] self._assible_internal_redirect_list = data.get('_assible_internal_redirect_list', []) self.implicit = data.get('implicit', False) super(Task, self).deserialize(data)
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')
def deserialize(self, data): ''' Override of the default deserialize method, to match the above overridden serialize method ''' # import is here to avoid import loops from assible.playbook.task_include import TaskInclude from assible.playbook.handler_task_include import HandlerTaskInclude # we don't want the full set of attributes (the task lists), as that # would lead to a serialize/deserialize loop for attr in self._valid_attrs: if attr in data and attr not in ('block', 'rescue', 'always'): setattr(self, attr, data.get(attr)) self._dep_chain = data.get('dep_chain', None) self._eor = data.get('eor', False) # if there was a serialized role, unpack it too role_data = data.get('role') if role_data: r = Role() r.deserialize(role_data) self._role = r parent_data = data.get('parent') if parent_data: parent_type = data.get('parent_type') if parent_type == 'Block': p = Block() elif parent_type == 'TaskInclude': p = TaskInclude() elif parent_type == 'HandlerTaskInclude': p = HandlerTaskInclude() p.deserialize(parent_data) self._parent = p self._dep_chain = self._parent.get_dep_chain()