def _translate_image_exception(image_id, exc_value): if isinstance(exc_value, (glance_exc.Forbidden, glance_exc.Unauthorized)): return exception.ImageNotAuthorized(image_id=image_id) if isinstance(exc_value, glance_exc.NotFound): return exception.ImageNotFound(image_id=image_id) if isinstance(exc_value, glance_exc.BadRequest): return exception.Invalid(exc_value) return exc_value
def test_validate_image_properties_glance_image_not_authorized(self, image_service_mock): d_info = {'image_source': 'uuid'} show_mock = image_service_mock.return_value.show show_mock.side_effect = exception.ImageNotAuthorized(image_id='uuid') self.assertRaises(exception.InvalidParameterValue, iscsi_deploy.validate_image_properties, self.context, d_info, [])
def test_validate_fail_glance_conn_problem(self, mock_glance): exceptions = (exception.GlanceConnectionFailed('connection fail'), exception.ImageNotAuthorized('not authorized'), exception.Invalid('invalid')) mock_glance.side_effect = exceptions for exc in exceptions: with task_manager.acquire(self.context, self.node.uuid, shared=True) as task: self.assertRaises(exception.InvalidParameterValue, task.driver.deploy.validate, task)