Yair Fried | f37dae3 | 2013-09-01 15:35:14 +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 | |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 16 | from tempest.api.network import base_security_groups as base |
Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 17 | from tempest.test import attr |
| 18 | |
| 19 | |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 20 | class SecGroupTest(base.BaseSecGroupTest): |
Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 21 | _interface = 'json' |
| 22 | |
Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 23 | @attr(type='smoke') |
| 24 | def test_list_security_groups(self): |
| 25 | # Verify the that security group belonging to tenant exist in list |
| 26 | resp, body = self.client.list_security_groups() |
| 27 | self.assertEqual('200', resp['status']) |
| 28 | security_groups = body['security_groups'] |
| 29 | found = None |
| 30 | for n in security_groups: |
| 31 | if (n['name'] == 'default'): |
| 32 | found = n['id'] |
| 33 | msg = "Security-group list doesn't contain default security-group" |
| 34 | self.assertIsNotNone(found, msg) |
| 35 | |
| 36 | @attr(type='smoke') |
Yair Fried | bcdcb3b | 2013-10-11 09:08:15 +0300 | [diff] [blame] | 37 | def test_create_show_delete_security_group(self): |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 38 | group_create_body, name = self._create_security_group() |
Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 39 | |
| 40 | # Show details of the created security group |
| 41 | resp, show_body = self.client.show_security_group( |
| 42 | group_create_body['security_group']['id']) |
| 43 | self.assertEqual('200', resp['status']) |
| 44 | self.assertEqual(show_body['security_group']['name'], name) |
| 45 | |
| 46 | # List security groups and verify if created group is there in response |
| 47 | resp, list_body = self.client.list_security_groups() |
| 48 | self.assertEqual('200', resp['status']) |
| 49 | secgroup_list = list() |
| 50 | for secgroup in list_body['security_groups']: |
| 51 | secgroup_list.append(secgroup['id']) |
| 52 | self.assertIn(group_create_body['security_group']['id'], secgroup_list) |
Yair Fried | bcdcb3b | 2013-10-11 09:08:15 +0300 | [diff] [blame] | 53 | |
| 54 | @attr(type='smoke') |
| 55 | def test_create_show_delete_security_group_rule(self): |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 56 | group_create_body, _ = self._create_security_group() |
Yair Fried | bcdcb3b | 2013-10-11 09:08:15 +0300 | [diff] [blame] | 57 | |
| 58 | # Create rules for each protocol |
| 59 | protocols = ['tcp', 'udp', 'icmp'] |
| 60 | for protocol in protocols: |
| 61 | resp, rule_create_body = self.client.create_security_group_rule( |
| 62 | group_create_body['security_group']['id'], |
| 63 | protocol=protocol |
| 64 | ) |
| 65 | self.assertEqual('201', resp['status']) |
| 66 | self.addCleanup(self._delete_security_group_rule, |
| 67 | rule_create_body['security_group_rule']['id'] |
| 68 | ) |
| 69 | |
Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 70 | # Show details of the created security rule |
| 71 | resp, show_rule_body = self.client.show_security_group_rule( |
| 72 | rule_create_body['security_group_rule']['id'] |
| 73 | ) |
| 74 | self.assertEqual('200', resp['status']) |
| 75 | |
| 76 | # List rules and verify created rule is in response |
| 77 | resp, rule_list_body = self.client.list_security_group_rules() |
| 78 | self.assertEqual('200', resp['status']) |
| 79 | rule_list = [rule['id'] |
| 80 | for rule in rule_list_body['security_group_rules']] |
| 81 | self.assertIn(rule_create_body['security_group_rule']['id'], rule_list) |
| 82 | |
jun xie | e31dbe9 | 2014-01-13 18:10:37 +0800 | [diff] [blame] | 83 | @attr(type='smoke') |
| 84 | def test_create_security_group_rule_with_additional_args(self): |
| 85 | # Verify creating security group rule with the following |
| 86 | # arguments works: "protocol": "tcp", "port_range_max": 77, |
| 87 | # "port_range_min": 77, "direction":"ingress". |
| 88 | group_create_body, _ = self._create_security_group() |
| 89 | |
| 90 | direction = 'ingress' |
| 91 | protocol = 'tcp' |
| 92 | port_range_min = 77 |
| 93 | port_range_max = 77 |
| 94 | resp, rule_create_body = self.client.create_security_group_rule( |
| 95 | group_create_body['security_group']['id'], |
| 96 | direction=direction, |
| 97 | protocol=protocol, |
| 98 | port_range_min=port_range_min, |
| 99 | port_range_max=port_range_max |
| 100 | ) |
| 101 | |
| 102 | self.assertEqual('201', resp['status']) |
| 103 | sec_group_rule = rule_create_body['security_group_rule'] |
| 104 | self.addCleanup(self._delete_security_group_rule, |
| 105 | sec_group_rule['id'] |
| 106 | ) |
| 107 | |
| 108 | self.assertEqual(sec_group_rule['direction'], direction) |
| 109 | self.assertEqual(sec_group_rule['protocol'], protocol) |
| 110 | self.assertEqual(int(sec_group_rule['port_range_min']), port_range_min) |
| 111 | self.assertEqual(int(sec_group_rule['port_range_max']), port_range_max) |
| 112 | |
Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 113 | |
| 114 | class SecGroupTestXML(SecGroupTest): |
| 115 | _interface = 'xml' |