blob: 90be454d59d516e9849bfab7ec893524e5b20ba3 [file] [log] [blame]
Yair Friedd5479822013-10-14 15:33:32 +03001# Copyright 2013 OpenStack Foundation
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from tempest.api.network import base
17from tempest.common.utils import data_utils
18
19
20class BaseSecGroupTest(base.BaseNetworkTest):
21
22 @classmethod
23 def setUpClass(cls):
24 super(BaseSecGroupTest, cls).setUpClass()
25
26 def _create_security_group(self):
27 # Create a security group
28 name = data_utils.rand_name('secgroup-')
nayna-patel3e361372014-01-29 10:25:41 +000029 resp, group_create_body = self.client.create_security_group(name=name)
Yair Friedd5479822013-10-14 15:33:32 +030030 self.assertEqual('201', resp['status'])
31 self.addCleanup(self._delete_security_group,
32 group_create_body['security_group']['id'])
33 self.assertEqual(group_create_body['security_group']['name'], name)
34 return group_create_body, name
35
36 def _delete_security_group(self, secgroup_id):
37 resp, _ = self.client.delete_security_group(secgroup_id)
38 self.assertEqual(204, resp.status)
39 # Asserting that the security group is not found in the list
40 # after deletion
41 resp, list_body = self.client.list_security_groups()
42 self.assertEqual('200', resp['status'])
43 secgroup_list = list()
44 for secgroup in list_body['security_groups']:
45 secgroup_list.append(secgroup['id'])
46 self.assertNotIn(secgroup_id, secgroup_list)
47
48 def _delete_security_group_rule(self, rule_id):
49 resp, _ = self.client.delete_security_group_rule(rule_id)
50 self.assertEqual(204, resp.status)
51 # Asserting that the security group is not found in the list
52 # after deletion
53 resp, list_body = self.client.list_security_group_rules()
54 self.assertEqual('200', resp['status'])
55 rules_list = list()
56 for rule in list_body['security_group_rules']:
57 rules_list.append(rule['id'])
58 self.assertNotIn(rule_id, rules_list)