Merge "Adding test_security_group_rules_create_with_invalid_port_range"
diff --git a/tempest/tests/compute/security_groups/test_security_group_rules.py b/tempest/tests/compute/security_groups/test_security_group_rules.py
index 32ac52b..dc85f4b 100644
--- a/tempest/tests/compute/security_groups/test_security_group_rules.py
+++ b/tempest/tests/compute/security_groups/test_security_group_rules.py
@@ -37,18 +37,19 @@
#Creating a Security Group to add rules to it
s_name = rand_name('securitygroup-')
s_description = rand_name('description-')
- resp, securitygroup =\
- self.client.create_security_group(s_name, s_description)
+ resp, securitygroup = \
+ self.client.create_security_group(s_name, s_description)
securitygroup_id = securitygroup['id']
#Adding rules to the created Security Group
parent_group_id = securitygroup['id']
ip_protocol = 'tcp'
from_port = 22
to_port = 22
- resp, rule =\
- self.client.create_security_group_rule(parent_group_id,
- ip_protocol, from_port,
- to_port)
+ resp, rule = \
+ self.client.create_security_group_rule(parent_group_id,
+ ip_protocol,
+ from_port,
+ to_port)
self.assertEqual(200, resp.status)
finally:
#Deleting the Security Group rule, created in this method
@@ -70,14 +71,14 @@
#Creating a Security Group to add rules to it
s_name = rand_name('securitygroup-')
s_description = rand_name('description-')
- resp, securitygroup =\
- self.client.create_security_group(s_name, s_description)
+ resp, securitygroup = \
+ self.client.create_security_group(s_name, s_description)
secgroup1 = securitygroup['id']
#Creating a Security Group so as to assign group_id to the rule
s_name2 = rand_name('securitygroup-')
s_description2 = rand_name('description-')
- resp, securitygroup =\
- self.client.create_security_group(s_name2, s_description2)
+ resp, securitygroup = \
+ self.client.create_security_group(s_name2, s_description2)
secgroup2 = securitygroup['id']
#Adding rules to the created Security Group with optional arguments
parent_group_id = secgroup1
@@ -86,12 +87,13 @@
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,
- cidr=cidr,
- group_id=group_id)
+ resp, rule = \
+ self.client.create_security_group_rule(parent_group_id,
+ ip_protocol,
+ from_port,
+ to_port,
+ cidr=cidr,
+ group_id=group_id)
rule_id = rule['id']
self.assertEqual(200, resp.status)
finally:
@@ -112,18 +114,19 @@
#Creating a Security Group to add rule to it
s_name = rand_name('securitygroup-')
s_description = rand_name('description-')
- resp, securitygroup =\
- self.client.create_security_group(s_name, s_description)
+ resp, securitygroup = \
+ self.client.create_security_group(s_name, s_description)
securitygroup_id = securitygroup['id']
#Adding rules to the created Security Group
parent_group_id = securitygroup['id']
ip_protocol = 'tcp'
from_port = 22
to_port = 22
- resp, rule =\
- self.client.create_security_group_rule(parent_group_id,
- ip_protocol,
- from_port, to_port)
+ resp, rule = \
+ self.client.create_security_group_rule(parent_group_id,
+ ip_protocol,
+ from_port,
+ to_port)
finally:
#Deleting the Security Group rule, created in this method
group_rule_id = rule['id']
@@ -203,6 +206,25 @@
parent_group_id, ip_protocol, from_port, to_port)
@attr(type='negative')
+ def test_security_group_rules_create_with_invalid_port_range(self):
+ # 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-')
+ resp, securitygroup = self.client.create_security_group(s_name,
+ s_description)
+ # Adding a rule to the created Security Group
+ secgroup_id = securitygroup['id']
+ ip_protocol = 'tcp'
+ from_port = 22
+ to_port = 21
+ self.addCleanup(self.client.delete_security_group, securitygroup['id'])
+ self.assertRaises(exceptions.BadRequest,
+ self.client.create_security_group_rule,
+ secgroup_id, ip_protocol, from_port, to_port)
+
+ @attr(type='negative')
def test_security_group_rules_delete_with_invalid_id(self):
# Negative test: Deletion of Security Group rule should be FAIL
# with invalid rule id