wrap sqlalchemy exceptions in a generic error
This commit is contained in:
parent
ffe08ea0c5
commit
9bdcc71733
@ -61,7 +61,6 @@ import sys
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import IPy
|
import IPy
|
||||||
from sqlalchemy import exc
|
|
||||||
|
|
||||||
# If ../nova/__init__.py exists, add ../ to Python search path, so that
|
# If ../nova/__init__.py exists, add ../ to Python search path, so that
|
||||||
# it will override what happens to be installed in /usr/(local/)lib/python...
|
# it will override what happens to be installed in /usr/(local/)lib/python...
|
||||||
@ -280,7 +279,7 @@ class UserCommands(object):
|
|||||||
arguments: name [access] [secret]"""
|
arguments: name [access] [secret]"""
|
||||||
try:
|
try:
|
||||||
user = self.manager.create_user(name, access, secret, True)
|
user = self.manager.create_user(name, access, secret, True)
|
||||||
except exc.OperationalError, e:
|
except exception.DBError, e:
|
||||||
_db_error(e)
|
_db_error(e)
|
||||||
self._print_export(user)
|
self._print_export(user)
|
||||||
|
|
||||||
@ -289,7 +288,7 @@ class UserCommands(object):
|
|||||||
arguments: name [access] [secret]"""
|
arguments: name [access] [secret]"""
|
||||||
try:
|
try:
|
||||||
user = self.manager.create_user(name, access, secret, False)
|
user = self.manager.create_user(name, access, secret, False)
|
||||||
except exc.OperationalError, e:
|
except exception.DBError, e:
|
||||||
_db_error(e)
|
_db_error(e)
|
||||||
self._print_export(user)
|
self._print_export(user)
|
||||||
|
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
DIR=`pwd`
|
DIR=`pwd`
|
||||||
CMD=$1
|
CMD=$1
|
||||||
SOURCE_BRANCH=lp:nova
|
if [ "$CMD" = "branch" ]; then
|
||||||
if [ -n "$2" ]; then
|
SOURCE_BRANCH=${2:-lp:nova}
|
||||||
SOURCE_BRANCH=$2
|
DIRNAME=${3:-nova}
|
||||||
|
else
|
||||||
|
DIRNAME=${2:-nova}
|
||||||
fi
|
fi
|
||||||
DIRNAME=nova
|
|
||||||
NOVA_DIR=$DIR/$DIRNAME
|
NOVA_DIR=$DIR/$DIRNAME
|
||||||
if [ -n "$3" ]; then
|
|
||||||
NOVA_DIR=$DIR/$3
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -n "$HOST_IP" ]; then
|
if [ ! -n "$HOST_IP" ]; then
|
||||||
# NOTE(vish): This will just get the first ip in the list, so if you
|
# NOTE(vish): This will just get the first ip in the list, so if you
|
||||||
@ -45,34 +44,17 @@ else
|
|||||||
AUTH=dbdriver.DbDriver
|
AUTH=dbdriver.DbDriver
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p /etc/nova
|
|
||||||
cat >$NOVA_DIR/bin/nova.conf << NOVA_CONF_EOF
|
|
||||||
--verbose
|
|
||||||
--nodaemon
|
|
||||||
--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf
|
|
||||||
--network_manager=nova.network.manager.$NET_MAN
|
|
||||||
--cc_host=$HOST_IP
|
|
||||||
--routing_source_ip=$HOST_IP
|
|
||||||
--sql_connection=$SQL_CONN
|
|
||||||
--auth_driver=nova.auth.$AUTH
|
|
||||||
--libvirt_type=$LIBVIRT_TYPE
|
|
||||||
NOVA_CONF_EOF
|
|
||||||
|
|
||||||
if [ -n "$FLAT_INTERFACE" ]; then
|
|
||||||
echo "--flat_interface=$FLAT_INTERFACE" >>$NOVA_DIR/bin/nova.conf
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$USE_IPV6" == 1 ]; then
|
|
||||||
echo "--use_ipv6" >>$NOVA_DIR/bin/nova.conf
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$CMD" == "branch" ]; then
|
if [ "$CMD" == "branch" ]; then
|
||||||
sudo apt-get install -y bzr
|
sudo apt-get install -y bzr
|
||||||
|
if [ ! -e "$DIR/.bzr" ]; then
|
||||||
|
bzr init-repo $DIR
|
||||||
|
fi
|
||||||
rm -rf $NOVA_DIR
|
rm -rf $NOVA_DIR
|
||||||
bzr branch $SOURCE_BRANCH $NOVA_DIR
|
bzr branch $SOURCE_BRANCH $NOVA_DIR
|
||||||
cd $NOVA_DIR
|
cd $NOVA_DIR
|
||||||
mkdir -p $NOVA_DIR/instances
|
mkdir -p $NOVA_DIR/instances
|
||||||
mkdir -p $NOVA_DIR/networks
|
mkdir -p $NOVA_DIR/networks
|
||||||
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# You should only have to run this once
|
# You should only have to run this once
|
||||||
@ -91,7 +73,7 @@ if [ "$CMD" == "install" ]; then
|
|||||||
sudo /etc/init.d/libvirt-bin restart
|
sudo /etc/init.d/libvirt-bin restart
|
||||||
sudo modprobe nbd
|
sudo modprobe nbd
|
||||||
sudo apt-get install -y python-twisted python-sqlalchemy python-mox python-greenlet python-carrot
|
sudo apt-get install -y python-twisted python-sqlalchemy python-mox python-greenlet python-carrot
|
||||||
sudo apt-get install -y python-daemon python-eventlet python-gflags python-ipy python-tempita
|
sudo apt-get install -y python-migrate python-eventlet python-gflags python-ipy python-tempita
|
||||||
sudo apt-get install -y python-libvirt python-libxml2 python-routes python-cheetah
|
sudo apt-get install -y python-libvirt python-libxml2 python-routes python-cheetah
|
||||||
sudo apt-get install -y python-netaddr python-paste python-pastedeploy python-glance
|
sudo apt-get install -y python-netaddr python-paste python-pastedeploy python-glance
|
||||||
|
|
||||||
@ -109,8 +91,10 @@ mysql-server-5.1 mysql-server/start_on_boot boolean true
|
|||||||
MYSQL_PRESEED
|
MYSQL_PRESEED
|
||||||
apt-get install -y mysql-server python-mysqldb
|
apt-get install -y mysql-server python-mysqldb
|
||||||
fi
|
fi
|
||||||
wget -c http://c2477062.cdn.cloudfiles.rackspacecloud.com/images.tgz
|
mkdir -p $DIR/images
|
||||||
tar -C $DIR -zxf images.tgz
|
wget -c http://images.ansolabs.com/tty.tgz
|
||||||
|
tar -C $DIR/images -zxf tty.tgz
|
||||||
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
NL=`echo -ne '\015'`
|
NL=`echo -ne '\015'`
|
||||||
@ -121,6 +105,27 @@ function screen_it {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if [ "$CMD" == "run" ]; then
|
if [ "$CMD" == "run" ]; then
|
||||||
|
|
||||||
|
cat >$NOVA_DIR/bin/nova.conf << NOVA_CONF_EOF
|
||||||
|
--verbose
|
||||||
|
--nodaemon
|
||||||
|
--dhcpbridge_flagfile=$NOVA_DIR/bin/nova.conf
|
||||||
|
--network_manager=nova.network.manager.$NET_MAN
|
||||||
|
--cc_host=$HOST_IP
|
||||||
|
--routing_source_ip=$HOST_IP
|
||||||
|
--sql_connection=$SQL_CONN
|
||||||
|
--auth_driver=nova.auth.$AUTH
|
||||||
|
--libvirt_type=$LIBVIRT_TYPE
|
||||||
|
NOVA_CONF_EOF
|
||||||
|
|
||||||
|
if [ -n "$FLAT_INTERFACE" ]; then
|
||||||
|
echo "--flat_interface=$FLAT_INTERFACE" >>$NOVA_DIR/bin/nova.conf
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$USE_IPV6" == 1 ]; then
|
||||||
|
echo "--use_ipv6" >>$NOVA_DIR/bin/nova.conf
|
||||||
|
fi
|
||||||
|
|
||||||
killall dnsmasq
|
killall dnsmasq
|
||||||
if [ "$USE_IPV6" == 1 ]; then
|
if [ "$USE_IPV6" == 1 ]; then
|
||||||
killall radvd
|
killall radvd
|
||||||
|
@ -71,7 +71,6 @@ class NoMoreTargets(exception.Error):
|
|||||||
"""No more available blades"""
|
"""No more available blades"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
###################
|
###################
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ Session Handling for SQLAlchemy backend
|
|||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
|
||||||
|
from nova import exception
|
||||||
from nova import flags
|
from nova import flags
|
||||||
|
|
||||||
FLAGS = flags.FLAGS
|
FLAGS = flags.FLAGS
|
||||||
@ -43,4 +44,6 @@ def get_session(autocommit=True, expire_on_commit=False):
|
|||||||
autocommit=autocommit,
|
autocommit=autocommit,
|
||||||
expire_on_commit=expire_on_commit))
|
expire_on_commit=expire_on_commit))
|
||||||
session = _MAKER()
|
session = _MAKER()
|
||||||
|
session.query = exception.wrap_db_error(session.query)
|
||||||
|
session.flush = exception.wrap_db_error(session.flush)
|
||||||
return session
|
return session
|
||||||
|
@ -80,6 +80,24 @@ class TimeoutException(Error):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class DBError(Error):
|
||||||
|
"""Wraps an implementation specific exception"""
|
||||||
|
def __init__(self, inner_exception):
|
||||||
|
self.inner_exception = inner_exception
|
||||||
|
super(DBError, self).__init__(str(inner_exception))
|
||||||
|
|
||||||
|
|
||||||
|
def wrap_db_error(f):
|
||||||
|
def _wrap(*args, **kwargs):
|
||||||
|
try:
|
||||||
|
return f(*args, **kwargs)
|
||||||
|
except Exception, e:
|
||||||
|
LOG.exception(_('DB exception wrapped'))
|
||||||
|
raise DBError(e)
|
||||||
|
return _wrap
|
||||||
|
_wrap.func_name = f.func_name
|
||||||
|
|
||||||
|
|
||||||
def wrap_exception(f):
|
def wrap_exception(f):
|
||||||
def _wrap(*args, **kw):
|
def _wrap(*args, **kw):
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user