Merge "Replace dateutils usage with datetime and oslo.utils"
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Removed the ``python-dateutil`` dependency from Watcher to reduce the
|
||||
number of external dependencies and improve maintainability.
|
@@ -30,7 +30,7 @@ states, visit :ref:`the Audit State machine <audit_state_machine>`.
|
||||
"""
|
||||
|
||||
import datetime
|
||||
from dateutil import tz
|
||||
from datetime import timezone
|
||||
|
||||
from http import HTTPStatus
|
||||
import jsonschema
|
||||
@@ -635,13 +635,11 @@ class AuditsController(rest.RestController):
|
||||
start_time_value = audit_dict.get('start_time')
|
||||
end_time_value = audit_dict.get('end_time')
|
||||
if start_time_value:
|
||||
audit_dict['start_time'] = start_time_value.replace(
|
||||
tzinfo=tz.tzlocal()).astimezone(
|
||||
tz.tzutc()).replace(tzinfo=None)
|
||||
audit_dict['start_time'] = start_time_value.astimezone(
|
||||
timezone.utc).replace(tzinfo=None)
|
||||
if end_time_value:
|
||||
audit_dict['end_time'] = end_time_value.replace(
|
||||
tzinfo=tz.tzlocal()).astimezone(
|
||||
tz.tzutc()).replace(tzinfo=None)
|
||||
audit_dict['end_time'] = end_time_value.astimezone(
|
||||
timezone.utc).replace(tzinfo=None)
|
||||
|
||||
new_audit = objects.Audit(context, **audit_dict)
|
||||
new_audit.create()
|
||||
@@ -688,9 +686,8 @@ class AuditsController(rest.RestController):
|
||||
patch_value = api_utils.get_patch_value(patch, patch_path)
|
||||
# convert string format to UTC time
|
||||
new_patch_value = wutils.parse_isodatetime(
|
||||
patch_value).replace(
|
||||
tzinfo=tz.tzlocal()).astimezone(
|
||||
tz.tzutc()).replace(tzinfo=None)
|
||||
patch_value).astimezone(
|
||||
timezone.utc).replace(tzinfo=None)
|
||||
api_utils.set_patch_value(patch, patch_path, new_patch_value)
|
||||
|
||||
audit = Audit(**api_utils.apply_jsonpatch(audit_dict, patch))
|
||||
|
@@ -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',
|
||||
|
@@ -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,
|
||||
|
@@ -11,7 +11,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
import datetime
|
||||
from dateutil import tz
|
||||
from datetime import timezone
|
||||
import itertools
|
||||
from unittest import mock
|
||||
from urllib import parse as urlparse
|
||||
@@ -942,10 +942,8 @@ class TestPost(api_base.FunctionalTest):
|
||||
response.json['start_time'])
|
||||
return_end_time = timeutils.parse_isotime(
|
||||
response.json['end_time'])
|
||||
iso_start_time = start_time.replace(
|
||||
tzinfo=tz.tzlocal()).astimezone(tz.tzutc())
|
||||
iso_end_time = end_time.replace(
|
||||
tzinfo=tz.tzlocal()).astimezone(tz.tzutc())
|
||||
iso_start_time = start_time.astimezone(timezone.utc)
|
||||
iso_end_time = end_time.astimezone(timezone.utc)
|
||||
|
||||
self.assertEqual(iso_start_time, return_start_time)
|
||||
self.assertEqual(iso_end_time, return_end_time)
|
||||
|
Reference in New Issue
Block a user