Abhijeet Malawade | 3e06738 | 2013-12-08 21:54:56 -0800 | [diff] [blame] | 1 | # 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 | |
Abhijeet Malawade | 3e06738 | 2013-12-08 21:54:56 -0800 | [diff] [blame] | 16 | from tempest.api.compute import base |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 17 | from tempest.common.utils import data_utils |
Abhijeet Malawade | 3e06738 | 2013-12-08 21:54:56 -0800 | [diff] [blame] | 18 | from tempest import config |
Masayuki Igawa | 394d8d9 | 2014-03-04 17:21:56 +0900 | [diff] [blame] | 19 | from tempest import test |
Abhijeet Malawade | 3e06738 | 2013-12-08 21:54:56 -0800 | [diff] [blame] | 20 | |
Sean Dague | 86bd842 | 2013-12-20 09:56:44 -0500 | [diff] [blame] | 21 | CONF = config.CONF |
| 22 | |
Abhijeet Malawade | 3e06738 | 2013-12-08 21:54:56 -0800 | [diff] [blame] | 23 | |
| 24 | class SecurityGroupsTestAdminJSON(base.BaseV2ComputeAdminTest): |
Abhijeet Malawade | 3e06738 | 2013-12-08 21:54:56 -0800 | [diff] [blame] | 25 | |
| 26 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 27 | def setup_clients(cls): |
| 28 | super(SecurityGroupsTestAdminJSON, cls).setup_clients() |
John Warren | f234551 | 2015-12-10 13:39:30 -0500 | [diff] [blame] | 29 | cls.adm_client = cls.os_adm.compute_security_groups_client |
Abhijeet Malawade | 3e06738 | 2013-12-08 21:54:56 -0800 | [diff] [blame] | 30 | cls.client = cls.security_groups_client |
| 31 | |
| 32 | def _delete_security_group(self, securitygroup_id, admin=True): |
| 33 | if admin: |
David Kranz | 9964b4e | 2015-02-06 15:45:29 -0500 | [diff] [blame] | 34 | self.adm_client.delete_security_group(securitygroup_id) |
Abhijeet Malawade | 3e06738 | 2013-12-08 21:54:56 -0800 | [diff] [blame] | 35 | else: |
David Kranz | 9964b4e | 2015-02-06 15:45:29 -0500 | [diff] [blame] | 36 | self.client.delete_security_group(securitygroup_id) |
Abhijeet Malawade | 3e06738 | 2013-12-08 21:54:56 -0800 | [diff] [blame] | 37 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 38 | @test.idempotent_id('49667619-5af9-4c63-ab5d-2cfdd1c8f7f1') |
Matthew Treinish | 2df9748 | 2014-06-13 15:02:26 -0400 | [diff] [blame] | 39 | @test.services('network') |
Abhijeet Malawade | 3e06738 | 2013-12-08 21:54:56 -0800 | [diff] [blame] | 40 | def test_list_security_groups_list_all_tenants_filter(self): |
| 41 | # Admin can list security groups of all tenants |
| 42 | # List of all security groups created |
| 43 | security_group_list = [] |
| 44 | # Create two security groups for a non-admin tenant |
| 45 | for i in range(2): |
Ken'ichi Ohmichi | 4937f56 | 2015-03-23 00:15:01 +0000 | [diff] [blame] | 46 | name = data_utils.rand_name('securitygroup') |
| 47 | description = data_utils.rand_name('description') |
ghanshyam | b610b77 | 2015-08-24 17:29:38 +0900 | [diff] [blame] | 48 | securitygroup = self.client.create_security_group( |
| 49 | name=name, description=description)['security_group'] |
Abhijeet Malawade | 3e06738 | 2013-12-08 21:54:56 -0800 | [diff] [blame] | 50 | self.addCleanup(self._delete_security_group, |
| 51 | securitygroup['id'], admin=False) |
| 52 | security_group_list.append(securitygroup) |
| 53 | |
| 54 | client_tenant_id = securitygroup['tenant_id'] |
| 55 | # Create two security groups for admin tenant |
| 56 | for i in range(2): |
Ken'ichi Ohmichi | 4937f56 | 2015-03-23 00:15:01 +0000 | [diff] [blame] | 57 | name = data_utils.rand_name('securitygroup') |
| 58 | description = data_utils.rand_name('description') |
Ken'ichi Ohmichi | 34563cc | 2015-07-21 00:53:17 +0000 | [diff] [blame] | 59 | adm_securitygroup = self.adm_client.create_security_group( |
ghanshyam | b610b77 | 2015-08-24 17:29:38 +0900 | [diff] [blame] | 60 | name=name, description=description)['security_group'] |
Abhijeet Malawade | 3e06738 | 2013-12-08 21:54:56 -0800 | [diff] [blame] | 61 | self.addCleanup(self._delete_security_group, |
| 62 | adm_securitygroup['id']) |
| 63 | security_group_list.append(adm_securitygroup) |
| 64 | |
| 65 | # Fetch all security groups based on 'all_tenants' search filter |
ghanshyam | b610b77 | 2015-08-24 17:29:38 +0900 | [diff] [blame] | 66 | fetched_list = self.adm_client.list_security_groups( |
| 67 | all_tenants='true')['security_groups'] |
Sirushti Murugesan | 935f2cc | 2016-07-12 19:48:24 +0530 | [diff] [blame] | 68 | sec_group_id_list = [sg['id'] for sg in fetched_list] |
Abhijeet Malawade | 3e06738 | 2013-12-08 21:54:56 -0800 | [diff] [blame] | 69 | # Now check if all created Security Groups are present in fetched list |
| 70 | for sec_group in security_group_list: |
| 71 | self.assertIn(sec_group['id'], sec_group_id_list) |
| 72 | |
| 73 | # Fetch all security groups for non-admin user with 'all_tenants' |
| 74 | # search filter |
ghanshyam | b610b77 | 2015-08-24 17:29:38 +0900 | [diff] [blame] | 75 | fetched_list = (self.client.list_security_groups(all_tenants='true') |
| 76 | ['security_groups']) |
Abhijeet Malawade | 3e06738 | 2013-12-08 21:54:56 -0800 | [diff] [blame] | 77 | # Now check if all created Security Groups are present in fetched list |
| 78 | for sec_group in fetched_list: |
| 79 | self.assertEqual(sec_group['tenant_id'], client_tenant_id, |
| 80 | "Failed to get all security groups for " |
| 81 | "non admin user.") |