blob: 94fab09955b0690ece7c5659aa3c6dd338fe6681 [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 Treinish01472ff2015-02-20 17:26:52 -050016from tempest_lib.common.utils import data_utils
17
Chris Hoge7579c1a2015-02-26 14:12:15 -080018from tempest import test
Masayuki Igawa224a8272014-02-17 15:07:43 +090019from tempest.thirdparty.boto import test as boto_test
Attila Fazekasa23f5002012-10-23 19:32:45 +020020
21
Masayuki Igawa224a8272014-02-17 15:07:43 +090022class EC2SecurityGroupTest(boto_test.BotoTestCase):
Attila Fazekasa23f5002012-10-23 19:32:45 +020023
24 @classmethod
Emily Hugenbruche252a4a2015-02-27 15:43:12 +000025 def setup_clients(cls):
26 super(EC2SecurityGroupTest, cls).setup_clients()
Attila Fazekasa23f5002012-10-23 19:32:45 +020027 cls.client = cls.os.ec2api_client
28
Chris Hoge7579c1a2015-02-26 14:12:15 -080029 @test.idempotent_id('519b566e-0c38-4629-905e-7d6b6355f524')
Attila Fazekasa23f5002012-10-23 19:32:45 +020030 def test_create_authorize_security_group(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050031 # EC2 Create, authorize/revoke security group
Ken'ichi Ohmichia498b1d2015-03-23 01:56:52 +000032 group_name = data_utils.rand_name("securty_group")
Attila Fazekasa23f5002012-10-23 19:32:45 +020033 group_description = group_name + " security group description "
34 group = self.client.create_security_group(group_name,
35 group_description)
36 self.addResourceCleanUp(self.client.delete_security_group, group_name)
Matthew Treinish12eb3aa2012-11-30 16:52:14 -050037 groups_get = self.client.get_all_security_groups(
Zhongyue Luoa1343de2013-01-04 16:21:35 +080038 groupnames=(group_name,))
Attila Fazekasa23f5002012-10-23 19:32:45 +020039 self.assertEqual(len(groups_get), 1)
40 group_get = groups_get[0]
41 self.assertEqual(group.name, group_get.name)
42 self.assertEqual(group.name, group_get.name)
Attila Fazekas3e381f72013-08-01 16:52:23 +020043 # ping (icmp_echo) and other icmp allowed from everywhere
Attila Fazekasa23f5002012-10-23 19:32:45 +020044 # from_port and to_port act as icmp type
45 success = self.client.authorize_security_group(group_name,
46 ip_protocol="icmp",
47 cidr_ip="0.0.0.0/0",
48 from_port=-1,
49 to_port=-1)
50 self.assertTrue(success)
Attila Fazekas3e381f72013-08-01 16:52:23 +020051 # allow standard ssh port from anywhere
Attila Fazekasa23f5002012-10-23 19:32:45 +020052 success = self.client.authorize_security_group(group_name,
53 ip_protocol="tcp",
54 cidr_ip="0.0.0.0/0",
55 from_port=22,
56 to_port=22)
57 self.assertTrue(success)
Attila Fazekas3e381f72013-08-01 16:52:23 +020058 # TODO(afazekas): Duplicate tests
Matthew Treinish12eb3aa2012-11-30 16:52:14 -050059 group_get = self.client.get_all_security_groups(
Zhongyue Luoa1343de2013-01-04 16:21:35 +080060 groupnames=(group_name,))[0]
Attila Fazekas3e381f72013-08-01 16:52:23 +020061 # remove listed rules
Attila Fazekasa23f5002012-10-23 19:32:45 +020062 for ip_permission in group_get.rules:
63 for cidr in ip_permission.grants:
64 self.assertTrue(self.client.revoke_security_group(group_name,
65 ip_protocol=ip_permission.ip_protocol,
66 cidr_ip=cidr,
67 from_port=ip_permission.from_port,
68 to_port=ip_permission.to_port))
69
Matthew Treinish12eb3aa2012-11-30 16:52:14 -050070 group_get = self.client.get_all_security_groups(
Zhongyue Luoa1343de2013-01-04 16:21:35 +080071 groupnames=(group_name,))[0]
Attila Fazekas3e381f72013-08-01 16:52:23 +020072 # all rules shuld be removed now
Attila Fazekasa23f5002012-10-23 19:32:45 +020073 self.assertEqual(0, len(group_get.rules))