blob: b95182d94ac661b3ff2a6d5a2e0cbeafe48f0522 [file] [log] [blame]
Yair Friedf37dae32013-09-01 15:35:14 +03001# Copyright 2013 OpenStack Foundation
2# 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
Yair Friedd5479822013-10-14 15:33:32 +030016from tempest.api.network import base_security_groups as base
Yair Friedf37dae32013-09-01 15:35:14 +030017from tempest.test import attr
18
19
Yair Friedd5479822013-10-14 15:33:32 +030020class SecGroupTest(base.BaseSecGroupTest):
Yair Friedf37dae32013-09-01 15:35:14 +030021 _interface = 'json'
22
Yair Friedf37dae32013-09-01 15:35:14 +030023 @attr(type='smoke')
24 def test_list_security_groups(self):
25 # Verify the that security group belonging to tenant exist in list
26 resp, body = self.client.list_security_groups()
27 self.assertEqual('200', resp['status'])
28 security_groups = body['security_groups']
29 found = None
30 for n in security_groups:
31 if (n['name'] == 'default'):
32 found = n['id']
33 msg = "Security-group list doesn't contain default security-group"
34 self.assertIsNotNone(found, msg)
35
36 @attr(type='smoke')
Yair Friedbcdcb3b2013-10-11 09:08:15 +030037 def test_create_show_delete_security_group(self):
Yair Friedd5479822013-10-14 15:33:32 +030038 group_create_body, name = self._create_security_group()
Yair Friedf37dae32013-09-01 15:35:14 +030039
40 # Show details of the created security group
41 resp, show_body = self.client.show_security_group(
42 group_create_body['security_group']['id'])
43 self.assertEqual('200', resp['status'])
44 self.assertEqual(show_body['security_group']['name'], name)
45
46 # List security groups and verify if created group is there in response
47 resp, list_body = self.client.list_security_groups()
48 self.assertEqual('200', resp['status'])
49 secgroup_list = list()
50 for secgroup in list_body['security_groups']:
51 secgroup_list.append(secgroup['id'])
52 self.assertIn(group_create_body['security_group']['id'], secgroup_list)
Yair Friedbcdcb3b2013-10-11 09:08:15 +030053
54 @attr(type='smoke')
55 def test_create_show_delete_security_group_rule(self):
Yair Friedd5479822013-10-14 15:33:32 +030056 group_create_body, _ = self._create_security_group()
Yair Friedbcdcb3b2013-10-11 09:08:15 +030057
58 # Create rules for each protocol
59 protocols = ['tcp', 'udp', 'icmp']
60 for protocol in protocols:
61 resp, rule_create_body = self.client.create_security_group_rule(
62 group_create_body['security_group']['id'],
63 protocol=protocol
64 )
65 self.assertEqual('201', resp['status'])
66 self.addCleanup(self._delete_security_group_rule,
67 rule_create_body['security_group_rule']['id']
68 )
69
Yair Friedf37dae32013-09-01 15:35:14 +030070 # Show details of the created security rule
71 resp, show_rule_body = self.client.show_security_group_rule(
72 rule_create_body['security_group_rule']['id']
73 )
74 self.assertEqual('200', resp['status'])
75
76 # List rules and verify created rule is in response
77 resp, rule_list_body = self.client.list_security_group_rules()
78 self.assertEqual('200', resp['status'])
79 rule_list = [rule['id']
80 for rule in rule_list_body['security_group_rules']]
81 self.assertIn(rule_create_body['security_group_rule']['id'], rule_list)
82
jun xiee31dbe92014-01-13 18:10:37 +080083 @attr(type='smoke')
84 def test_create_security_group_rule_with_additional_args(self):
85 # Verify creating security group rule with the following
86 # arguments works: "protocol": "tcp", "port_range_max": 77,
87 # "port_range_min": 77, "direction":"ingress".
88 group_create_body, _ = self._create_security_group()
89
90 direction = 'ingress'
91 protocol = 'tcp'
92 port_range_min = 77
93 port_range_max = 77
94 resp, rule_create_body = self.client.create_security_group_rule(
95 group_create_body['security_group']['id'],
96 direction=direction,
97 protocol=protocol,
98 port_range_min=port_range_min,
99 port_range_max=port_range_max
100 )
101
102 self.assertEqual('201', resp['status'])
103 sec_group_rule = rule_create_body['security_group_rule']
104 self.addCleanup(self._delete_security_group_rule,
105 sec_group_rule['id']
106 )
107
108 self.assertEqual(sec_group_rule['direction'], direction)
109 self.assertEqual(sec_group_rule['protocol'], protocol)
110 self.assertEqual(int(sec_group_rule['port_range_min']), port_range_min)
111 self.assertEqual(int(sec_group_rule['port_range_max']), port_range_max)
112
Yair Friedf37dae32013-09-01 15:35:14 +0300113
114class SecGroupTestXML(SecGroupTest):
115 _interface = 'xml'