blob: 63e456e28376429fb6e993fc461898dcedf1f2a2 [file] [log] [blame]
ravikumar-venkatesanacf99d72014-07-09 14:58:25 +00001# Copyright 2014 Hewlett-Packard Development Company, L.P
ravikumar-venkatesan3052e942014-05-12 18:25:17 +00002# 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
16from tempest.api.identity import base
Ken'ichi Ohmichi7bd25752017-03-10 10:45:39 -080017from tempest.lib.common.utils import data_utils
Castulo J. Martinez0a592b42016-05-13 09:15:23 -070018from tempest.lib.common.utils import test_utils
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080019from tempest.lib import decorators
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000020
21
22class RegionsTestJSON(base.BaseIdentityV3AdminTest):
zhufla7635d72020-04-29 14:36:41 +080023 """Test regions"""
24
Trevor McCaslande4c8a6a2019-01-14 09:23:43 -060025 # NOTE: force_tenant_isolation is true in the base class by default but
26 # overridden to false here to allow test execution for clouds using the
27 # pre-provisioned credentials provider.
28 force_tenant_isolation = False
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000029
30 @classmethod
Rohan Kanadeb645e172015-02-05 17:38:59 +053031 def setup_clients(cls):
32 super(RegionsTestJSON, cls).setup_clients()
Yaroslav Lobankov757d1a22015-12-18 11:43:02 +030033 cls.client = cls.regions_client
Rohan Kanadeb645e172015-02-05 17:38:59 +053034
35 @classmethod
Andrea Frittoli7688e742014-09-15 12:38:22 +010036 def resource_setup(cls):
37 super(RegionsTestJSON, cls).resource_setup()
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000038 cls.setup_regions = list()
zhufl8e9a0732017-01-26 16:15:21 +080039 for _ in range(2):
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000040 r_description = data_utils.rand_name('description')
Yaroslav Lobankov1a67f7b2015-11-11 16:27:15 +030041 region = cls.client.create_region(
42 description=r_description)['region']
Ankit Purohit90ef8f32017-12-06 05:01:24 +000043 cls.addClassResourceCleanup(
44 cls.client.delete_region, region['id'])
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000045 cls.setup_regions.append(region)
46
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080047 @decorators.idempotent_id('56186092-82e4-43f2-b954-91013218ba42')
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000048 def test_create_update_get_delete_region(self):
zhufla7635d72020-04-29 14:36:41 +080049 """Test creating, updating, getting and updating region"""
Castulo J. Martinez0a592b42016-05-13 09:15:23 -070050 # Create region
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000051 r_description = data_utils.rand_name('description')
David Kranzd8ccb792014-12-29 11:32:05 -050052 region = self.client.create_region(
Yaroslav Lobankov1a67f7b2015-11-11 16:27:15 +030053 description=r_description,
John Warrenc3e50142015-08-13 13:31:56 +000054 parent_region_id=self.setup_regions[0]['id'])['region']
Castulo J. Martinez0a592b42016-05-13 09:15:23 -070055 # This test will delete the region as part of the validation
56 # procedure, so it needs a different cleanup method that
57 # would be useful in case the tests fails at any point before
58 # reaching the deletion part.
59 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
60 self.client.delete_region, region['id'])
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000061 self.assertEqual(r_description, region['description'])
62 self.assertEqual(self.setup_regions[0]['id'],
63 region['parent_region_id'])
64 # Update region with new description and parent ID
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000065 r_alt_description = data_utils.rand_name('description')
David Kranzd8ccb792014-12-29 11:32:05 -050066 region = self.client.update_region(
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000067 region['id'],
68 description=r_alt_description,
John Warrenc3e50142015-08-13 13:31:56 +000069 parent_region_id=self.setup_regions[1]['id'])['region']
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000070 self.assertEqual(r_alt_description, region['description'])
71 self.assertEqual(self.setup_regions[1]['id'],
72 region['parent_region_id'])
73 # Get the details of region
lei zhangcc5a0f82015-11-28 23:55:23 +080074 region = self.client.show_region(region['id'])['region']
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000075 self.assertEqual(r_alt_description, region['description'])
76 self.assertEqual(self.setup_regions[1]['id'],
77 region['parent_region_id'])
Castulo J. Martinez0a592b42016-05-13 09:15:23 -070078 # Delete the region
79 self.client.delete_region(region['id'])
80 body = self.client.list_regions()['regions']
81 regions_list = [r['id'] for r in body]
82 self.assertNotIn(region['id'], regions_list)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000083
Jordan Pittier3b46d272017-04-12 16:17:28 +020084 @decorators.attr(type='smoke')
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080085 @decorators.idempotent_id('2c12c5b5-efcf-4aa5-90c5-bff1ab0cdbe2')
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000086 def test_create_region_with_specific_id(self):
zhufla7635d72020-04-29 14:36:41 +080087 """Test creating region with specific id"""
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000088 r_region_id = data_utils.rand_uuid()
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000089 r_description = data_utils.rand_name('description')
David Kranzd8ccb792014-12-29 11:32:05 -050090 region = self.client.create_region(
Yaroslav Lobankov1a67f7b2015-11-11 16:27:15 +030091 region_id=r_region_id, description=r_description)['region']
Castulo J. Martinez0a592b42016-05-13 09:15:23 -070092 self.addCleanup(self.client.delete_region, region['id'])
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000093 # Asserting Create Region with specific id response body
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000094 self.assertEqual(r_region_id, region['id'])
95 self.assertEqual(r_description, region['description'])
96
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080097 @decorators.idempotent_id('d180bf99-544a-445c-ad0d-0c0d27663796')
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000098 def test_list_regions(self):
zhufla7635d72020-04-29 14:36:41 +080099 """Test getting a list of regions"""
John Warrenc3e50142015-08-13 13:31:56 +0000100 fetched_regions = self.client.list_regions()['regions']
ravikumar-venkatesan3052e942014-05-12 18:25:17 +0000101 missing_regions =\
102 [e for e in self.setup_regions if e not in fetched_regions]
103 # Asserting List Regions response
Masayuki Igawaf9009b42017-04-10 14:49:29 +0900104 self.assertEmpty(missing_regions,
ravikumar-venkatesan3052e942014-05-12 18:25:17 +0000105 "Failed to find region %s in fetched list" %
106 ', '.join(str(e) for e in missing_regions))
Castulo J. Martinez0a592b42016-05-13 09:15:23 -0700107
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -0800108 @decorators.idempotent_id('2d1057cb-bbde-413a-acdf-e2d265284542')
Castulo J. Martinez0a592b42016-05-13 09:15:23 -0700109 def test_list_regions_filter_by_parent_region_id(self):
zhufla7635d72020-04-29 14:36:41 +0800110 """Test listing regions filtered by parent region id"""
Castulo J. Martinez0a592b42016-05-13 09:15:23 -0700111 # Add a sub-region to one of the existing test regions
112 r_description = data_utils.rand_name('description')
113 region = self.client.create_region(
114 description=r_description,
115 parent_region_id=self.setup_regions[0]['id'])['region']
116 self.addCleanup(self.client.delete_region, region['id'])
117 # Get the list of regions filtering with the parent_region_id
118 params = {'parent_region_id': self.setup_regions[0]['id']}
119 fetched_regions = self.client.list_regions(params=params)['regions']
120 # Asserting list regions response
121 self.assertIn(region, fetched_regions)
122 for r in fetched_regions:
123 self.assertEqual(self.setup_regions[0]['id'],
124 r['parent_region_id'])