[openstack-dev] [cinder][oslo] Serialising exceptions

2014-04-14 Thread git harry
A bug has been submitted, https://bugs.launchpad.net/cinder/+bug/1301249, which 
shows a failure when oslo.messaging tries to serialise an exception with 
jsonutils - a ValueError is raised. I've had a search through the code and I'm 
pretty sure there are around 50+ cases where this will happen:

cinder/backup/drivers/swift.py raise exception.SwiftConnectionFailed(reason=err)
cinder/backup/drivers/swift.py raise exception.SwiftConnectionFailed(reason=err)
cinder/backup/drivers/swift.py raise exception.SwiftConnectionFailed(reason=err)
cinder/backup/drivers/swift.py raise exception.SwiftConnectionFailed(reason=err)
cinder/backup/drivers/swift.py raise exception.SwiftConnectionFailed(reason=err)
cinder/backup/drivers/swift.py raise exception.SwiftConnectionFailed(reason=err)
cinder/volume/driver.py raise exception.ExportFailure(reason=ex)
cinder/volume/drivers/coraid.py raise exception.CoraidESMNotAvailable(reason=e)
cinder/volume/drivers/netapp/api.py raise NaApiError('Unexpected error', e)
cinder/volume/drivers/san/hp/hp_3par_common.py raise exception.InvalidInput(ex)
cinder/volume/drivers/san/hp/hp_3par_common.py raise 
exception.CinderException(ex)
cinder/volume/drivers/san/hp/hp_3par_common.py raise 
exception.CinderException(ex)
cinder/volume/drivers/san/hp/hp_3par_common.py raise 
exception.CinderException(ex)
cinder/volume/drivers/san/hp/hp_3par_common.py raise 
exception.CinderException(ex)
cinder/volume/drivers/san/hp/hp_3par_common.py raise 
exception.CinderException(ex)
cinder/volume/drivers/san/hp/hp_3par_common.py raise 
exception.CinderException(ex)
cinder/volume/drivers/san/hp/hp_3par_common.py raise 
exception.CinderException(ex)
cinder/volume/drivers/san/hp/hp_3par_common.py raise 
exception.CinderException(ex)
cinder/volume/drivers/san/hp/hp_3par_common.py raise 
exception.CinderException(ex)
cinder/volume/drivers/san/hp/hp_lefthand_cliq_proxy.py raise 
exception.SnapshotIsBusy(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise 
exception.DriverNotInitialized(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise 
exception.VolumeBackendAPIException(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise 
exception.VolumeBackendAPIException(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise 
exception.VolumeBackendAPIException(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise 
exception.VolumeBackendAPIException(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise 
exception.SnapshotIsBusy(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise 
exception.VolumeBackendAPIException(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise 
exception.VolumeBackendAPIException(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise 
exception.VolumeBackendAPIException(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise 
exception.VolumeBackendAPIException(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise 
exception.VolumeBackendAPIException(ex)
cinder/volume/drivers/san/hp/hp_msa_common.py raise exception.Invalid(ex)
cinder/volume/drivers/san/hp/hp_msa_common.py raise exception.Invalid(ex)
cinder/volume/drivers/san/hp/hp_msa_common.py raise exception.Invalid(ex)
cinder/volume/drivers/san/hp/hp_msa_common.py raise exception.Invalid(ex)
cinder/volume/drivers/san/hp/hp_msa_common.py raise exception.Invalid(ex)
cinder/volume/drivers/san/hp/hp_msa_common.py raise exception.Invalid(ex)
cinder/volume/drivers/san/hp/hp_msa_common.py raise exception.Invalid(ex)
cinder/volume/drivers/san/hp/hp_msa_common.py raise exception.Invalid(ex)
cinder/volume/drivers/san/hp/hp_msa_common.py raise exception.Invalid(ex)
cinder/volume/drivers/vmware/vim.py raise 
error_util.VimFaultException(fault_list, excep)
cinder/volume/flows/manager/create_volume.py raise 
exception.MetadataCopyFailure(reason=ex)
cinder/volume/flows/manager/create_volume.py raise 
exception.MetadataUpdateFailure(reason=ex)
cinder/volume/flows/manager/create_volume.py raise 
exception.MetadataUpdateFailure(reason=ex)
cinder/volume/flows/manager/create_volume.py raise 
exception.ImageUnacceptable(ex)

There seem to me to be three ways to fix this:
1. throw six.text_type round all the arguments that are exceptions - although 
this doesn't stop the same thing happening again
2. modify CinderException so that if message is an exception or, args or kwarg 
contains one it get converted to a string
3. modify jsonutils.py in oslo-incubator to automatically convert exceptions to 
strings.

Does anyone have any thoughts on this? I lean towards trying to get an 
additional test in to_primitive in jsonutils to convert exceptions but I don't 
know if there is a reason why that isn't already done.

Thanks,
git-harry 
___
OpenStack-dev mailing list
OpenStack-dev@lists.openstack.org
http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev


Re: [openstack-dev] [cinder][oslo] Serialising exceptions

2014-04-14 Thread Joshua Harlow
Taskflow has some code that might help for this @
https://github.com/openstack/taskflow/blob/master/taskflow/utils/misc.py#L5
47; might be useful to share to handle serializing failures (and
deserialising them). The issue from what I can tell is that jsonutils is
imho not at the right level to know how to serialize or deserialize
exceptions correctly (it's to low-level to know the difference). In
taskflow this object is used instead (and the appropriate places where
exceptions are expected in the message or data format can use this failure
object to translate to a dictionary or back from a dictionary).

Another idea is to use something like http://jsonpickle.github.io/ which
retains the types (jsonutils is lossy in that it loses information when
serializing and deserializing). This probably would also avoid that same
issue (being unable to serialize exceptions, and being unable to
deserialize them back into there original types).

-Original Message-
From: git harry git-ha...@live.co.uk
Reply-To: OpenStack Development Mailing List (not for usage questions)
openstack-dev@lists.openstack.org
Date: Monday, April 14, 2014 at 10:08 AM
To: openstack-dev@lists.openstack.org openstack-dev@lists.openstack.org
Subject: [openstack-dev] [cinder][oslo] Serialising exceptions

A bug has been submitted, https://bugs.launchpad.net/cinder/+bug/1301249,
which shows a failure when oslo.messaging tries to serialise an exception
with jsonutils - a ValueError is raised. I've had a search through the
code and I'm pretty sure there are around 50+ cases where this will
happen:

cinder/backup/drivers/swift.py raise
exception.SwiftConnectionFailed(reason=err)
cinder/backup/drivers/swift.py raise
exception.SwiftConnectionFailed(reason=err)
cinder/backup/drivers/swift.py raise
exception.SwiftConnectionFailed(reason=err)
cinder/backup/drivers/swift.py raise
exception.SwiftConnectionFailed(reason=err)
cinder/backup/drivers/swift.py raise
exception.SwiftConnectionFailed(reason=err)
cinder/backup/drivers/swift.py raise
exception.SwiftConnectionFailed(reason=err)
cinder/volume/driver.py raise exception.ExportFailure(reason=ex)
cinder/volume/drivers/coraid.py raise
exception.CoraidESMNotAvailable(reason=e)
cinder/volume/drivers/netapp/api.py raise NaApiError('Unexpected error',
e)
cinder/volume/drivers/san/hp/hp_3par_common.py raise
exception.InvalidInput(ex)
cinder/volume/drivers/san/hp/hp_3par_common.py raise
exception.CinderException(ex)
cinder/volume/drivers/san/hp/hp_3par_common.py raise
exception.CinderException(ex)
cinder/volume/drivers/san/hp/hp_3par_common.py raise
exception.CinderException(ex)
cinder/volume/drivers/san/hp/hp_3par_common.py raise
exception.CinderException(ex)
cinder/volume/drivers/san/hp/hp_3par_common.py raise
exception.CinderException(ex)
cinder/volume/drivers/san/hp/hp_3par_common.py raise
exception.CinderException(ex)
cinder/volume/drivers/san/hp/hp_3par_common.py raise
exception.CinderException(ex)
cinder/volume/drivers/san/hp/hp_3par_common.py raise
exception.CinderException(ex)
cinder/volume/drivers/san/hp/hp_3par_common.py raise
exception.CinderException(ex)
cinder/volume/drivers/san/hp/hp_lefthand_cliq_proxy.py raise
exception.SnapshotIsBusy(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise
exception.DriverNotInitialized(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise
exception.VolumeBackendAPIException(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise
exception.VolumeBackendAPIException(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise
exception.VolumeBackendAPIException(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise
exception.VolumeBackendAPIException(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise
exception.SnapshotIsBusy(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise
exception.VolumeBackendAPIException(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise
exception.VolumeBackendAPIException(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise
exception.VolumeBackendAPIException(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise
exception.VolumeBackendAPIException(ex)
cinder/volume/drivers/san/hp/hp_lefthand_rest_proxy.py raise
exception.VolumeBackendAPIException(ex)
cinder/volume/drivers/san/hp/hp_msa_common.py raise exception.Invalid(ex)
cinder/volume/drivers/san/hp/hp_msa_common.py raise exception.Invalid(ex)
cinder/volume/drivers/san/hp/hp_msa_common.py raise exception.Invalid(ex)
cinder/volume/drivers/san/hp/hp_msa_common.py raise exception.Invalid(ex)
cinder/volume/drivers/san/hp/hp_msa_common.py raise exception.Invalid(ex)
cinder/volume/drivers/san/hp/hp_msa_common.py raise exception.Invalid(ex)
cinder/volume/drivers/san/hp/hp_msa_common.py raise exception.Invalid(ex)
cinder/volume/drivers/san/hp/hp_msa_common.py raise exception.Invalid(ex)
cinder/volume/drivers/san/hp/hp_msa_common.py raise exception.Invalid(ex)
cinder/volume/drivers