Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 1 | # 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 | |
| 16 | from tempest.api.network import base |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 17 | from tempest.common.utils import data_utils |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 18 | |
| 19 | |
| 20 | class BaseSecGroupTest(base.BaseNetworkTest): |
| 21 | |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 22 | def _create_security_group(self): |
| 23 | # Create a security group |
| 24 | name = data_utils.rand_name('secgroup-') |
John Warren | f9606e9 | 2015-12-10 12:12:42 -0500 | [diff] [blame] | 25 | group_create_body = ( |
| 26 | self.security_groups_client.create_security_group(name=name)) |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 27 | 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 Warren | f9606e9 | 2015-12-10 12:12:42 -0500 | [diff] [blame] | 33 | self.security_groups_client.delete_security_group(secgroup_id) |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 34 | # Asserting that the security group is not found in the list |
| 35 | # after deletion |
John Warren | f9606e9 | 2015-12-10 12:12:42 -0500 | [diff] [blame] | 36 | list_body = self.security_groups_client.list_security_groups() |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 37 | 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 Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 43 | self.client.delete_security_group_rule(rule_id) |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 44 | # Asserting that the security group is not found in the list |
| 45 | # after deletion |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 46 | list_body = self.client.list_security_group_rules() |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 47 | 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) |