Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
| 3 | # Copyright 2013 OpenStack Foundation |
| 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 18 | from tempest.api.network import base_security_groups as base |
Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 19 | from tempest.test import attr |
| 20 | |
| 21 | |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 22 | class SecGroupTest(base.BaseSecGroupTest): |
Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 23 | _interface = 'json' |
| 24 | |
Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 25 | @attr(type='smoke') |
| 26 | def test_list_security_groups(self): |
| 27 | # Verify the that security group belonging to tenant exist in list |
| 28 | resp, body = self.client.list_security_groups() |
| 29 | self.assertEqual('200', resp['status']) |
| 30 | security_groups = body['security_groups'] |
| 31 | found = None |
| 32 | for n in security_groups: |
| 33 | if (n['name'] == 'default'): |
| 34 | found = n['id'] |
| 35 | msg = "Security-group list doesn't contain default security-group" |
| 36 | self.assertIsNotNone(found, msg) |
| 37 | |
| 38 | @attr(type='smoke') |
Yair Fried | bcdcb3b | 2013-10-11 09:08:15 +0300 | [diff] [blame] | 39 | def test_create_show_delete_security_group(self): |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 40 | group_create_body, name = self._create_security_group() |
Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 41 | |
| 42 | # Show details of the created security group |
| 43 | resp, show_body = self.client.show_security_group( |
| 44 | group_create_body['security_group']['id']) |
| 45 | self.assertEqual('200', resp['status']) |
| 46 | self.assertEqual(show_body['security_group']['name'], name) |
| 47 | |
| 48 | # List security groups and verify if created group is there in response |
| 49 | resp, list_body = self.client.list_security_groups() |
| 50 | self.assertEqual('200', resp['status']) |
| 51 | secgroup_list = list() |
| 52 | for secgroup in list_body['security_groups']: |
| 53 | secgroup_list.append(secgroup['id']) |
| 54 | self.assertIn(group_create_body['security_group']['id'], secgroup_list) |
Yair Fried | bcdcb3b | 2013-10-11 09:08:15 +0300 | [diff] [blame] | 55 | |
| 56 | @attr(type='smoke') |
| 57 | def test_create_show_delete_security_group_rule(self): |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 58 | group_create_body, _ = self._create_security_group() |
Yair Fried | bcdcb3b | 2013-10-11 09:08:15 +0300 | [diff] [blame] | 59 | |
| 60 | # Create rules for each protocol |
| 61 | protocols = ['tcp', 'udp', 'icmp'] |
| 62 | for protocol in protocols: |
| 63 | resp, rule_create_body = self.client.create_security_group_rule( |
| 64 | group_create_body['security_group']['id'], |
| 65 | protocol=protocol |
| 66 | ) |
| 67 | self.assertEqual('201', resp['status']) |
| 68 | self.addCleanup(self._delete_security_group_rule, |
| 69 | rule_create_body['security_group_rule']['id'] |
| 70 | ) |
| 71 | |
Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 72 | # Show details of the created security rule |
| 73 | resp, show_rule_body = self.client.show_security_group_rule( |
| 74 | rule_create_body['security_group_rule']['id'] |
| 75 | ) |
| 76 | self.assertEqual('200', resp['status']) |
| 77 | |
| 78 | # List rules and verify created rule is in response |
| 79 | resp, rule_list_body = self.client.list_security_group_rules() |
| 80 | self.assertEqual('200', resp['status']) |
| 81 | rule_list = [rule['id'] |
| 82 | for rule in rule_list_body['security_group_rules']] |
| 83 | self.assertIn(rule_create_body['security_group_rule']['id'], rule_list) |
| 84 | |
Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 85 | |
| 86 | class SecGroupTestXML(SecGroupTest): |
| 87 | _interface = 'xml' |