Use shared values for test_security_group_rules
In test_security_group_rules, most created security group rules are
the same. This patch adds shared values and makes these tests use
them for cleanup.
Change-Id: Ie86c33217fc6b065844e31f9b6e37be93322f2cb
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 b28124c..901c377 100644
--- a/tempest/api/compute/security_groups/test_security_group_rules.py
+++ b/tempest/api/compute/security_groups/test_security_group_rules.py
@@ -28,6 +28,13 @@
cls.client = cls.security_groups_client
cls.neutron_available = CONF.service_available.neutron
+ @classmethod
+ def setUpClass(self):
+ super(SecurityGroupRulesTestJSON, self).setUpClass()
+ self.ip_protocol = 'tcp'
+ self.from_port = 22
+ self.to_port = 22
+
@test.attr(type='smoke')
@test.services('network')
def test_security_group_rules_create(self):
@@ -37,14 +44,11 @@
resp, security_group = self.create_security_group()
securitygroup_id = security_group['id']
# Adding rules to the created Security Group
- ip_protocol = 'tcp'
- from_port = 22
- to_port = 22
resp, rule = \
self.client.create_security_group_rule(securitygroup_id,
- ip_protocol,
- from_port,
- to_port)
+ self.ip_protocol,
+ self.from_port,
+ self.to_port)
self.addCleanup(self.client.delete_security_group_rule, rule['id'])
self.assertEqual(200, resp.status)
@@ -65,16 +69,13 @@
secgroup2 = security_group['id']
# Adding rules to the created Security Group with optional arguments
parent_group_id = secgroup1
- ip_protocol = 'tcp'
- from_port = 22
- to_port = 22
cidr = '10.2.3.124/24'
group_id = secgroup2
resp, rule = \
self.client.create_security_group_rule(parent_group_id,
- ip_protocol,
- from_port,
- to_port,
+ self.ip_protocol,
+ self.from_port,
+ self.to_port,
cidr=cidr,
group_id=group_id)
self.assertEqual(200, resp.status)
@@ -89,13 +90,11 @@
securitygroup_id = security_group['id']
# Add a first rule to the created Security Group
- ip_protocol1 = 'tcp'
- from_port1 = 22
- to_port1 = 22
resp, rule = \
self.client.create_security_group_rule(securitygroup_id,
- ip_protocol1,
- from_port1, to_port1)
+ self.ip_protocol,
+ self.from_port,
+ self.to_port)
rule1_id = rule['id']
# Add a second rule to the created Security Group
@@ -127,14 +126,11 @@
resp, security_group = self.create_security_group()
sg2_id = security_group['id']
# Adding rules to the Group1
- ip_protocol = 'tcp'
- from_port = 22
- to_port = 22
resp, rule = \
self.client.create_security_group_rule(sg1_id,
- ip_protocol,
- from_port,
- to_port,
+ self.ip_protocol,
+ self.from_port,
+ self.to_port,
group_id=sg2_id)
self.assertEqual(200, resp.status)