Use the enum library for the retry strategy enumerations

Instead of having a set of string constants that are the
retry strategy/decision result have it instead be an enumerator
that can be more clearly associated in docs and in code that
these values are explicitly the strategies that the retry
code can use (making it more obvious to users of these constants
what they are for).

This also updates the retry docs to use this new linkable
class when describing the various strategies that can be
used/returned.

Change-Id: I944e521562be26f5315d7553da8d5820fc284c49
This commit is contained in:
Joshua Harlow
2015-02-17 21:39:48 -08:00
committed by Joshua Harlow
parent f874b396b7
commit 37b72ec7b5
5 changed files with 70 additions and 26 deletions

View File

@@ -26,6 +26,7 @@ import threading
import time
import types
import enum
from oslo_serialization import jsonutils
from oslo_utils import importutils
from oslo_utils import netutils
@@ -57,6 +58,17 @@ _MONOTONIC_LOCATIONS = tuple([
])
class StrEnum(str, enum.Enum):
"""An enumeration that is also a string and can be compared to strings."""
def __new__(cls, *args, **kwargs):
for a in args:
if not isinstance(a, str):
raise TypeError("Enumeration '%s' (%s) is not"
" a string" % (a, type(a).__name__))
return super(StrEnum, cls).__new__(cls, *args, **kwargs)
def find_monotonic(allow_time_time=False):
"""Tries to find a monotonic time providing function (and returns it)."""
for import_str in _MONOTONIC_LOCATIONS: