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