Use designate.utils.generate_uuid instead of str(uuid.uuid4)

This patch replaces str(uuid.uuid4) with designate.utils.generate_uuid

Change-Id: I424a13f9d241930414bfb4c4508fc56de2df0dcc
Closes-Bug: #1656765
This commit is contained in:
Cuong Nguyen 2017-01-16 16:12:08 +07:00
parent d7bedee680
commit 423e539e1e
9 changed files with 22 additions and 26 deletions

View File

@ -15,11 +15,11 @@
# under the License. # under the License.
import os import os
import logging import logging
import uuid
from requests import auth from requests import auth
import kerberos import kerberos
from designate.utils import generate_uuid
from designate.backend.impl_ipa import IPAAuthError from designate.backend.impl_ipa import IPAAuthError
from designate.i18n import _LW from designate.i18n import _LW
from designate.i18n import _LE from designate.i18n import _LE
@ -31,7 +31,7 @@ LOG = logging.getLogger(__name__)
class IPAAuth(auth.AuthBase): class IPAAuth(auth.AuthBase):
def __init__(self, keytab, hostname): def __init__(self, keytab, hostname):
# store the kerberos credentials in memory rather than on disk # 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.token = None
self.keytab = keytab self.keytab = keytab
self.hostname = hostname self.hostname = hostname

View File

@ -16,7 +16,6 @@
import sys import sys
import logging import logging
import uuid
import pprint import pprint
import json import json
import copy import copy
@ -264,7 +263,7 @@ def main():
assert(zone) assert(zone)
# create a fake subdomain of this 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) args = copy.copy(zone)
del args['idnsname'] del args['idnsname']
args['version'] = version args['version'] = version

View File

@ -16,12 +16,13 @@
# under the License. # under the License.
import os import os
import sys import sys
import uuid
from designateclient import v1 from designateclient import v1
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
from designate.utils import generate_uuid
cfg.CONF.register_cli_opts([ cfg.CONF.register_cli_opts([
cfg.StrOpt("domain_id", help="ID of domain to use."), cfg.StrOpt("domain_id", help="ID of domain to use."),
@ -51,6 +52,6 @@ if __name__ == '__main__':
msg = "Creating %s records", cfg.CONF.records msg = "Creating %s records", cfg.CONF.records
LOG.info(msg) LOG.info(msg)
for i in range(0, cfg.CONF.records): 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"} record = {"name": name, "type": "A", "data": "10.0.0.1"}
client.records.create(domain, record) client.records.create(domain, record)

View File

@ -18,13 +18,13 @@
import math import math
import time import time
import uuid
from oslo_config import cfg from oslo_config import cfg
from oslo_log import log from oslo_log import log
import retrying import retrying
import tooz.coordination import tooz.coordination
from designate.utils import generate_uuid
from designate.i18n import _LI from designate.i18n import _LI
from designate.i18n import _LW from designate.i18n import _LW
from designate.i18n import _LE from designate.i18n import _LE
@ -64,7 +64,7 @@ class CoordinationMixin(object):
self._coordinator = None self._coordinator = None
def start(self): 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: if CONF.coordination.backend_url is not None:
backend_url = cfg.CONF.coordination.backend_url backend_url = cfg.CONF.coordination.backend_url
@ -105,7 +105,7 @@ class CoordinationMixin(object):
except Exception: except Exception:
LOG.warning(_LW("Failed to start Coordinator:"), LOG.warning(_LW("Failed to start Coordinator:"),
exc_info=True) exc_info=True)
time.sleep(15) time.sleep(15)
def stop(self): def stop(self):

View File

@ -13,17 +13,16 @@
# 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 uuid
import six import six
from oslo_log import log as logging from oslo_log import log as logging
from designate.utils import generate_uuid
from designate.network_api import base from designate.network_api import base
LOG = logging.getLogger(__name__) 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)]) range(0, 254)])
ALLOCATIONS = {} ALLOCATIONS = {}

View File

@ -13,9 +13,6 @@
# 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 uuid
from oslo_log import log from oslo_log import log
import oslo_messaging as messaging import oslo_messaging as messaging
from mock import call from mock import call
@ -24,6 +21,7 @@ from mock import patch
from designate import exceptions from designate import exceptions
from designate import objects from designate import objects
from designate.utils import generate_uuid
from designate.backend import impl_fake from designate.backend import impl_fake
from designate.central import rpcapi as central_rpcapi from designate.central import rpcapi as central_rpcapi
from designate.mdns import rpcapi as mdns_rpcapi from designate.mdns import rpcapi as mdns_rpcapi
@ -79,7 +77,7 @@ class PoolManagerServiceNoopTest(PoolManagerTestCase):
def _build_zones(self, n, action, status): def _build_zones(self, n, action, status):
return [ return [
self._build_zone("zone%02X.example" % cnt, action, self._build_zone("zone%02X.example" % cnt, action,
status, id=str(uuid.uuid4())) status, id=generate_uuid())
for cnt in range(n) for cnt in range(n)
] ]

View File

@ -13,7 +13,6 @@
# 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 uuid
import math import math
import mock import mock
@ -23,6 +22,7 @@ from oslo_log import log as logging
from designate import exceptions from designate import exceptions
from designate import objects from designate import objects
from designate.utils import generate_uuid
from designate.storage.base import Storage as StorageBase from designate.storage.base import Storage as StorageBase
from designate.utils import DEFAULT_MDNS_PORT from designate.utils import DEFAULT_MDNS_PORT
@ -154,7 +154,7 @@ class StorageTestCase(object):
def test_paging_marker_not_found(self): def test_paging_marker_not_found(self):
with testtools.ExpectedException(exceptions.MarkerNotFound): with testtools.ExpectedException(exceptions.MarkerNotFound):
self.storage.find_pool_attributes( 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): def test_paging_marker_invalid(self):
with testtools.ExpectedException(exceptions.InvalidMarker): with testtools.ExpectedException(exceptions.InvalidMarker):

View File

@ -17,8 +17,6 @@
""" """
Unit test Backend Unit test Backend
""" """
import uuid
from designateclient import exceptions from designateclient import exceptions
from mock import patch from mock import patch
from mock import NonCallableMagicMock from mock import NonCallableMagicMock
@ -28,6 +26,7 @@ import fixtures
import oslotest.base import oslotest.base
import testtools import testtools
from designate.utils import generate_uuid
from designate import objects from designate import objects
from designate.backend import impl_designate from designate.backend import impl_designate
@ -35,7 +34,7 @@ LOG = logging.getLogger(__name__)
def create_zone(): def create_zone():
id_ = str(uuid.uuid4()) id_ = generate_uuid()
return objects.Zone( return objects.Zone(
id=id_, id=id_,
name='%s-example.com.' % id_, name='%s-example.com.' % id_,

View File

@ -18,7 +18,6 @@
Unit test Producer tasks Unit test Producer tasks
""" """
import datetime import datetime
import uuid
from oslo_utils import timeutils from oslo_utils import timeutils
from oslotest import base as test from oslotest import base as test
@ -26,6 +25,7 @@ import fixtures
import mock import mock
import testtools import testtools
from designate.utils import generate_uuid
from designate.central import rpcapi as central_api from designate.central import rpcapi as central_api
from designate import context from designate import context
from designate import rpc from designate import rpc
@ -87,7 +87,7 @@ class PeriodicTest(TaskTest):
ctxt = mock.Mock() ctxt = mock.Mock()
iterer = self.task._iter_zones(ctxt) 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 central.find_zones.return_value = items
# Iterate through the items causing the "paging" to be done. # Iterate through the items causing the "paging" to be done.
@ -156,7 +156,7 @@ class PeriodicExistsTest(TaskTest):
def test_emit_exists(self): def test_emit_exists(self):
zone = RoObject( zone = RoObject(
id=str(uuid.uuid4())) id=generate_uuid())
with mock.patch.object(self.task, '_iter_zones') as iter_: with mock.patch.object(self.task, '_iter_zones') as iter_:
iter_.return_value = [zone] iter_.return_value = [zone]
@ -237,7 +237,7 @@ class PeriodicSecondaryRefreshTest(TaskTest):
def test_refresh_zone(self): def test_refresh_zone(self):
transferred = timeutils.utcnow(True) - datetime.timedelta(minutes=62) transferred = timeutils.utcnow(True) - datetime.timedelta(minutes=62)
zone = RoObject( zone = RoObject(
id=str(uuid.uuid4()), id=generate_uuid(),
transferred_at=datetime.datetime.isoformat(transferred), transferred_at=datetime.datetime.isoformat(transferred),
refresh=3600) refresh=3600)
@ -251,7 +251,7 @@ class PeriodicSecondaryRefreshTest(TaskTest):
# Dummy zone object # Dummy zone object
transferred = timeutils.utcnow(True) - datetime.timedelta(minutes=50) transferred = timeutils.utcnow(True) - datetime.timedelta(minutes=50)
zone = RoObject( zone = RoObject(
id=str(uuid.uuid4()), id=generate_uuid(),
transferred_at=datetime.datetime.isoformat(transferred), transferred_at=datetime.datetime.isoformat(transferred),
refresh=3600) refresh=3600)