Merge "Replace deprecated datetime.utcnow()"

This commit is contained in:
Zuul 2024-10-17 02:40:39 +00:00 committed by Gerrit Code Review
commit 57177aebb2
24 changed files with 94 additions and 89 deletions

View File

@ -23,7 +23,7 @@ oslo.reports>=1.27.0 # Apache-2.0
oslo.serialization>=2.25.0 # Apache-2.0
oslo.service>=1.30.0 # Apache-2.0
oslo.upgradecheck>=1.3.0 # Apache-2.0
oslo.utils>=3.36.0 # Apache-2.0
oslo.utils>=7.0.0 # Apache-2.0
oslo.versionedobjects>=1.32.0 # Apache-2.0
PasteDeploy>=1.5.2 # MIT
pbr>=3.1.1 # Apache-2.0

View File

@ -55,9 +55,8 @@ possible to :ref:`develop new implementations <implement_action_plugin>` which
are dynamically loaded by Watcher at launch time.
"""
import datetime
from http import HTTPStatus
from oslo_utils import timeutils
import pecan
from pecan import rest
import wsme
@ -194,9 +193,9 @@ class Action(base.APIBase):
sample = cls(uuid='27e3153e-d5bf-4b7e-b517-fb518e17f34c',
description='action description',
state='PENDING',
created_at=datetime.datetime.utcnow(),
created_at=timeutils.utcnow(),
deleted_at=None,
updated_at=datetime.datetime.utcnow(),
updated_at=timeutils.utcnow(),
parents=[])
sample._action_plan_uuid = '7ae81bb3-dec3-4289-8d6c-da80bd8001ae'
return cls._convert_with_links(sample, 'http://localhost:9322', expand)

View File

@ -54,10 +54,9 @@ To see the life-cycle and description of
state machine <action_plan_state_machine>`.
"""
import datetime
from http import HTTPStatus
from oslo_log import log
from oslo_utils import timeutils
import pecan
from pecan import rest
import wsme
@ -293,9 +292,9 @@ class ActionPlan(base.APIBase):
def sample(cls, expand=True):
sample = cls(uuid='9ef4d84c-41e8-4418-9220-ce55be0436af',
state='ONGOING',
created_at=datetime.datetime.utcnow(),
created_at=timeutils.utcnow(),
deleted_at=None,
updated_at=datetime.datetime.utcnow())
updated_at=timeutils.utcnow())
sample._audit_uuid = 'abcee106-14d3-4515-b744-5a26885cf6f6'
sample._efficacy_indicators = [{'description': 'Test indicator',
'name': 'test_indicator',

View File

@ -33,6 +33,8 @@ import datetime
from dateutil import tz
from http import HTTPStatus
from oslo_log import log
from oslo_utils import timeutils
import pecan
from pecan import rest
import wsme
@ -40,8 +42,6 @@ from wsme import types as wtypes
from wsme import utils as wutils
import wsmeext.pecan as wsme_pecan
from oslo_log import log
from watcher._i18n import _
from watcher.api.controllers import base
from watcher.api.controllers import link
@ -171,16 +171,16 @@ class AuditPostType(wtypes.Base):
strategy = _get_object_by_value(context, objects.Strategy,
self.strategy)
self.name = "%s-%s" % (strategy.name,
datetime.datetime.utcnow().isoformat())
timeutils.utcnow().isoformat())
elif self.audit_template_uuid:
audit_template = objects.AuditTemplate.get(
context, self.audit_template_uuid)
self.name = "%s-%s" % (audit_template.name,
datetime.datetime.utcnow().isoformat())
timeutils.utcnow().isoformat())
else:
goal = _get_object_by_value(context, objects.Goal, self.goal)
self.name = "%s-%s" % (goal.name,
datetime.datetime.utcnow().isoformat())
timeutils.utcnow().isoformat())
# No more than 63 characters
if len(self.name) > 63:
LOG.warning("Audit: %s length exceeds 63 characters",
@ -424,15 +424,15 @@ class Audit(base.APIBase):
name='My Audit',
audit_type='ONESHOT',
state='PENDING',
created_at=datetime.datetime.utcnow(),
created_at=timeutils.utcnow(),
deleted_at=None,
updated_at=datetime.datetime.utcnow(),
updated_at=timeutils.utcnow(),
interval='7200',
scope=[],
auto_trigger=False,
next_run_time=datetime.datetime.utcnow(),
start_time=datetime.datetime.utcnow(),
end_time=datetime.datetime.utcnow())
next_run_time=timeutils.utcnow(),
start_time=timeutils.utcnow(),
end_time=timeutils.utcnow())
sample.goal_id = '7ae81bb3-dec3-4289-8d6c-da80bd8001ae'
sample.strategy_id = '7ae81bb3-dec3-4289-8d6c-da80bd8001ff'

