mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[opentelemetry][callback] fix warning when using the include_tasks (#4623)
* opentelemetry: fix include_tasks missing _task_fields * opentelemetry: add uts for the include_tasks * opentelemetry: add changelog fragment * pep8: fix spaces
This commit is contained in:
parent
b711038b3b
commit
841b46ff6a
3 changed files with 19 additions and 1 deletions
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- opentelemetry callback plugin - fix warning for the include_tasks (https://github.com/ansible-collections/community.general/pull/4623).
|
|
@ -197,7 +197,7 @@ class OpenTelemetrySource(object):
|
|||
|
||||
task = tasks_data[task_uuid]
|
||||
|
||||
if self.ansible_version is None and result._task_fields['args'].get('_ansible_version'):
|
||||
if self.ansible_version is None and hasattr(result, '_task_fields') and result._task_fields['args'].get('_ansible_version'):
|
||||
self.ansible_version = result._task_fields['args'].get('_ansible_version')
|
||||
|
||||
task.add_host(HostData(host_uuid, host_name, status, result))
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# (C) 2021, Victor Martinez <VictorMartinezRubio@gmail.com>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
|
@ -91,6 +92,21 @@ class TestOpentelemetry(unittest.TestCase):
|
|||
self.assertEqual(host_data.uuid, 'include')
|
||||
self.assertEqual(host_data.name, 'include')
|
||||
self.assertEqual(host_data.status, 'ok')
|
||||
self.assertEqual(self.opentelemetry.ansible_version, None)
|
||||
|
||||
def test_finish_task_include_with_ansible_version(self):
|
||||
task_fields = {'args': {'_ansible_version': '1.2.3'}}
|
||||
result = TaskResult(host=None, task=self.mock_task, return_data={}, task_fields=task_fields)
|
||||
tasks_data = OrderedDict()
|
||||
tasks_data['myuuid'] = self.my_task
|
||||
|
||||
self.opentelemetry.finish_task(
|
||||
tasks_data,
|
||||
'ok',
|
||||
result
|
||||
)
|
||||
|
||||
self.assertEqual(self.opentelemetry.ansible_version, '1.2.3')
|
||||
|
||||
def test_get_error_message(self):
|
||||
test_cases = (
|
||||
|
|
Loading…
Reference in a new issue