Replaces uuid.uuid4 with uuidutils.generate_uuid()

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

Change-Id: I03a683f02ef0bb98afce2c91d4186ce63522dbeb
This commit is contained in:
liangcui 2017-03-24 16:06:18 +08:00
parent 2bd049d1af
commit d1798c92f8
10 changed files with 30 additions and 30 deletions

View File

@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from uuid import uuid4
from oslo_serialization import jsonutils as json
from oslo_utils import uuidutils
from tempest import config
from tempest.lib.common.utils import data_utils
import tempest.test
@ -50,7 +50,7 @@ class BaseAlmanachTest(tempest.test.BaseTestCase):
@staticmethod
def get_server_creation_payload():
server = {'id': str(uuid4()),
server = {'id': uuidutils.generate_uuid(),
'created_at': '2016-01-01T18:30:00Z',
'name': 'api_test_instance_create',
'flavor': 'api_flavor',
@ -61,7 +61,7 @@ class BaseAlmanachTest(tempest.test.BaseTestCase):
@staticmethod
def get_volume_creation_payload(volume_type_name):
return {'volume_id': str(uuid4()),
return {'volume_id': uuidutils.generate_uuid(),
'attached_to': [],
'volume_name': 'a-test-volume',
'volume_type': volume_type_name,
@ -69,14 +69,14 @@ class BaseAlmanachTest(tempest.test.BaseTestCase):
'size': 100}
def create_volume_type(self):
volume_type = {'type_id': str(uuid4()),
volume_type = {'type_id': uuidutils.generate_uuid(),
'type_name': data_utils.rand_name('scenario-volume-type')}
volume_type_body = json.dumps(volume_type)
return volume_type, self.almanach_client.create_volume_type(volume_type_body)
def create_volume(self):
volume_type, _ = self.create_volume_type()
tenant_id = str(uuid4())
tenant_id = uuidutils.generate_uuid()
volume = self.get_volume_creation_payload(volume_type['type_id'])
resp, response_body = self.almanach_client.create_volume(tenant_id, json.dumps(volume))
return resp, tenant_id, volume

View File

@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from uuid import uuid4
from oslo_serialization import jsonutils as json
from oslo_utils import uuidutils
from tempest.lib import exceptions
from almanach.tests.tempest.tests.api import base
@ -25,7 +25,7 @@ class TestServerCreation(base.BaseAlmanachTest):
def setUp(self):
super(base.BaseAlmanachTest, self).setUp()
self.tenant_id = str(uuid4())
self.tenant_id = uuidutils.generate_uuid()
@classmethod
def resource_setup(cls):

View File

@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from uuid import uuid4
from oslo_serialization import jsonutils as json
from oslo_utils import uuidutils
from almanach.tests.tempest.tests.api import base
@ -29,7 +29,7 @@ class TestServerDeletion(base.BaseAlmanachTest):
super(TestServerDeletion, cls).resource_setup()
def test_instance_delete(self):
tenant_id = str(uuid4())
tenant_id = uuidutils.generate_uuid()
server = self.get_server_creation_payload()
self.create_server_through_api(tenant_id, server)

View File

@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from uuid import uuid4
from oslo_serialization import jsonutils as json
from oslo_utils import uuidutils
from almanach.tests.tempest.tests.api import base
@ -29,7 +29,7 @@ class TestServerRebuild(base.BaseAlmanachTest):
super(TestServerRebuild, cls).resource_setup()
def test_server_rebuild(self):
tenant_id = str(uuid4())
tenant_id = uuidutils.generate_uuid()
server = self.get_server_creation_payload()
self.create_server_through_api(tenant_id, server)

View File

@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from uuid import uuid4
from oslo_serialization import jsonutils as json
from oslo_utils import uuidutils
from almanach.tests.tempest.tests.api import base
@ -29,7 +29,7 @@ class TestServerResize(base.BaseAlmanachTest):
super(TestServerResize, cls).resource_setup()
def test_instance_resize(self):
tenant_id = str(uuid4())
tenant_id = uuidutils.generate_uuid()
server = self.get_server_creation_payload()
self.create_server_through_api(tenant_id, server)

View File

@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from uuid import uuid4
from oslo_serialization import jsonutils as json
from oslo_utils import uuidutils
from almanach.tests.tempest.tests.api import base
@ -30,7 +30,7 @@ class TestServerUpdate(base.BaseAlmanachTest):
def test_instance_update(self):
server = self.get_server_creation_payload()
self.create_server_through_api(str(uuid4()), server)
self.create_server_through_api(uuidutils.generate_uuid(), server)
update_field = json.dumps({'start_date': '2016-04-14T18:30:00.00Z',
'flavor': 'NewFlavor'})

View File

@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from uuid import uuid4
from oslo_serialization import jsonutils as json
from oslo_utils import uuidutils
from almanach.tests.tempest.tests.api import base
@ -29,7 +29,7 @@ class TestVolumeAttach(base.BaseAlmanachTest):
resp, tenant_id, volume = self.create_volume()
self.assertEqual(resp.status, 201)
attached_to_id = str(uuid4())
attached_to_id = uuidutils.generate_uuid()
attach_data = {'date': '2016-01-01T18:40:00Z', 'attachments': [attached_to_id]}
resp, _ = self.almanach_client.attach_volume(volume['volume_id'], json.dumps(attach_data))
self.assertEqual(resp.status, 200)

View File

@ -12,9 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from uuid import uuid4
from oslo_serialization import jsonutils as json
from oslo_utils import uuidutils
from almanach.tests.tempest.tests.api import base
@ -29,7 +29,7 @@ class TestVolumeDetach(base.BaseAlmanachTest):
resp, tenant_id, volume = self.create_volume()
self.assertEqual(resp.status, 201)
attached_to_id = str(uuid4())
attached_to_id = uuidutils.generate_uuid()
date = '2016-01-01 18:30:00+00:00'
attach_data = {'date': '2016-01-01T18:30:00Z', 'attachments': [attached_to_id]}
resp, _ = self.almanach_client.attach_volume(volume['volume_id'], json.dumps(attach_data))

View File

@ -12,10 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from uuid import uuid4
from almanach.core import exception
from almanach.tests.unit.api.v1 import base_api
from oslo_utils import uuidutils
class TestApiVolume(base_api.BaseApi):
@ -180,7 +180,7 @@ class TestApiVolume(base_api.BaseApi):
def test_successful_volume_attach(self):
data = dict(date="UPDATED_AT",
attachments=[str(uuid4())])
attachments=[uuidutils.generate_uuid()])
code, result = self.api_put('/volume/VOLUME_ID/attach', data=data, headers={'X-Auth-Token': 'some token value'})
@ -210,7 +210,7 @@ class TestApiVolume(base_api.BaseApi):
def test_volume_attach_bad_date_format_returns_bad_request_code(self):
self.volume_ctl.attach_volume.side_effect = exception.DateFormatException
data = dict(date="A_BAD_DATE",
attachments=[str(uuid4())])
attachments=[uuidutils.generate_uuid()])
code, result = self.api_put('/volume/VOLUME_ID/attach', data=data, headers={'X-Auth-Token': 'some token value'})
@ -228,7 +228,7 @@ class TestApiVolume(base_api.BaseApi):
def test_successful_volume_detach(self):
data = dict(date="UPDATED_AT",
attachments=[str(uuid4())])
attachments=[uuidutils.generate_uuid()])
code, result = self.api_put('/volume/VOLUME_ID/detach', data=data, headers={'X-Auth-Token': 'some token value'})
@ -254,7 +254,7 @@ class TestApiVolume(base_api.BaseApi):
def test_volume_detach_bad_date_format_returns_bad_request_code(self):
self.volume_ctl.detach_volume.side_effect = exception.DateFormatException
data = dict(date="A_BAD_DATE",
attachments=[str(uuid4())])
attachments=[uuidutils.generate_uuid()])
code, result = self.api_put('/volume/VOLUME_ID/detach', data=data, headers={'X-Auth-Token': 'some token value'})

View File

@ -14,7 +14,7 @@
from copy import copy
from datetime import datetime
from uuid import uuid4
from oslo_utils import uuidutils
import pytz
@ -117,8 +117,8 @@ class VolumeTypeBuilder(Builder):
def instance():
return EntityBuilder({
"entity_id": str(uuid4()),
"project_id": str(uuid4()),
"entity_id": uuidutils.generate_uuid(),
"project_id": uuidutils.generate_uuid(),
"start": datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
"end": None,
"last_event": datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
@ -139,8 +139,8 @@ def instance():
def volume():
return VolumeBuilder({
"entity_id": str(uuid4()),
"project_id": str(uuid4()),
"entity_id": uuidutils.generate_uuid(),
"project_id": uuidutils.generate_uuid(),
"start": datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
"end": None,
"last_event": datetime(2014, 1, 1, 0, 0, 0, 0, pytz.utc),
@ -154,7 +154,7 @@ def volume():
def volume_type():
return VolumeTypeBuilder({
"volume_type_id": str(uuid4()),
"volume_type_id": uuidutils.generate_uuid(),
"volume_type_name": "a_type_name"
})