Don't use monotonic with Python >=3.3

A change to the global-requirements has limited use of monotonic
library to Python versions earlier than 3.3 (later versions have
built-in support for a monotonic clock), so limit it in
requirements.txt.

Note: this patch updates kafka driver (due to deprecated exception
in library) in order to pass unit tests

Change-Id: Id6b0814e05a0e548a8c2a5359daf1a6878cf6859
This commit is contained in:
Andy Smith 2018-12-03 10:21:54 -05:00
parent 274b7c3eb4
commit 252844879d
4 changed files with 15 additions and 5 deletions

View File

@ -27,14 +27,19 @@ functions scheduled by the Controller.
import abc import abc
import collections import collections
import logging import logging
from monotonic import monotonic as now # noqa
import os import os
import platform import platform
import random import random
import sys import sys
import threading import threading
import time
import uuid import uuid
if hasattr(time, 'monotonic'):
now = time.monotonic
else:
from monotonic import monotonic as now # noqa
import proton import proton
import pyngus import pyngus
from six import iteritems from six import iteritems

View File

@ -27,13 +27,18 @@ import errno
import heapq import heapq
import logging import logging
import math import math
from monotonic import monotonic as now # noqa
import os import os
import select import select
import socket import socket
import threading import threading
import time
import uuid import uuid
if hasattr(time, 'monotonic'):
now = time.monotonic
else:
from monotonic import monotonic as now # noqa
import pyngus import pyngus
from oslo_messaging._i18n import _LE, _LI, _LW from oslo_messaging._i18n import _LE, _LI, _LW

View File

@ -173,7 +173,7 @@ class ConsumerConnection(Connection):
if not messages: if not messages:
# NOTE(sileht): really ? you return payload but no messages... # NOTE(sileht): really ? you return payload but no messages...
# simulate timeout to consume message again # simulate timeout to consume message again
raise kafka.errors.ConsumerTimeout() raise kafka.errors.ConsumerNoMoreData()
if not self.enable_auto_commit: if not self.enable_auto_commit:
self.consumer.commit() self.consumer.commit()
@ -200,7 +200,7 @@ class ConsumerConnection(Connection):
return return
try: try:
return self._poll_messages(poll_timeout) return self._poll_messages(poll_timeout)
except kafka.errors.ConsumerTimeout as exc: except kafka.errors.ConsumerNoMoreData as exc:
poll_timeout = timer.check_return( poll_timeout = timer.check_return(
_raise_timeout, exc, maximum=self.consumer_timeout) _raise_timeout, exc, maximum=self.consumer_timeout)
except Exception: except Exception:

View File

@ -13,7 +13,7 @@ oslo.service!=1.28.1,>=1.24.0 # Apache-2.0
oslo.i18n>=3.15.3 # Apache-2.0 oslo.i18n>=3.15.3 # Apache-2.0
stevedore>=1.20.0 # Apache-2.0 stevedore>=1.20.0 # Apache-2.0
debtcollector>=1.2.0 # Apache-2.0 debtcollector>=1.2.0 # Apache-2.0
monotonic>=0.6 # Apache-2.0 monotonic>=0.6;python_version<'3.3' # Apache-2.0
# for jsonutils # for jsonutils
six>=1.10.0 # MIT six>=1.10.0 # MIT