View File

@ -43,9 +43,8 @@ will be launched automatically or will need a manual confirmation from the
:ref:`Administrator <administrator_definition>`.
"""
import datetime
from http import HTTPStatus
from oslo_utils import timeutils
import pecan
from pecan import rest
import wsme
@ -440,9 +439,9 @@ class AuditTemplate(base.APIBase):
description='Description of my audit template',
goal_uuid='83e44733-b640-40e2-8d8a-7dd3be7134e6',
strategy_uuid='367d826e-b6a4-4b70-bc44-c3f6fe1c9986',
created_at=datetime.datetime.utcnow(),
created_at=timeutils.utcnow(),
deleted_at=None,
updated_at=datetime.datetime.utcnow(),
updated_at=timeutils.utcnow(),
scope=[],)
return cls._convert_with_links(sample, 'http://localhost:9322', expand)

View File

@ -26,6 +26,7 @@ from oslo_reports import guru_meditation_report as gmr
from oslo_reports import opts as gmr_opts
from oslo_service import service
from oslo_service import wsgi
from oslo_utils import timeutils
from watcher._i18n import _
from watcher.api import app
@ -120,7 +121,7 @@ class ServiceHeartbeat(scheduling.BackgroundSchedulerService):
'host': host})
if watcher_list:
watcher_service = watcher_list[0]
watcher_service.last_seen_up = datetime.datetime.utcnow()
watcher_service.last_seen_up = timeutils.utcnow()
watcher_service.save()
else:
watcher_service = objects.Service(self.context)

View File

@ -19,9 +19,10 @@
import datetime
from dateutil import tz
from croniter import croniter
from dateutil import tz
from oslo_utils import timeutils
from watcher.common import context
from watcher.common import scheduling
@ -97,7 +98,7 @@ class ContinuousAuditHandler(base.AuditHandler):
@staticmethod
def _next_cron_time(audit):
if utils.is_cron_like(audit.interval):
return croniter(audit.interval, datetime.datetime.utcnow()
return croniter(audit.interval, timeutils.utcnow()
).get_next(datetime.datetime)
@classmethod
@ -111,7 +112,7 @@ class ContinuousAuditHandler(base.AuditHandler):
finally:
if utils.is_int_like(audit.interval):
audit.next_run_time = (
datetime.datetime.utcnow() +
timeutils.utcnow() +
datetime.timedelta(seconds=int(audit.interval)))
else:
audit.next_run_time = self._next_cron_time(audit)
@ -129,7 +130,7 @@ class ContinuousAuditHandler(base.AuditHandler):
**trigger_args)
def check_audit_expired(self, audit):
current = datetime.datetime.utcnow()
current = timeutils.utcnow()
# Note: if audit still didn't get into the timeframe,
# skip it
if audit.start_time and audit.start_time > current:
@ -196,7 +197,7 @@ class ContinuousAuditHandler(base.AuditHandler):
# to restore it after shutdown
if audit.next_run_time is not None:
old_run_time = audit.next_run_time
current = datetime.datetime.utcnow()
current = timeutils.utcnow()
if old_run_time < current:
delta = datetime.timedelta(
seconds=(int(audit.interval) - (
@ -206,7 +207,7 @@ class ContinuousAuditHandler(base.AuditHandler):
next_run_time = audit.next_run_time
# if audit is new one
else:
next_run_time = datetime.datetime.utcnow()
next_run_time = timeutils.utcnow()
self._add_job('interval', audit, audit_context,
seconds=int(audit.interval),
next_run_time=next_run_time)

View File

@ -158,7 +158,7 @@ class CeilometerHelper(base.DataSourceBase):
def statistic_aggregation(self, resource=None, resource_type=None,
meter_name=None, period=300, granularity=300,
aggregate='mean'):
end_time = datetime.datetime.utcnow()
end_time = timeutils.utcnow()
start_time = end_time - datetime.timedelta(seconds=int(period))
meter = self._get_meter(meter_name)

View File

@ -16,12 +16,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from datetime import datetime
from datetime import timedelta
from gnocchiclient import exceptions as gnc_exc
from oslo_config import cfg
from oslo_log import log
from oslo_utils import timeutils
from watcher.common import clients
from watcher.decision_engine.datasources import base
@ -69,7 +69,7 @@ class GnocchiHelper(base.DataSourceBase):
def statistic_aggregation(self, resource=None, resource_type=None,
meter_name=None, period=300, aggregate='mean',
granularity=300):
stop_time = datetime.utcnow()
stop_time = timeutils.utcnow()
start_time = stop_time - timedelta(seconds=(int(period)))
meter = self._get_meter(meter_name)

View File

@ -19,6 +19,7 @@
import datetime
from monascaclient import exc
from oslo_utils import timeutils
from watcher.common import clients
from watcher.decision_engine.datasources import base
@ -58,8 +59,7 @@ class MonascaHelper(base.DataSourceBase):
period = int(datetime.timedelta(hours=3).total_seconds())
if not start_time:
start_time = (
datetime.datetime.utcnow() -
datetime.timedelta(seconds=period))
timeutils.utcnow() - datetime.timedelta(seconds=period))
start_timestamp = None if not start_time else start_time.isoformat()
end_timestamp = None if not end_time else end_time.isoformat()
@ -86,7 +86,7 @@ class MonascaHelper(base.DataSourceBase):
def statistic_aggregation(self, resource=None, resource_type=None,
meter_name=None, period=300, aggregate='mean',
granularity=300):
stop_time = datetime.datetime.utcnow()
stop_time = timeutils.utcnow()
start_time = stop_time - datetime.timedelta(seconds=(int(period)))
meter = self._get_meter(meter_name)

View File

@ -73,6 +73,8 @@ state may be one of the following:
"""
import datetime
from oslo_utils import timeutils
from watcher.common import exception
from watcher.common import utils
from watcher import conf
@ -332,7 +334,7 @@ class StateManager(object):
def check_expired(self, context):
action_plan_expiry = (
CONF.watcher_decision_engine.action_plan_expiry)
date_created = datetime.datetime.utcnow() - datetime.timedelta(
date_created = timeutils.utcnow() - datetime.timedelta(
hours=action_plan_expiry)
filters = {'state__eq': State.RECOMMENDED,
'created_at__lt': date_created}

View File

@ -12,11 +12,12 @@
# License for the specific language governing permissions and limitations
# under the License.
from apscheduler.schedulers import background
import datetime
import freezegun
from unittest import mock
from apscheduler.schedulers import background
import freezegun
from oslo_utils import timeutils
from watcher.api import scheduling
from watcher.notifications import service
from watcher import objects
@ -41,7 +42,7 @@ class TestSchedulingServiceFunctions(db_base.DbTestCase):
def setUp(self):
super(TestSchedulingServiceFunctions, self).setUp()
fake_service = utils.get_test_service(
created_at=datetime.datetime.utcnow())
created_at=timeutils.utcnow())
self.fake_service = objects.Service(**fake_service)
@mock.patch.object(scheduling.APISchedulingService, 'get_service_status')

