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