From f5bce8398a7e3fe7131f35b082d2eebf4238c753 Mon Sep 17 00:00:00 2001 From: Takashi Natsume Date: Sat, 28 Sep 2024 01:29:34 +0900 Subject: [PATCH] Replace deprecated datetime.utcnow() The datetime.utcnow() is deprecated in Python 3.12. Replace datetime.utcnow() with oslo_utils.timeutils.utcnow(). Change-Id: I243453adb165e2fbcee4c615ce69a6fd9a7bc3c6 Signed-off-by: Takashi Natsume --- requirements.txt | 2 +- tacker/api/vnflcm/v1/controller.py | 4 +- tacker/conductor/conductor_server.py | 7 +- tacker/context.py | 4 +- tacker/objects/vnf_lcm_op_occs.py | 4 +- .../sol_refactored/common/fm_alarm_utils.py | 7 +- .../sol_refactored/common/lcm_op_occ_utils.py | 9 +- .../tests/unit/db/test_db_migration_to_v2.py | 10 +- .../conductor/test_conductor_v2.py | 14 +- .../conductor/test_vnflcm_driver_v2.py | 170 +++++++++--------- .../controller/test_vnflcm_v2.py | 26 +-- .../sol_refactored/nfvo/test_local_nfvo.py | 14 +- tacker/vnflcm/vnflcm_driver.py | 11 +- 13 files changed, 139 insertions(+), 143 deletions(-) diff --git a/requirements.txt b/requirements.txt index 4c6b50945..b0a902632 100644 --- a/requirements.txt +++ b/requirements.txt @@ -34,7 +34,7 @@ oslo.rootwrap>=5.8.0 # Apache-2.0 oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0 oslo.service>=2.5.0 # Apache-2.0 oslo.upgradecheck>=1.3.0 # Apache-2.0 -oslo.utils>=4.8.0 # Apache-2.0 +oslo.utils>=7.0.0 # Apache-2.0 oslo.versionedobjects>=1.33.3 # Apache-2.0 openstacksdk>=0.44.0 # Apache-2.0 python-barbicanclient>=4.5.2 # Apache-2.0 diff --git a/tacker/api/vnflcm/v1/controller.py b/tacker/api/vnflcm/v1/controller.py index be3529ec2..6035276c7 100644 --- a/tacker/api/vnflcm/v1/controller.py +++ b/tacker/api/vnflcm/v1/controller.py @@ -1402,7 +1402,7 @@ class VnfLcmController(wsgi.Controller): if vnf_info['before_error_point'] == fields.ErrorPoint.INITIAL: vnf_lcm_op_occs_id = uuidutils.generate_uuid() - timestamp = datetime.datetime.utcnow() + timestamp = timeutils.utcnow() operation_params = { 'type': scale_vnf_request.type, 'aspect_id': scale_vnf_request.aspect_id, @@ -1760,7 +1760,7 @@ class VnfLcmController(wsgi.Controller): vnf_lcm_op_occs.operation_state = "FAILED" vnf_lcm_op_occs.state_entered_time = \ - datetime.datetime.utcnow().isoformat() + timeutils.utcnow().isoformat() vnf_lcm_op_occs.updated_at = vnf_lcm_op_occs.state_entered_time error_details = objects.ProblemDetails( diff --git a/tacker/conductor/conductor_server.py b/tacker/conductor/conductor_server.py index 454955152..cf925e925 100644 --- a/tacker/conductor/conductor_server.py +++ b/tacker/conductor/conductor_server.py @@ -267,7 +267,7 @@ def grant_error_common(function): try: vnf_lcm_op_occs = objects.VnfLcmOpOcc.get_by_id( context, vnf_lcm_op_occ_id) - timestamp = datetime.datetime.utcnow() + timestamp = timeutils.utcnow() vnf_lcm_op_occs.operation_state = 'ROLLED_BACK' vnf_lcm_op_occs.state_entered_time = timestamp vnf_lcm_op_occs.save() @@ -927,7 +927,7 @@ class Conductor(manager.Manager, v2_hook.ConductorV2Hook): csar zip files and vnf packages files from the extracted path. """ - time_duration = datetime.datetime.utcnow() - datetime.timedelta( + time_duration = timeutils.utcnow() - datetime.timedelta( seconds=CONF.vnf_package_delete_interval) filters = {'field': 'deleted_at', 'model': 'VnfPackage', 'value': time_duration, @@ -1893,8 +1893,7 @@ class Conductor(manager.Manager, v2_hook.ConductorV2Hook): notification['links']['subscription']['href'] = \ CONF.vnf_lcm.endpoint_url + \ "/vnflcm/v1/subscriptions/" + line.id - notification['timeStamp'] = datetime.datetime.utcnow( - ).isoformat() + notification['timeStamp'] = timeutils.utcnow().isoformat() try: self.__set_auth_subscription(line) diff --git a/tacker/context.py b/tacker/context.py index 9ef8f65b1..ce9ab5a44 100644 --- a/tacker/context.py +++ b/tacker/context.py @@ -16,12 +16,12 @@ """Context: context for security/db session.""" import copy -import datetime from castellan.common.credentials import keystone_password from oslo_config import cfg from oslo_context import context as oslo_context from oslo_db.sqlalchemy import enginefacade +from oslo_utils import timeutils from tacker.common import exceptions from tacker.common.ext_oauth2_auth import ExtOAuth2Auth @@ -53,7 +53,7 @@ class ContextBase(oslo_context.RequestContext): self.user_name = user_name if not timestamp: - timestamp = datetime.datetime.utcnow() + timestamp = timeutils.utcnow() self.timestamp = timestamp # self.is_advsvc = is_advsvc # if self.is_advsvc is None: diff --git a/tacker/objects/vnf_lcm_op_occs.py b/tacker/objects/vnf_lcm_op_occs.py index 34d99156d..d1e483123 100644 --- a/tacker/objects/vnf_lcm_op_occs.py +++ b/tacker/objects/vnf_lcm_op_occs.py @@ -10,8 +10,6 @@ # License for the specific language governing permissions and limitations # under the License. -from datetime import datetime - from oslo_log import log as logging from oslo_serialization import jsonutils from oslo_utils import timeutils @@ -67,7 +65,7 @@ def _vnf_lcm_op_occ_update(context, values): update = {'operation_state': values.operation_state, 'state_entered_time': values.state_entered_time, 'error_point': values.error_point, - 'updated_at': datetime.utcnow()} + 'updated_at': timeutils.utcnow()} LOG.debug('values %s', values) if 'resource_changes' in values: if values.resource_changes: diff --git a/tacker/sol_refactored/common/fm_alarm_utils.py b/tacker/sol_refactored/common/fm_alarm_utils.py index 01a59ac83..1ac595d7f 100644 --- a/tacker/sol_refactored/common/fm_alarm_utils.py +++ b/tacker/sol_refactored/common/fm_alarm_utils.py @@ -13,9 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. -from datetime import datetime - from oslo_log import log as logging +from oslo_utils import timeutils from oslo_utils import uuidutils from tacker.sol_refactored.common import exceptions as sol_ex @@ -61,7 +60,7 @@ def make_alarm_notif_data(subsc, alarm, endpoint): id=uuidutils.generate_uuid(), notificationType="AlarmClearedNotification", subscriptionId=subsc.id, - timeStamp=datetime.utcnow(), + timeStamp=timeutils.utcnow(), alarmId=alarm.id, alarmClearedTime=alarm.alarmClearedTime, _links=objects.AlarmClearedNotificationV1_Links( @@ -76,7 +75,7 @@ def make_alarm_notif_data(subsc, alarm, endpoint): id=uuidutils.generate_uuid(), notificationType="AlarmNotification", subscriptionId=subsc.id, - timeStamp=datetime.utcnow(), + timeStamp=timeutils.utcnow(), alarm=alarm, _links=objects.AlarmNotificationV1_Links( subscription=objects.NotificationLink( diff --git a/tacker/sol_refactored/common/lcm_op_occ_utils.py b/tacker/sol_refactored/common/lcm_op_occ_utils.py index d4f51e314..95612e8fe 100644 --- a/tacker/sol_refactored/common/lcm_op_occ_utils.py +++ b/tacker/sol_refactored/common/lcm_op_occ_utils.py @@ -14,9 +14,8 @@ # under the License. -from datetime import datetime - from oslo_log import log as logging +from oslo_utils import timeutils from oslo_utils import uuidutils from tacker.sol_refactored.common import exceptions as sol_ex @@ -71,7 +70,7 @@ def make_lcmocc_notif_data(subsc, lcmocc, endpoint): id=uuidutils.generate_uuid(), notificationType="VnfLcmOperationOccurrenceNotification", subscriptionId=subsc.id, - timeStamp=datetime.utcnow(), + timeStamp=timeutils.utcnow(), operationState=lcmocc.operationState, vnfInstanceId=lcmocc.vnfInstanceId, operation=lcmocc.operation, @@ -609,13 +608,13 @@ def check_lcmocc_in_progress(context, inst_id): def update_lcmocc_status(lcmocc, op_state): lcmocc.operationState = op_state - lcmocc.stateEnteredTime = datetime.utcnow() + lcmocc.stateEnteredTime = timeutils.utcnow() def new_lcmocc(inst_id, operation, req_body, op_state=fields.LcmOperationStateType.STARTING, auto_invocation=False): - now = datetime.utcnow() + now = timeutils.utcnow() lcmocc = objects.VnfLcmOpOccV2( id=uuidutils.generate_uuid(), operationState=op_state, diff --git a/tacker/tests/unit/db/test_db_migration_to_v2.py b/tacker/tests/unit/db/test_db_migration_to_v2.py index 3f883fe8c..f9bf7a886 100644 --- a/tacker/tests/unit/db/test_db_migration_to_v2.py +++ b/tacker/tests/unit/db/test_db_migration_to_v2.py @@ -18,7 +18,9 @@ import datetime import iso8601 import sys +from oslo_utils import timeutils from oslo_utils import uuidutils + from tacker.common import exceptions from tacker import context from tacker.db.db_sqlalchemy import api @@ -893,8 +895,8 @@ class TestDbMigrationToV2(SqlTestCase): # required fields id=uuidutils.generate_uuid(), operationState=op_state, - stateEnteredTime=datetime.datetime.utcnow(), - startTime=datetime.datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields_v2.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, @@ -906,8 +908,8 @@ class TestDbMigrationToV2(SqlTestCase): # required fields id=uuidutils.generate_uuid(), operationState=op_state, - stateEnteredTime=datetime.datetime.utcnow(), - startTime=datetime.datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields_v2.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, diff --git a/tacker/tests/unit/sol_refactored/conductor/test_conductor_v2.py b/tacker/tests/unit/sol_refactored/conductor/test_conductor_v2.py index ba4154bdf..7a4f34c48 100644 --- a/tacker/tests/unit/sol_refactored/conductor/test_conductor_v2.py +++ b/tacker/tests/unit/sol_refactored/conductor/test_conductor_v2.py @@ -13,12 +13,12 @@ # License for the specific language governing permissions and limitations # under the License. -from datetime import datetime from unittest import mock import ddt from kubernetes import client from oslo_log import log as logging +from oslo_utils import timeutils from oslo_utils import uuidutils from tooz.drivers import file @@ -66,8 +66,8 @@ class TestConductorV2(db_base.SqlTestCase): # required fields id=uuidutils.generate_uuid(), operationState=op_state, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, @@ -99,8 +99,8 @@ class TestConductorV2(db_base.SqlTestCase): # required fields id=uuidutils.generate_uuid(), operationState=op_state, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.CHANGE_VNFPKG, isAutomaticInvocation=False, @@ -555,8 +555,8 @@ class TestConductorV2(db_base.SqlTestCase): # required fields id=uuidutils.generate_uuid(), operationState=op_state, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.SCALE, isAutomaticInvocation=False, diff --git a/tacker/tests/unit/sol_refactored/conductor/test_vnflcm_driver_v2.py b/tacker/tests/unit/sol_refactored/conductor/test_vnflcm_driver_v2.py index 825eee8e9..540c5e300 100644 --- a/tacker/tests/unit/sol_refactored/conductor/test_vnflcm_driver_v2.py +++ b/tacker/tests/unit/sol_refactored/conductor/test_vnflcm_driver_v2.py @@ -13,13 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. import copy -from datetime import datetime import os import pickle import subprocess from unittest import mock from kubernetes import client +from oslo_utils import timeutils from oslo_utils import uuidutils from tacker import context @@ -851,8 +851,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, @@ -943,8 +943,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.TERMINATE, isAutomaticInvocation=False, @@ -1038,8 +1038,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.SCALE, isAutomaticInvocation=False, @@ -1328,8 +1328,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.PROCESSING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), operation=fields.LcmOperationType.MODIFY_INFO, isAutomaticInvocation=False, isCancelPending=False, @@ -1458,8 +1458,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.PROCESSING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), operation=fields.LcmOperationType.MODIFY_INFO, isAutomaticInvocation=False, isCancelPending=False, @@ -1534,8 +1534,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.CHANGE_EXT_CONN, isAutomaticInvocation=False, @@ -1634,8 +1634,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.HEAL, isAutomaticInvocation=False, @@ -1939,8 +1939,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.PROCESSING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.CHANGE_VNFPKG, isAutomaticInvocation=False, @@ -2024,8 +2024,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, @@ -2089,8 +2089,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.TERMINATE, isAutomaticInvocation=False, @@ -2170,8 +2170,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.CHANGE_VNFPKG, isAutomaticInvocation=False, @@ -2201,8 +2201,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.CHANGE_VNFPKG, isAutomaticInvocation=False, @@ -2234,8 +2234,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, @@ -2274,8 +2274,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, @@ -2302,8 +2302,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.TERMINATE, isAutomaticInvocation=False, @@ -2328,8 +2328,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.MODIFY_INFO, isAutomaticInvocation=False, @@ -2364,8 +2364,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, @@ -2379,8 +2379,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.TERMINATE, isAutomaticInvocation=False, @@ -2398,8 +2398,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.SCALE, isAutomaticInvocation=False, @@ -2532,8 +2532,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, @@ -2572,8 +2572,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, @@ -2610,8 +2610,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, @@ -2646,8 +2646,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, @@ -2675,8 +2675,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, @@ -2703,8 +2703,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, @@ -2738,8 +2738,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, @@ -2766,8 +2766,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, @@ -2805,8 +2805,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.TERMINATE, isAutomaticInvocation=False, @@ -2838,8 +2838,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.TERMINATE, isAutomaticInvocation=False, @@ -2867,8 +2867,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.TERMINATE, isAutomaticInvocation=False, @@ -2937,8 +2937,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.SCALE, isAutomaticInvocation=False, @@ -2964,8 +2964,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.SCALE, isAutomaticInvocation=False, @@ -3004,8 +3004,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.SCALE, isAutomaticInvocation=False, @@ -3021,8 +3021,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.SCALE, isAutomaticInvocation=False, @@ -3051,8 +3051,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.SCALE, isAutomaticInvocation=False, @@ -3090,8 +3090,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.HEAL, isAutomaticInvocation=False, @@ -3117,8 +3117,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.HEAL, isAutomaticInvocation=False, @@ -3157,8 +3157,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.CHANGE_EXT_CONN, isAutomaticInvocation=False, @@ -3187,8 +3187,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.CHANGE_EXT_CONN, isAutomaticInvocation=False, @@ -3271,8 +3271,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.CHANGE_VNFPKG, isAutomaticInvocation=False, @@ -3368,8 +3368,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.CHANGE_EXT_CONN, isAutomaticInvocation=False, @@ -3426,8 +3426,8 @@ class TestVnfLcmDriverV2(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.STARTING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.CHANGE_VNFPKG, isAutomaticInvocation=False, diff --git a/tacker/tests/unit/sol_refactored/controller/test_vnflcm_v2.py b/tacker/tests/unit/sol_refactored/controller/test_vnflcm_v2.py index 4c8bbe32e..8ce9873d8 100644 --- a/tacker/tests/unit/sol_refactored/controller/test_vnflcm_v2.py +++ b/tacker/tests/unit/sol_refactored/controller/test_vnflcm_v2.py @@ -13,13 +13,13 @@ # License for the specific language governing permissions and limitations # under the License. import copy -from datetime import datetime import ddt from http import client as http_client import requests from unittest import mock from oslo_policy import policy as oslo_policy +from oslo_utils import timeutils from oslo_utils import uuidutils from tacker.common.exceptions import PolicyNotAuthorized @@ -830,8 +830,8 @@ class TestVnflcmV2(db_base.SqlTestCase): # required fields id=uuidutils.generate_uuid(), operationState=op_state, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, @@ -1447,8 +1447,8 @@ class TestVnflcmV2(db_base.SqlTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.FAILED_TEMP, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId='inst-1', operation=fields.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, @@ -1471,8 +1471,8 @@ class TestVnflcmV2(db_base.SqlTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.FAILED_TEMP, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId='inst-1', operation=fields.LcmOperationType.HEAL, isAutomaticInvocation=False, @@ -1512,8 +1512,8 @@ class TestVnflcmV2(db_base.SqlTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.FAILED_TEMP, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId='inst-1', operation=fields.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, @@ -1536,8 +1536,8 @@ class TestVnflcmV2(db_base.SqlTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.FAILED_TEMP, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId='inst-1', operation=fields.LcmOperationType.HEAL, isAutomaticInvocation=False, @@ -2064,8 +2064,8 @@ class TestVnflcmV2EnhancedPolicy(TestVnflcmV2): # required fields id=uuidutils.generate_uuid(), operationState=op_state, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, diff --git a/tacker/tests/unit/sol_refactored/nfvo/test_local_nfvo.py b/tacker/tests/unit/sol_refactored/nfvo/test_local_nfvo.py index 857a99dd0..ec9c5c011 100644 --- a/tacker/tests/unit/sol_refactored/nfvo/test_local_nfvo.py +++ b/tacker/tests/unit/sol_refactored/nfvo/test_local_nfvo.py @@ -12,10 +12,10 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -from datetime import datetime import os from unittest import mock +from oslo_utils import timeutils from oslo_utils import uuidutils from tacker import context @@ -696,8 +696,8 @@ class TestLocalNfvo(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.PROCESSING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.TERMINATE, isAutomaticInvocation=False, @@ -724,8 +724,8 @@ class TestLocalNfvo(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.PROCESSING, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.CHANGE_VNFPKG, isAutomaticInvocation=False, @@ -759,8 +759,8 @@ class TestLocalNfvo(base.BaseTestCase): # required fields id=uuidutils.generate_uuid(), operationState=fields.LcmOperationStateType.ROLLED_BACK, - stateEnteredTime=datetime.utcnow(), - startTime=datetime.utcnow(), + stateEnteredTime=timeutils.utcnow(), + startTime=timeutils.utcnow(), vnfInstanceId=inst.id, operation=fields.LcmOperationType.INSTANTIATE, isAutomaticInvocation=False, diff --git a/tacker/vnflcm/vnflcm_driver.py b/tacker/vnflcm/vnflcm_driver.py index 035f9b442..9345c5e7f 100644 --- a/tacker/vnflcm/vnflcm_driver.py +++ b/tacker/vnflcm/vnflcm_driver.py @@ -15,7 +15,6 @@ import ast import copy -from datetime import datetime import functools import hashlib import inspect @@ -106,7 +105,7 @@ def revert_to_error_scale(function): detail=str(ex)) try: - timestamp = datetime.utcnow() + timestamp = timeutils.utcnow() vnf_lcm_op_occ = vnf_info['vnf_lcm_op_occ'] vnf_lcm_op_occ.operation_state = 'FAILED_TEMP' vnf_lcm_op_occ.state_entered_time = timestamp @@ -241,7 +240,7 @@ def revert_to_error_rollback(function): detail=str(ex)) try: - timestamp = datetime.utcnow() + timestamp = timeutils.utcnow() vnf_lcm_op_occ = vnf_info['vnf_lcm_op_occ'] vnf_lcm_op_occ.operation_state = 'FAILED_TEMP' vnf_lcm_op_occ.state_entered_time = timestamp @@ -1342,7 +1341,7 @@ class VnfLcmDriver(abstract_driver.VnfInstanceAbstractDriver): def scale_vnf(self, context, vnf_info, vnf_instance, scale_vnf_request): LOG.info("Request received for scale vnf '%s'", vnf_instance.id) - timestamp = datetime.utcnow() + timestamp = timeutils.utcnow() vnf_lcm_op_occ = vnf_info['vnf_lcm_op_occ'] vnf_lcm_op_occ.operation_state = 'PROCESSING' @@ -1810,7 +1809,7 @@ class VnfLcmDriver(abstract_driver.VnfInstanceAbstractDriver): vnf_lcm_op_occs.error_point = EP.VNF_CONFIG_START - timestamp = datetime.utcnow() + timestamp = timeutils.utcnow() vnf_lcm_op_occs.operation_state = 'ROLLED_BACK' vnf_lcm_op_occs.state_entered_time = timestamp vnf_lcm_op_occs.resource_changes = resource_changes @@ -1844,7 +1843,7 @@ class VnfLcmDriver(abstract_driver.VnfInstanceAbstractDriver): vnf_info['after_scale_level'] = scale.scale_level break - timestamp = datetime.utcnow() + timestamp = timeutils.utcnow() vnf_lcm_op_occs.operation_state = 'ROLLING_BACK' vnf_lcm_op_occs.state_entered_time = timestamp