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 | |
Matthew Treinish | 01472ff | 2015-02-20 17:26:52 -0500 | [diff] [blame] | 16 | from tempest_lib.common.utils import data_utils |
| 17 | |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 18 | from tempest.api.network import base |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 19 | |
| 20 | |
| 21 | class BaseSecGroupTest(base.BaseNetworkTest): |
| 22 | |
| 23 | @classmethod |
Andrea Frittoli | da4a245 | 2014-09-15 13:12:08 +0100 | [diff] [blame] | 24 | def resource_setup(cls): |
| 25 | super(BaseSecGroupTest, cls).resource_setup() |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 26 | |
| 27 | def _create_security_group(self): |
| 28 | # Create a security group |
| 29 | name = data_utils.rand_name('secgroup-') |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 30 | group_create_body = self.client.create_security_group(name=name) |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 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): |
Rohan Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 37 | self.client.delete_security_group(secgroup_id) |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 38 | # Asserting that the security group is not found in the list |
| 39 | # after deletion |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 40 | list_body = self.client.list_security_groups() |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 41 | 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 Kanade | eeb2164 | 2014-08-14 12:00:26 +0200 | [diff] [blame] | 47 | self.client.delete_security_group_rule(rule_id) |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 48 | # Asserting that the security group is not found in the list |
| 49 | # after deletion |
David Kranz | 34e8812 | 2014-12-11 15:24:05 -0500 | [diff] [blame] | 50 | list_body = self.client.list_security_group_rules() |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 51 | 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) |