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