diff --git a/contrib/archive/backends/impl_ipa/auth.py b/contrib/archive/backends/impl_ipa/auth.py index b12096cc9..6f851b8db 100644 --- a/contrib/archive/backends/impl_ipa/auth.py +++ b/contrib/archive/backends/impl_ipa/auth.py @@ -15,11 +15,11 @@ # under the License. import os import logging -import uuid from requests import auth import kerberos +from designate.utils import generate_uuid from designate.backend.impl_ipa import IPAAuthError from designate.i18n import _LW from designate.i18n import _LE @@ -31,7 +31,7 @@ LOG = logging.getLogger(__name__) class IPAAuth(auth.AuthBase): def __init__(self, keytab, hostname): # store the kerberos credentials in memory rather than on disk - os.environ['KRB5CCNAME'] = "MEMORY:" + str(uuid.uuid4()) + os.environ['KRB5CCNAME'] = "MEMORY:" + generate_uuid() self.token = None self.keytab = keytab self.hostname = hostname diff --git a/contrib/ipaextractor.py b/contrib/ipaextractor.py index 08fa7b763..e4b83c399 100644 --- a/contrib/ipaextractor.py +++ b/contrib/ipaextractor.py @@ -16,7 +16,6 @@ import sys import logging -import uuid import pprint import json import copy @@ -264,7 +263,7 @@ def main(): assert(zone) # create a fake subdomain of this zone - domname = "%s.%s" % (uuid.uuid4(), zone['idnsname']) + domname = "%s.%s" % (utils.generate_uuid(), zone['idnsname']) args = copy.copy(zone) del args['idnsname'] args['version'] = version diff --git a/contrib/records_mass_create.py b/contrib/records_mass_create.py index 7cdf1ca9c..9a74503f9 100644 --- a/contrib/records_mass_create.py +++ b/contrib/records_mass_create.py @@ -16,12 +16,13 @@ # under the License. import os import sys -import uuid from designateclient import v1 from oslo_config import cfg from oslo_log import log as logging +from designate.utils import generate_uuid + cfg.CONF.register_cli_opts([ cfg.StrOpt("domain_id", help="ID of domain to use."), @@ -51,6 +52,6 @@ if __name__ == '__main__': msg = "Creating %s records", cfg.CONF.records LOG.info(msg) for i in range(0, cfg.CONF.records): - name = '%s.%s' % (str(uuid.uuid4()), domain.name) + name = '%s.%s' % (generate_uuid(), domain.name) record = {"name": name, "type": "A", "data": "10.0.0.1"} client.records.create(domain, record) diff --git a/designate/coordination.py b/designate/coordination.py index fc20a2828..4a84840a8 100644 --- a/designate/coordination.py +++ b/designate/coordination.py @@ -18,13 +18,13 @@ import math import time -import uuid from oslo_config import cfg from oslo_log import log import retrying import tooz.coordination +from designate.utils import generate_uuid from designate.i18n import _LI from designate.i18n import _LW from designate.i18n import _LE @@ -64,7 +64,7 @@ class CoordinationMixin(object): self._coordinator = None def start(self): - self._coordination_id = ":".join([CONF.host, str(uuid.uuid4())]) + self._coordination_id = ":".join([CONF.host, generate_uuid()]) if CONF.coordination.backend_url is not None: backend_url = cfg.CONF.coordination.backend_url @@ -105,7 +105,7 @@ class CoordinationMixin(object): except Exception: LOG.warning(_LW("Failed to start Coordinator:"), - exc_info=True) + exc_info=True) time.sleep(15) def stop(self): diff --git a/designate/network_api/fake.py b/designate/network_api/fake.py index 8cc74e4b0..ca7906b8f 100644 --- a/designate/network_api/fake.py +++ b/designate/network_api/fake.py @@ -13,17 +13,16 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import uuid - import six from oslo_log import log as logging +from designate.utils import generate_uuid from designate.network_api import base LOG = logging.getLogger(__name__) -POOL = dict([(str(uuid.uuid4()), '192.168.2.%s' % i) for i in +POOL = dict([(generate_uuid(), '192.168.2.%s' % i) for i in range(0, 254)]) ALLOCATIONS = {} diff --git a/designate/tests/test_pool_manager/test_service.py b/designate/tests/test_pool_manager/test_service.py index 9b1971d5b..2680a9e70 100644 --- a/designate/tests/test_pool_manager/test_service.py +++ b/designate/tests/test_pool_manager/test_service.py @@ -13,9 +13,6 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - -import uuid - from oslo_log import log import oslo_messaging as messaging from mock import call @@ -24,6 +21,7 @@ from mock import patch from designate import exceptions from designate import objects +from designate.utils import generate_uuid from designate.backend import impl_fake from designate.central import rpcapi as central_rpcapi from designate.mdns import rpcapi as mdns_rpcapi @@ -79,7 +77,7 @@ class PoolManagerServiceNoopTest(PoolManagerTestCase): def _build_zones(self, n, action, status): return [ self._build_zone("zone%02X.example" % cnt, action, - status, id=str(uuid.uuid4())) + status, id=generate_uuid()) for cnt in range(n) ] diff --git a/designate/tests/test_storage/__init__.py b/designate/tests/test_storage/__init__.py index ed1279e9e..21a2a9574 100644 --- a/designate/tests/test_storage/__init__.py +++ b/designate/tests/test_storage/__init__.py @@ -13,7 +13,6 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. -import uuid import math import mock @@ -23,6 +22,7 @@ from oslo_log import log as logging from designate import exceptions from designate import objects +from designate.utils import generate_uuid from designate.storage.base import Storage as StorageBase from designate.utils import DEFAULT_MDNS_PORT @@ -154,7 +154,7 @@ class StorageTestCase(object): def test_paging_marker_not_found(self): with testtools.ExpectedException(exceptions.MarkerNotFound): self.storage.find_pool_attributes( - self.admin_context, marker=str(uuid.uuid4()), limit=5) + self.admin_context, marker=generate_uuid(), limit=5) def test_paging_marker_invalid(self): with testtools.ExpectedException(exceptions.InvalidMarker): diff --git a/designate/tests/unit/test_backend/test_designate.py b/designate/tests/unit/test_backend/test_designate.py index 56dc75cbd..d4c527cb4 100644 --- a/designate/tests/unit/test_backend/test_designate.py +++ b/designate/tests/unit/test_backend/test_designate.py @@ -17,8 +17,6 @@ """ Unit test Backend """ -import uuid - from designateclient import exceptions from mock import patch from mock import NonCallableMagicMock @@ -28,6 +26,7 @@ import fixtures import oslotest.base import testtools +from designate.utils import generate_uuid from designate import objects from designate.backend import impl_designate @@ -35,7 +34,7 @@ LOG = logging.getLogger(__name__) def create_zone(): - id_ = str(uuid.uuid4()) + id_ = generate_uuid() return objects.Zone( id=id_, name='%s-example.com.' % id_, diff --git a/designate/tests/unit/test_producer/test_tasks.py b/designate/tests/unit/test_producer/test_tasks.py index 2a2eb5dc4..f3138ef4a 100644 --- a/designate/tests/unit/test_producer/test_tasks.py +++ b/designate/tests/unit/test_producer/test_tasks.py @@ -18,7 +18,6 @@ Unit test Producer tasks """ import datetime -import uuid from oslo_utils import timeutils from oslotest import base as test @@ -26,6 +25,7 @@ import fixtures import mock import testtools +from designate.utils import generate_uuid from designate.central import rpcapi as central_api from designate import context from designate import rpc @@ -87,7 +87,7 @@ class PeriodicTest(TaskTest): ctxt = mock.Mock() iterer = self.task._iter_zones(ctxt) - items = [RoObject(id=str(uuid.uuid4())) for i in range(0, 5)] + items = [RoObject(id=generate_uuid()) for i in range(0, 5)] central.find_zones.return_value = items # Iterate through the items causing the "paging" to be done. @@ -156,7 +156,7 @@ class PeriodicExistsTest(TaskTest): def test_emit_exists(self): zone = RoObject( - id=str(uuid.uuid4())) + id=generate_uuid()) with mock.patch.object(self.task, '_iter_zones') as iter_: iter_.return_value = [zone] @@ -237,7 +237,7 @@ class PeriodicSecondaryRefreshTest(TaskTest): def test_refresh_zone(self): transferred = timeutils.utcnow(True) - datetime.timedelta(minutes=62) zone = RoObject( - id=str(uuid.uuid4()), + id=generate_uuid(), transferred_at=datetime.datetime.isoformat(transferred), refresh=3600) @@ -251,7 +251,7 @@ class PeriodicSecondaryRefreshTest(TaskTest): # Dummy zone object transferred = timeutils.utcnow(True) - datetime.timedelta(minutes=50) zone = RoObject( - id=str(uuid.uuid4()), + id=generate_uuid(), transferred_at=datetime.datetime.isoformat(transferred), refresh=3600)