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