Add generate_random_security_group_id in BaseSecurityGroupsTest
This is to add generate_random_security_group_id in BaseSecurityGroupsTest,
so that all security_group tests can use it.
Besides, currently there are two functions which are used to generate
not_existing_id(_generate_a_non_existent_security_group_id and
not_existing_id), because generally speaking, rand_uuid or rand_int_id
can seldom be same, so we can use the simple way to generate
not_existing_id.
Change-Id: Ib6118c74ac080b3fdd7f1e77ac37f24792793d57
diff --git a/tempest/api/compute/security_groups/base.py b/tempest/api/compute/security_groups/base.py
index f70f6d3..cb18775 100644
--- a/tempest/api/compute/security_groups/base.py
+++ b/tempest/api/compute/security_groups/base.py
@@ -14,6 +14,11 @@
# under the License.
from tempest.api.compute import base
+from tempest.common.utils import data_utils
+from tempest import config
+from tempest import test
+
+CONF = config.CONF
class BaseSecurityGroupsTest(base.BaseV2ComputeTest):
@@ -23,3 +28,11 @@
# A network and a subnet will be created for these tests
cls.set_network_resources(network=True, subnet=True)
super(BaseSecurityGroupsTest, cls).setup_credentials()
+
+ @staticmethod
+ def generate_random_security_group_id():
+ if (CONF.service_available.neutron and
+ test.is_extension_enabled('security-group', 'network')):
+ return data_utils.rand_uuid()
+ else:
+ return data_utils.rand_int_id(start=999)
diff --git a/tempest/api/compute/security_groups/test_security_group_rules_negative.py b/tempest/api/compute/security_groups/test_security_group_rules_negative.py
index 32b3ea3..78c19ca 100644
--- a/tempest/api/compute/security_groups/test_security_group_rules_negative.py
+++ b/tempest/api/compute/security_groups/test_security_group_rules_negative.py
@@ -15,20 +15,9 @@
from tempest.api.compute.security_groups import base
from tempest.common.utils import data_utils
-from tempest import config
from tempest.lib import exceptions as lib_exc
from tempest import test
-CONF = config.CONF
-
-
-def not_existing_id():
- if (CONF.service_available.neutron and
- test.is_extension_enabled('security-group', 'network')):
- return data_utils.rand_uuid()
- else:
- return data_utils.rand_int_id(start=999)
-
class SecurityGroupRulesNegativeTestJSON(base.BaseSecurityGroupsTest):
@@ -44,7 +33,7 @@
# Negative test: Creation of Security Group rule should FAIL
# with non existent Parent group id
# Adding rules to the non existent Security Group id
- parent_group_id = not_existing_id()
+ parent_group_id = self.generate_random_security_group_id()
ip_protocol = 'tcp'
from_port = 22
to_port = 22
@@ -179,7 +168,7 @@
def test_delete_security_group_rule_with_non_existent_id(self):
# Negative test: Deletion of Security Group rule should be FAIL
# with non existent id
- non_existent_rule_id = not_existing_id()
+ non_existent_rule_id = self.generate_random_security_group_id()
self.assertRaises(lib_exc.NotFound,
self.rules_client.delete_security_group_rule,
non_existent_rule_id)
diff --git a/tempest/api/compute/security_groups/test_security_groups_negative.py b/tempest/api/compute/security_groups/test_security_groups_negative.py
index e6abf28..bcada1e 100644
--- a/tempest/api/compute/security_groups/test_security_groups_negative.py
+++ b/tempest/api/compute/security_groups/test_security_groups_negative.py
@@ -37,29 +37,13 @@
super(SecurityGroupsNegativeTestJSON, cls).resource_setup()
cls.neutron_available = CONF.service_available.neutron
- def _generate_a_non_existent_security_group_id(self):
- security_group_id = []
- body = self.client.list_security_groups()['security_groups']
- for i in range(len(body)):
- security_group_id.append(body[i]['id'])
- # Generate a non-existent security group id
- while True:
- if (self.neutron_available and
- test.is_extension_enabled('security-group', 'network')):
- non_exist_id = data_utils.rand_uuid()
- else:
- non_exist_id = data_utils.rand_int_id(start=999)
- if non_exist_id not in security_group_id:
- break
- return non_exist_id
-
@test.attr(type=['negative'])
@test.idempotent_id('673eaec1-9b3e-48ed-bdf1-2786c1b9661c')
@test.services('network')
def test_security_group_get_nonexistent_group(self):
# Negative test:Should not be able to GET the details
# of non-existent Security Group
- non_exist_id = self._generate_a_non_existent_security_group_id()
+ non_exist_id = self.generate_random_security_group_id()
self.assertRaises(lib_exc.NotFound, self.client.show_security_group,
non_exist_id)
@@ -139,7 +123,7 @@
@test.services('network')
def test_delete_nonexistent_security_group(self):
# Negative test:Deletion of a non-existent Security Group should fail
- non_exist_id = self._generate_a_non_existent_security_group_id()
+ non_exist_id = self.generate_random_security_group_id()
self.assertRaises(lib_exc.NotFound,
self.client.delete_security_group, non_exist_id)
@@ -204,7 +188,7 @@
@test.services('network')
def test_update_non_existent_security_group(self):
# Update a non-existent Security Group should Fail
- non_exist_id = self._generate_a_non_existent_security_group_id()
+ non_exist_id = self.generate_random_security_group_id()
s_name = data_utils.rand_name('sg')
s_description = data_utils.rand_name('description')
self.assertRaises(lib_exc.NotFound,