def test_create_bay_with_nonexist_image(self, mock_valid_os_res): bdict = apiutils.bay_post_data() mock_valid_os_res.side_effect = exception.ImageNotFound('test-img') response = self.post_json('/bays', bdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertTrue(mock_valid_os_res.called) self.assertEqual(400, response.status_int)
def test_replace_baymodel_with_no_exist_image_id(self): self.mock_valid_os_res.side_effect = exception.ImageNotFound("aaa") response = self.patch_json('/baymodels/%s' % self.baymodel.uuid, [{'path': '/image_id', 'value': 'aaa', 'op': 'replace'}], expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(400, response.status_code) self.assertTrue(response.json['errors'])
def validate_image(cli, image): """Validate image""" try: image_found = api_utils.get_openstack_resource(cli.glance().images, image, 'images') except (glance_exception.NotFound, exception.ResourceNotFound): raise exception.ImageNotFound(image_id=image) except glance_exception.HTTPForbidden: raise exception.ImageNotAuthorized(image_id=image) if not image_found.get('os_distro'): raise exception.OSDistroFieldNotFound(image_id=image) return image_found
def _get_image_data(self, context, image_ident): """Retrieves os_distro and other metadata from the Glance image. :param image_ident: image id or name of baymodel. """ try: cli = clients.OpenStackClients(context) return api_utils.get_openstack_resource(cli.glance().images, image_ident, 'images') except glanceclient.exc.NotFound: raise exception.ImageNotFound(image_id=image_ident) except glanceclient.exc.HTTPForbidden: raise exception.ImageNotAuthorized(image_id=image_ident)