View File

@ -16,7 +16,9 @@ Utils for testing the API service.
"""
import datetime
from oslo_serialization import jsonutils
from oslo_utils import timeutils
from watcher.api.controllers.v1 import action as action_ctrl
from watcher.api.controllers.v1 import action_plan as action_plan_ctrl
@ -65,7 +67,7 @@ class FakeMemcache(object):
self.token_expiration = None
def get(self, key):
dt = datetime.datetime.utcnow() + datetime.timedelta(minutes=5)
dt = timeutils.utcnow() + datetime.timedelta(minutes=5)
return jsonutils.dumps((self._cache.get(key), dt.isoformat()))
def set(self, key, value, time=0, min_compress_len=0):

View File

@ -18,6 +18,7 @@ import datetime
from unittest import mock
from oslo_config import cfg
from oslo_utils import timeutils
from oslo_utils import uuidutils
from apscheduler import job
@ -486,7 +487,7 @@ class TestContinuousAuditHandler(base.DbTestCase):
self.assertFalse(is_inactive)
def test_check_audit_expired(self):
current = datetime.datetime.utcnow()
current = timeutils.utcnow()
# start_time and end_time are None
audit_handler = continuous.ContinuousAuditHandler()

View File

@ -14,11 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import datetime
import os
from unittest import mock
from oslo_serialization import jsonutils
from oslo_utils import timeutils
from watcher.common import cinder_helper
from watcher.common import context
@ -64,7 +64,7 @@ class TestReceiveCinderNotifications(NotificationTestCase):
m_get_service_list = p_get_service_list.start()
m_update_service = p_update_service.start()
fake_service = utils.get_test_service(
created_at=datetime.datetime.utcnow())
created_at=timeutils.utcnow())
m_get_service_list.return_value = [fake_service]
m_update_service.return_value = fake_service.copy()

View File

@ -14,11 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import datetime
from unittest import mock
import freezegun
import oslo_messaging as om
from oslo_utils import timeutils
from watcher.common import rpc
from watcher import notifications
@ -45,7 +45,7 @@ class TestActionPlanNotification(base.DbTestCase):
def test_service_failed(self):
service = utils.get_test_service(mock.Mock(),
created_at=datetime.datetime.utcnow())
created_at=timeutils.utcnow())
state = w_service.ServiceStatus.FAILED
notifications.service.send_service_update(mock.MagicMock(),
service,

View File

@ -13,10 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import datetime
from unittest import mock
import iso8601
from oslo_utils import timeutils
from watcher.common import exception
from watcher.common import utils as c_utils
@ -123,7 +123,7 @@ class TestActionObject(base.DbTestCase):
uuid=c_utils.generate_uuid())
mock_get_strategy.return_value = mock.PropertyMock(
uuid=c_utils.generate_uuid())
fake_saved_action['updated_at'] = datetime.datetime.utcnow()
fake_saved_action['updated_at'] = timeutils.utcnow()
mock_update_action.return_value = fake_saved_action
uuid = self.fake_action['uuid']
action = objects.Action.get_by_uuid(
@ -172,7 +172,7 @@ class TestCreateDeleteActionObject(base.DbTestCase):
self.fake_audit = utils.create_test_audit()
self.fake_action_plan = utils.create_test_action_plan()
self.fake_action = utils.get_test_action(
created_at=datetime.datetime.utcnow())
created_at=timeutils.utcnow())
@mock.patch.object(db_api.Connection, 'create_action')
def test_create(self, mock_create_action):
@ -195,7 +195,7 @@ class TestCreateDeleteActionObject(base.DbTestCase):
mock_send_update, mock_send_delete):
mock_get_action.return_value = self.fake_action
fake_deleted_action = self.fake_action.copy()
fake_deleted_action['deleted_at'] = datetime.datetime.utcnow()
fake_deleted_action['deleted_at'] = timeutils.utcnow()
mock_soft_delete_action.return_value = fake_deleted_action
mock_update_action.return_value = fake_deleted_action

View File

@ -14,10 +14,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import datetime
from unittest import mock
import iso8601
from oslo_utils import timeutils
from watcher.db.sqlalchemy import api as db_api
from watcher import objects
@ -30,7 +30,7 @@ class TestActionDescriptionObject(base.DbTestCase):
def setUp(self):
super(TestActionDescriptionObject, self).setUp()
self.fake_action_desc = utils.get_test_action_desc(
created_at=datetime.datetime.utcnow())
created_at=timeutils.utcnow())
@mock.patch.object(db_api.Connection, 'get_action_description_by_id')
def test_get_by_id(self, mock_get_action_desc):
@ -70,7 +70,7 @@ class TestActionDescriptionObject(base.DbTestCase):
def test_save(self, mock_get_action_desc, mock_update_action_desc):
mock_get_action_desc.return_value = self.fake_action_desc
fake_saved_action_desc = self.fake_action_desc.copy()
fake_saved_action_desc['updated_at'] = datetime.datetime.utcnow()
fake_saved_action_desc['updated_at'] = timeutils.utcnow()
mock_update_action_desc.return_value = fake_saved_action_desc
_id = self.fake_action_desc['id']
action_desc = objects.ActionDescription.get(self.context, _id)
@ -102,7 +102,7 @@ class TestActionDescriptionObject(base.DbTestCase):
def test_soft_delete(self, mock_get_action_desc, mock_soft_delete):
mock_get_action_desc.return_value = self.fake_action_desc
fake_deleted_action_desc = self.fake_action_desc.copy()
fake_deleted_action_desc['deleted_at'] = datetime.datetime.utcnow()
fake_deleted_action_desc['deleted_at'] = timeutils.utcnow()
mock_soft_delete.return_value = fake_deleted_action_desc
expected_action_desc = fake_deleted_action_desc.copy()

View File

@ -13,10 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import datetime
from unittest import mock
import iso8601
from oslo_utils import timeutils
from watcher.common import exception
from watcher.common import utils as common_utils
@ -39,19 +39,19 @@ class TestActionPlanObject(base.DbTestCase):
('non_eager', dict(
eager=False,
fake_action_plan=utils.get_test_action_plan(
created_at=datetime.datetime.utcnow(),
created_at=timeutils.utcnow(),
audit_id=audit_id,
strategy_id=strategy_id))),
('eager_with_non_eager_load', dict(
eager=True,
fake_action_plan=utils.get_test_action_plan(
created_at=datetime.datetime.utcnow(),
created_at=timeutils.utcnow(),
audit_id=audit_id,
strategy_id=strategy_id))),
('eager_with_eager_load', dict(
eager=True,
fake_action_plan=utils.get_test_action_plan(
created_at=datetime.datetime.utcnow(),
created_at=timeutils.utcnow(),
strategy_id=strategy_id,
strategy=utils.get_test_strategy(id=strategy_id),
audit_id=audit_id,
@ -132,7 +132,7 @@ class TestActionPlanObject(base.DbTestCase):
mock_get_action_plan.return_value = self.fake_action_plan
fake_saved_action_plan = self.fake_action_plan.copy()
fake_saved_action_plan['state'] = objects.action_plan.State.SUCCEEDED
fake_saved_action_plan['updated_at'] = datetime.datetime.utcnow()
fake_saved_action_plan['updated_at'] = timeutils.utcnow()
mock_update_action_plan.return_value = fake_saved_action_plan
@ -197,7 +197,7 @@ class TestCreateDeleteActionPlanObject(base.DbTestCase):
self.fake_strategy = utils.create_test_strategy(name="DUMMY")
self.fake_audit = utils.create_test_audit()
self.fake_action_plan = utils.get_test_action_plan(
created_at=datetime.datetime.utcnow())
created_at=timeutils.utcnow())
@mock.patch.object(db_api.Connection, 'create_action_plan')
def test_create(self, mock_create_action_plan):
@ -234,7 +234,7 @@ class TestCreateDeleteActionPlanObject(base.DbTestCase):
m_get_action_plan.return_value = self.fake_action_plan
fake_deleted_action_plan = self.fake_action_plan.copy()
fake_deleted_action_plan['deleted_at'] = datetime.datetime.utcnow()
fake_deleted_action_plan['deleted_at'] = timeutils.utcnow()
m_update_action_plan.return_value = fake_deleted_action_plan
m_soft_delete_action_plan.return_value = fake_deleted_action_plan
expected_action_plan = fake_deleted_action_plan.copy()

View File

@ -13,10 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import datetime
from unittest import mock
import iso8601
from oslo_utils import timeutils
from watcher.common import exception
from watcher.common import rpc
@ -40,17 +40,17 @@ class TestAuditObject(base.DbTestCase):
('non_eager', dict(
eager=False,
fake_audit=utils.get_test_audit(
created_at=datetime.datetime.utcnow(),
created_at=timeutils.utcnow(),
goal_id=goal_id))),
('eager_with_non_eager_load', dict(
eager=True,
fake_audit=utils.get_test_audit(
created_at=datetime.datetime.utcnow(),
created_at=timeutils.utcnow(),
goal_id=goal_id))),
('eager_with_eager_load', dict(
eager=True,
fake_audit=utils.get_test_audit(
created_at=datetime.datetime.utcnow(),
created_at=timeutils.utcnow(),
goal_id=goal_id, goal=goal_data))),
]
@ -125,7 +125,7 @@ class TestAuditObject(base.DbTestCase):
mock_get_audit.return_value = self.fake_audit
fake_saved_audit = self.fake_audit.copy()
fake_saved_audit['state'] = objects.audit.State.SUCCEEDED
fake_saved_audit['updated_at'] = datetime.datetime.utcnow()
fake_saved_audit['updated_at'] = timeutils.utcnow()
mock_update_audit.return_value = fake_saved_audit
expected_audit = fake_saved_audit.copy()
@ -184,7 +184,7 @@ class TestCreateDeleteAuditObject(base.DbTestCase):
self.goal_id = 1
self.goal = utils.create_test_goal(id=self.goal_id, name="DUMMY")
self.fake_audit = utils.get_test_audit(
goal_id=self.goal_id, created_at=datetime.datetime.utcnow())
goal_id=self.goal_id, created_at=timeutils.utcnow())
@mock.patch.object(db_api.Connection, 'create_audit')
def test_create(self, mock_create_audit):
@ -204,7 +204,7 @@ class TestCreateDeleteAuditObject(base.DbTestCase):
mock_soft_delete_audit, mock_update_audit):
mock_get_audit.return_value = self.fake_audit
fake_deleted_audit = self.fake_audit.copy()
fake_deleted_audit['deleted_at'] = datetime.datetime.utcnow()
fake_deleted_audit['deleted_at'] = timeutils.utcnow()
mock_soft_delete_audit.return_value = fake_deleted_audit
mock_update_audit.return_value = fake_deleted_audit
@ -305,7 +305,7 @@ class TestAuditObjectSendNotifications(base.DbTestCase):
strategy=self.fake_strategy.as_dict())
m_get_audit.return_value = fake_audit
fake_deleted_audit = self.fake_audit.copy()
fake_deleted_audit['deleted_at'] = datetime.datetime.utcnow()
fake_deleted_audit['deleted_at'] = timeutils.utcnow()
expected_audit = fake_deleted_audit.copy()
expected_audit['deleted_at'] = expected_audit['deleted_at'].replace(
tzinfo=iso8601.UTC)

View File

@ -13,10 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import datetime
from unittest import mock
import iso8601
from oslo_utils import timeutils
from watcher.common import exception
from watcher.common import utils as w_utils
@ -37,17 +37,17 @@ class TestAuditTemplateObject(base.DbTestCase):
('non_eager', dict(
eager=False,
fake_audit_template=utils.get_test_audit_template(
created_at=datetime.datetime.utcnow(),
created_at=timeutils.utcnow(),
goal_id=goal_id))),
('eager_with_non_eager_load', dict(
eager=True,
fake_audit_template=utils.get_test_audit_template(
created_at=datetime.datetime.utcnow(),
created_at=timeutils.utcnow(),
goal_id=goal_id))),
('eager_with_eager_load', dict(
eager=True,
fake_audit_template=utils.get_test_audit_template(
created_at=datetime.datetime.utcnow(),
created_at=timeutils.utcnow(),
goal_id=goal_id, goal=goal_data))),
]
@ -127,7 +127,7 @@ class TestAuditTemplateObject(base.DbTestCase):
def test_save(self, mock_get_audit_template, mock_update_audit_template):
mock_get_audit_template.return_value = self.fake_audit_template
fake_saved_audit_template = self.fake_audit_template.copy()
fake_saved_audit_template['updated_at'] = datetime.datetime.utcnow()
fake_saved_audit_template['updated_at'] = timeutils.utcnow()
mock_update_audit_template.return_value = fake_saved_audit_template
uuid = self.fake_audit_template['uuid']
audit_template = objects.AuditTemplate.get_by_uuid(
@ -165,7 +165,7 @@ class TestCreateDeleteAuditTemplateObject(base.DbTestCase):
def setUp(self):
super(TestCreateDeleteAuditTemplateObject, self).setUp()
self.fake_audit_template = utils.get_test_audit_template(
created_at=datetime.datetime.utcnow())
created_at=timeutils.utcnow())
@mock.patch.object(db_api.Connection, 'create_audit_template')
def test_create(self, mock_create_audit_template):
@ -188,7 +188,7 @@ class TestCreateDeleteAuditTemplateObject(base.DbTestCase):
m_soft_delete_audit_template):
m_get_audit_template.return_value = self.fake_audit_template
fake_deleted_audit_template = self.fake_audit_template.copy()
fake_deleted_audit_template['deleted_at'] = datetime.datetime.utcnow()
fake_deleted_audit_template['deleted_at'] = timeutils.utcnow()
m_soft_delete_audit_template.return_value = fake_deleted_audit_template
expected_audit_template = fake_deleted_audit_template.copy()

View File

@ -13,10 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import datetime
from unittest import mock
import iso8601
from oslo_utils import timeutils
from watcher.db.sqlalchemy import api as db_api
from watcher import objects
@ -29,7 +29,7 @@ class TestGoalObject(base.DbTestCase):
def setUp(self):
super(TestGoalObject, self).setUp()
self.fake_goal = utils.get_test_goal(
created_at=datetime.datetime.utcnow())
created_at=timeutils.utcnow())
@mock.patch.object(db_api.Connection, 'get_goal_by_id')
def test_get_by_id(self, mock_get_goal):
@ -93,7 +93,7 @@ class TestGoalObject(base.DbTestCase):
mock_get_goal.return_value = self.fake_goal
goal_uuid = self.fake_goal['uuid']
fake_saved_goal = self.fake_goal.copy()
fake_saved_goal['updated_at'] = datetime.datetime.utcnow()
fake_saved_goal['updated_at'] = timeutils.utcnow()
mock_update_goal.return_value = fake_saved_goal
goal = objects.Goal.get_by_uuid(self.context, goal_uuid)
@ -125,7 +125,7 @@ class TestGoalObject(base.DbTestCase):
def test_soft_delete(self, mock_get_goal, mock_soft_delete_goal):
mock_get_goal.return_value = self.fake_goal
fake_deleted_goal = self.fake_goal.copy()
fake_deleted_goal['deleted_at'] = datetime.datetime.utcnow()
fake_deleted_goal['deleted_at'] = timeutils.utcnow()
mock_soft_delete_goal.return_value = fake_deleted_goal
expected_goal = fake_deleted_goal.copy()

View File

@ -13,10 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import datetime
from unittest import mock
import iso8601
from oslo_utils import timeutils
from watcher.db.sqlalchemy import api as db_api
from watcher import objects
@ -29,7 +29,7 @@ class TestScoringEngineObject(base.DbTestCase):
def setUp(self):
super(TestScoringEngineObject, self).setUp()
self.fake_scoring_engine = utils.get_test_scoring_engine(
created_at=datetime.datetime.utcnow())
created_at=timeutils.utcnow())
@mock.patch.object(db_api.Connection, 'get_scoring_engine_by_id')
def test_get_by_id(self, mock_get_scoring_engine):
@ -100,7 +100,7 @@ class TestScoringEngineObject(base.DbTestCase):
def test_save(self, mock_get_scoring_engine, mock_update_scoring_engine):
mock_get_scoring_engine.return_value = self.fake_scoring_engine
fake_saved_scoring_engine = self.fake_scoring_engine.copy()
fake_saved_scoring_engine['updated_at'] = datetime.datetime.utcnow()
fake_saved_scoring_engine['updated_at'] = timeutils.utcnow()
mock_update_scoring_engine.return_value = fake_saved_scoring_engine
uuid = self.fake_scoring_engine['uuid']
@ -134,7 +134,7 @@ class TestScoringEngineObject(base.DbTestCase):
def test_soft_delete(self, mock_get_scoring_engine, mock_soft_delete):
mock_get_scoring_engine.return_value = self.fake_scoring_engine
fake_deleted_scoring_engine = self.fake_scoring_engine.copy()
fake_deleted_scoring_engine['deleted_at'] = datetime.datetime.utcnow()
fake_deleted_scoring_engine['deleted_at'] = timeutils.utcnow()
mock_soft_delete.return_value = fake_deleted_scoring_engine
expected_scoring_engine = fake_deleted_scoring_engine.copy()

View File

@ -13,10 +13,10 @@
# License for the specific language governing permissions and limitations
# under the License.
import datetime
from unittest import mock
import iso8601
from oslo_utils import timeutils
from watcher.db.sqlalchemy import api as db_api
from watcher import objects
@ -29,7 +29,7 @@ class TestServiceObject(base.DbTestCase):
def setUp(self):
super(TestServiceObject, self).setUp()
self.fake_service = utils.get_test_service(
created_at=datetime.datetime.utcnow())
created_at=timeutils.utcnow())
@mock.patch.object(db_api.Connection, 'get_service_by_id')
def test_get_by_id(self, mock_get_service):
@ -66,7 +66,7 @@ class TestServiceObject(base.DbTestCase):
def test_save(self, mock_get_service, mock_update_service):
mock_get_service.return_value = self.fake_service
fake_saved_service = self.fake_service.copy()
fake_saved_service['updated_at'] = datetime.datetime.utcnow()
fake_saved_service['updated_at'] = timeutils.utcnow()
mock_update_service.return_value = fake_saved_service
_id = self.fake_service['id']
service = objects.Service.get(self.context, _id)
@ -98,7 +98,7 @@ class TestServiceObject(base.DbTestCase):
def test_soft_delete(self, mock_get_service, mock_soft_delete):
mock_get_service.return_value = self.fake_service
fake_deleted_service = self.fake_service.copy()
fake_deleted_service['deleted_at'] = datetime.datetime.utcnow()
fake_deleted_service['deleted_at'] = timeutils.utcnow()
mock_soft_delete.return_value = fake_deleted_service
expected_service = fake_deleted_service.copy()