blob: c5d5824035d8e59ca287b11ced83aeec483350ca [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
17from tempest.common.utils import data_utils
18from tempest import exceptions
19from tempest import test
20
21
22class RegionsTestJSON(base.BaseIdentityV3AdminTest):
23 _interface = 'json'
24
25 @classmethod
Andrea Frittoli7688e742014-09-15 12:38:22 +010026 def resource_setup(cls):
27 super(RegionsTestJSON, cls).resource_setup()
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000028 cls.setup_regions = list()
29 cls.client = cls.region_client
30 for i in range(2):
31 r_description = data_utils.rand_name('description-')
32 _, region = cls.client.create_region(r_description)
33 cls.setup_regions.append(region)
34
35 @classmethod
Andrea Frittoli7688e742014-09-15 12:38:22 +010036 def resource_cleanup(cls):
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000037 for r in cls.setup_regions:
38 cls.client.delete_region(r['id'])
Andrea Frittoli7688e742014-09-15 12:38:22 +010039 super(RegionsTestJSON, cls).resource_cleanup()
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000040
41 def _delete_region(self, region_id):
David Kranz2aaf5312014-08-29 09:22:10 -040042 self.client.delete_region(region_id)
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000043 self.assertRaises(exceptions.NotFound,
44 self.client.get_region, region_id)
45
46 @test.attr(type='gate')
47 def test_create_update_get_delete_region(self):
48 r_description = data_utils.rand_name('description-')
David Kranz2aaf5312014-08-29 09:22:10 -040049 _, region = self.client.create_region(
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000050 r_description, parent_region_id=self.setup_regions[0]['id'])
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000051 self.addCleanup(self._delete_region, region['id'])
52 self.assertEqual(r_description, region['description'])
53 self.assertEqual(self.setup_regions[0]['id'],
54 region['parent_region_id'])
55 # Update region with new description and parent ID
56 r_alt_description = data_utils.rand_name('description-')
David Kranz2aaf5312014-08-29 09:22:10 -040057 _, region = self.client.update_region(
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000058 region['id'],
59 description=r_alt_description,
60 parent_region_id=self.setup_regions[1]['id'])
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000061 self.assertEqual(r_alt_description, region['description'])
62 self.assertEqual(self.setup_regions[1]['id'],
63 region['parent_region_id'])
64 # Get the details of region
David Kranz2aaf5312014-08-29 09:22:10 -040065 _, region = self.client.get_region(region['id'])
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000066 self.assertEqual(r_alt_description, region['description'])
67 self.assertEqual(self.setup_regions[1]['id'],
68 region['parent_region_id'])
69
70 @test.attr(type='smoke')
71 def test_create_region_with_specific_id(self):
72 # Create a region with a specific id
73 r_region_id = data_utils.rand_uuid()
74 r_description = data_utils.rand_name('description-')
David Kranz2aaf5312014-08-29 09:22:10 -040075 _, region = self.client.create_region(
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000076 r_description, unique_region_id=r_region_id)
77 self.addCleanup(self._delete_region, region['id'])
78 # Asserting Create Region with specific id response body
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000079 self.assertEqual(r_region_id, region['id'])
80 self.assertEqual(r_description, region['description'])
81
82 @test.attr(type='gate')
83 def test_list_regions(self):
84 # Get a list of regions
David Kranz2aaf5312014-08-29 09:22:10 -040085 _, fetched_regions = self.client.list_regions()
ravikumar-venkatesan3052e942014-05-12 18:25:17 +000086 missing_regions =\
87 [e for e in self.setup_regions if e not in fetched_regions]
88 # Asserting List Regions response
89 self.assertEqual(0, len(missing_regions),
90 "Failed to find region %s in fetched list" %
91 ', '.join(str(e) for e in missing_regions))
92
93
94class RegionsTestXML(RegionsTestJSON):
95 _interface = 'xml'