blob: 92fe59d70112ef154dfb0c31f5b2f351d77922be [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Attila Fazekasa23f5002012-10-23 19:32:45 +02002# 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 Igawa259c1132013-10-31 17:48:44 +090016from tempest.common.utils import data_utils
Chris Hoge7579c1a2015-02-26 14:12:15 -080017from tempest import test
Masayuki Igawa224a8272014-02-17 15:07:43 +090018from tempest.thirdparty.boto import test as boto_test
Attila Fazekasa23f5002012-10-23 19:32:45 +020019
20
Masayuki Igawa224a8272014-02-17 15:07:43 +090021class EC2SecurityGroupTest(boto_test.BotoTestCase):
Attila Fazekasa23f5002012-10-23 19:32:45 +020022
23 @classmethod
Andrea Frittoli29fea352014-09-15 13:31:14 +010024 def resource_setup(cls):
25 super(EC2SecurityGroupTest, cls).resource_setup()
Attila Fazekasa23f5002012-10-23 19:32:45 +020026 cls.client = cls.os.ec2api_client
27
Chris Hoge7579c1a2015-02-26 14:12:15 -080028 @test.idempotent_id('519b566e-0c38-4629-905e-7d6b6355f524')
Attila Fazekasa23f5002012-10-23 19:32:45 +020029 def test_create_authorize_security_group(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050030 # EC2 Create, authorize/revoke security group
Masayuki Igawa259c1132013-10-31 17:48:44 +090031 group_name = data_utils.rand_name("securty_group-")
Attila Fazekasa23f5002012-10-23 19:32:45 +020032 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 Treinish12eb3aa2012-11-30 16:52:14 -050036 groups_get = self.client.get_all_security_groups(
Zhongyue Luoa1343de2013-01-04 16:21:35 +080037 groupnames=(group_name,))
Attila Fazekasa23f5002012-10-23 19:32:45 +020038 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 Fazekas3e381f72013-08-01 16:52:23 +020042 # ping (icmp_echo) and other icmp allowed from everywhere
Attila Fazekasa23f5002012-10-23 19:32:45 +020043 # 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 Fazekas3e381f72013-08-01 16:52:23 +020050 # allow standard ssh port from anywhere
Attila Fazekasa23f5002012-10-23 19:32:45 +020051 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 Fazekas3e381f72013-08-01 16:52:23 +020057 # TODO(afazekas): Duplicate tests
Matthew Treinish12eb3aa2012-11-30 16:52:14 -050058 group_get = self.client.get_all_security_groups(
Zhongyue Luoa1343de2013-01-04 16:21:35 +080059 groupnames=(group_name,))[0]
Attila Fazekas3e381f72013-08-01 16:52:23 +020060 # remove listed rules
Attila Fazekasa23f5002012-10-23 19:32:45 +020061 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 Treinish12eb3aa2012-11-30 16:52:14 -050069 group_get = self.client.get_all_security_groups(
Zhongyue Luoa1343de2013-01-04 16:21:35 +080070 groupnames=(group_name,))[0]
Attila Fazekas3e381f72013-08-01 16:52:23 +020071 # all rules shuld be removed now
Attila Fazekasa23f5002012-10-23 19:32:45 +020072 self.assertEqual(0, len(group_get.rules))