blob: 95894a61a408a177a7ff2b06621c4042775b991b [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
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000019from tempest import test
20
21
22class RegionsTestJSON(base.BaseIdentityV3AdminTest):
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000023
24 @classmethod
Rohan Kanadeb645e172015-02-05 17:38:59 +053025 def setup_clients(cls):
26 super(RegionsTestJSON, cls).setup_clients()
Yaroslav Lobankov757d1a22015-12-18 11:43:02 +030027 cls.client = cls.regions_client
Rohan Kanadeb645e172015-02-05 17:38:59 +053028
29 @classmethod
Andrea Frittoli7688e742014-09-15 12:38:22 +010030 def resource_setup(cls):
31 super(RegionsTestJSON, cls).resource_setup()
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000032 cls.setup_regions = list()
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000033 for i in range(2):
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000034 r_description = data_utils.rand_name('description')
Yaroslav Lobankov1a67f7b2015-11-11 16:27:15 +030035 region = cls.client.create_region(
36 description=r_description)['region']
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000037 cls.setup_regions.append(region)
38
39 @classmethod
Andrea Frittoli7688e742014-09-15 12:38:22 +010040 def resource_cleanup(cls):
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000041 for r in cls.setup_regions:
42 cls.client.delete_region(r['id'])
Andrea Frittoli7688e742014-09-15 12:38:22 +010043 super(RegionsTestJSON, cls).resource_cleanup()
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000044
Chris Hoge7579c1a2015-02-26 14:12:15 -080045 @test.idempotent_id('56186092-82e4-43f2-b954-91013218ba42')
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000046 def test_create_update_get_delete_region(self):
Castulo J. Martinez0a592b42016-05-13 09:15:23 -070047 # Create region
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000048 r_description = data_utils.rand_name('description')
David Kranzd8ccb792014-12-29 11:32:05 -050049 region = self.client.create_region(
Yaroslav Lobankov1a67f7b2015-11-11 16:27:15 +030050 description=r_description,
John Warrenc3e50142015-08-13 13:31:56 +000051 parent_region_id=self.setup_regions[0]['id'])['region']
Castulo J. Martinez0a592b42016-05-13 09:15:23 -070052 # This test will delete the region as part of the validation
53 # procedure, so it needs a different cleanup method that
54 # would be useful in case the tests fails at any point before
55 # reaching the deletion part.
56 self.addCleanup(test_utils.call_and_ignore_notfound_exc,
57 self.client.delete_region, region['id'])
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000058 self.assertEqual(r_description, region['description'])
59 self.assertEqual(self.setup_regions[0]['id'],
60 region['parent_region_id'])
61 # Update region with new description and parent ID
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000062 r_alt_description = data_utils.rand_name('description')
David Kranzd8ccb792014-12-29 11:32:05 -050063 region = self.client.update_region(
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000064 region['id'],
65 description=r_alt_description,
John Warrenc3e50142015-08-13 13:31:56 +000066 parent_region_id=self.setup_regions[1]['id'])['region']
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000067 self.assertEqual(r_alt_description, region['description'])
68 self.assertEqual(self.setup_regions[1]['id'],
69 region['parent_region_id'])
70 # Get the details of region
lei zhangcc5a0f82015-11-28 23:55:23 +080071 region = self.client.show_region(region['id'])['region']
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000072 self.assertEqual(r_alt_description, region['description'])
73 self.assertEqual(self.setup_regions[1]['id'],
74 region['parent_region_id'])
Castulo J. Martinez0a592b42016-05-13 09:15:23 -070075 # Delete the region
76 self.client.delete_region(region['id'])
77 body = self.client.list_regions()['regions']
78 regions_list = [r['id'] for r in body]
79 self.assertNotIn(region['id'], regions_list)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000080
81 @test.attr(type='smoke')
Chris Hoge7579c1a2015-02-26 14:12:15 -080082 @test.idempotent_id('2c12c5b5-efcf-4aa5-90c5-bff1ab0cdbe2')
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000083 def test_create_region_with_specific_id(self):
84 # Create a region with a specific id
85 r_region_id = data_utils.rand_uuid()
Ken'ichi Ohmichi96508472015-03-23 01:43:42 +000086 r_description = data_utils.rand_name('description')
David Kranzd8ccb792014-12-29 11:32:05 -050087 region = self.client.create_region(
Yaroslav Lobankov1a67f7b2015-11-11 16:27:15 +030088 region_id=r_region_id, description=r_description)['region']
Castulo J. Martinez0a592b42016-05-13 09:15:23 -070089 self.addCleanup(self.client.delete_region, region['id'])
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000090 # Asserting Create Region with specific id response body
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000091 self.assertEqual(r_region_id, region['id'])
92 self.assertEqual(r_description, region['description'])
93
Chris Hoge7579c1a2015-02-26 14:12:15 -080094 @test.idempotent_id('d180bf99-544a-445c-ad0d-0c0d27663796')
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000095 def test_list_regions(self):
96 # Get a list of regions
John Warrenc3e50142015-08-13 13:31:56 +000097 fetched_regions = self.client.list_regions()['regions']
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000098 missing_regions =\
99 [e for e in self.setup_regions if e not in fetched_regions]
100 # Asserting List Regions response
101 self.assertEqual(0, len(missing_regions),
102 "Failed to find region %s in fetched list" %
103 ', '.join(str(e) for e in missing_regions))
Castulo J. Martinez0a592b42016-05-13 09:15:23 -0700104
105 @test.idempotent_id('2d1057cb-bbde-413a-acdf-e2d265284542')
106 def test_list_regions_filter_by_parent_region_id(self):
107 # Add a sub-region to one of the existing test regions
108 r_description = data_utils.rand_name('description')
109 region = self.client.create_region(
110 description=r_description,
111 parent_region_id=self.setup_regions[0]['id'])['region']
112 self.addCleanup(self.client.delete_region, region['id'])
113 # Get the list of regions filtering with the parent_region_id
114 params = {'parent_region_id': self.setup_regions[0]['id']}
115 fetched_regions = self.client.list_regions(params=params)['regions']
116 # Asserting list regions response
117 self.assertIn(region, fetched_regions)
118 for r in fetched_regions:
119 self.assertEqual(self.setup_regions[0]['id'],
120 r['parent_region_id'])