summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2013-02-04 16:40:01 +0000
committerMark McLoughlin <markmc@redhat.com>2013-02-07 15:25:29 -0500
commit06d1156248566322a7932dddfb833f46a8f573b8 (patch)
treeb3e6ac915b6b9fc2940815536d2ee0b12efe5e52
parent1575b00bb383b35d0251a5f74e67c1b18d61e51d (diff)
downloadoslo-06d1156248566322a7932dddfb833f46a8f573b8.tar.gz
oslo-06d1156248566322a7932dddfb833f46a8f573b8.tar.xz
oslo-06d1156248566322a7932dddfb833f46a8f573b8.zip
Remove openstack.common.db.common
Since this only contains exceptions that are either used in session.py or utils.py (not both), it seems sensible to move them into the modules where they are used. Also, remove the use of the Invalid base exception class since we don't seem to be making use of the base class anywhere by catching it rather than the more specialized exceptions. Change-Id: Ib05bb2e0a9494e1dc60c60b8eee0e76b5d2ee555
-rw-r--r--openstack/common/db/common.py51
-rw-r--r--openstack/common/db/sqlalchemy/session.py28
-rw-r--r--openstack/common/db/sqlalchemy/utils.py7
-rw-r--r--tests/unit/db/sqlalchemy/test_sqlalchemy.py5
4 files changed, 30 insertions, 61 deletions
diff --git a/openstack/common/db/common.py b/openstack/common/db/common.py
deleted file mode 100644
index 65f67bc..0000000
--- a/openstack/common/db/common.py
+++ /dev/null
@@ -1,51 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2010 United States Government as represented by the
-# Administrator of the National Aeronautics and Space Administration.
-# All Rights Reserved.
-# Copyright 2012 Cloudscaling Group, Inc
-#
-# 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.
-
-from openstack.common.gettextutils import _
-from openstack.common import log as logging
-
-
-LOG = logging.getLogger(__name__)
-
-
-class Invalid(Exception):
- pass
-
-
-class InvalidSortKey(Invalid):
- message = _("Sort key supplied was not valid.")
-
-
-class InvalidUnicodeParameter(Invalid):
- message = _("Invalid Parameter: "
- "Unicode is not supported by the current database.")
-
-
-class DBError(Exception):
- """Wraps an implementation specific exception."""
- def __init__(self, inner_exception=None):
- self.inner_exception = inner_exception
- super(DBError, self).__init__(str(inner_exception))
-
-
-class DBDuplicateEntry(DBError):
- """Wraps an implementation specific exception."""
- def __init__(self, columns=[], inner_exception=None):
- self.columns = columns
- super(DBDuplicateEntry, self).__init__(inner_exception)
diff --git a/openstack/common/db/sqlalchemy/session.py b/openstack/common/db/sqlalchemy/session.py
index a796b92..99c214b 100644
--- a/openstack/common/db/sqlalchemy/session.py
+++ b/openstack/common/db/sqlalchemy/session.py
@@ -258,7 +258,6 @@ import sqlalchemy.orm
from sqlalchemy.pool import NullPool, StaticPool
from sqlalchemy.sql.expression import literal_column
-import openstack.common.db.common as db_common
from openstack.common import cfg
import openstack.common.log as logging
from openstack.common.gettextutils import _
@@ -338,6 +337,25 @@ def get_session(autocommit=True, expire_on_commit=False):
return session
+class DBError(Exception):
+ """Wraps an implementation specific exception."""
+ def __init__(self, inner_exception=None):
+ self.inner_exception = inner_exception
+ super(DBError, self).__init__(str(inner_exception))
+
+
+class DBDuplicateEntry(DBError):
+ """Wraps an implementation specific exception."""
+ def __init__(self, columns=[], inner_exception=None):
+ self.columns = columns
+ super(DBDuplicateEntry, self).__init__(inner_exception)
+
+
+class InvalidUnicodeParameter(Exception):
+ message = _("Invalid Parameter: "
+ "Unicode is not supported by the current database.")
+
+
# note(boris-42): In current versions of DB backends unique constraint
# violation messages follow the structure:
#
@@ -391,7 +409,7 @@ def raise_if_duplicate_entry_error(integrity_error, engine_name):
columns = columns.strip().split(", ")
else:
columns = get_columns_from_uniq_cons_or_name(columns)
- raise db_common.DBDuplicateEntry(columns, integrity_error)
+ raise DBDuplicateEntry(columns, integrity_error)
def wrap_db_error(f):
@@ -399,7 +417,7 @@ def wrap_db_error(f):
try:
return f(*args, **kwargs)
except UnicodeEncodeError:
- raise db_common.InvalidUnicodeParameter()
+ raise InvalidUnicodeParameter()
# note(boris-42): We should catch unique constraint violation and
# wrap it by our own DBDuplicateEntry exception. Unique constraint
# violation is wrapped by IntegrityError.
@@ -410,10 +428,10 @@ def wrap_db_error(f):
# means we should get names of columns, which values violate
# unique constraint, from error message.
raise_if_duplicate_entry_error(e, get_engine().name)
- raise db_common.DBError(e)
+ raise DBError(e)
except Exception, e:
LOG.exception(_('DB exception wrapped.'))
- raise db_common.DBError(e)
+ raise DBError(e)
_wrap.func_name = f.func_name
return _wrap
diff --git a/openstack/common/db/sqlalchemy/utils.py b/openstack/common/db/sqlalchemy/utils.py
index f7bb2f9..c8ab93e 100644
--- a/openstack/common/db/sqlalchemy/utils.py
+++ b/openstack/common/db/sqlalchemy/utils.py
@@ -22,7 +22,6 @@
import sqlalchemy
-from openstack.common.db import common as db_common
from openstack.common.gettextutils import _
from openstack.common import log as logging
@@ -30,6 +29,10 @@ from openstack.common import log as logging
LOG = logging.getLogger(__name__)
+class InvalidSortKey(Exception):
+ message = _("Sort key supplied was not valid.")
+
+
# copy from glance/db/sqlalchemy/api.py
def paginate_query(query, model, limit, sort_keys, marker=None,
sort_dir=None, sort_dirs=None):
@@ -90,7 +93,7 @@ def paginate_query(query, model, limit, sort_keys, marker=None,
try:
sort_key_attr = getattr(model, current_sort_key)
except AttributeError:
- raise db_common.InvalidSortKey()
+ raise InvalidSortKey()
query = query.order_by(sort_dir_func(sort_key_attr))
# Add pagination
diff --git a/tests/unit/db/sqlalchemy/test_sqlalchemy.py b/tests/unit/db/sqlalchemy/test_sqlalchemy.py
index 10f7e41..ea01bc8 100644
--- a/tests/unit/db/sqlalchemy/test_sqlalchemy.py
+++ b/tests/unit/db/sqlalchemy/test_sqlalchemy.py
@@ -29,7 +29,6 @@ from sqlalchemy import DateTime, Integer
from openstack.common import context
from openstack.common import exception
-from openstack.common.db import common as common_db
from openstack.common.db.sqlalchemy import models
from openstack.common.db.sqlalchemy import session
from tests import utils as test_utils
@@ -118,7 +117,7 @@ class SessionErrorWrapperTestCase(test_utils.BaseTestCase):
tbl2 = TmpTable()
tbl2.update({'foo': 10})
- self.assertRaises(common_db.DBDuplicateEntry, tbl2.save)
+ self.assertRaises(session.DBDuplicateEntry, tbl2.save)
def test_execute_wrapper(self):
_session = session.get_session()
@@ -131,5 +130,5 @@ class SessionErrorWrapperTestCase(test_utils.BaseTestCase):
method = _session.query(TmpTable).\
filter_by(foo=10).\
update
- self.assertRaises(common_db.DBDuplicateEntry,
+ self.assertRaises(session.DBDuplicateEntry,
method, {'foo': 20})