blob: da2a1a1aa22cab3d29c699612a15e86d84264e38 [file] [log] [blame]
Abhijeet Malawade3e067382013-12-08 21:54:56 -08001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2013 NTT Data
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
18import testtools
19
20from tempest.api.compute import base
21from tempest.common.utils import data_utils
22from tempest import config
23from tempest.test import attr
24
Sean Dague86bd8422013-12-20 09:56:44 -050025CONF = config.CONF
26
Abhijeet Malawade3e067382013-12-08 21:54:56 -080027
28class SecurityGroupsTestAdminJSON(base.BaseV2ComputeAdminTest):
29 _interface = 'json'
30
31 @classmethod
32 def setUpClass(cls):
33 super(SecurityGroupsTestAdminJSON, cls).setUpClass()
34 cls.adm_client = cls.os_adm.security_groups_client
35 cls.client = cls.security_groups_client
36
37 def _delete_security_group(self, securitygroup_id, admin=True):
38 if admin:
39 resp, _ = self.adm_client.delete_security_group(securitygroup_id)
40 else:
41 resp, _ = self.client.delete_security_group(securitygroup_id)
42
43 self.assertEqual(202, resp.status)
44
Sean Dague86bd8422013-12-20 09:56:44 -050045 @testtools.skipIf(CONF.service_available.neutron,
Abhijeet Malawade3e067382013-12-08 21:54:56 -080046 "Skipped because neutron do not support all_tenants"
47 "search filter.")
48 @attr(type='smoke')
49 def test_list_security_groups_list_all_tenants_filter(self):
50 # Admin can list security groups of all tenants
51 # List of all security groups created
52 security_group_list = []
53 # Create two security groups for a non-admin tenant
54 for i in range(2):
55 name = data_utils.rand_name('securitygroup-')
56 description = data_utils.rand_name('description-')
57 resp, securitygroup = (self.client
58 .create_security_group(name, description))
59 self.assertEqual(200, resp.status)
60 self.addCleanup(self._delete_security_group,
61 securitygroup['id'], admin=False)
62 security_group_list.append(securitygroup)
63
64 client_tenant_id = securitygroup['tenant_id']
65 # Create two security groups for admin tenant
66 for i in range(2):
67 name = data_utils.rand_name('securitygroup-')
68 description = data_utils.rand_name('description-')
69 resp, adm_securitygroup = (self.adm_client
70 .create_security_group(name,
71 description))
72 self.assertEqual(200, resp.status)
73 self.addCleanup(self._delete_security_group,
74 adm_securitygroup['id'])
75 security_group_list.append(adm_securitygroup)
76
77 # Fetch all security groups based on 'all_tenants' search filter
78 param = {'all_tenants': 'true'}
79 resp, fetched_list = self.adm_client.list_security_groups(params=param)
80 self.assertEqual(200, resp.status)
81 sec_group_id_list = map(lambda sg: sg['id'], fetched_list)
82 # Now check if all created Security Groups are present in fetched list
83 for sec_group in security_group_list:
84 self.assertIn(sec_group['id'], sec_group_id_list)
85
86 # Fetch all security groups for non-admin user with 'all_tenants'
87 # search filter
88 resp, fetched_list = self.client.list_security_groups(params=param)
89 self.assertEqual(200, resp.status)
90 # Now check if all created Security Groups are present in fetched list
91 for sec_group in fetched_list:
92 self.assertEqual(sec_group['tenant_id'], client_tenant_id,
93 "Failed to get all security groups for "
94 "non admin user.")
95
96
97class SecurityGroupsTestAdminXML(SecurityGroupsTestAdminJSON):
98 _interface = 'xml'