Fix to use proper random values
In several tests, they need int values but use rand_name().
Especially, test_security_group_rules.py has a potentially bug.
And, when we will change the rand_name() to return string value, the
errors will occur in others.
So this commit fixes it and belows:
* just import the module instead of importing the function
* minor comment typo
Change-Id: Ic957c741b9ad3631d726dc6cfb5ecb9e0077a884
diff --git a/tempest/api/compute/floating_ips/test_floating_ips_actions.py b/tempest/api/compute/floating_ips/test_floating_ips_actions.py
index b747b46..a5a361e 100644
--- a/tempest/api/compute/floating_ips/test_floating_ips_actions.py
+++ b/tempest/api/compute/floating_ips/test_floating_ips_actions.py
@@ -15,8 +15,10 @@
# License for the specific language governing permissions and limitations
# under the License.
+import uuid
+
from tempest.api.compute import base
-from tempest.common.utils.data_utils import rand_name
+from tempest.common.utils import data_utils
from tempest import exceptions
from tempest.test import attr
@@ -46,7 +48,9 @@
for i in range(len(body)):
cls.floating_ip_ids.append(body[i]['id'])
while True:
- cls.non_exist_id = rand_name('999')
+ cls.non_exist_id = data_utils.rand_int_id(start=999)
+ if cls.config.service_available.neutron:
+ cls.non_exist_id = str(uuid.uuid4())
if cls.non_exist_id not in cls.floating_ip_ids:
break
diff --git a/tempest/api/compute/floating_ips/test_list_floating_ips.py b/tempest/api/compute/floating_ips/test_list_floating_ips.py
index 3c76069..fb9610a 100644
--- a/tempest/api/compute/floating_ips/test_list_floating_ips.py
+++ b/tempest/api/compute/floating_ips/test_list_floating_ips.py
@@ -15,8 +15,10 @@
# License for the specific language governing permissions and limitations
# under the License.
+import uuid
+
from tempest.api.compute import base
-from tempest.common.utils.data_utils import rand_name
+from tempest.common.utils import data_utils
from tempest import exceptions
from tempest.test import attr
@@ -87,7 +89,9 @@
floating_ip_id.append(body[i]['id'])
# Creating a non-existent floatingIP id
while True:
- non_exist_id = rand_name('999')
+ non_exist_id = data_utils.rand_int_id(start=999)
+ if self.config.service_available.neutron:
+ non_exist_id = str(uuid.uuid4())
if non_exist_id not in floating_ip_id:
break
self.assertRaises(exceptions.NotFound,
diff --git a/tempest/api/compute/security_groups/test_security_group_rules.py b/tempest/api/compute/security_groups/test_security_group_rules.py
index cbc0080..5faa9a4 100644
--- a/tempest/api/compute/security_groups/test_security_group_rules.py
+++ b/tempest/api/compute/security_groups/test_security_group_rules.py
@@ -16,7 +16,7 @@
# under the License.
from tempest.api.compute import base
-from tempest.common.utils.data_utils import rand_name
+from tempest.common.utils import data_utils
from tempest import config
from tempest import exceptions
from tempest.test import attr
@@ -36,8 +36,8 @@
# Positive test: Creation of Security Group rule
# should be successful
# Creating a Security Group to add rules to it
- s_name = rand_name('securitygroup-')
- s_description = rand_name('description-')
+ s_name = data_utils.rand_name('securitygroup-')
+ s_description = data_utils.rand_name('description-')
resp, securitygroup = \
self.client.create_security_group(s_name, s_description)
securitygroup_id = securitygroup['id']
@@ -63,15 +63,15 @@
secgroup1 = None
secgroup2 = None
# Creating a Security Group to add rules to it
- s_name = rand_name('securitygroup-')
- s_description = rand_name('description-')
+ s_name = data_utils.rand_name('securitygroup-')
+ s_description = data_utils.rand_name('description-')
resp, securitygroup = \
self.client.create_security_group(s_name, s_description)
secgroup1 = securitygroup['id']
self.addCleanup(self.client.delete_security_group, secgroup1)
# Creating a Security Group so as to assign group_id to the rule
- s_name2 = rand_name('securitygroup-')
- s_description2 = rand_name('description-')
+ s_name2 = data_utils.rand_name('securitygroup-')
+ s_description2 = data_utils.rand_name('description-')
resp, securitygroup = \
self.client.create_security_group(s_name2, s_description2)
secgroup2 = securitygroup['id']
@@ -100,7 +100,7 @@
# Negative test: Creation of Security Group rule should FAIL
# with invalid Parent group id
# Adding rules to the invalid Security Group id
- parent_group_id = rand_name('999')
+ parent_group_id = data_utils.rand_int_id(start=999)
ip_protocol = 'tcp'
from_port = 22
to_port = 22
@@ -113,13 +113,13 @@
# Negative test: Creation of Security Group rule should FAIL
# with invalid ip_protocol
# Creating a Security Group to add rule to it
- s_name = rand_name('securitygroup-')
- s_description = rand_name('description-')
+ s_name = data_utils.rand_name('securitygroup-')
+ s_description = data_utils.rand_name('description-')
resp, securitygroup = self.client.create_security_group(s_name,
s_description)
# Adding rules to the created Security Group
parent_group_id = securitygroup['id']
- ip_protocol = rand_name('999')
+ ip_protocol = data_utils.rand_name('999')
from_port = 22
to_port = 22
@@ -133,14 +133,14 @@
# Negative test: Creation of Security Group rule should FAIL
# with invalid from_port
# Creating a Security Group to add rule to it
- s_name = rand_name('securitygroup-')
- s_description = rand_name('description-')
+ s_name = data_utils.rand_name('securitygroup-')
+ s_description = data_utils.rand_name('description-')
resp, securitygroup = self.client.create_security_group(s_name,
s_description)
# Adding rules to the created Security Group
parent_group_id = securitygroup['id']
ip_protocol = 'tcp'
- from_port = rand_name('999')
+ from_port = data_utils.rand_int_id(start=999, end=65535)
to_port = 22
self.addCleanup(self.client.delete_security_group, securitygroup['id'])
self.assertRaises(exceptions.BadRequest,
@@ -150,17 +150,17 @@
@attr(type=['negative', 'gate'])
def test_security_group_rules_create_with_invalid_to_port(self):
# Negative test: Creation of Security Group rule should FAIL
- # with invalid from_port
+ # with invalid to_port
# Creating a Security Group to add rule to it
- s_name = rand_name('securitygroup-')
- s_description = rand_name('description-')
+ s_name = data_utils.rand_name('securitygroup-')
+ s_description = data_utils.rand_name('description-')
resp, securitygroup = self.client.create_security_group(s_name,
s_description)
# Adding rules to the created Security Group
parent_group_id = securitygroup['id']
ip_protocol = 'tcp'
from_port = 22
- to_port = rand_name('999')
+ to_port = data_utils.rand_int_id(start=65536)
self.addCleanup(self.client.delete_security_group, securitygroup['id'])
self.assertRaises(exceptions.BadRequest,
self.client.create_security_group_rule,
@@ -171,8 +171,8 @@
# Negative test: Creation of Security Group rule should FAIL
# with invalid port range.
# Creating a Security Group to add rule to it.
- s_name = rand_name('securitygroup-')
- s_description = rand_name('description-')
+ s_name = data_utils.rand_name('securitygroup-')
+ s_description = data_utils.rand_name('description-')
resp, securitygroup = self.client.create_security_group(s_name,
s_description)
# Adding a rule to the created Security Group
@@ -193,15 +193,15 @@
# with invalid rule id
self.assertRaises(exceptions.NotFound,
self.client.delete_security_group_rule,
- rand_name('999'))
+ data_utils.rand_int_id(start=999))
@attr(type='gate')
def test_security_group_rules_list(self):
# Positive test: Created Security Group rules should be
# in the list of all rules
# Creating a Security Group to add rules to it
- s_name = rand_name('securitygroup-')
- s_description = rand_name('description-')
+ s_name = data_utils.rand_name('securitygroup-')
+ s_description = data_utils.rand_name('description-')
resp, securitygroup = \
self.client.create_security_group(s_name, s_description)
securitygroup_id = securitygroup['id']
diff --git a/tempest/api/compute/security_groups/test_security_groups.py b/tempest/api/compute/security_groups/test_security_groups.py
index fba2f53..2d9c62d 100644
--- a/tempest/api/compute/security_groups/test_security_groups.py
+++ b/tempest/api/compute/security_groups/test_security_groups.py
@@ -18,7 +18,7 @@
import testtools
from tempest.api.compute import base
-from tempest.common.utils.data_utils import rand_name
+from tempest.common.utils import data_utils
from tempest import config
from tempest import exceptions
from tempest.test import attr
@@ -43,8 +43,8 @@
# Create 3 Security Groups
security_group_list = list()
for i in range(3):
- s_name = rand_name('securitygroup-')
- s_description = rand_name('description-')
+ s_name = data_utils.rand_name('securitygroup-')
+ s_description = data_utils.rand_name('description-')
resp, securitygroup = \
self.client.create_security_group(s_name, s_description)
self.assertEqual(200, resp.status)
@@ -68,8 +68,8 @@
@attr(type='gate')
def test_security_group_create_delete(self):
# Security Group should be created, verified and deleted
- s_name = rand_name('securitygroup-')
- s_description = rand_name('description-')
+ s_name = data_utils.rand_name('securitygroup-')
+ s_description = data_utils.rand_name('description-')
resp, securitygroup = \
self.client.create_security_group(s_name, s_description)
self.assertIn('id', securitygroup)
@@ -87,8 +87,8 @@
@attr(type='gate')
def test_security_group_create_get_delete(self):
# Security Group should be created, fetched and deleted
- s_name = rand_name('securitygroup-')
- s_description = rand_name('description-')
+ s_name = data_utils.rand_name('securitygroup-')
+ s_description = data_utils.rand_name('description-')
resp, securitygroup = \
self.client.create_security_group(s_name, s_description)
self.addCleanup(self._delete_security_group,
@@ -120,7 +120,7 @@
security_group_id.append(body[i]['id'])
# Creating a non-existent Security Group id
while True:
- non_exist_id = rand_name('999')
+ non_exist_id = data_utils.rand_int_id(start=999)
if non_exist_id not in security_group_id:
break
self.assertRaises(exceptions.NotFound, self.client.get_security_group,
@@ -132,7 +132,7 @@
def test_security_group_create_with_invalid_group_name(self):
# Negative test: Security Group should not be created with group name
# as an empty string/with white spaces/chars more than 255
- s_description = rand_name('description-')
+ s_description = data_utils.rand_name('description-')
# Create Security Group with empty string as group name
self.assertRaises(exceptions.BadRequest,
self.client.create_security_group, "", s_description)
@@ -152,7 +152,7 @@
def test_security_group_create_with_invalid_group_description(self):
# Negative test:Security Group should not be created with description
# as an empty string/with white spaces/chars more than 255
- s_name = rand_name('securitygroup-')
+ s_name = data_utils.rand_name('securitygroup-')
# Create Security Group with empty string as description
self.assertRaises(exceptions.BadRequest,
self.client.create_security_group, s_name, "")
@@ -171,8 +171,8 @@
def test_security_group_create_with_duplicate_name(self):
# Negative test:Security Group with duplicate name should not
# be created
- s_name = rand_name('securitygroup-')
- s_description = rand_name('description-')
+ s_name = data_utils.rand_name('securitygroup-')
+ s_description = data_utils.rand_name('description-')
resp, security_group =\
self.client.create_security_group(s_name, s_description)
self.assertEqual(200, resp.status)
@@ -209,7 +209,7 @@
security_group_id.append(body[i]['id'])
# Creating non-existent Security Group
while True:
- non_exist_id = rand_name('999')
+ non_exist_id = data_utils.rand_int_id(start=999)
if non_exist_id not in security_group_id:
break
self.assertRaises(exceptions.NotFound,
@@ -228,19 +228,19 @@
# and not deleted if the server is active.
# Create a couple security groups that we will use
# for the server resource this test creates
- sg_name = rand_name('sg')
- sg_desc = rand_name('sg-desc')
+ sg_name = data_utils.rand_name('sg')
+ sg_desc = data_utils.rand_name('sg-desc')
resp, sg = self.client.create_security_group(sg_name, sg_desc)
sg_id = sg['id']
- sg2_name = rand_name('sg')
- sg2_desc = rand_name('sg-desc')
+ sg2_name = data_utils.rand_name('sg')
+ sg2_desc = data_utils.rand_name('sg-desc')
resp, sg2 = self.client.create_security_group(sg2_name, sg2_desc)
sg2_id = sg2['id']
# Create server and add the security group created
# above to the server we just created
- server_name = rand_name('server')
+ server_name = data_utils.rand_name('server')
resp, server = self.servers_client.create_server(server_name,
self.image_ref,
self.flavor_ref)
diff --git a/tempest/api/compute/volumes/test_volumes_negative.py b/tempest/api/compute/volumes/test_volumes_negative.py
index 9ca1380..90e6946 100644
--- a/tempest/api/compute/volumes/test_volumes_negative.py
+++ b/tempest/api/compute/volumes/test_volumes_negative.py
@@ -15,8 +15,10 @@
# License for the specific language governing permissions and limitations
# under the License.
+import uuid
+
from tempest.api.compute import base
-from tempest.common.utils.data_utils import rand_name
+from tempest.common.utils import data_utils
from tempest import exceptions
from tempest.test import attr
@@ -36,39 +38,23 @@
def test_volume_get_nonexistant_volume_id(self):
# Negative: Should not be able to get details of nonexistant volume
# Creating a nonexistant volume id
- volume_id_list = list()
- resp, body = self.client.list_volumes()
- for i in range(len(body)):
- volume_id_list.append(body[i]['id'])
- while True:
- non_exist_id = rand_name('999')
- if non_exist_id not in volume_id_list:
- break
# Trying to GET a non existant volume
self.assertRaises(exceptions.NotFound, self.client.get_volume,
- non_exist_id)
+ str(uuid.uuid4()))
@attr(type=['negative', 'gate'])
def test_volume_delete_nonexistant_volume_id(self):
# Negative: Should not be able to delete nonexistant Volume
# Creating nonexistant volume id
- volume_id_list = list()
- resp, body = self.client.list_volumes()
- for i in range(len(body)):
- volume_id_list.append(body[i]['id'])
- while True:
- non_exist_id = rand_name('999')
- if non_exist_id not in volume_id_list:
- break
# Trying to DELETE a non existant volume
self.assertRaises(exceptions.NotFound, self.client.delete_volume,
- non_exist_id)
+ str(uuid.uuid4()))
@attr(type=['negative', 'gate'])
def test_create_volume_with_invalid_size(self):
# Negative: Should not be able to create volume with invalid size
# in request
- v_name = rand_name('Volume-')
+ v_name = data_utils.rand_name('Volume-')
metadata = {'Type': 'work'}
self.assertRaises(exceptions.BadRequest, self.client.create_volume,
size='#$%', display_name=v_name, metadata=metadata)
@@ -77,7 +63,7 @@
def test_create_volume_with_out_passing_size(self):
# Negative: Should not be able to create volume without passing size
# in request
- v_name = rand_name('Volume-')
+ v_name = data_utils.rand_name('Volume-')
metadata = {'Type': 'work'}
self.assertRaises(exceptions.BadRequest, self.client.create_volume,
size='', display_name=v_name, metadata=metadata)
@@ -85,7 +71,7 @@
@attr(type=['negative', 'gate'])
def test_create_volume_with_size_zero(self):
# Negative: Should not be able to create volume with size zero
- v_name = rand_name('Volume-')
+ v_name = data_utils.rand_name('Volume-')
metadata = {'Type': 'work'}
self.assertRaises(exceptions.BadRequest, self.client.create_volume,
size='0', display_name=v_name, metadata=metadata)
diff --git a/tempest/api/identity/admin/test_users.py b/tempest/api/identity/admin/test_users.py
index 66d35cb..906fad3 100644
--- a/tempest/api/identity/admin/test_users.py
+++ b/tempest/api/identity/admin/test_users.py
@@ -18,7 +18,7 @@
from testtools.matchers import Contains
from tempest.api.identity import base
-from tempest.common.utils.data_utils import rand_name
+from tempest.common.utils import data_utils
from tempest.test import attr
@@ -28,11 +28,11 @@
@classmethod
def setUpClass(cls):
super(UsersTestJSON, cls).setUpClass()
- cls.alt_user = rand_name('test_user_')
- cls.alt_password = rand_name('pass_')
+ cls.alt_user = data_utils.rand_name('test_user_')
+ cls.alt_password = data_utils.rand_name('pass_')
cls.alt_email = cls.alt_user + '@testmail.tm'
- cls.alt_tenant = rand_name('test_tenant_')
- cls.alt_description = rand_name('desc_')
+ cls.alt_tenant = data_utils.rand_name('test_tenant_')
+ cls.alt_description = data_utils.rand_name('desc_')
@attr(type='smoke')
def test_create_user(self):
@@ -49,7 +49,7 @@
def test_create_user_with_enabled(self):
# Create a user with enabled : False
self.data.setup_test_tenant()
- name = rand_name('test_user_')
+ name = data_utils.rand_name('test_user_')
resp, user = self.client.create_user(name, self.alt_password,
self.data.tenant['id'],
self.alt_email, enabled=False)
@@ -62,7 +62,7 @@
@attr(type='smoke')
def test_update_user(self):
# Test case to check if updating of user attributes is successful.
- test_user = rand_name('test_user_')
+ test_user = data_utils.rand_name('test_user_')
self.data.setup_test_tenant()
resp, user = self.client.create_user(test_user, self.alt_password,
self.data.tenant['id'],
@@ -70,7 +70,7 @@
# Delete the User at the end of this method
self.addCleanup(self.client.delete_user, user['id'])
# Updating user details with new values
- u_name2 = rand_name('user2-')
+ u_name2 = data_utils.rand_name('user2-')
u_email2 = u_name2 + '@testmail.tm'
resp, update_user = self.client.update_user(user['id'], name=u_name2,
email=u_email2,
@@ -90,7 +90,7 @@
@attr(type='smoke')
def test_delete_user(self):
# Delete a user
- test_user = rand_name('test_user_')
+ test_user = data_utils.rand_name('test_user_')
self.data.setup_test_tenant()
resp, user = self.client.create_user(test_user, self.alt_password,
self.data.tenant['id'],
@@ -144,7 +144,7 @@
self.data.setup_test_tenant()
user_ids = list()
fetched_user_ids = list()
- alt_tenant_user1 = rand_name('tenant_user1_')
+ alt_tenant_user1 = data_utils.rand_name('tenant_user1_')
resp, user1 = self.client.create_user(alt_tenant_user1, 'password1',
self.data.tenant['id'],
'user1@123')
@@ -152,7 +152,7 @@
user_ids.append(user1['id'])
self.data.users.append(user1)
- alt_tenant_user2 = rand_name('tenant_user2_')
+ alt_tenant_user2 = data_utils.rand_name('tenant_user2_')
resp, user2 = self.client.create_user(alt_tenant_user2, 'password2',
self.data.tenant['id'],
'user2@123')
@@ -187,7 +187,7 @@
role['id'])
self.assertEqual('200', resp['status'])
- alt_user2 = rand_name('second_user_')
+ alt_user2 = data_utils.rand_name('second_user_')
resp, second_user = self.client.create_user(alt_user2, 'password1',
self.data.tenant['id'],
'user2@123')