blob: c704049ea68444f09ae52feb4291481834048863 [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
Matthew Treinish01472ff2015-02-20 17:26:52 -050016from tempest_lib.common.utils import data_utils
17
Yair Friedd5479822013-10-14 15:33:32 +030018from tempest.api.network import base
Yair Friedd5479822013-10-14 15:33:32 +030019
20
21class BaseSecGroupTest(base.BaseNetworkTest):
22
23 @classmethod
Andrea Frittolida4a2452014-09-15 13:12:08 +010024 def resource_setup(cls):
25 super(BaseSecGroupTest, cls).resource_setup()
Yair Friedd5479822013-10-14 15:33:32 +030026
27 def _create_security_group(self):
28 # Create a security group
29 name = data_utils.rand_name('secgroup-')
David Kranz34e88122014-12-11 15:24:05 -050030 group_create_body = self.client.create_security_group(name=name)
Yair Friedd5479822013-10-14 15:33:32 +030031 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):
Rohan Kanadeeeb21642014-08-14 12:00:26 +020037 self.client.delete_security_group(secgroup_id)
Yair Friedd5479822013-10-14 15:33:32 +030038 # Asserting that the security group is not found in the list
39 # after deletion
David Kranz34e88122014-12-11 15:24:05 -050040 list_body = self.client.list_security_groups()
Yair Friedd5479822013-10-14 15:33:32 +030041 secgroup_list = list()
42 for secgroup in list_body['security_groups']:
43 secgroup_list.append(secgroup['id'])
44 self.assertNotIn(secgroup_id, secgroup_list)
45
46 def _delete_security_group_rule(self, rule_id):
Rohan Kanadeeeb21642014-08-14 12:00:26 +020047 self.client.delete_security_group_rule(rule_id)
Yair Friedd5479822013-10-14 15:33:32 +030048 # Asserting that the security group is not found in the list
49 # after deletion
David Kranz34e88122014-12-11 15:24:05 -050050 list_body = self.client.list_security_group_rules()
Yair Friedd5479822013-10-14 15:33:32 +030051 rules_list = list()
52 for rule in list_body['security_group_rules']:
53 rules_list.append(rule['id'])
54 self.assertNotIn(rule_id, rules_list)