Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 3 | # Copyright 2012 OpenStack Foundation |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 4 | # All Rights Reserved. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 7 | # not use this file except in compliance with the License. You may obtain |
| 8 | # a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 14 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 15 | # License for the specific language governing permissions and limitations |
| 16 | # under the License. |
| 17 | |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 18 | from tempest import clients |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 19 | from tempest.common.utils import data_utils |
Chris Yeoh | 01cb279 | 2013-02-09 22:25:37 +1030 | [diff] [blame] | 20 | from tempest.test import attr |
Sean Dague | 09761f6 | 2013-05-13 15:20:40 -0400 | [diff] [blame] | 21 | from tempest.thirdparty.boto.test import BotoTestCase |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 22 | |
| 23 | |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 24 | class EC2SecurityGroupTest(BotoTestCase): |
| 25 | |
| 26 | @classmethod |
| 27 | def setUpClass(cls): |
| 28 | super(EC2SecurityGroupTest, cls).setUpClass() |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 29 | cls.os = clients.Manager() |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 30 | cls.client = cls.os.ec2api_client |
| 31 | |
| 32 | @attr(type='smoke') |
| 33 | def test_create_authorize_security_group(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 34 | # EC2 Create, authorize/revoke security group |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 35 | group_name = data_utils.rand_name("securty_group-") |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 36 | group_description = group_name + " security group description " |
| 37 | group = self.client.create_security_group(group_name, |
| 38 | group_description) |
| 39 | self.addResourceCleanUp(self.client.delete_security_group, group_name) |
Matthew Treinish | 12eb3aa | 2012-11-30 16:52:14 -0500 | [diff] [blame] | 40 | groups_get = self.client.get_all_security_groups( |
Zhongyue Luo | a1343de | 2013-01-04 16:21:35 +0800 | [diff] [blame] | 41 | groupnames=(group_name,)) |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 42 | self.assertEqual(len(groups_get), 1) |
| 43 | group_get = groups_get[0] |
| 44 | self.assertEqual(group.name, group_get.name) |
| 45 | self.assertEqual(group.name, group_get.name) |
Attila Fazekas | 3e381f7 | 2013-08-01 16:52:23 +0200 | [diff] [blame] | 46 | # ping (icmp_echo) and other icmp allowed from everywhere |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 47 | # from_port and to_port act as icmp type |
| 48 | success = self.client.authorize_security_group(group_name, |
| 49 | ip_protocol="icmp", |
| 50 | cidr_ip="0.0.0.0/0", |
| 51 | from_port=-1, |
| 52 | to_port=-1) |
| 53 | self.assertTrue(success) |
Attila Fazekas | 3e381f7 | 2013-08-01 16:52:23 +0200 | [diff] [blame] | 54 | # allow standard ssh port from anywhere |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 55 | success = self.client.authorize_security_group(group_name, |
| 56 | ip_protocol="tcp", |
| 57 | cidr_ip="0.0.0.0/0", |
| 58 | from_port=22, |
| 59 | to_port=22) |
| 60 | self.assertTrue(success) |
Attila Fazekas | 3e381f7 | 2013-08-01 16:52:23 +0200 | [diff] [blame] | 61 | # TODO(afazekas): Duplicate tests |
Matthew Treinish | 12eb3aa | 2012-11-30 16:52:14 -0500 | [diff] [blame] | 62 | group_get = self.client.get_all_security_groups( |
Zhongyue Luo | a1343de | 2013-01-04 16:21:35 +0800 | [diff] [blame] | 63 | groupnames=(group_name,))[0] |
Attila Fazekas | 3e381f7 | 2013-08-01 16:52:23 +0200 | [diff] [blame] | 64 | # remove listed rules |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 65 | for ip_permission in group_get.rules: |
| 66 | for cidr in ip_permission.grants: |
| 67 | self.assertTrue(self.client.revoke_security_group(group_name, |
| 68 | ip_protocol=ip_permission.ip_protocol, |
| 69 | cidr_ip=cidr, |
| 70 | from_port=ip_permission.from_port, |
| 71 | to_port=ip_permission.to_port)) |
| 72 | |
Matthew Treinish | 12eb3aa | 2012-11-30 16:52:14 -0500 | [diff] [blame] | 73 | group_get = self.client.get_all_security_groups( |
Zhongyue Luo | a1343de | 2013-01-04 16:21:35 +0800 | [diff] [blame] | 74 | groupnames=(group_name,))[0] |
Attila Fazekas | 3e381f7 | 2013-08-01 16:52:23 +0200 | [diff] [blame] | 75 | # all rules shuld be removed now |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 76 | self.assertEqual(0, len(group_get.rules)) |