blob: 75dd254aa45cc7a5959e5ba52dda24bc0221f2cc [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
Matthew Treinish481466b2012-12-20 17:16:01 -050016from tempest import clients
Masayuki Igawa259c1132013-10-31 17:48:44 +090017from tempest.common.utils import data_utils
Chris Yeoh01cb2792013-02-09 22:25:37 +103018from tempest.test import attr
Sean Dague09761f62013-05-13 15:20:40 -040019from tempest.thirdparty.boto.test import BotoTestCase
Attila Fazekasa23f5002012-10-23 19:32:45 +020020
21
Attila Fazekasa23f5002012-10-23 19:32:45 +020022class EC2SecurityGroupTest(BotoTestCase):
23
24 @classmethod
25 def setUpClass(cls):
26 super(EC2SecurityGroupTest, cls).setUpClass()
Matthew Treinish481466b2012-12-20 17:16:01 -050027 cls.os = clients.Manager()
Attila Fazekasa23f5002012-10-23 19:32:45 +020028 cls.client = cls.os.ec2api_client
29
30 @attr(type='smoke')
31 def test_create_authorize_security_group(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050032 # EC2 Create, authorize/revoke security group
Masayuki Igawa259c1132013-10-31 17:48:44 +090033 group_name = data_utils.rand_name("securty_group-")
Attila Fazekasa23f5002012-10-23 19:32:45 +020034 group_description = group_name + " security group description "
35 group = self.client.create_security_group(group_name,
36 group_description)
37 self.addResourceCleanUp(self.client.delete_security_group, group_name)
Matthew Treinish12eb3aa2012-11-30 16:52:14 -050038 groups_get = self.client.get_all_security_groups(
Zhongyue Luoa1343de2013-01-04 16:21:35 +080039 groupnames=(group_name,))
Attila Fazekasa23f5002012-10-23 19:32:45 +020040 self.assertEqual(len(groups_get), 1)
41 group_get = groups_get[0]
42 self.assertEqual(group.name, group_get.name)
43 self.assertEqual(group.name, group_get.name)
Attila Fazekas3e381f72013-08-01 16:52:23 +020044 # ping (icmp_echo) and other icmp allowed from everywhere
Attila Fazekasa23f5002012-10-23 19:32:45 +020045 # from_port and to_port act as icmp type
46 success = self.client.authorize_security_group(group_name,
47 ip_protocol="icmp",
48 cidr_ip="0.0.0.0/0",
49 from_port=-1,
50 to_port=-1)
51 self.assertTrue(success)
Attila Fazekas3e381f72013-08-01 16:52:23 +020052 # allow standard ssh port from anywhere
Attila Fazekasa23f5002012-10-23 19:32:45 +020053 success = self.client.authorize_security_group(group_name,
54 ip_protocol="tcp",
55 cidr_ip="0.0.0.0/0",
56 from_port=22,
57 to_port=22)
58 self.assertTrue(success)
Attila Fazekas3e381f72013-08-01 16:52:23 +020059 # TODO(afazekas): Duplicate tests
Matthew Treinish12eb3aa2012-11-30 16:52:14 -050060 group_get = self.client.get_all_security_groups(
Zhongyue Luoa1343de2013-01-04 16:21:35 +080061 groupnames=(group_name,))[0]
Attila Fazekas3e381f72013-08-01 16:52:23 +020062 # remove listed rules
Attila Fazekasa23f5002012-10-23 19:32:45 +020063 for ip_permission in group_get.rules:
64 for cidr in ip_permission.grants:
65 self.assertTrue(self.client.revoke_security_group(group_name,
66 ip_protocol=ip_permission.ip_protocol,
67 cidr_ip=cidr,
68 from_port=ip_permission.from_port,
69 to_port=ip_permission.to_port))
70
Matthew Treinish12eb3aa2012-11-30 16:52:14 -050071 group_get = self.client.get_all_security_groups(
Zhongyue Luoa1343de2013-01-04 16:21:35 +080072 groupnames=(group_name,))[0]
Attila Fazekas3e381f72013-08-01 16:52:23 +020073 # all rules shuld be removed now
Attila Fazekasa23f5002012-10-23 19:32:45 +020074 self.assertEqual(0, len(group_get.rules))