blob: 623e2d0617a66e90aaa1cd8796a9e7dbe083e1e2 [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
Andrea Frittolida4a2452014-09-15 13:12:08 +010023 def resource_setup(cls):
24 super(BaseSecGroupTest, cls).resource_setup()
Yair Friedd5479822013-10-14 15:33:32 +030025
26 def _create_security_group(self):
27 # Create a security group
28 name = data_utils.rand_name('secgroup-')
David Kranz34e88122014-12-11 15:24:05 -050029 group_create_body = self.client.create_security_group(name=name)
Yair Friedd5479822013-10-14 15:33:32 +030030 self.addCleanup(self._delete_security_group,
31 group_create_body['security_group']['id'])
32 self.assertEqual(group_create_body['security_group']['name'], name)
33 return group_create_body, name
34
35 def _delete_security_group(self, secgroup_id):
Rohan Kanadeeeb21642014-08-14 12:00:26 +020036 self.client.delete_security_group(secgroup_id)
Yair Friedd5479822013-10-14 15:33:32 +030037 # Asserting that the security group is not found in the list
38 # after deletion
David Kranz34e88122014-12-11 15:24:05 -050039 list_body = self.client.list_security_groups()
Yair Friedd5479822013-10-14 15:33:32 +030040 secgroup_list = list()
41 for secgroup in list_body['security_groups']:
42 secgroup_list.append(secgroup['id'])
43 self.assertNotIn(secgroup_id, secgroup_list)
44
45 def _delete_security_group_rule(self, rule_id):
Rohan Kanadeeeb21642014-08-14 12:00:26 +020046 self.client.delete_security_group_rule(rule_id)
Yair Friedd5479822013-10-14 15:33:32 +030047 # Asserting that the security group is not found in the list
48 # after deletion
David Kranz34e88122014-12-11 15:24:05 -050049 list_body = self.client.list_security_group_rules()
Yair Friedd5479822013-10-14 15:33:32 +030050 rules_list = list()
51 for rule in list_body['security_group_rules']:
52 rules_list.append(rule['id'])
53 self.assertNotIn(rule_id, rules_list)