From d547982650b540ee9d1f95dc6468627fedde99b6 Mon Sep 17 00:00:00 2001 From: Yair Fried Date: Mon, 14 Oct 2013 15:33:32 +0300 Subject: [PATCH] edit inheritence tree api/network/security_groups changed negative tests from "smoke" to "gate" avoid running "father's" test cases in son both positive and negative now derive from common TestCase without "test_" methods previous: BaseNetworkTest SecGroupTest NegativeSecGroupTest new tree: BaseNetworkTest BaseSecGroupTest SecGroupTest NegativeSecGroupTest Change-Id: Ia438b9d0c591c1c250443f6b6d069d41b6d71097 --- tempest/api/network/base_security_groups.py | 60 +++++++++++++++++++ tempest/api/network/test_security_groups.py | 49 ++------------- .../network/test_security_groups_negative.py | 36 ++++------- 3 files changed, 76 insertions(+), 69 deletions(-) create mode 100644 tempest/api/network/base_security_groups.py diff --git a/tempest/api/network/base_security_groups.py b/tempest/api/network/base_security_groups.py new file mode 100644 index 0000000000..5ab17489fb --- /dev/null +++ b/tempest/api/network/base_security_groups.py @@ -0,0 +1,60 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2013 OpenStack Foundation +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from tempest.api.network import base +from tempest.common.utils import data_utils + + +class BaseSecGroupTest(base.BaseNetworkTest): + + @classmethod + def setUpClass(cls): + super(BaseSecGroupTest, cls).setUpClass() + + def _create_security_group(self): + # Create a security group + name = data_utils.rand_name('secgroup-') + resp, group_create_body = self.client.create_security_group(name) + self.assertEqual('201', resp['status']) + self.addCleanup(self._delete_security_group, + group_create_body['security_group']['id']) + self.assertEqual(group_create_body['security_group']['name'], name) + return group_create_body, name + + def _delete_security_group(self, secgroup_id): + resp, _ = self.client.delete_security_group(secgroup_id) + self.assertEqual(204, resp.status) + # Asserting that the security group is not found in the list + # after deletion + resp, list_body = self.client.list_security_groups() + self.assertEqual('200', resp['status']) + secgroup_list = list() + for secgroup in list_body['security_groups']: + secgroup_list.append(secgroup['id']) + self.assertNotIn(secgroup_id, secgroup_list) + + def _delete_security_group_rule(self, rule_id): + resp, _ = self.client.delete_security_group_rule(rule_id) + self.assertEqual(204, resp.status) + # Asserting that the security group is not found in the list + # after deletion + resp, list_body = self.client.list_security_group_rules() + self.assertEqual('200', resp['status']) + rules_list = list() + for rule in list_body['security_group_rules']: + rules_list.append(rule['id']) + self.assertNotIn(rule_id, rules_list) diff --git a/tempest/api/network/test_security_groups.py b/tempest/api/network/test_security_groups.py index 9218f0c64e..9b0a3de3f7 100644 --- a/tempest/api/network/test_security_groups.py +++ b/tempest/api/network/test_security_groups.py @@ -15,42 +15,13 @@ # License for the specific language governing permissions and limitations # under the License. -from tempest.api.network import base -from tempest.common.utils import data_utils +from tempest.api.network import base_security_groups as base from tempest.test import attr -class SecGroupTest(base.BaseNetworkTest): +class SecGroupTest(base.BaseSecGroupTest): _interface = 'json' - @classmethod - def setUpClass(cls): - super(SecGroupTest, cls).setUpClass() - - def _delete_security_group(self, secgroup_id): - resp, _ = self.client.delete_security_group(secgroup_id) - self.assertEqual(204, resp.status) - # Asserting that the security group is not found in the list - # after deletion - resp, list_body = self.client.list_security_groups() - self.assertEqual('200', resp['status']) - secgroup_list = list() - for secgroup in list_body['security_groups']: - secgroup_list.append(secgroup['id']) - self.assertNotIn(secgroup_id, secgroup_list) - - def _delete_security_group_rule(self, rule_id): - resp, _ = self.client.delete_security_group_rule(rule_id) - self.assertEqual(204, resp.status) - # Asserting that the security group is not found in the list - # after deletion - resp, list_body = self.client.list_security_group_rules() - self.assertEqual('200', resp['status']) - rules_list = list() - for rule in list_body['security_group_rules']: - rules_list.append(rule['id']) - self.assertNotIn(rule_id, rules_list) - @attr(type='smoke') def test_list_security_groups(self): # Verify the that security group belonging to tenant exist in list @@ -66,13 +37,7 @@ class SecGroupTest(base.BaseNetworkTest): @attr(type='smoke') def test_create_show_delete_security_group(self): - # Create a security group - name = data_utils.rand_name('secgroup-') - resp, group_create_body = self.client.create_security_group(name) - self.assertEqual('201', resp['status']) - self.addCleanup(self._delete_security_group, - group_create_body['security_group']['id']) - self.assertEqual(group_create_body['security_group']['name'], name) + group_create_body, name = self._create_security_group() # Show details of the created security group resp, show_body = self.client.show_security_group( @@ -90,13 +55,7 @@ class SecGroupTest(base.BaseNetworkTest): @attr(type='smoke') def test_create_show_delete_security_group_rule(self): - # Create a security group - name = data_utils.rand_name('secgroup-') - resp, group_create_body = self.client.create_security_group(name) - self.assertEqual('201', resp['status']) - self.addCleanup(self._delete_security_group, - group_create_body['security_group']['id']) - self.assertEqual(group_create_body['security_group']['name'], name) + group_create_body, _ = self._create_security_group() # Create rules for each protocol protocols = ['tcp', 'udp', 'icmp'] diff --git a/tempest/api/network/test_security_groups_negative.py b/tempest/api/network/test_security_groups_negative.py index daeb89f844..cb0c2475ce 100644 --- a/tempest/api/network/test_security_groups_negative.py +++ b/tempest/api/network/test_security_groups_negative.py @@ -15,46 +15,39 @@ # License for the specific language governing permissions and limitations # under the License. -from tempest.api.network import test_security_groups as base -from tempest.common.utils import data_utils +from tempest.api.network import base_security_groups as base from tempest import exceptions from tempest.test import attr import uuid -class NegativeSecGroupTest(base.SecGroupTest): +class NegativeSecGroupTest(base.BaseSecGroupTest): _interface = 'json' - @attr(type=['negative', 'smoke']) + @attr(type=['negative', 'gate']) def test_show_non_existent_security_group(self): non_exist_id = str(uuid.uuid4()) self.assertRaises(exceptions.NotFound, self.client.show_security_group, non_exist_id) - @attr(type=['negative', 'smoke']) + @attr(type=['negative', 'gate']) def test_show_non_existent_security_group_rule(self): non_exist_id = str(uuid.uuid4()) self.assertRaises(exceptions.NotFound, self.client.show_security_group_rule, non_exist_id) - @attr(type=['negative', 'smoke']) + @attr(type=['negative', 'gate']) def test_delete_non_existent_security_group(self): - non_exist_id = 'fictional-id' + non_exist_id = str(uuid.uuid4()) self.assertRaises(exceptions.NotFound, self.client.delete_security_group, non_exist_id ) - @attr(type=['negative', 'smoke']) + @attr(type=['negative', 'gate']) def test_create_security_group_rule_with_bad_protocol(self): - # Create a security group - name = data_utils.rand_name('secgroup-') - resp, group_create_body = self.client.create_security_group(name) - self.assertEqual('201', resp['status']) - self.addCleanup(self._delete_security_group, - group_create_body['security_group']['id']) - self.assertEqual(group_create_body['security_group']['name'], name) + group_create_body, _ = self._create_security_group() #Create rule with bad protocol name pname = 'bad_protocol_name' @@ -63,20 +56,15 @@ class NegativeSecGroupTest(base.SecGroupTest): group_create_body['security_group']['id'], protocol=pname) - @attr(type=['negative', 'smoke']) + @attr(type=['negative', 'gate']) def test_create_security_group_rule_with_invalid_ports(self): - # Create a security group - name = data_utils.rand_name('secgroup-') - resp, group_create_body = self.client.create_security_group(name) - self.assertEqual('201', resp['status']) - self.addCleanup(self._delete_security_group, - group_create_body['security_group']['id']) - self.assertEqual(group_create_body['security_group']['name'], name) + group_create_body, _ = self._create_security_group() #Create rule with invalid ports states = [(-16, 80, 'Invalid value for port -16'), (80, 79, 'port_range_min must be <= port_range_max'), - (80, 65536, 'Invalid value for port 65536')] + (80, 65536, 'Invalid value for port 65536'), + (-16, 65536, 'Invalid value for port')] for pmin, pmax, msg in states: ex = self.assertRaises(exceptions.BadRequest, self.client.create_security_group_rule,