Comment 0 for bug 1413781

Revision history for this message
HT_Sergio (sergio-martins) wrote :

For the same action, cinderclient will raise a different exception depending on how the cinderclient object was created.

Example that shows this behaviour:

from keystoneclient.auth.identity import v2
from keystoneclient.session import Session
from cinderclient.v1 import client as cinder_client

username = "admin"
password = "password"
project_name = "admin"
auth_url = "http://127.0.0.1:5000/v2.0/"

cinder = cinder_client.Client(username, password, project_name, auth_url)
cinder.volumes.create(0) # raises cinderclient.exceptions.BadRequest

auth = v2.Password(auth_url=auth_url, username=username, password=password, tenant_name=project_name)
session = Session(auth=auth)
cinder = cinder_client.Client(session=session)
cinder.volumes.create(0) # raises keystoneclient.openstack.common.apiclient.exceptions.BadRequest

Expected exception:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sergio/code/env/local/lib/python2.7/site-packages/cinderclient/v1/volumes.py", line 187, in create
    return self._create('/volumes', body, 'volume')
  File "/home/sergio/code/env/local/lib/python2.7/site-packages/cinderclient/base.py", line 157, in _create
    resp, body = self.api.client.post(url, body=body)
  File "/home/sergio/code/env/local/lib/python2.7/site-packages/cinderclient/client.py", line 305, in post
    return self._cs_request(url, 'POST', **kwargs)
  File "/home/sergio/code/env/local/lib/python2.7/site-packages/cinderclient/client.py", line 269, in _cs_request
    **kwargs)
  File "/home/sergio/code/env/local/lib/python2.7/site-packages/cinderclient/client.py", line 252, in request
    raise exceptions.from_response(resp, body)
cinderclient.exceptions.BadRequest: Invalid input received: Volume size 0 must be an integer and greater than 0 (HTTP 400) (Request-ID: req-a60d45b2-3b8f-4e45-8a79-7b3157c0c973)

Exception when using a keystone session:
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sergio/code/env/local/lib/python2.7/site-packages/cinderclient/v1/volumes.py", line 187, in create
    return self._create('/volumes', body, 'volume')
  File "/home/sergio/code/env/local/lib/python2.7/site-packages/cinderclient/base.py", line 157, in _create
    resp, body = self.api.client.post(url, body=body)
  File "/home/sergio/code/env/local/lib/python2.7/site-packages/cinderclient/client.py", line 91, in post
    return self._cs_request(url, 'POST', **kwargs)
  File "/home/sergio/code/env/local/lib/python2.7/site-packages/cinderclient/client.py", line 85, in _cs_request
    return self.request(url, method, **kwargs)
  File "/home/sergio/code/env/local/lib/python2.7/site-packages/cinderclient/client.py", line 80, in request
    return super(SessionClient, self).request(*args, **kwargs)
  File "/home/sergio/code/env/local/lib/python2.7/site-packages/keystoneclient/adapter.py", line 158, in request
    resp = super(LegacyJsonAdapter, self).request(*args, **kwargs)
  File "/home/sergio/code/env/local/lib/python2.7/site-packages/keystoneclient/adapter.py", line 88, in request
    return self.session.request(url, method, **kwargs)
  File "/home/sergio/code/env/local/lib/python2.7/site-packages/keystoneclient/utils.py", line 318, in inner
    return func(*args, **kwargs)
  File "/home/sergio/code/env/local/lib/python2.7/site-packages/keystoneclient/session.py", line 354, in request
    raise exceptions.from_response(resp, method, url)
keystoneclient.openstack.common.apiclient.exceptions.BadRequest: Bad Request (HTTP 400) (Request-ID: req-86c3e79d-ad38-43d8-a6fb-99a709d2b04d)

The second exception (keystoneclient.openstack.common.apiclient.exceptions.BadRequest) is an instance of keystoneclient.exceptions.BadRequest, which seems to me like that should only be exceptions coming from keystoneclient.