From 3a7fc7a8e502f9ac0db28aefcd1e9f2742a15e44 Mon Sep 17 00:00:00 2001 From: chenghuiyu Date: Thu, 7 Sep 2017 11:36:23 +0800 Subject: [PATCH] Utils: fix usage of strtime As oslo_utils.timeutils.strtime() is deprecated in version '1.6', and will be removed in a future version. For more informations: https://docs.openstack.org/oslo.utils/latest/reference/timeutils.html Change-Id: I1aca257fbe8b08c3478c5da9639835033b19144a Partial-Bug: #1715325 --- watcher/common/context.py | 4 +--- watcher/common/utils.py | 2 -- watcher/tests/api/v1/test_audits.py | 6 ++++-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/watcher/common/context.py b/watcher/common/context.py index 3da7b220b..99fcb797b 100644 --- a/watcher/common/context.py +++ b/watcher/common/context.py @@ -15,8 +15,6 @@ from oslo_log import log as logging from oslo_utils import timeutils import six -from watcher.common import utils - LOG = logging.getLogger(__name__) @@ -102,7 +100,7 @@ class RequestContext(context.RequestContext): 'domain_name': getattr(self, 'domain_name', None), 'auth_token_info': getattr(self, 'auth_token_info', None), 'is_admin': getattr(self, 'is_admin', None), - 'timestamp': utils.strtime(self.timestamp) if hasattr( + 'timestamp': self.timestamp.isoformat() if hasattr( self, 'timestamp') else None, 'request_id': getattr(self, 'request_id', None), }) diff --git a/watcher/common/utils.py b/watcher/common/utils.py index 86e5ecb00..16e97384f 100644 --- a/watcher/common/utils.py +++ b/watcher/common/utils.py @@ -26,7 +26,6 @@ from croniter import croniter from jsonschema import validators from oslo_log import log as logging from oslo_utils import strutils -from oslo_utils import timeutils from oslo_utils import uuidutils import six @@ -65,7 +64,6 @@ class Struct(dict): generate_uuid = uuidutils.generate_uuid is_uuid_like = uuidutils.is_uuid_like is_int_like = strutils.is_int_like -strtime = timeutils.strtime def is_cron_like(value): diff --git a/watcher/tests/api/v1/test_audits.py b/watcher/tests/api/v1/test_audits.py index b26f62cd1..c81eaa4ed 100644 --- a/watcher/tests/api/v1/test_audits.py +++ b/watcher/tests/api/v1/test_audits.py @@ -829,8 +829,10 @@ class TestDelete(api_base.FunctionalTest): self.context.show_deleted = True audit = objects.Audit.get_by_uuid(self.context, self.audit.uuid) - return_deleted_at = timeutils.strtime(audit['deleted_at']) - self.assertEqual(timeutils.strtime(test_time), return_deleted_at) + return_deleted_at = \ + audit['deleted_at'].strftime('%Y-%m-%dT%H:%M:%S.%f') + self.assertEqual(test_time.strftime('%Y-%m-%dT%H:%M:%S.%f'), + return_deleted_at) self.assertEqual(objects.audit.State.DELETED, audit['state']) def test_delete_audit_not_found(self):