diff --git a/blazarclient/tests/v1/shell_commands/test_leases.py b/blazarclient/tests/v1/shell_commands/test_leases.py index 8355315..6af44ac 100644 --- a/blazarclient/tests/v1/shell_commands/test_leases.py +++ b/blazarclient/tests/v1/shell_commands/test_leases.py @@ -28,7 +28,7 @@ FIRST_LEASE = 'd1e43d6d-8f6f-4c2e-b0a9-2982b39dc698' SECOND_LEASE = '424d21c3-45a2-448a-81ad-32eddc888375' -@mock.patch('blazarclient.v1.shell_commands.leases._utc_now', mock_time) +@mock.patch('oslo_utils.timeutils.utcnow', mock_time) class CreateLeaseTestCase(tests.TestCase): def setUp(self): diff --git a/blazarclient/v1/shell_commands/leases.py b/blazarclient/v1/shell_commands/leases.py index 3f8b407..9f767fa 100644 --- a/blazarclient/v1/shell_commands/leases.py +++ b/blazarclient/v1/shell_commands/leases.py @@ -20,6 +20,7 @@ import re from oslo_serialization import jsonutils from oslo_utils import strutils +from oslo_utils import timeutils from blazarclient import command from blazarclient import exception @@ -64,16 +65,6 @@ CREATE_RESERVATION_KEYS = { } -def _utc_now(): - """Wrap datetime.datetime.utcnow so it can be mocked in unit tests. - - This is required because some of the tests require understanding the - 'current time'; simply mocking utcnow() is made very difficult by - the many different ways the datetime package is used in this module. - """ - return datetime.datetime.utcnow() - - class ListLeases(command.ListCommand): """Print a list of leases.""" resource = 'lease' @@ -113,7 +104,7 @@ class CreateLeaseBase(command.CreateCommand): json_indent = 4 log = logging.getLogger(__name__ + '.CreateLease') default_start = 'now' - default_end = _utc_now() + datetime.timedelta(days=1) + default_end = timeutils.utcnow() + datetime.timedelta(days=1) def get_parser(self, prog_name): parser = super(CreateLeaseBase, self).get_parser(prog_name) @@ -189,7 +180,7 @@ class CreateLeaseBase(command.CreateCommand): raise exception.IncorrectLease if parsed_args.start == 'now': - start = _utc_now() + start = timeutils.utcnow() else: start = parsed_args.start diff --git a/requirements.txt b/requirements.txt index a983a02..035afb8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,6 +10,6 @@ cliff!=2.9.0,>=2.8.0 # Apache-2.0 PrettyTable>=0.7.1 # BSD oslo.i18n>=3.15.3 # Apache-2.0 oslo.log>=3.36.0 # Apache-2.0 -oslo.utils>=3.33.0 # Apache-2.0 +oslo.utils>=7.0.0 # Apache-2.0 keystoneauth1>=3.4.0 # Apache-2.0 osc-lib>=1.3.0 # Apache-2.0