Replaces uuid.uuid4 with uuidutils.generate_uuid()

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

Change-Id: Ic6045a3b8dabedf3ecaa14d94707614fc4d454e4
Closes-Bug: #1082248
This commit is contained in:
Luong Anh Tuan 2016-12-05 16:20:23 +07:00 committed by Tuan Luong-Anh
parent 9388fd1d89
commit d77aa05049
7 changed files with 23 additions and 26 deletions

View File

@ -12,7 +12,6 @@
import os
import time
import uuid
from cinderclient.v2 import client as cinderclient
import fixtures
@ -23,7 +22,7 @@ from keystoneauth1 import session as ksession
from keystoneclient import client as keystoneclient
from keystoneclient import discover as keystone_discover
import os_client_config
import six
from oslo_utils import uuidutils
import tempest.lib.cli.base
import testtools
@ -380,7 +379,7 @@ class ClientTestBase(testtools.TestCase):
:param prefix: string prefix
"""
name = "%s-%s" % (prefix, six.text_type(uuid.uuid4()))
name = "%s-%s" % (prefix, uuidutils.generate_uuid())
return name
def _get_value_from_the_table(self, table, key):

View File

@ -11,8 +11,8 @@
# under the License.
import tempfile
import uuid
from oslo_utils import uuidutils
from tempest.lib import exceptions
from novaclient.tests.functional import base
@ -36,7 +36,7 @@ class TestKeypairsNovaClient(base.ClientTestBase):
return key_name
def _raw_create_keypair(self, **kwargs):
key_name = 'keypair-' + str(uuid.uuid4())
key_name = 'keypair-' + uuidutils.generate_uuid()
kwargs_str = self._serialize_kwargs(kwargs)
self.nova('keypair-add %s %s' % (kwargs_str, key_name))
return key_name

View File

@ -11,7 +11,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import uuid
from oslo_utils import uuidutils
from novaclient.tests.functional import base
@ -22,7 +22,7 @@ class TestServerGroupClient(base.ClientTestBase):
COMPUTE_API_VERSION = "2.1"
def _create_sg(self, policy):
sg_name = 'server_group-' + str(uuid.uuid4())
sg_name = 'server_group-' + uuidutils.generate_uuid()
output = self.nova('server-group-create %s %s' % (sg_name, policy))
sg_id = self._get_column_value_from_single_row_table(output, "Id")
return sg_id

View File

@ -11,9 +11,9 @@
# under the License.
import datetime
import uuid
from oslo_utils import timeutils
from oslo_utils import uuidutils
from novaclient.tests.functional import base
@ -25,7 +25,7 @@ class TestServersBootNovaClient(base.ClientTestBase):
def _boot_server_with_legacy_bdm(self, bdm_params=()):
volume_size = 1
volume_name = str(uuid.uuid4())
volume_name = uuidutils.generate_uuid()
volume = self.cinder.volumes.create(size=volume_size,
name=volume_name,
imageRef=self.image.id)
@ -38,7 +38,7 @@ class TestServersBootNovaClient(base.ClientTestBase):
server_info = self.nova("boot", params=(
"%(name)s --flavor %(flavor)s --poll "
"--block-device-mapping vda=%(volume_id)s%(bdm_params)s" % {
"name": str(uuid.uuid4()), "flavor":
"name": uuidutils.generate_uuid(), "flavor":
self.flavor.id,
"volume_id": volume.id,
"bdm_params": bdm_params}))
@ -60,7 +60,7 @@ class TestServersBootNovaClient(base.ClientTestBase):
def test_boot_server_with_net_name(self):
server_info = self.nova("boot", params=(
"%(name)s --flavor %(flavor)s --image %(image)s --poll "
"--nic net-name=%(net-name)s" % {"name": str(uuid.uuid4()),
"--nic net-name=%(net-name)s" % {"name": uuidutils.generate_uuid(),
"image": self.image.id,
"flavor": self.flavor.id,
"net-name": self.network.label}))
@ -79,7 +79,7 @@ class TestServersListNovaClient(base.ClientTestBase):
return [self._create_server(name) for i in range(number)]
def test_list_with_limit(self):
name = str(uuid.uuid4())
name = uuidutils.generate_uuid()
self._create_servers(name, 2)
output = self.nova("list", params="--limit 1 --name %s" % name)
# Cut header and footer of the table
@ -88,7 +88,7 @@ class TestServersListNovaClient(base.ClientTestBase):
def test_list_with_changes_since(self):
now = datetime.datetime.isoformat(timeutils.utcnow())
name = str(uuid.uuid4())
name = uuidutils.generate_uuid()
self._create_servers(name, 1)
output = self.nova("list", params="--changes-since %s" % now)
self.assertIn(name, output, output)
@ -97,7 +97,7 @@ class TestServersListNovaClient(base.ClientTestBase):
self.assertNotIn(name, output, output)
def test_list_all_servers(self):
name = str(uuid.uuid4())
name = uuidutils.generate_uuid()
precreated_servers = self._create_servers(name, 3)
# there are no possibility to exceed the limit on API side, so just
# check that "-1" limit processes by novaclient side

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import uuid
from oslo_utils import uuidutils
from novaclient.tests.functional import base
@ -27,7 +27,7 @@ class TestDeviceTaggingCLI(base.ClientTestBase):
'--nic net-id=%(net-uuid)s,tag=foo '
'--block-device '
'source=image,dest=volume,id=%(image)s,size=1,'
'bootindex=0,tag=bar' % {'name': str(uuid.uuid4()),
'bootindex=0,tag=bar' % {'name': uuidutils.generate_uuid(),
'flavor': self.flavor.id,
'net-uuid': self.network.id,
'image': self.image.id}))

View File

@ -10,8 +10,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import uuid
from oslo_utils import uuidutils
import six
from tempest.lib import exceptions
@ -31,13 +30,13 @@ class TestInstanceActionCLI(base.ClientTestBase):
self.fail("%s is not failed on non existing instance." % cmd)
def test_show_action_with_not_existing_instance(self):
name_or_uuid = str(uuid.uuid4())
request_id = str(uuid.uuid4())
name_or_uuid = uuidutils.generate_uuid()
request_id = uuidutils.generate_uuid()
self._test_cmd_with_not_existing_instance(
"instance-action", "%s %s" % (name_or_uuid, request_id))
def test_list_actions_with_not_existing_instance(self):
name_or_uuid = str(uuid.uuid4())
name_or_uuid = uuidutils.generate_uuid()
self._test_cmd_with_not_existing_instance("instance-action-list",
name_or_uuid)

View File

@ -10,9 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import uuid
from keystoneauth1 import session
from oslo_utils import uuidutils
from novaclient import api_versions
from novaclient.tests.unit import utils
@ -23,8 +22,8 @@ class ClientTest(utils.TestCase):
def test_adapter_properties(self):
# sample of properties, there are many more
user_agent = uuid.uuid4().hex
endpoint_override = uuid.uuid4().hex
user_agent = uuidutils.generate_uuid(dashed=False)
endpoint_override = uuidutils.generate_uuid(dashed=False)
s = session.Session()
c = client.Client(session=s,
@ -37,7 +36,7 @@ class ClientTest(utils.TestCase):
self.assertEqual(endpoint_override, c.client.endpoint_override)
def test_passing_endpoint_type(self):
endpoint_type = uuid.uuid4().hex
endpoint_type = uuidutils.generate_uuid(dashed=False)
s = session.Session()
c = client.Client(session=s,