ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 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 | |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 16 | from tempest.common.utils import data_utils |
Masayuki Igawa | 224a827 | 2014-02-17 15:07:43 +0900 | [diff] [blame] | 17 | from tempest.thirdparty.boto import test as boto_test |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 18 | |
| 19 | |
Masayuki Igawa | 224a827 | 2014-02-17 15:07:43 +0900 | [diff] [blame] | 20 | class EC2SecurityGroupTest(boto_test.BotoTestCase): |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 21 | |
| 22 | @classmethod |
Andrea Frittoli | 29fea35 | 2014-09-15 13:31:14 +0100 | [diff] [blame^] | 23 | def resource_setup(cls): |
| 24 | super(EC2SecurityGroupTest, cls).resource_setup() |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 25 | cls.client = cls.os.ec2api_client |
| 26 | |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 27 | def test_create_authorize_security_group(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 28 | # EC2 Create, authorize/revoke security group |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 29 | group_name = data_utils.rand_name("securty_group-") |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 30 | group_description = group_name + " security group description " |
| 31 | group = self.client.create_security_group(group_name, |
| 32 | group_description) |
| 33 | self.addResourceCleanUp(self.client.delete_security_group, group_name) |
Matthew Treinish | 12eb3aa | 2012-11-30 16:52:14 -0500 | [diff] [blame] | 34 | groups_get = self.client.get_all_security_groups( |
Zhongyue Luo | a1343de | 2013-01-04 16:21:35 +0800 | [diff] [blame] | 35 | groupnames=(group_name,)) |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 36 | self.assertEqual(len(groups_get), 1) |
| 37 | group_get = groups_get[0] |
| 38 | self.assertEqual(group.name, group_get.name) |
| 39 | self.assertEqual(group.name, group_get.name) |
Attila Fazekas | 3e381f7 | 2013-08-01 16:52:23 +0200 | [diff] [blame] | 40 | # ping (icmp_echo) and other icmp allowed from everywhere |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 41 | # from_port and to_port act as icmp type |
| 42 | success = self.client.authorize_security_group(group_name, |
| 43 | ip_protocol="icmp", |
| 44 | cidr_ip="0.0.0.0/0", |
| 45 | from_port=-1, |
| 46 | to_port=-1) |
| 47 | self.assertTrue(success) |
Attila Fazekas | 3e381f7 | 2013-08-01 16:52:23 +0200 | [diff] [blame] | 48 | # allow standard ssh port from anywhere |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 49 | success = self.client.authorize_security_group(group_name, |
| 50 | ip_protocol="tcp", |
| 51 | cidr_ip="0.0.0.0/0", |
| 52 | from_port=22, |
| 53 | to_port=22) |
| 54 | self.assertTrue(success) |
Attila Fazekas | 3e381f7 | 2013-08-01 16:52:23 +0200 | [diff] [blame] | 55 | # TODO(afazekas): Duplicate tests |
Matthew Treinish | 12eb3aa | 2012-11-30 16:52:14 -0500 | [diff] [blame] | 56 | group_get = self.client.get_all_security_groups( |
Zhongyue Luo | a1343de | 2013-01-04 16:21:35 +0800 | [diff] [blame] | 57 | groupnames=(group_name,))[0] |
Attila Fazekas | 3e381f7 | 2013-08-01 16:52:23 +0200 | [diff] [blame] | 58 | # remove listed rules |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 59 | for ip_permission in group_get.rules: |
| 60 | for cidr in ip_permission.grants: |
| 61 | self.assertTrue(self.client.revoke_security_group(group_name, |
| 62 | ip_protocol=ip_permission.ip_protocol, |
| 63 | cidr_ip=cidr, |
| 64 | from_port=ip_permission.from_port, |
| 65 | to_port=ip_permission.to_port)) |
| 66 | |
Matthew Treinish | 12eb3aa | 2012-11-30 16:52:14 -0500 | [diff] [blame] | 67 | group_get = self.client.get_all_security_groups( |
Zhongyue Luo | a1343de | 2013-01-04 16:21:35 +0800 | [diff] [blame] | 68 | groupnames=(group_name,))[0] |
Attila Fazekas | 3e381f7 | 2013-08-01 16:52:23 +0200 | [diff] [blame] | 69 | # all rules shuld be removed now |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 70 | self.assertEqual(0, len(group_get.rules)) |