Replace dateutils usage with datetime and oslo.utils

This cr fixes:
* Replaced ``dateutil.tz.tzlocal()`` and ``dateutil.tz.tzutc()`` with
  ``datetime.timezone`` built-in classes in audit controllers and
  continuous audit scheduling.

* Replaced ``dateutil.parser.parse()`` with
  ``oslo_utils.timeutils.parse_isotime()`` in the zone migration
  strategy for parsing datetime strings.

Closes-Bug: #2118404

Change-Id: I6d8a345fa4339a688769b147413dcdf3016bf4a0
Signed-off-by: Chandan Kumar (raukadah) <chkumar@redhat.com>
This commit is contained in:
Chandan Kumar (raukadah)
2025-08-05 23:09:29 +05:30
parent a1e7156c7e
commit 95d975f339
5 changed files with 22 additions and 21 deletions

View File

@@ -21,7 +21,7 @@
import datetime
from croniter import croniter
from dateutil import tz
from datetime import timezone
from oslo_utils import timeutils
from watcher.common import context
@@ -123,7 +123,7 @@ class ContinuousAuditHandler(base.AuditHandler):
'next_run_time') else 'run_date'
# We should convert UTC time to local time without tzinfo
trigger_args[time_var] = trigger_args[time_var].replace(
tzinfo=tz.tzutc()).astimezone(tz.tzlocal()).replace(tzinfo=None)
tzinfo=timezone.utc).astimezone().replace(tzinfo=None)
self.scheduler.add_job(self.execute_audit, trigger,
args=[audit, audit_context],
name='execute_audit',

View File

@@ -12,9 +12,8 @@
# limitations under the License.
#
from dateutil.parser import parse
from oslo_log import log
from oslo_utils import timeutils
from cinderclient.v3.volumes import Volume
from novaclient.v2.servers import Server
@@ -893,7 +892,8 @@ class ComputeSpecSortFilter(BaseFilter):
reverse=True)
elif sort_key == 'created_at':
result = sorted(items,
key=lambda x: parse(getattr(x, sort_key)),
key=lambda x: timeutils.parse_isotime(
getattr(x, sort_key)),
reverse=False)
return result
@@ -959,7 +959,8 @@ class StorageSpecSortFilter(BaseFilter):
if sort_key == 'created_at':
result = sorted(items,
key=lambda x: parse(getattr(x, sort_key)),
key=lambda x: timeutils.parse_isotime(
getattr(x, sort_key)),
reverse=False)
else:
result = sorted(items,