Use oslo database code

Bring in the new database code from oslo.

Uses get_session() from oslo as well as changing NovaBase to derive from
a common class.

Remove test_sqlalchemy.py now that this code is test in oslo.

Implements blueprint db-common.

Change-Id: I090754981c871250dd981cbbe1a08e7181440120
This commit is contained in:
Eric Windisch 2013-01-17 15:38:02 -05:00 committed by Mark McLoughlin
parent 519ef472bc
commit 9b725ce7c2
3 changed files with 16 additions and 10 deletions

View File

@ -35,14 +35,14 @@ from sqlalchemy.sql.expression import desc
from sqlalchemy.sql import func
from nova import block_device
from nova.common import sqlalchemyutils
from nova.compute import task_states
from nova.compute import vm_states
from nova import db
from nova.db.sqlalchemy import models
from nova.db.sqlalchemy.session import get_session
from nova import exception
from nova.openstack.common import cfg
from nova.openstack.common.db.sqlalchemy import session as db_session
from nova.openstack.common.db.sqlalchemy import utils as sqlalchemyutils
from nova.openstack.common import log as logging
from nova.openstack.common import timeutils
from nova.openstack.common import uuidutils
@ -58,10 +58,13 @@ db_opts = [
CONF = cfg.CONF
CONF.register_opts(db_opts)
CONF.import_opt('compute_topic', 'nova.compute.rpcapi')
CONF.import_opt('sql_connection', 'nova.db.sqlalchemy.session')
CONF.import_opt('sql_connection',
'nova.openstack.common.db.sqlalchemy.session')
LOG = logging.getLogger(__name__)
get_session = db_session.get_session
def is_user_context(context):
"""Indicates if the request context is a normal user."""
@ -1251,7 +1254,7 @@ def virtual_interface_create(context, values):
vif_ref = models.VirtualInterface()
vif_ref.update(values)
vif_ref.save()
except exception.DBError:
except db_session.DBError:
raise exception.VirtualInterfaceCreateException()
return vif_ref
@ -3535,7 +3538,7 @@ def instance_type_create(context, values):
instance_type_ref.update(values)
instance_type_ref.save(session=session)
except Exception, e:
raise exception.DBError(e)
raise db_session.DBError(e)
return _dict_with_extra_specs(instance_type_ref)
@ -4238,7 +4241,7 @@ def s3_image_create(context, image_uuid):
s3_image_ref.update({'uuid': image_uuid})
s3_image_ref.save()
except Exception, e:
raise exception.DBError(e)
raise db_session.DBError(e)
return s3_image_ref

View File

@ -20,8 +20,8 @@ import distutils.version as dist_version
import os
from nova.db import migration
from nova.db.sqlalchemy.session import get_engine
from nova import exception
from nova.openstack.common.db.sqlalchemy import session as db_session
from nova.openstack.common import log as logging
@ -62,6 +62,8 @@ from migrate.versioning.repository import Repository
_REPOSITORY = None
get_engine = db_session.get_engine
def db_sync(version=None):
if version is not None:

View File

@ -37,9 +37,9 @@ import testtools
from nova import context
from nova import db
from nova.db import migration
from nova.db.sqlalchemy import session
from nova.network import manager as network_manager
from nova.openstack.common import cfg
from nova.openstack.common.db.sqlalchemy import session
from nova.openstack.common import log as logging
from nova.openstack.common import timeutils
from nova import paths
@ -56,8 +56,9 @@ test_opts = [
CONF = cfg.CONF
CONF.register_opts(test_opts)
CONF.import_opt('sql_connection', 'nova.db.sqlalchemy.session')
CONF.import_opt('sqlite_db', 'nova.db.sqlalchemy.session')
CONF.import_opt('sql_connection',
'nova.openstack.common.db.sqlalchemy.session')
CONF.import_opt('sqlite_db', 'nova.openstack.common.db.sqlalchemy.session')
CONF.set_override('use_stderr', False)
logging.setup('nova')