blob: 9b0a3de3f708e157477677ff6cc32298c041f568 [file] [log] [blame]
Yair Friedf37dae32013-09-01 15:35:14 +03001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 OpenStack Foundation
4# 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
Yair Friedd5479822013-10-14 15:33:32 +030018from tempest.api.network import base_security_groups as base
Yair Friedf37dae32013-09-01 15:35:14 +030019from tempest.test import attr
20
21
Yair Friedd5479822013-10-14 15:33:32 +030022class SecGroupTest(base.BaseSecGroupTest):
Yair Friedf37dae32013-09-01 15:35:14 +030023 _interface = 'json'
24
Yair Friedf37dae32013-09-01 15:35:14 +030025 @attr(type='smoke')
26 def test_list_security_groups(self):
27 # Verify the that security group belonging to tenant exist in list
28 resp, body = self.client.list_security_groups()
29 self.assertEqual('200', resp['status'])
30 security_groups = body['security_groups']
31 found = None
32 for n in security_groups:
33 if (n['name'] == 'default'):
34 found = n['id']
35 msg = "Security-group list doesn't contain default security-group"
36 self.assertIsNotNone(found, msg)
37
38 @attr(type='smoke')
Yair Friedbcdcb3b2013-10-11 09:08:15 +030039 def test_create_show_delete_security_group(self):
Yair Friedd5479822013-10-14 15:33:32 +030040 group_create_body, name = self._create_security_group()
Yair Friedf37dae32013-09-01 15:35:14 +030041
42 # Show details of the created security group
43 resp, show_body = self.client.show_security_group(
44 group_create_body['security_group']['id'])
45 self.assertEqual('200', resp['status'])
46 self.assertEqual(show_body['security_group']['name'], name)
47
48 # List security groups and verify if created group is there in response
49 resp, list_body = self.client.list_security_groups()
50 self.assertEqual('200', resp['status'])
51 secgroup_list = list()
52 for secgroup in list_body['security_groups']:
53 secgroup_list.append(secgroup['id'])
54 self.assertIn(group_create_body['security_group']['id'], secgroup_list)
Yair Friedbcdcb3b2013-10-11 09:08:15 +030055
56 @attr(type='smoke')
57 def test_create_show_delete_security_group_rule(self):
Yair Friedd5479822013-10-14 15:33:32 +030058 group_create_body, _ = self._create_security_group()
Yair Friedbcdcb3b2013-10-11 09:08:15 +030059
60 # Create rules for each protocol
61 protocols = ['tcp', 'udp', 'icmp']
62 for protocol in protocols:
63 resp, rule_create_body = self.client.create_security_group_rule(
64 group_create_body['security_group']['id'],
65 protocol=protocol
66 )
67 self.assertEqual('201', resp['status'])
68 self.addCleanup(self._delete_security_group_rule,
69 rule_create_body['security_group_rule']['id']
70 )
71
Yair Friedf37dae32013-09-01 15:35:14 +030072 # Show details of the created security rule
73 resp, show_rule_body = self.client.show_security_group_rule(
74 rule_create_body['security_group_rule']['id']
75 )
76 self.assertEqual('200', resp['status'])
77
78 # List rules and verify created rule is in response
79 resp, rule_list_body = self.client.list_security_group_rules()
80 self.assertEqual('200', resp['status'])
81 rule_list = [rule['id']
82 for rule in rule_list_body['security_group_rules']]
83 self.assertIn(rule_create_body['security_group_rule']['id'], rule_list)
84
Yair Friedf37dae32013-09-01 15:35:14 +030085
86class SecGroupTestXML(SecGroupTest):
87 _interface = 'xml'