Merge "Fix exceptions handling in controllers"

This commit is contained in:
Jenkins
2013-10-25 18:42:10 +00:00
committed by Gerrit Code Review
3 changed files with 10 additions and 9 deletions

View File

@@ -33,6 +33,7 @@ from ironic.api.controllers.v1 import node
from ironic.api.controllers.v1 import utils
from ironic.common import exception
from ironic import objects
from ironic.openstack.common import excutils
from ironic.openstack.common import log
LOG = log.getLogger(__name__)
@@ -165,15 +166,14 @@ class ChassisController(rest.RestController):
rpc_chassis = objects.Chassis.get_by_uuid(pecan.request.context, uuid)
return Chassis.convert_with_links(rpc_chassis)
@wsme.validate(Chassis)
@wsme_pecan.wsexpose(Chassis, body=Chassis)
def post(self, chassis):
"""Create a new chassis."""
try:
new_chassis = pecan.request.dbapi.create_chassis(chassis.as_dict())
except exception.IronicException as e:
LOG.exception(e)
raise wsme.exc.ClientSideError(_("Invalid data"))
except Exception as e:
with excutils.save_and_reraise_exception():
LOG.exception(e)
return Chassis.convert_with_links(new_chassis)
@wsme_pecan.wsexpose(Chassis, unicode, body=[unicode])

View File

@@ -397,8 +397,8 @@ class NodesController(rest.RestController):
try:
new_node = pecan.request.dbapi.create_node(node_dict)
except Exception as e:
LOG.exception(e)
raise wsme.exc.ClientSideError(_("Invalid data"))
with excutils.save_and_reraise_exception():
LOG.exception(e)
return Node.convert_with_links(new_node)
@wsme_pecan.wsexpose(Node, unicode, body=[unicode])

View File

@@ -32,6 +32,7 @@ from ironic.api.controllers.v1 import utils as api_utils
from ironic.common import exception
from ironic.common import utils
from ironic import objects
from ironic.openstack.common import excutils
from ironic.openstack.common import log
LOG = log.getLogger(__name__)
@@ -222,9 +223,9 @@ class PortsController(rest.RestController):
try:
new_port = pecan.request.dbapi.create_port(port_dict)
except exception.IronicException as e:
LOG.exception(e)
raise wsme.exc.ClientSideError(_("Invalid data"))
except Exception as e:
with excutils.save_and_reraise_exception():
LOG.exception(e)
return Port.convert_with_links(new_port)
@wsme_pecan.wsexpose(Port, unicode, body=[unicode])