blob: f57a07c5108c4d96b93301a0d6643d50ac35eaeb [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
Fei Long Wangd39431f2015-05-14 11:30:48 +120017from tempest.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 +000020from tempest import test
21
22
23class RegionsTestJSON(base.BaseIdentityV3AdminTest):
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000024
25 @classmethod
Rohan Kanadeb645e172015-02-05 17:38:59 +053026 def setup_clients(cls):
27 super(RegionsTestJSON, cls).setup_clients()
Yaroslav Lobankov757d1a22015-12-18 11:43:02 +030028 cls.client = cls.regions_client
Rohan Kanadeb645e172015-02-05 17:38:59 +053029
30 @classmethod
Andrea Frittoli7688e742014-09-15 12:38:22 +010031 def resource_setup(cls):
32 super(RegionsTestJSON, cls).resource_setup()
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000033 cls.setup_regions = list()
zhufl8e9a0732017-01-26 16:15:21 +080034 for _ in range(2):
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000035 r_description = data_utils.rand_name('description')
Yaroslav Lobankov1a67f7b2015-11-11 16:27:15 +030036 region = cls.client.create_region(
37 description=r_description)['region']
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000038 cls.setup_regions.append(region)
39
40 @classmethod
Andrea Frittoli7688e742014-09-15 12:38:22 +010041 def resource_cleanup(cls):
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000042 for r in cls.setup_regions:
43 cls.client.delete_region(r['id'])
Andrea Frittoli7688e742014-09-15 12:38:22 +010044 super(RegionsTestJSON, cls).resource_cleanup()
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000045
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080046 @decorators.idempotent_id('56186092-82e4-43f2-b954-91013218ba42')
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000047 def test_create_update_get_delete_region(self):
Castulo J. Martinez0a592b42016-05-13 09:15:23 -070048 # Create region
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000049 r_description = data_utils.rand_name('description')
David Kranzd8ccb792014-12-29 11:32:05 -050050 region = self.client.create_region(
Yaroslav Lobankov1a67f7b2015-11-11 16:27:15 +030051 description=r_description,
John Warrenc3e50142015-08-13 13:31:56 +000052 parent_region_id=self.setup_regions[0]['id'])['region']
Castulo J. Martinez0a592b42016-05-13 09:15:23 -070053 # This test will delete the region as part of the validation
54 # procedure, so it needs a different cleanup method that
55 # would be useful in case the tests fails at any point before
56 # reaching the deletion part.
57 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
58 self.client.delete_region, region['id'])
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000059 self.assertEqual(r_description, region['description'])
60 self.assertEqual(self.setup_regions[0]['id'],
61 region['parent_region_id'])
62 # Update region with new description and parent ID
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000063 r_alt_description = data_utils.rand_name('description')
David Kranzd8ccb792014-12-29 11:32:05 -050064 region = self.client.update_region(
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000065 region['id'],
66 description=r_alt_description,
John Warrenc3e50142015-08-13 13:31:56 +000067 parent_region_id=self.setup_regions[1]['id'])['region']
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000068 self.assertEqual(r_alt_description, region['description'])
69 self.assertEqual(self.setup_regions[1]['id'],
70 region['parent_region_id'])
71 # Get the details of region
lei zhangcc5a0f82015-11-28 23:55:23 +080072 region = self.client.show_region(region['id'])['region']
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000073 self.assertEqual(r_alt_description, region['description'])
74 self.assertEqual(self.setup_regions[1]['id'],
75 region['parent_region_id'])
Castulo J. Martinez0a592b42016-05-13 09:15:23 -070076 # Delete the region
77 self.client.delete_region(region['id'])
78 body = self.client.list_regions()['regions']
79 regions_list = [r['id'] for r in body]
80 self.assertNotIn(region['id'], regions_list)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000081
82 @test.attr(type='smoke')
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080083 @decorators.idempotent_id('2c12c5b5-efcf-4aa5-90c5-bff1ab0cdbe2')
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000084 def test_create_region_with_specific_id(self):
85 # Create a region with a specific id
86 r_region_id = data_utils.rand_uuid()
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000087 r_description = data_utils.rand_name('description')
David Kranzd8ccb792014-12-29 11:32:05 -050088 region = self.client.create_region(
Yaroslav Lobankov1a67f7b2015-11-11 16:27:15 +030089 region_id=r_region_id, description=r_description)['region']
Castulo J. Martinez0a592b42016-05-13 09:15:23 -070090 self.addCleanup(self.client.delete_region, region['id'])
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000091 # Asserting Create Region with specific id response body
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000092 self.assertEqual(r_region_id, region['id'])
93 self.assertEqual(r_description, region['description'])
94
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -080095 @decorators.idempotent_id('d180bf99-544a-445c-ad0d-0c0d27663796')
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000096 def test_list_regions(self):
97 # Get a list of regions
John Warrenc3e50142015-08-13 13:31:56 +000098 fetched_regions = self.client.list_regions()['regions']
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000099 missing_regions =\
100 [e for e in self.setup_regions if e not in fetched_regions]
101 # Asserting List Regions response
102 self.assertEqual(0, len(missing_regions),
103 "Failed to find region %s in fetched list" %
104 ', '.join(str(e) for e in missing_regions))
Castulo J. Martinez0a592b42016-05-13 09:15:23 -0700105
Ken'ichi Ohmichieeabdd22017-01-27 17:46:00 -0800106 @decorators.idempotent_id('2d1057cb-bbde-413a-acdf-e2d265284542')
Castulo J. Martinez0a592b42016-05-13 09:15:23 -0700107 def test_list_regions_filter_by_parent_region_id(self):
108 # Add a sub-region to one of the existing test regions
109 r_description = data_utils.rand_name('description')
110 region = self.client.create_region(
111 description=r_description,
112 parent_region_id=self.setup_regions[0]['id'])['region']
113 self.addCleanup(self.client.delete_region, region['id'])
114 # Get the list of regions filtering with the parent_region_id
115 params = {'parent_region_id': self.setup_regions[0]['id']}
116 fetched_regions = self.client.list_regions(params=params)['regions']
117 # Asserting list regions response
118 self.assertIn(region, fetched_regions)
119 for r in fetched_regions:
120 self.assertEqual(self.setup_regions[0]['id'],
121 r['parent_region_id'])