blob: d8679e0e14e7972c60ed4bb5b9e260e3ab792b02 [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
Matthew Treinish01472ff2015-02-20 17:26:52 -050016from tempest_lib.common.utils import data_utils
Abhijeet Malawade3e067382013-12-08 21:54:56 -080017import testtools
18
19from tempest.api.compute import base
Abhijeet Malawade3e067382013-12-08 21:54:56 -080020from tempest import config
Masayuki Igawa394d8d92014-03-04 17:21:56 +090021from tempest import test
Abhijeet Malawade3e067382013-12-08 21:54:56 -080022
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
Rohan Kanade60b73092015-02-04 17:58:19 +053029 def setup_clients(cls):
30 super(SecurityGroupsTestAdminJSON, cls).setup_clients()
Abhijeet Malawade3e067382013-12-08 21:54:56 -080031 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:
David Kranz9964b4e2015-02-06 15:45:29 -050036 self.adm_client.delete_security_group(securitygroup_id)
Abhijeet Malawade3e067382013-12-08 21:54:56 -080037 else:
David Kranz9964b4e2015-02-06 15:45:29 -050038 self.client.delete_security_group(securitygroup_id)
Abhijeet Malawade3e067382013-12-08 21:54:56 -080039
Chris Hoge7579c1a2015-02-26 14:12:15 -080040 @test.idempotent_id('49667619-5af9-4c63-ab5d-2cfdd1c8f7f1')
Sean Dague86bd8422013-12-20 09:56:44 -050041 @testtools.skipIf(CONF.service_available.neutron,
Yaroslav Lobankov48509c32015-03-17 21:18:30 +030042 "Skipped because neutron does not support all_tenants "
Abhijeet Malawade3e067382013-12-08 21:54:56 -080043 "search filter.")
Matthew Treinish2df97482014-06-13 15:02:26 -040044 @test.services('network')
Abhijeet Malawade3e067382013-12-08 21:54:56 -080045 def test_list_security_groups_list_all_tenants_filter(self):
46 # Admin can list security groups of all tenants
47 # List of all security groups created
48 security_group_list = []
49 # Create two security groups for a non-admin tenant
50 for i in range(2):
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000051 name = data_utils.rand_name('securitygroup')
52 description = data_utils.rand_name('description')
David Kranz9964b4e2015-02-06 15:45:29 -050053 securitygroup = (self.client
54 .create_security_group(name, description))
Abhijeet Malawade3e067382013-12-08 21:54:56 -080055 self.addCleanup(self._delete_security_group,
56 securitygroup['id'], admin=False)
57 security_group_list.append(securitygroup)
58
59 client_tenant_id = securitygroup['tenant_id']
60 # Create two security groups for admin tenant
61 for i in range(2):
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000062 name = data_utils.rand_name('securitygroup')
63 description = data_utils.rand_name('description')
David Kranz9964b4e2015-02-06 15:45:29 -050064 adm_securitygroup = (self.adm_client
65 .create_security_group(name,
66 description))
Abhijeet Malawade3e067382013-12-08 21:54:56 -080067 self.addCleanup(self._delete_security_group,
68 adm_securitygroup['id'])
69 security_group_list.append(adm_securitygroup)
70
71 # Fetch all security groups based on 'all_tenants' search filter
72 param = {'all_tenants': 'true'}
David Kranz9964b4e2015-02-06 15:45:29 -050073 fetched_list = self.adm_client.list_security_groups(params=param)
Abhijeet Malawade3e067382013-12-08 21:54:56 -080074 sec_group_id_list = map(lambda sg: sg['id'], fetched_list)
75 # Now check if all created Security Groups are present in fetched list
76 for sec_group in security_group_list:
77 self.assertIn(sec_group['id'], sec_group_id_list)
78
79 # Fetch all security groups for non-admin user with 'all_tenants'
80 # search filter
David Kranz9964b4e2015-02-06 15:45:29 -050081 fetched_list = self.client.list_security_groups(params=param)
Abhijeet Malawade3e067382013-12-08 21:54:56 -080082 # Now check if all created Security Groups are present in fetched list
83 for sec_group in fetched_list:
84 self.assertEqual(sec_group['tenant_id'], client_tenant_id,
85 "Failed to get all security groups for "
86 "non admin user.")