blob: e8c64661bcb160e6da08e2347ffbd4dea242f07f [file] [log] [blame]
Attila Fazekasa23f5002012-10-23 19:32:45 +02001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Attila Fazekasa23f5002012-10-23 19:32:45 +02004# 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 Treinish481466b2012-12-20 17:16:01 -050018from tempest import clients
Masayuki Igawa259c1132013-10-31 17:48:44 +090019from tempest.common.utils import data_utils
Chris Yeoh01cb2792013-02-09 22:25:37 +103020from tempest.test import attr
Sean Dague09761f62013-05-13 15:20:40 -040021from tempest.thirdparty.boto.test import BotoTestCase
Attila Fazekasa23f5002012-10-23 19:32:45 +020022
23
Attila Fazekasa23f5002012-10-23 19:32:45 +020024class EC2SecurityGroupTest(BotoTestCase):
25
26 @classmethod
27 def setUpClass(cls):
28 super(EC2SecurityGroupTest, cls).setUpClass()
Matthew Treinish481466b2012-12-20 17:16:01 -050029 cls.os = clients.Manager()
Attila Fazekasa23f5002012-10-23 19:32:45 +020030 cls.client = cls.os.ec2api_client
31
32 @attr(type='smoke')
33 def test_create_authorize_security_group(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050034 # EC2 Create, authorize/revoke security group
Masayuki Igawa259c1132013-10-31 17:48:44 +090035 group_name = data_utils.rand_name("securty_group-")
Attila Fazekasa23f5002012-10-23 19:32:45 +020036 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 Treinish12eb3aa2012-11-30 16:52:14 -050040 groups_get = self.client.get_all_security_groups(
Zhongyue Luoa1343de2013-01-04 16:21:35 +080041 groupnames=(group_name,))
Attila Fazekasa23f5002012-10-23 19:32:45 +020042 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 Fazekas3e381f72013-08-01 16:52:23 +020046 # ping (icmp_echo) and other icmp allowed from everywhere
Attila Fazekasa23f5002012-10-23 19:32:45 +020047 # 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 Fazekas3e381f72013-08-01 16:52:23 +020054 # allow standard ssh port from anywhere
Attila Fazekasa23f5002012-10-23 19:32:45 +020055 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 Fazekas3e381f72013-08-01 16:52:23 +020061 # TODO(afazekas): Duplicate tests
Matthew Treinish12eb3aa2012-11-30 16:52:14 -050062 group_get = self.client.get_all_security_groups(
Zhongyue Luoa1343de2013-01-04 16:21:35 +080063 groupnames=(group_name,))[0]
Attila Fazekas3e381f72013-08-01 16:52:23 +020064 # remove listed rules
Attila Fazekasa23f5002012-10-23 19:32:45 +020065 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 Treinish12eb3aa2012-11-30 16:52:14 -050073 group_get = self.client.get_all_security_groups(
Zhongyue Luoa1343de2013-01-04 16:21:35 +080074 groupnames=(group_name,))[0]
Attila Fazekas3e381f72013-08-01 16:52:23 +020075 # all rules shuld be removed now
Attila Fazekasa23f5002012-10-23 19:32:45 +020076 self.assertEqual(0, len(group_get.rules))