1
0
Fork 0
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) (#4628)

* opentelemetry: fix include_tasks missing _task_fields

* opentelemetry: add uts for the include_tasks

* opentelemetry: add changelog fragment

* pep8: fix spaces

(cherry picked from commit 841b46ff6a)

Co-authored-by: Victor Martinez <victormartinezrubio@gmail.com>
This commit is contained in:
patchback[bot] 2022-05-05 06:56:26 +00:00 committed by GitHub
parent 45d461c0ec
commit 7c987d7498
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- opentelemetry callback plugin - fix warning for the include_tasks (https://github.com/ansible-collections/community.general/pull/4623).

View file

@ -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))

View file

@ -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 = (