diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-10-15 06:06:28 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-10-15 06:06:28 +0000 |
commit | 9b0aed330df3ae842ebaad0494988c7a336acfe3 (patch) | |
tree | c95eeb3aa334566b3700f5b1dd2992b57683cd09 | |
parent | 4653d8ce0aa2db857e8a1b5a2226a9db819e90c6 (diff) | |
parent | ba1a05bb3c129d1b9a9782f637f7d32133543382 (diff) | |
download | tempest-9b0aed330df3ae842ebaad0494988c7a336acfe3.tar.gz |
Merge "Add expected response checks of secgroup rules"
-rw-r--r-- | tempest/api/compute/security_groups/test_security_group_rules.py | 84 |
1 files changed, 63 insertions, 21 deletions
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 45b913aa6..4fd5c0291 100644 --- a/tempest/api/compute/security_groups/test_security_group_rules.py +++ b/tempest/api/compute/security_groups/test_security_group_rules.py @@ -13,6 +13,8 @@ # License for the specific language governing permissions and limitations # under the License. +import six + from tempest.api.compute.security_groups import base from tempest import config from tempest import test @@ -31,22 +33,54 @@ class SecurityGroupRulesTestJSON(base.BaseSecurityGroupsTest): cls.from_port = 22 cls.to_port = 22 + def setUp(cls): + super(SecurityGroupRulesTestJSON, cls).setUp() + + from_port = cls.from_port + to_port = cls.to_port + group = {} + ip_range = {} + if cls._interface == 'xml': + # NOTE: An XML response is different from the one of JSON + # like the following. + from_port = six.text_type(from_port) + to_port = six.text_type(to_port) + group = {'tenant_id': 'None', 'name': 'None'} + ip_range = {'cidr': 'None'} + cls.expected = { + 'id': None, + 'parent_group_id': None, + 'ip_protocol': cls.ip_protocol, + 'from_port': from_port, + 'to_port': to_port, + 'ip_range': ip_range, + 'group': group + } + + def _check_expected_response(self, actual_rule): + for key in self.expected: + if key == 'id': + continue + self.assertEqual(self.expected[key], actual_rule[key], + "Miss-matched key is %s" % key) + @test.attr(type='smoke') @test.services('network') def test_security_group_rules_create(self): # Positive test: Creation of Security Group rule # should be successful # Creating a Security Group to add rules to it - resp, security_group = self.create_security_group() + _, security_group = self.create_security_group() securitygroup_id = security_group['id'] # Adding rules to the created Security Group - resp, rule = \ + _, rule = \ self.client.create_security_group_rule(securitygroup_id, self.ip_protocol, self.from_port, self.to_port) - self.addCleanup(self.client.delete_security_group_rule, rule['id']) - self.assertEqual(200, resp.status) + self.expected['parent_group_id'] = securitygroup_id + self.expected['ip_range'] = {'cidr': '0.0.0.0/0'} + self._check_expected_response(rule) @test.attr(type='smoke') @test.services('network') @@ -56,16 +90,20 @@ class SecurityGroupRulesTestJSON(base.BaseSecurityGroupsTest): # should be successful # Creating a Security Group to add rules to it - resp, security_group = self.create_security_group() + _, security_group = self.create_security_group() parent_group_id = security_group['id'] # Adding rules to the created Security Group with optional cidr cidr = '10.2.3.124/24' - self.client.create_security_group_rule(parent_group_id, - self.ip_protocol, - self.from_port, - self.to_port, - cidr=cidr) + _, rule = \ + self.client.create_security_group_rule(parent_group_id, + self.ip_protocol, + self.from_port, + self.to_port, + cidr=cidr) + self.expected['parent_group_id'] = parent_group_id + self.expected['ip_range'] = {'cidr': cidr} + self._check_expected_response(rule) @test.attr(type='smoke') @test.services('network') @@ -75,21 +113,25 @@ class SecurityGroupRulesTestJSON(base.BaseSecurityGroupsTest): # should be successful # Creating a Security Group to add rules to it - resp, security_group = self.create_security_group() - secgroup1 = security_group['id'] + _, security_group = self.create_security_group() + parent_group_id = security_group['id'] # Creating a Security Group so as to assign group_id to the rule - resp, security_group = self.create_security_group() - secgroup2 = security_group['id'] + _, security_group = self.create_security_group() + group_id = security_group['id'] + group_name = security_group['name'] # Adding rules to the created Security Group with optional group_id - parent_group_id = secgroup1 - group_id = secgroup2 - self.client.create_security_group_rule(parent_group_id, - self.ip_protocol, - self.from_port, - self.to_port, - group_id=group_id) + _, rule = \ + self.client.create_security_group_rule(parent_group_id, + self.ip_protocol, + self.from_port, + self.to_port, + group_id=group_id) + self.expected['parent_group_id'] = parent_group_id + self.expected['group'] = {'tenant_id': self.client.tenant_id, + 'name': group_name} + self._check_expected_response(rule) @test.attr(type='smoke') @test.services('network') |