blob: 1525e1931048ecd00e9d4f258785eaa5bdca04e2 [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
Fei Long Wangd39431f2015-05-14 11:30:48 +120017from tempest.common.utils import data_utils
Yair Friedd5479822013-10-14 15:33:32 +030018
19
20class BaseSecGroupTest(base.BaseNetworkTest):
21
Yair Friedd5479822013-10-14 15:33:32 +030022 def _create_security_group(self):
23 # Create a security group
24 name = data_utils.rand_name('secgroup-')
John Warrenf9606e92015-12-10 12:12:42 -050025 group_create_body = (
26 self.security_groups_client.create_security_group(name=name))
Yair Friedd5479822013-10-14 15:33:32 +030027 self.addCleanup(self._delete_security_group,
28 group_create_body['security_group']['id'])
29 self.assertEqual(group_create_body['security_group']['name'], name)
30 return group_create_body, name
31
32 def _delete_security_group(self, secgroup_id):
John Warrenf9606e92015-12-10 12:12:42 -050033 self.security_groups_client.delete_security_group(secgroup_id)
Yair Friedd5479822013-10-14 15:33:32 +030034 # Asserting that the security group is not found in the list
35 # after deletion
John Warrenf9606e92015-12-10 12:12:42 -050036 list_body = self.security_groups_client.list_security_groups()
Yair Friedd5479822013-10-14 15:33:32 +030037 secgroup_list = list()
38 for secgroup in list_body['security_groups']:
39 secgroup_list.append(secgroup['id'])
40 self.assertNotIn(secgroup_id, secgroup_list)
41
42 def _delete_security_group_rule(self, rule_id):
Rohan Kanadeeeb21642014-08-14 12:00:26 +020043 self.client.delete_security_group_rule(rule_id)
Yair Friedd5479822013-10-14 15:33:32 +030044 # Asserting that the security group is not found in the list
45 # after deletion
David Kranz34e88122014-12-11 15:24:05 -050046 list_body = self.client.list_security_group_rules()
Yair Friedd5479822013-10-14 15:33:32 +030047 rules_list = list()
48 for rule in list_body['security_group_rules']:
49 rules_list.append(rule['id'])
50 self.assertNotIn(rule_id, rules_list)