diff --git a/openstack-common.conf b/openstack-common.conf index 91db5962..b3b06c4c 100644 --- a/openstack-common.conf +++ b/openstack-common.conf @@ -1,7 +1,7 @@ [DEFAULT] # The list of modules to copy from oslo-incubator.git -modules=excutils,install_venv_common,exception,importutils,timeutils,uuidutils +modules=excutils,install_venv_common,importutils,timeutils,uuidutils # The base module to hold the copy of openstack.common base=taskflow diff --git a/taskflow/db/sqlalchemy/api.py b/taskflow/db/sqlalchemy/api.py index f31c952b..e82e2ea3 100644 --- a/taskflow/db/sqlalchemy/api.py +++ b/taskflow/db/sqlalchemy/api.py @@ -21,12 +21,12 @@ import logging +from taskflow import exceptions from taskflow import states from taskflow.db.sqlalchemy import models from taskflow.db.sqlalchemy import session as sql_session -from taskflow.openstack.common import exception LOG = logging.getLogger(__name__) @@ -49,8 +49,8 @@ def logbook_get(context, lb_id, session=None): filter_by(logbook_id=lb_id) if not query.first(): - raise exception.NotFound("No LogBook found with id " - "%s." % (lb_id,)) + raise exceptions.NotFound("No LogBook found with id " + "%s." % (lb_id,)) return query.first() @@ -61,8 +61,8 @@ def logbook_get_by_name(context, lb_name): filter_by(name=lb_name) if not query.all(): - raise exception.NotFound("LogBook %s not found." - % (lb_name,)) + raise exceptions.NotFound("LogBook %s not found." + % (lb_name,)) return query.all() @@ -118,8 +118,8 @@ def job_get(context, job_id, session=None): filter_by(job_id=job_id) if not query.first(): - raise exception.NotFound("No Job with id %s found" - % (job_id,)) + raise exceptions.NotFound("No Job with id %s found" + % (job_id,)) return query.first() @@ -194,7 +194,7 @@ def workflow_get(context, wf_name, session=None): filter_by(name=wf_name) if not query.first(): - raise exception.NotFound("Workflow %s not found." % (wf_name,)) + raise exceptions.NotFound("Workflow %s not found." % (wf_name,)) return query.first() @@ -204,7 +204,7 @@ def workflow_get_all(context): results = model_query(context, models.Workflow).all() if not results: - raise exception.NotFound("No Workflows were found.") + raise exceptions.NotFound("No Workflows were found.") return results @@ -263,8 +263,8 @@ def task_get(context, task_id, session=None): filter_by(task_id=task_id) if not query.first(): - raise exception.NotFound("No Task found with id " - "%s." % (task_id,)) + raise exceptions.NotFound("No Task found with id " + "%s." % (task_id,)) return query.first() diff --git a/taskflow/db/sqlalchemy/models.py b/taskflow/db/sqlalchemy/models.py index 2e2a08af..47a9cfdc 100644 --- a/taskflow/db/sqlalchemy/models.py +++ b/taskflow/db/sqlalchemy/models.py @@ -30,7 +30,7 @@ from sqlalchemy import DateTime, ForeignKey from sqlalchemy import types as types from taskflow.db.sqlalchemy import session as sql_session -from taskflow.openstack.common import exception +from taskflow import exceptions from taskflow.openstack.common import timeutils from taskflow.openstack.common import uuidutils @@ -64,7 +64,7 @@ class TaskFlowBase(object): session.flush() except IntegrityError, e: if str(e).endswith('is not unique'): - raise exception.Duplicate(str(e)) + raise exceptions.Duplicate(str(e)) else: raise @@ -100,9 +100,9 @@ class TaskFlowBase(object): setattr(self, k, v) def iteritems(self): - """Make the model object behave like a dict + """Make the model object behave like a dict. - Includes attributes from joins. + Includes attributes from joins. """ local = dict(self) joined = dict([k, v] for k, v in self.__dict__.iteritems() diff --git a/taskflow/exceptions.py b/taskflow/exceptions.py index 5b7d65dc..d50e30d9 100644 --- a/taskflow/exceptions.py +++ b/taskflow/exceptions.py @@ -16,14 +16,17 @@ # License for the specific language governing permissions and limitations # under the License. -from taskflow.openstack.common import exception as exc - -class TaskFlowException(exc.Error): +class TaskFlowException(Exception): """Base class for exceptions emitted from this library.""" pass +class Duplicate(TaskFlowException): + """Raised when a duplicate entry is found.""" + pass + + class NotFound(TaskFlowException): """Raised when some entry in some object doesn't exist.""" pass diff --git a/taskflow/openstack/common/exception.py b/taskflow/openstack/common/exception.py deleted file mode 100644 index 861a9a81..00000000 --- a/taskflow/openstack/common/exception.py +++ /dev/null @@ -1,146 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2011 OpenStack Foundation. -# All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -""" -Exceptions common to OpenStack projects -""" - -import logging - -from taskflow.openstack.common.gettextutils import _ - -_FATAL_EXCEPTION_FORMAT_ERRORS = False - - -class Error(Exception): - def __init__(self, message=None): - super(Error, self).__init__(message) - - -class ApiError(Error): - def __init__(self, message='Unknown', code='Unknown'): - self.message = message - self.code = code - super(ApiError, self).__init__('%s: %s' % (code, message)) - - -class NotFound(Error): - msg = " %s not found." - - def __init__(self, obj): - msg = self.__class__.msg % obj - super(NotFound, self).__init__(msg) - - -class UnknownScheme(Error): - - msg = "Unknown scheme '%s' found in URI" - - def __init__(self, scheme): - msg = self.__class__.msg % scheme - super(UnknownScheme, self).__init__(msg) - - -class BadStoreUri(Error): - - msg = "The Store URI %s was malformed. Reason: %s" - - def __init__(self, uri, reason): - msg = self.__class__.msg % (uri, reason) - super(BadStoreUri, self).__init__(msg) - - -class Duplicate(Error): - pass - - -class NotAuthorized(Error): - pass - - -class NotEmpty(Error): - pass - - -class Invalid(Error): - pass - - -class BadInputError(Exception): - """Error resulting from a client sending bad input to a server""" - pass - - -class MissingArgumentError(Error): - pass - - -class DatabaseMigrationError(Error): - pass - - -class ClientConnectionError(Exception): - """Error resulting from a client connecting to a server""" - pass - - -def wrap_exception(f): - def _wrap(*args, **kw): - try: - return f(*args, **kw) - except Exception as e: - if not isinstance(e, Error): - #exc_type, exc_value, exc_traceback = sys.exc_info() - logging.exception(_('Uncaught exception')) - #logging.error(traceback.extract_stack(exc_traceback)) - raise Error(str(e)) - raise - _wrap.func_name = f.func_name - return _wrap - - -class OpenstackException(Exception): - """ - Base Exception - - To correctly use this class, inherit from it and define - a 'message' property. That message will get printf'd - with the keyword arguments provided to the constructor. - """ - message = "An unknown exception occurred" - - def __init__(self, **kwargs): - try: - self._error_string = self.message % kwargs - - except Exception as e: - if _FATAL_EXCEPTION_FORMAT_ERRORS: - raise e - else: - # at least get the core message out if something happened - self._error_string = self.message - - def __str__(self): - return self._error_string - - -class MalformedRequestBody(OpenstackException): - message = "Malformed message body: %(reason)s" - - -class InvalidContentType(OpenstackException): - message = "Invalid content type %(content_type)s" diff --git a/taskflow/tests/unit/test_sql_db_api.py b/taskflow/tests/unit/test_sql_db_api.py index d8a9bbc9..845059ff 100644 --- a/taskflow/tests/unit/test_sql_db_api.py +++ b/taskflow/tests/unit/test_sql_db_api.py @@ -22,10 +22,9 @@ import unittest2 from os import path -from taskflow.openstack.common import exception - from taskflow.db import api as db_api from taskflow.db.sqlalchemy import models +from taskflow import exceptions from taskflow import states db_api.configure() @@ -92,7 +91,7 @@ class JobTest(unittest2.TestCase): self.assertEquals(expected, actual) - self.assertRaises(exception.NotFound, db_api.job_get, '', 9001) + self.assertRaises(exceptions.NotFound, db_api.job_get, '', 9001) def test_job_update(self): db_api.job_update('', 1, dict(owner='OwnerTest', state=states.CLAIMED)) @@ -108,7 +107,7 @@ class JobTest(unittest2.TestCase): self.assertEquals(expected, actual) - self.assertRaises(exception.NotFound, db_api.job_update, '', 9001, + self.assertRaises(exceptions.NotFound, db_api.job_update, '', 9001, dict(owner='OwnerTest', state=states.CLAIMED)) def test_job_add_workflow(self): @@ -125,9 +124,9 @@ class JobTest(unittest2.TestCase): self.assertEquals(expected, actual) - self.assertRaises(exception.NotFound, db_api.job_add_workflow, '', + self.assertRaises(exceptions.NotFound, db_api.job_add_workflow, '', 9001, u'workflow_10') - self.assertRaises(exception.NotFound, db_api.job_add_workflow, '', + self.assertRaises(exceptions.NotFound, db_api.job_add_workflow, '', 1, u'workflow_9001') def test_job_get_owner(self): @@ -135,7 +134,7 @@ class JobTest(unittest2.TestCase): self.assertIsNone(actual) - self.assertRaises(exception.NotFound, db_api.job_get_owner, '', 9001) + self.assertRaises(exceptions.NotFound, db_api.job_get_owner, '', 9001) def test_job_get_state(self): expected = states.UNCLAIMED @@ -143,7 +142,7 @@ class JobTest(unittest2.TestCase): self.assertEquals(expected, actual) - self.assertRaises(exception.NotFound, db_api.job_get_state, '', 9001) + self.assertRaises(exceptions.NotFound, db_api.job_get_state, '', 9001) def test_job_get_logbook(self): expected = self.lb_names[0] @@ -151,7 +150,8 @@ class JobTest(unittest2.TestCase): self.assertEquals(expected, actual) - self.assertRaises(exception.NotFound, db_api.job_get_logbook, '', 9001) + self.assertRaises(exceptions.NotFound, db_api.job_get_logbook, + '', 9001) def test_job_create(self): id = 1 @@ -169,7 +169,7 @@ class JobTest(unittest2.TestCase): db_api.job_destroy('', id) self.job_names.pop() - self.assertRaises(exception.NotFound, db_api.job_get, '', id) + self.assertRaises(exceptions.NotFound, db_api.job_get, '', id) """ LogBookTest @@ -213,7 +213,7 @@ class LogBookTest(unittest2.TestCase): self.assertEquals(expected, actual) - self.assertRaises(exception.NotFound, db_api.logbook_get, '', 9001) + self.assertRaises(exceptions.NotFound, db_api.logbook_get, '', 9001) def test_logbook_get_by_name(self): expected = [self.lb_ids[0]] @@ -223,7 +223,7 @@ class LogBookTest(unittest2.TestCase): self.assertEquals(expected, actual) - self.assertRaises(exception.NotFound, db_api.logbook_get_by_name, '', + self.assertRaises(exceptions.NotFound, db_api.logbook_get_by_name, '', u'logbook_9001') def test_logbook_create(self): @@ -248,7 +248,7 @@ class LogBookTest(unittest2.TestCase): self.assertEquals(expected, actual) - self.assertRaises(exception.NotFound, db_api.logbook_get_workflows, + self.assertRaises(exceptions.NotFound, db_api.logbook_get_workflows, '', 9001) def test_logbook_add_workflow(self): @@ -265,9 +265,9 @@ class LogBookTest(unittest2.TestCase): self.assertEquals(expected, actual) - self.assertRaises(exception.NotFound, db_api.logbook_add_workflow, '', + self.assertRaises(exceptions.NotFound, db_api.logbook_add_workflow, '', 9001, u'workflow_10') - self.assertRaises(exception.NotFound, db_api.logbook_add_workflow, '', + self.assertRaises(exceptions.NotFound, db_api.logbook_add_workflow, '', 1, u'workflow_9001') def test_logbook_destroy(self): @@ -275,7 +275,7 @@ class LogBookTest(unittest2.TestCase): db_api.logbook_destroy('', id) self.lb_names.pop() - self.assertRaises(exception.NotFound, db_api.logbook_get, '', id) + self.assertRaises(exceptions.NotFound, db_api.logbook_get, '', id) """ WorkflowTest @@ -320,7 +320,7 @@ class WorkflowTest(unittest2.TestCase): self.assertEquals(expected, actual) - self.assertRaises(exception.NotFound, db_api.workflow_get, '', + self.assertRaises(exceptions.NotFound, db_api.workflow_get, '', u'workflow_9001') def test_workflow_get_all(self): @@ -353,7 +353,7 @@ class WorkflowTest(unittest2.TestCase): self.assertEquals(expected, actual) - self.assertRaises(exception.NotFound, db_api.workflow_get_tasks, '', + self.assertRaises(exceptions.NotFound, db_api.workflow_get_tasks, '', u'workflow_9001') def test_workflow_add_task(self): @@ -367,9 +367,9 @@ class WorkflowTest(unittest2.TestCase): self.assertEquals(expected, actual) - self.assertRaises(exception.NotFound, db_api.workflow_add_task, '', + self.assertRaises(exceptions.NotFound, db_api.workflow_add_task, '', u'workflow_9001', 10) - self.assertRaises(exception.NotFound, db_api.workflow_add_task, '', + self.assertRaises(exceptions.NotFound, db_api.workflow_add_task, '', u'workflow_1', 9001) def test_workflow_create(self): @@ -388,7 +388,7 @@ class WorkflowTest(unittest2.TestCase): db_api.workflow_destroy('', name) self.wf_ids.pop() - self.assertRaises(exception.NotFound, db_api.workflow_get, '', name) + self.assertRaises(exceptions.NotFound, db_api.workflow_get, '', name) """ TaskTest @@ -420,7 +420,7 @@ class TaskTest(unittest2.TestCase): self.assertEquals(expected, actual.name) - self.assertRaises(exception.NotFound, db_api.task_get, '', 9001) + self.assertRaises(exceptions.NotFound, db_api.task_get, '', 9001) def test_task_create(self): id = 1 @@ -447,7 +447,7 @@ class TaskTest(unittest2.TestCase): self.assertEquals(expected, actual) - self.assertRaises(exception.NotFound, db_api.task_update, '', 9001, + self.assertRaises(exceptions.NotFound, db_api.task_update, '', 9001, dict(exception='ExceptionTest', stacktrace='StacktraceTest')) @@ -456,4 +456,4 @@ class TaskTest(unittest2.TestCase): db_api.task_destroy('', id) self.tsk_names.pop() - self.assertRaises(exception.NotFound, db_api.task_get, '', id) + self.assertRaises(exceptions.NotFound, db_api.task_get, '', id)