blob: fb3d32b1d8edfa32755ca77b963c2089e3918070 [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
Masayuki Igawa224a8272014-02-17 15:07:43 +090017from tempest.thirdparty.boto import test as boto_test
Attila Fazekasa23f5002012-10-23 19:32:45 +020018
19
Masayuki Igawa224a8272014-02-17 15:07:43 +090020class EC2SecurityGroupTest(boto_test.BotoTestCase):
Attila Fazekasa23f5002012-10-23 19:32:45 +020021
22 @classmethod
Andrea Frittoli29fea352014-09-15 13:31:14 +010023 def resource_setup(cls):
24 super(EC2SecurityGroupTest, cls).resource_setup()
Attila Fazekasa23f5002012-10-23 19:32:45 +020025 cls.client = cls.os.ec2api_client
26
Attila Fazekasa23f5002012-10-23 19:32:45 +020027 def test_create_authorize_security_group(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050028 # EC2 Create, authorize/revoke security group
Masayuki Igawa259c1132013-10-31 17:48:44 +090029 group_name = data_utils.rand_name("securty_group-")
Attila Fazekasa23f5002012-10-23 19:32:45 +020030 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 Treinish12eb3aa2012-11-30 16:52:14 -050034 groups_get = self.client.get_all_security_groups(
Zhongyue Luoa1343de2013-01-04 16:21:35 +080035 groupnames=(group_name,))
Attila Fazekasa23f5002012-10-23 19:32:45 +020036 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 Fazekas3e381f72013-08-01 16:52:23 +020040 # ping (icmp_echo) and other icmp allowed from everywhere
Attila Fazekasa23f5002012-10-23 19:32:45 +020041 # 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 Fazekas3e381f72013-08-01 16:52:23 +020048 # allow standard ssh port from anywhere
Attila Fazekasa23f5002012-10-23 19:32:45 +020049 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 Fazekas3e381f72013-08-01 16:52:23 +020055 # TODO(afazekas): Duplicate tests
Matthew Treinish12eb3aa2012-11-30 16:52:14 -050056 group_get = self.client.get_all_security_groups(
Zhongyue Luoa1343de2013-01-04 16:21:35 +080057 groupnames=(group_name,))[0]
Attila Fazekas3e381f72013-08-01 16:52:23 +020058 # remove listed rules
Attila Fazekasa23f5002012-10-23 19:32:45 +020059 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 Treinish12eb3aa2012-11-30 16:52:14 -050067 group_get = self.client.get_all_security_groups(
Zhongyue Luoa1343de2013-01-04 16:21:35 +080068 groupnames=(group_name,))[0]
Attila Fazekas3e381f72013-08-01 16:52:23 +020069 # all rules shuld be removed now
Attila Fazekasa23f5002012-10-23 19:32:45 +020070 self.assertEqual(0, len(group_get.rules))