Hello<div><br></div><div>I am trying to write a wrapper class which will use python-novaclient api. But in wrapper class, i am not able to handle 'novaclient.exceptions.Unauthorized' exception class .Could anyone pl help me out on this.?</div>
<div><br></div><div>-------------- Details -------------</div><div><div><br></div></div><div><div>/root/work/ # ls -l lib/openstack/</div><div>-rw-r--r-- 1 root root 0 Dec 24 00:44 __init__.py</div><div>drwxr-xr-x 4 root root 4096 Dec 23 22:01 novaclient <<< copied from python-novaclient/novaclient>>></div>
<div>-rw-r--r-- 1 root root 1065 Dec 24 01:00 test.py</div><div>-rw-r--r-- 1 root root 248 Dec 24 00:45 test_sample.py</div></div><div> </div><div><div># echo $PYTHONPATH</div><div>/root/work</div></div><div>
<br></div><div><div>/root/work/# python lib/openstack/test_sample.py</div><div>Traceback (most recent call last):</div><div> File "lib/openstack/test_sample.py", line 8, in <module></div><div> cloud = test.Openstack(auth_url, username, password, project_id)</div>
<div> File "/root/work/lib/openstack/test.py", line 41, in __init__</div><div> self._authenticate()</div><div> File "/root/work/lib/openstack/test.py", line 54, in _authenticate</div><div> raise Exception("Wrong exception")</div>
<div>Exception: Wrong exception</div></div><div><br></div><div><br></div><div>------------------ Here is the debug output ----------------------------------------------------------------------------------------</div><div>
<div># python -m pdb lib/openstack/test_sample.py</div><div>> /root/work/lib/openstack/test_sample.py(1)<module>()</div><div>-> from lib.openstack import test</div><div>(Pdb) b lib/openstack/test.py:25</div><div>
Breakpoint 1 at /root/work/lib/openstack/test.py:25</div><div>(Pdb) c</div><div>> /root/work/lib/openstack/test.py(25)_authenticate()</div><div>-> self._cs.authenticate()</div><div>(Pdb) n</div><div>Unauthorized: Unauthorized()</div>
<div>> /root/work/lib/openstack/test.py(25)_authenticate()</div><div>-> self._cs.authenticate()</div><div>(Pdb) n</div><div>> /root/work/lib/openstack/test.py(26)_authenticate()</div><div>-> except exc.Unauthorized: <font color="#cc0000"> [MISSED TO HANDLE HERE]</font></div>
<div>(Pdb) n</div><div>> /root/work/lib/openstack/test.py(29)_authenticate()</div><div>-> except exc.AuthorizationFailure:</div><div>(Pdb) l</div><div> 24 try:</div><div> 25 B self._cs.authenticate()</div>
<div> 26 except exc.Unauthorized:</div><div> 27 print ("Gotcha: Invalid credentials for user %s" %</div><div> 28 self._username)</div><div> 29 -> except exc.AuthorizationFailure:</div>
<div> 30 print ("Gotcha: user %s not authorized" % self._username)</div><div> 31 except Exception as e:</div><div> 32 raise Exception("Wrong exception")</div>
<div>[EOF]</div><div>(Pdb) n</div><div>> /root/work/lib/openstack/test.py(31)_authenticate()</div><div>-> except Exception as e:</div><div>(Pdb) n</div><div>> /root/work/lib/openstack/test.py(32)_authenticate()</div>
<div>-> raise Exception("Wrong exception")</div><div>(Pdb) l</div><div> 27 print ("Gotcha: Invalid credentials for user %s" %</div><div> 28 self._username)</div>
<div> 29 except exc.AuthorizationFailure:</div><div> 30 print ("Gotcha: user %s not authorized" % self._username)</div><div> 31 except Exception as e:</div><div> 32 -> raise Exception("Wrong exception") <span style="background-color:rgb(255,255,255)"><font color="#cc0000"> [DEFAULT EXCEPTION HANDLED WHICH I DON"T WANT]</font></span></div>
<div>[EOF]</div><div>(Pdb) p e</div><div>Unauthorized()</div><div>(Pdb) p type(e)</div><div><class 'novaclient.exceptions.Unauthorized'></div><div>(Pdb) p exc.Unauthorized</div><div><class 'lib.openstack.novaclient.exceptions.Unauthorized'></div>
<div>(Pdb)</div></div><div><br></div><div><br></div><div><br></div><div>-------------------------------------------------------------------------- lib/openstack/test.py ----------------------------------------------------------------------------</div>
<div><br></div><div><div>#!/usr/bin/python</div><div><br></div><div>from novaclient import client</div><div>from novaclient import utils</div><div>from novaclient import exceptions as exc</div><div><br></div><div>DEFAULT_OS_COMPUTE_API_VERSION = "1.1"</div>
<div><br></div><div>class Openstack(object):</div><div> def __init__(self, auth_url=None, username=None, apikey=None,</div><div> project_id=None):</div><div><br></div><div> self._auth_url = auth_url</div>
<div> self._username = username</div><div> self._apikey = apikey</div><div> self._project_id = project_id</div><div> self._cs = client.Client(DEFAULT_OS_COMPUTE_API_VERSION,</div><div> self._username, self._apikey,</div>
<div> self._project_id, self._auth_url)</div><div> self._authenticate()</div><div><br></div><div><br></div><div> def _authenticate(self):</div><div> try:</div><div> self._cs.authenticate()</div>
<div> except exc.Unauthorized:</div><div> print ("Gotcha: Invalid credentials for user %s" %</div><div> self._username)</div><div> except exc.AuthorizationFailure:</div>
<div> print ("Gotcha: user %s not authorized" % self._username)</div><div> except Exception as e:</div><div> raise Exception("Wrong exception")</div></div><div><br></div><div>
<br></div><div>--------------------------------------- lib/openstack/test_sample.py ---------------------------------------------------------</div><div><br></div><div><div>from lib.openstack import test</div><div><br></div>
<div>if __name__ == '__main__':</div><div> auth_url = "<a href="http://xx.xx.xx.xx:5000/v2.0">http://xx.xx.xx.xx:5000/v2.0</a>"</div><div> username = "admin"</div><div> password = "passwor"</div>
<div> project_id = "admin"</div><div> cloud = test.Openstack(auth_url, username, password, project_id)</div></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br clear="all">
<div>- What could be the cause of this problem?</div><br>
</div>