On 02/25/2014 12:25 AM, Sheldon wrote:
On 02/24/2014 10:25 PM, Aline Manera wrote:
> From: Aline Manera <alinefm(a)br.ibm.com>
>
> The exception instance was being used as the missing parameter what is
> causing errors like below:
is KeyError?
dic = {"a": "a"}
In [124]: dic['b']
---------------------------------------------------------------------------
KeyError: 'b'
or TypeError?
>
> TypeError: coercing to Unicode: need string or buffer,
> exceptions.KeyError found
As you can see the TypeError is caused by an KeyError
>
> To fix use the string representation for the exception instance.
>
> Signed-off-by: Aline Manera <alinefm(a)br.ibm.com>
> ---
> src/kimchi/mockmodel.py | 4 ++--
> src/kimchi/model/storagepools.py | 2 +-
> src/kimchi/model/storagevolumes.py | 2 +-
> src/kimchi/root.py | 2 +-
> 4 files changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/src/kimchi/mockmodel.py b/src/kimchi/mockmodel.py
> index b50bf31..b23a024 100644
> --- a/src/kimchi/mockmodel.py
> +++ b/src/kimchi/mockmodel.py
> @@ -367,7 +367,7 @@ class MockModel(object):
> pool.info['autostart'] = False
> except KeyError, item:
> raise MissingParameter("KCHPOOL0004E",
> - {'item': item, 'name': name})
> + {'item': str(item), 'name':
name})
except KeyError, key:
key is right than item
>
> if name in self._mock_storagepools or name in
> (ISO_POOL_NAME,):
> raise InvalidOperation("KCHPOOL0001E", {'name':
name})
> @@ -428,7 +428,7 @@ class MockModel(object):
> pool.info['path'], name)
> except KeyError, item:
> raise MissingParameter("KCHVOL0004E",
> - {'item': item, 'volume': name})
> + {'item': str(item), 'volume':
name})
>
> if name in pool._volumes:
> raise InvalidOperation("KCHVOL0001E", {'name':
name})
> diff --git a/src/kimchi/model/storagepools.py
> b/src/kimchi/model/storagepools.py
> index cf66a86..011feb0 100644
> --- a/src/kimchi/model/storagepools.py
> +++ b/src/kimchi/model/storagepools.py
> @@ -90,7 +90,7 @@ class StoragePoolsModel(object):
> xml = poolDef.xml.encode("utf-8")
> except KeyError, item:
> raise MissingParameter("KCHPOOL0004E",
> - {'item': item, 'name': name})
> + {'item': str(item), 'name':
name})
>
> if name in self.get_list():
> raise InvalidOperation("KCHPOOL0001E", {'name':
name})
> diff --git a/src/kimchi/model/storagevolumes.py
> b/src/kimchi/model/storagevolumes.py
> index 20c65b9..6bd6ded 100644
> --- a/src/kimchi/model/storagevolumes.py
> +++ b/src/kimchi/model/storagevolumes.py
> @@ -62,7 +62,7 @@ class StorageVolumesModel(object):
> pool = StoragePoolModel.get_storagepool(pool, self.conn)
> xml = vol_xml % params
> except KeyError, item:
> - raise MissingParameter("KCHVOL0004E", {'item': item,
> + raise MissingParameter("KCHVOL0004E", {'item':
str(item),
> 'volume': name})
>
> try:
> diff --git a/src/kimchi/root.py b/src/kimchi/root.py
> index 4a1a9cd..08056d2 100644
> --- a/src/kimchi/root.py
> +++ b/src/kimchi/root.py
> @@ -106,7 +106,7 @@ class KimchiRoot(Root):
> userid = params['userid']
> password = params['password']
> except KeyError, item:
> - e = MissingParameter('KCHAUTH0003E', {'item': item})
> + e = MissingParameter('KCHAUTH0003E', {'item':
str(item)})
> raise cherrypy.HTTPError(400, e.message)
>
> try: