Replace uuid.uuid4().hex with uuidutils.generate_uuid()

Openstack common has a wrapper for generating uuids.
We should use that function to generate uuids for consistency.

Change-Id: If31cc81bbf2f386db660a760eb866c7c1abd786a
This commit is contained in:
ritesh.arya 2017-07-13 16:30:45 +05:30 committed by Ritesh
parent 91bbe35b6c
commit 490a44b733
5 changed files with 33 additions and 33 deletions

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import uuid
from oslo_utils import uuidutils
from oslo_serialization import jsonutils as json
from six.moves.urllib import parse as urllib
@ -36,7 +36,7 @@ class MessagingClient(rest_client.RestClient):
self.version = '1'
self.uri_prefix = 'v{0}'.format(self.version)
client_id = uuid.uuid4().hex
client_id = uuidutils.generate_uuid(dashed=False)
self.headers = {'Client-ID': client_id}

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import uuid
from oslo_utils import uuidutils
from tempest import config
from tempest.lib.common.utils import data_utils
@ -281,7 +281,7 @@ class TestClaimsNegative(base.BaseV2MessagingTest):
def test_query_from_a_nonexistent_queue(self):
# Query claim a non existent queue
non_existent_queue = data_utils.rand_name('rand_queuename')
non_existent_id = str(uuid.uuid4())
non_existent_id = uuidutils.generate_uuid()
uri = "/v2/queues/{0}/claims/{1}".format(non_existent_queue,
non_existent_id)
self.assertRaises(lib_exc.NotFound,
@ -291,7 +291,7 @@ class TestClaimsNegative(base.BaseV2MessagingTest):
@decorators.idempotent_id('a2af8e9b-08fb-4079-a77a-28c0390a614a')
def test_query_claim_with_non_existing_claim_id(self):
# Query claim using a non existing claim id
non_existent_id = str(uuid.uuid4())
non_existent_id = uuidutils.generate_uuid()
uri = "/v2/queues/{0}/claims/{1}".format(self.queue_name,
non_existent_id)
self.assertRaises(lib_exc.NotFound,
@ -332,7 +332,7 @@ class TestClaimsNegative(base.BaseV2MessagingTest):
claim_ttl = data_utils.rand_int_id(start=60,
end=CONF.messaging.max_claim_ttl)
update_rbody = {"ttl": claim_ttl}
claim_id = str(uuid.uuid4())
claim_id = uuidutils.generate_uuid()
claim_uri = "/v2/queues/{0}/claims/{1}".format(self.queue_name,
claim_id)
self.assertRaises(lib_exc.NotFound,
@ -381,7 +381,7 @@ class TestClaimsNegative(base.BaseV2MessagingTest):
def test_release_claim_from_a_non_existing_queue(self):
# Release claim from a non existing queue
non_existent_queue = data_utils.rand_name('rand_queuename')
non_existent_id = str(uuid.uuid4())
non_existent_id = uuidutils.generate_uuid()
uri = "/v2/queues/{0}/claims/{1}".format(non_existent_queue,
non_existent_id)
resp, body = self.client.delete_claim(uri)
@ -391,7 +391,7 @@ class TestClaimsNegative(base.BaseV2MessagingTest):
@decorators.idempotent_id('20a6e6ed-0f53-484d-aa78-717cdaa25e50')
def test_release_a_nonexisting_claim_id(self):
# Release a non existing claim
non_existent_id = str(uuid.uuid4())
non_existent_id = uuidutils.generate_uuid()
uri = "/v2/queues/{0}/claims/{1}".format(self.queue_name,
non_existent_id)
resp, body = self.client.delete_claim(uri)

View File

@ -14,8 +14,8 @@
# limitations under the License.
import random
import uuid
from oslo_utils import uuidutils
from six import moves
from tempest import config
from tempest.lib.common.utils import data_utils
@ -45,7 +45,7 @@ class TestMessagesNegative(base.BaseV2MessagingTest):
@decorators.idempotent_id('8246ee51-651c-4e2a-9a07-91848ca5e1e4')
def test_request_single_message_from_a_nonexistent_queue(self):
# List a message from a nonexistent queue
id = str(uuid.uuid4())
id = uuidutils.generate_uuid()
non_existent_queue = data_utils.rand_name('rand_queuename')
uri = "/v2/queues/{0}/messages/{1}".format(non_existent_queue, id)
self.assertRaises(lib_exc.NotFound,
@ -55,7 +55,7 @@ class TestMessagesNegative(base.BaseV2MessagingTest):
@decorators.idempotent_id('767fdad1-37df-485a-8063-5036e8d16a12')
def test_request_a_non_existing_message(self):
# List a message with an invalid id
invalid_id = str(uuid.uuid4())
invalid_id = uuidutils.generate_uuid()
queue_name = self.queues[data_utils.rand_int_id(0,
len(self.queues) - 1)]
uri = "/v2/queues/{0}/messages/{1}".format(queue_name, invalid_id)
@ -80,7 +80,7 @@ class TestMessagesNegative(base.BaseV2MessagingTest):
# List a message without a valid token
queue_name = self.queues[data_utils.rand_int_id(0,
len(self.queues) - 1)]
id = str(uuid.uuid4())
id = uuidutils.generate_uuid()
uri = "/v2/queues/{0}/messages/{1}".format(queue_name, id)
self.client.auth_provider.set_alt_auth_data(
request_part='headers',
@ -95,8 +95,8 @@ class TestMessagesNegative(base.BaseV2MessagingTest):
@decorators.idempotent_id('f544e745-f3da-451d-8621-c3711cd37453')
def test_request_multiple_messages_from_a_nonexistent_queue(self):
# List multiple messages from a non existent queue
id1 = str(uuid.uuid4())
id2 = str(uuid.uuid4())
id1 = uuidutils.generate_uuid()
id2 = uuidutils.generate_uuid()
queue = data_utils.rand_name('nonexistent_queue')
uri = "/v2/queues/{0}/messages?ids={1},{2}".format(queue,
id1, id2)
@ -107,7 +107,7 @@ class TestMessagesNegative(base.BaseV2MessagingTest):
@decorators.idempotent_id('654e64f8-01df-40a0-a09e-d5ec17a3e187')
def test_request_multiple_messages_with_invalid_message_id(self):
# List multiple messages by passing invalid id
invalid_id = str(uuid.uuid4())
invalid_id = uuidutils.generate_uuid()
queue_name = self.queues[data_utils.rand_int_id(0,
len(self.queues) - 1)]
uri = "/v2/queues/{0}/messages?ids={1},{2}".format(queue_name,
@ -122,7 +122,7 @@ class TestMessagesNegative(base.BaseV2MessagingTest):
# Default limit value is 20 , configurable
queue_name = self.queues[data_utils.rand_int_id(0,
len(self.queues) - 1)]
ids = str.join(',', (str(uuid.uuid4())) * 21)
ids = str.join(',', (uuidutils.generate_uuid()) * 21)
uri = "/v2/queues/{0}/messages?ids={1}".format(queue_name, ids)
self.assertRaises(lib_exc.BadRequest,
self.client.show_multiple_messages, uri)
@ -180,8 +180,8 @@ class TestMessagesNegative(base.BaseV2MessagingTest):
# List messages without a valid token
queue_name = self.queues[data_utils.rand_int_id(0,
len(self.queues) - 1)]
id1 = str(uuid.uuid4())
id2 = str(uuid.uuid4())
id1 = uuidutils.generate_uuid()
id2 = uuidutils.generate_uuid()
uri = "/v2/queues/{0}/messages/{1},{2}".format(queue_name, id1, id2)
self.client.auth_provider.set_alt_auth_data(
request_part='headers',
@ -440,7 +440,7 @@ class TestMessagesNegative(base.BaseV2MessagingTest):
def test_delete_message_from_a_nonexistent_queue(self):
# Delete is an idempotent operation
non_existent_queue = data_utils.rand_name('rand_queuename')
message_id = str(uuid.uuid4())
message_id = uuidutils.generate_uuid()
uri = "/v2/queues/{0}/messages?ids={1}".format(non_existent_queue,
message_id)
resp, _ = self.client.delete_messages(uri)
@ -452,7 +452,7 @@ class TestMessagesNegative(base.BaseV2MessagingTest):
# Delete is an idempotent operation
queue_name = self.queues[data_utils.rand_int_id(0,
len(self.queues) - 1)]
message_id = str(uuid.uuid4())
message_id = uuidutils.generate_uuid()
uri = "/v2/queues/{0}/messages?ids={1}".format(queue_name,
message_id)
resp, _ = self.client.delete_messages(uri)
@ -464,7 +464,7 @@ class TestMessagesNegative(base.BaseV2MessagingTest):
# Delete is an idempotent operation
queue_name = self.queues[data_utils.rand_int_id(0,
len(self.queues) - 1)]
message_id = str(uuid.uuid4())
message_id = uuidutils.generate_uuid()
uri = "/v2/queues/{0}/messages/{1}".format(queue_name,
message_id)
resp, _ = self.client.delete_messages(uri)
@ -476,9 +476,9 @@ class TestMessagesNegative(base.BaseV2MessagingTest):
# Delete is an idempotent operation
queue_name = self.queues[data_utils.rand_int_id(0,
len(self.queues) - 1)]
id1 = str(uuid.uuid4())
id2 = str(uuid.uuid4())
id3 = str(uuid.uuid4())
id1 = uuidutils.generate_uuid()
id2 = uuidutils.generate_uuid()
id3 = uuidutils.generate_uuid()
uri = "/v2/queues/{0}/messages?ids={1}{2}{3}".format(queue_name,
id1, id2, id3)
resp, _ = self.client.delete_messages(uri)
@ -504,7 +504,7 @@ class TestMessagesNegative(base.BaseV2MessagingTest):
# Delete a message with negative id
queue_name = self.queues[data_utils.rand_int_id(0,
len(self.queues) - 1)]
message_id = str(uuid.uuid4())
message_id = uuidutils.generate_uuid()
uri = "/v2/queues/{0}/messages?ids=-{1}".format(queue_name,
message_id)
resp, _ = self.client.delete_messages(uri)
@ -516,7 +516,7 @@ class TestMessagesNegative(base.BaseV2MessagingTest):
# Delete is an idempotent operation
queue_name = self.queues[data_utils.rand_int_id(0,
len(self.queues) - 1)]
message_id = str(uuid.uuid4())
message_id = uuidutils.generate_uuid()
uri = "/v2/queues/{0}/messages?ids={1}".format(queue_name,
message_id)
resp, _ = self.client.delete_messages(uri)
@ -530,7 +530,7 @@ class TestMessagesNegative(base.BaseV2MessagingTest):
# Default limit value is 20
queue_name = self.queues[data_utils.rand_int_id(0,
len(self.queues) - 1)]
ids = str.join(',', (str(uuid.uuid4())) * 21)
ids = str.join(',', (uuidutils.generate_uuid()) * 21)
uri = "/v2/queues/{0}/messages?ids={1}".format(queue_name, ids)
self.assertRaises(lib_exc.BadRequest,
self.client.delete_messages, uri)
@ -616,7 +616,7 @@ class TestMessagesNegative(base.BaseV2MessagingTest):
queue_name = self.queues[data_utils.rand_int_id(0,
len(self.queues) - 1)]
pop_value = 5
ids_value = str(uuid.uuid4())
ids_value = uuidutils.generate_uuid()
uri = "/v2/queues/{0}/messages?pop={1}&ids={2}".format(queue_name,
pop_value,
ids_value)

View File

@ -14,8 +14,8 @@
# limitations under the License.
import json
import uuid
from oslo_utils import uuidutils
from tempest.lib.common.utils import data_utils
from tempest.lib.common.utils import test_utils
from tempest.lib import decorators
@ -125,7 +125,7 @@ class TestSubscriptions(base.BaseV2MessagingTest):
post_body = json.dumps(
{'messages': [{'body': '$zaqar_message$', 'ttl': 60}]})
post_headers = {'X-Project-ID': self.client.tenant_id,
'Client-ID': str(uuid.uuid4())}
'Client-ID': uuidutils.generate_uuid()}
sub_body = {'ttl': 1200, 'subscriber': subscriber,
'options': {'post_data': post_body,
'post_headers': post_headers}}

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import uuid
from oslo_utils import uuidutils
from tempest import config
from tempest.lib.common.utils import data_utils
@ -251,7 +251,7 @@ class TestSubscriptionsNegative(base.BaseV2MessagingTest):
def test_update_subscription_with_invalid_id(self):
# Update subscription using invalid id
results = self._create_subscriptions()
subscription_id = str(uuid.uuid4())
subscription_id = uuidutils.generate_uuid()
update_rbody = {'ttl': 100}
self.assertRaises(lib_exc.NotFound,
self.client.update_subscription, self.queue_name,
@ -341,7 +341,7 @@ class TestSubscriptionsNegative(base.BaseV2MessagingTest):
def test_delete_subscription_using_a_nonexisting_id(self):
# Delete subscription with non existent id
results = self._create_subscriptions()
subscription_id = str(uuid.uuid4())
subscription_id = uuidutils.generate_uuid()
resp, _ = self.client.delete_subscription(self.queue_name,
subscription_id)
self.assertEqual('204', resp['status'])