Merge "Remove monotonic usage"

This commit is contained in:
Zuul 2020-05-07 16:58:27 +00:00 committed by Gerrit Code Review
commit 38306c8319
4 changed files with 6 additions and 20 deletions

View File

@ -22,7 +22,6 @@ keystoneauth1==3.4.0
linecache2==1.0.0 linecache2==1.0.0
MarkupSafe==1.0 MarkupSafe==1.0
mccabe==0.2.1 mccabe==0.2.1
monotonic==0.6
mox3==0.20.0 mox3==0.20.0
msgpack-python==0.4.0 msgpack-python==0.4.0
netaddr==0.7.18 netaddr==0.7.18

View File

@ -20,15 +20,6 @@ time = eventlet.patcher.original('time')
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
# TODO(bnemec): When we have a minimum dependency on a version of eventlet
# that uses monotonic by default, remove this monkey patching.
if hasattr(time, 'monotonic'):
# Use builtin monotonic clock, Python 3.3+
_monotonic = time.monotonic
else:
import monotonic
_monotonic = monotonic.monotonic
def service_hub(): def service_hub():
# NOTE(dims): Add a custom impl for EVENTLET_HUB, so we can # NOTE(dims): Add a custom impl for EVENTLET_HUB, so we can
@ -36,7 +27,7 @@ def service_hub():
# uses time.time() and we need to use a monotonic timer # uses time.time() and we need to use a monotonic timer
# to ensure that things like loopingcall work properly. # to ensure that things like loopingcall work properly.
hub = eventlet.hubs.get_default_hub().Hub() hub = eventlet.hubs.get_default_hub().Hub()
hub.clock = _monotonic hub.clock = time.monotonic
# get_default_hub() will return a hub that is supported on this platform # get_default_hub() will return a hub that is supported on this platform
hub.is_available = lambda: True hub.is_available = lambda: True
return hub return hub

View File

@ -16,16 +16,12 @@ import logging
import random import random
import six import six
import time import time
from time import monotonic as now
from oslo_service._i18n import _ from oslo_service._i18n import _
from oslo_service import _options from oslo_service import _options
from oslo_utils import reflection from oslo_utils import reflection
if hasattr(time, 'monotonic'):
now = time.monotonic
else:
from monotonic import monotonic as now # noqa
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
DEFAULT_INTERVAL = 60.0 DEFAULT_INTERVAL = 60.0

View File

@ -11,13 +11,13 @@
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import time
from unittest import mock from unittest import mock
import eventlet import eventlet
from eventlet.green import threading as greenthreading from eventlet.green import threading as greenthreading
from oslotest import base as test_base from oslotest import base as test_base
import oslo_service
from oslo_service import fixture from oslo_service import fixture
from oslo_service import loopingcall from oslo_service import loopingcall
@ -38,7 +38,7 @@ class LoopingCallTestCase(test_base.BaseTestCase):
def test_monotonic_timer(self): def test_monotonic_timer(self):
def _raise_it(): def _raise_it():
clock = eventlet.hubs.get_hub().clock clock = eventlet.hubs.get_hub().clock
ok = (clock == oslo_service._monotonic) ok = (clock == time.monotonic)
raise loopingcall.LoopingCallDone(ok) raise loopingcall.LoopingCallDone(ok)
timer = loopingcall.FixedIntervalLoopingCall(_raise_it) timer = loopingcall.FixedIntervalLoopingCall(_raise_it)
@ -48,7 +48,7 @@ class LoopingCallTestCase(test_base.BaseTestCase):
# Make sure that by default the oslo_service.service_hub() kicks in, # Make sure that by default the oslo_service.service_hub() kicks in,
# test in the main thread # test in the main thread
hub = eventlet.hubs.get_hub() hub = eventlet.hubs.get_hub()
self.assertEqual(oslo_service._monotonic, self.assertEqual(time.monotonic,
hub.clock) hub.clock)
def test_return_false(self): def test_return_false(self):
@ -172,7 +172,7 @@ class DynamicLoopingCallTestCase(test_base.BaseTestCase):
def test_monotonic_timer(self): def test_monotonic_timer(self):
def _raise_it(): def _raise_it():
clock = eventlet.hubs.get_hub().clock clock = eventlet.hubs.get_hub().clock
ok = (clock == oslo_service._monotonic) ok = (clock == time.monotonic)
raise loopingcall.LoopingCallDone(ok) raise loopingcall.LoopingCallDone(ok)
timer = loopingcall.DynamicLoopingCall(_raise_it) timer = loopingcall.DynamicLoopingCall(_raise_it)