diff --git a/ranger_tempest_plugin/tests/api/test_images.py b/ranger_tempest_plugin/tests/api/test_images.py index c6197df..ad701c9 100755 --- a/ranger_tempest_plugin/tests/api/test_images.py +++ b/ranger_tempest_plugin/tests/api/test_images.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +from ranger_tempest_plugin.data_utils import data_utils from ranger_tempest_plugin.tests.api import ims_base from tempest import config from tempest.lib import decorators @@ -65,6 +66,23 @@ class TestTempestIms(ims_base.ImsBaseOrmTest): return image + def _delete_image(self, id_): + """Try to delete from from dcp only""" + # delete the data and do get_image to ensure 404-NotFound response + self._del_img_validate_deletion_on_dcp_and_lcp(id_) + self.assertRaises(exceptions.NotFound, self.client.get_image, id_) + + def _create_region(self, status='functional'): + region_name = data_utils.rand_name() + _, region = self.os_admin.rms_client.create_region( + **{ + 'region_id': region_name, + 'status': status, + } + ) + self.addCleanup(self.os_admin.rms_client.delete_region, region_name) + return region + @decorators.idempotent_id('2b1bb28b-4151-4e75-ae1b-d21089c3418c') def test_get_image(self): """Execute 'get_image' using the following options: @@ -258,3 +276,53 @@ class TestTempestIms(ims_base.ImsBaseOrmTest): self._del_img_validate_deletion_on_dcp_and_lcp(test_image_id) self.assertRaises(exceptions.NotFound, self.client.get_image, test_image_id) + + @decorators.idempotent_id('e642fa39-1b69-4d17-8bd1-aee90ea042a3') + def test_image_while_region_down(self): + # create region with status down + region = self._create_region(status='down') + + # create flavor within that newly created region + post_body = self._get_image_params() + post_body['regions'][0]['name'] = region['name'] + self.assertRaises(exceptions.BadRequest, + self.client.create_image, **post_body) + + @decorators.idempotent_id('a1fee342-3000-41a6-97f9-b33fd2734e4d') + def test_image_while_region_building(self): + # create region with status building + region = self._create_region(status='building') + + # create image within that newly created region + post_body = self._get_image_params() + post_body['regions'][0]['name'] = region['name'] + _, body = self.client.create_image(**post_body) + self.assertIn('id', body['image']) + test_image_id = body['image']['id'] + self.addCleanup(self._delete_image, test_image_id) + + _, body = self.client.get_image(test_image_id) + # since region is building it will give error + # Notification to ORD failed + _, body = self.client.get_image(test_image_id) + self.assertEqual(body['image']['id'], test_image_id) + self.assertEqual(body['image']['status'], 'error') + + @decorators.idempotent_id('b967ce58-5d24-4af2-8416-a336772c8087') + def test_image_while_region_maintenance(self): + # create region with status maintenance + region = self._create_region(status='maintenance') + + # create image within that newly created region + post_body = self._get_image_params() + post_body['regions'][0]['name'] = region['name'] + _, body = self.client.create_image(**post_body) + self.assertIn('id', body['image']) + test_image_id = body['image']['id'] + self.addCleanup(self._delete_image, test_image_id) + + _, body = self.client.get_image(test_image_id) + # since region is maintenance it will give error + # Notification to ORD failed + self.assertEqual(body['image']['id'], test_image_id) + self.assertEqual(body['image']['status'], 'Error')