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 |
nayna-patel | 1c76bc9 | 2014-01-28 09:24:16 +0000 | [diff] [blame] | 17 | from tempest.common.utils import data_utils |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 18 | from tempest import test |
Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 19 | |
| 20 | |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 21 | class SecGroupTest(base.BaseSecGroupTest): |
Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 22 | _interface = 'json' |
| 23 | |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 24 | @classmethod |
| 25 | def setUpClass(cls): |
| 26 | super(SecGroupTest, cls).setUpClass() |
| 27 | if not test.is_extension_enabled('security-group', 'network'): |
| 28 | msg = "security-group extension not enabled." |
| 29 | raise cls.skipException(msg) |
| 30 | |
| 31 | @test.attr(type='smoke') |
Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 32 | def test_list_security_groups(self): |
| 33 | # Verify the that security group belonging to tenant exist in list |
| 34 | resp, body = self.client.list_security_groups() |
| 35 | self.assertEqual('200', resp['status']) |
| 36 | security_groups = body['security_groups'] |
| 37 | found = None |
| 38 | for n in security_groups: |
| 39 | if (n['name'] == 'default'): |
| 40 | found = n['id'] |
| 41 | msg = "Security-group list doesn't contain default security-group" |
| 42 | self.assertIsNotNone(found, msg) |
| 43 | |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 44 | @test.attr(type='smoke') |
nayna-patel | 1c76bc9 | 2014-01-28 09:24:16 +0000 | [diff] [blame] | 45 | def test_create_list_update_show_delete_security_group(self): |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 46 | group_create_body, name = self._create_security_group() |
Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 47 | |
Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 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) |
nayna-patel | 1c76bc9 | 2014-01-28 09:24:16 +0000 | [diff] [blame] | 55 | # Update the security group |
| 56 | new_name = data_utils.rand_name('security-') |
| 57 | new_description = data_utils.rand_name('security-description') |
| 58 | resp, update_body = self.client.update_security_group( |
| 59 | group_create_body['security_group']['id'], |
| 60 | name=new_name, |
| 61 | description=new_description) |
| 62 | # Verify if security group is updated |
| 63 | self.assertEqual('200', resp['status']) |
| 64 | self.assertEqual(update_body['security_group']['name'], new_name) |
| 65 | self.assertEqual(update_body['security_group']['description'], |
| 66 | new_description) |
| 67 | # Show details of the updated security group |
| 68 | resp, show_body = self.client.show_security_group( |
| 69 | group_create_body['security_group']['id']) |
| 70 | self.assertEqual(show_body['security_group']['name'], new_name) |
| 71 | self.assertEqual(show_body['security_group']['description'], |
| 72 | new_description) |
Yair Fried | bcdcb3b | 2013-10-11 09:08:15 +0300 | [diff] [blame] | 73 | |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 74 | @test.attr(type='smoke') |
Yair Fried | bcdcb3b | 2013-10-11 09:08:15 +0300 | [diff] [blame] | 75 | def test_create_show_delete_security_group_rule(self): |
Yair Fried | d547982 | 2013-10-14 15:33:32 +0300 | [diff] [blame] | 76 | group_create_body, _ = self._create_security_group() |
Yair Fried | bcdcb3b | 2013-10-11 09:08:15 +0300 | [diff] [blame] | 77 | |
| 78 | # Create rules for each protocol |
| 79 | protocols = ['tcp', 'udp', 'icmp'] |
| 80 | for protocol in protocols: |
| 81 | resp, rule_create_body = self.client.create_security_group_rule( |
nayna-patel | 3e36137 | 2014-01-29 10:25:41 +0000 | [diff] [blame] | 82 | security_group_id=group_create_body['security_group']['id'], |
| 83 | protocol=protocol, |
| 84 | direction='ingress' |
Yair Fried | bcdcb3b | 2013-10-11 09:08:15 +0300 | [diff] [blame] | 85 | ) |
| 86 | self.assertEqual('201', resp['status']) |
| 87 | self.addCleanup(self._delete_security_group_rule, |
| 88 | rule_create_body['security_group_rule']['id'] |
| 89 | ) |
| 90 | |
Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 91 | # Show details of the created security rule |
| 92 | resp, show_rule_body = self.client.show_security_group_rule( |
| 93 | rule_create_body['security_group_rule']['id'] |
| 94 | ) |
| 95 | self.assertEqual('200', resp['status']) |
| 96 | |
| 97 | # List rules and verify created rule is in response |
| 98 | resp, rule_list_body = self.client.list_security_group_rules() |
| 99 | self.assertEqual('200', resp['status']) |
| 100 | rule_list = [rule['id'] |
| 101 | for rule in rule_list_body['security_group_rules']] |
| 102 | self.assertIn(rule_create_body['security_group_rule']['id'], rule_list) |
| 103 | |
Yoshihiro Kaneko | 0567026 | 2014-01-18 19:22:44 +0900 | [diff] [blame] | 104 | @test.attr(type='smoke') |
jun xie | e31dbe9 | 2014-01-13 18:10:37 +0800 | [diff] [blame] | 105 | def test_create_security_group_rule_with_additional_args(self): |
| 106 | # Verify creating security group rule with the following |
| 107 | # arguments works: "protocol": "tcp", "port_range_max": 77, |
| 108 | # "port_range_min": 77, "direction":"ingress". |
| 109 | group_create_body, _ = self._create_security_group() |
| 110 | |
| 111 | direction = 'ingress' |
| 112 | protocol = 'tcp' |
| 113 | port_range_min = 77 |
| 114 | port_range_max = 77 |
| 115 | resp, rule_create_body = self.client.create_security_group_rule( |
nayna-patel | 3e36137 | 2014-01-29 10:25:41 +0000 | [diff] [blame] | 116 | security_group_id=group_create_body['security_group']['id'], |
jun xie | e31dbe9 | 2014-01-13 18:10:37 +0800 | [diff] [blame] | 117 | direction=direction, |
| 118 | protocol=protocol, |
| 119 | port_range_min=port_range_min, |
| 120 | port_range_max=port_range_max |
| 121 | ) |
| 122 | |
| 123 | self.assertEqual('201', resp['status']) |
| 124 | sec_group_rule = rule_create_body['security_group_rule'] |
| 125 | self.addCleanup(self._delete_security_group_rule, |
| 126 | sec_group_rule['id'] |
| 127 | ) |
| 128 | |
| 129 | self.assertEqual(sec_group_rule['direction'], direction) |
| 130 | self.assertEqual(sec_group_rule['protocol'], protocol) |
| 131 | self.assertEqual(int(sec_group_rule['port_range_min']), port_range_min) |
| 132 | self.assertEqual(int(sec_group_rule['port_range_max']), port_range_max) |
| 133 | |
Yair Fried | f37dae3 | 2013-09-01 15:35:14 +0300 | [diff] [blame] | 134 | |
| 135 | class SecGroupTestXML(SecGroupTest): |
| 136 | _interface = 'xml' |