[PR #8222/524d5883 backport][stable-8] Avoid deprecated utcnow() (#8243)

Avoid deprecated utcnow() (#8222)

Avoid deprecated utcnow().

(cherry picked from commit 524d5883b8)

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
patchback[bot] 2024-04-20 10:21:02 +02:00 committed by GitHub
parent 83738f21a3
commit 4832100d76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 142 additions and 64 deletions

View file

@ -59,13 +59,16 @@ import uuid
import socket
import getpass
from datetime import datetime
from os.path import basename
from ansible.module_utils.urls import open_url
from ansible.parsing.ajson import AnsibleJSONEncoder
from ansible.plugins.callback import CallbackBase
from ansible_collections.community.general.plugins.module_utils.datetime import (
now,
)
class AzureLogAnalyticsSource(object):
def __init__(self):
@ -93,7 +96,7 @@ class AzureLogAnalyticsSource(object):
return "https://{0}.ods.opinsights.azure.com/api/logs?api-version=2016-04-01".format(workspace_id)
def __rfc1123date(self):
return datetime.utcnow().strftime('%a, %d %b %Y %H:%M:%S GMT')
return now().strftime('%a, %d %b %Y %H:%M:%S GMT')
def send_event(self, workspace_id, shared_key, state, result, runtime):
if result._task_fields['args'].get('_ansible_check_mode') is True:
@ -167,7 +170,7 @@ class CallbackModule(CallbackBase):
def _seconds_since_start(self, result):
return (
datetime.utcnow() -
now() -
self.start_datetimes[result._task._uuid]
).total_seconds()
@ -185,10 +188,10 @@ class CallbackModule(CallbackBase):
self.loganalytics.ansible_playbook = basename(playbook._file_name)
def v2_playbook_on_task_start(self, task, is_conditional):
self.start_datetimes[task._uuid] = datetime.utcnow()
self.start_datetimes[task._uuid] = now()
def v2_playbook_on_handler_task_start(self, task):
self.start_datetimes[task._uuid] = datetime.utcnow()
self.start_datetimes[task._uuid] = now()
def v2_runner_on_ok(self, result, **kwargs):
self.loganalytics.send_event(