HewlettPackard / python-hpOneView

DEPRECATED - no longer actively maintained. New repository: https://github.com/HewlettPackard/oneview-python
MIT License
87 stars 57 forks source link

HPOneViewException not raised when connection with paused VM fails #309

Closed llvieira closed 7 years ago

llvieira commented 7 years ago

Hi guys,

When I try to create the OneView client but my VM is paused, an OSError exception is raised instead of a HPOneViewException. The HPOneViewException should not cover this type of exception in this scenario? For treat this exception is only possible if I catch an OSError, but is seems odd for me since this also could be used as a HPOneViewException maybe.

Code example:

#VM paused
config = {
    "ip": "x.x.x.x",
    "credentials": {
        "userName": "user_name",
        "password": "pass"
    }
}

oneview_client = OneViewClient(config)

Result:

Traceback (most recent call last):
  File "one_view.py", line 89, in <module>
    one_view = OneView(config)
  File "one_view.py", line 12, in __init__
    self.oneview_client = OneViewClient(config)
  File "/usr/local/lib/python3.5/dist-packages/hpOneView/oneview_client.py", line 118, in __init__
    self.__connection.login(config["credentials"])
  File "/usr/local/lib/python3.5/dist-packages/hpOneView/connection.py", line 483, in login
    self.validateVersion()
  File "/usr/local/lib/python3.5/dist-packages/hpOneView/connection.py", line 79, in validateVersion
    version = self.get(uri['version'])
  File "/usr/local/lib/python3.5/dist-packages/hpOneView/connection.py", line 324, in get
    resp, body = self.do_http('GET', uri, '')
  File "/usr/local/lib/python3.5/dist-packages/hpOneView/connection.py", line 126, in do_http
    conn.request(method, path, body, http_headers)
  File "/usr/lib/python3.5/http/client.py", line 1106, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1151, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.5/http/client.py", line 1102, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
    self.send(msg)
  File "/usr/lib/python3.5/http/client.py", line 877, in send
    self.connect()
  File "/usr/lib/python3.5/http/client.py", line 1252, in connect
    super().connect()
  File "/usr/lib/python3.5/http/client.py", line 849, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/lib/python3.5/socket.py", line 711, in create_connection
    raise err
  File "/usr/lib/python3.5/socket.py", line 702, in create_connection
    sock.connect(sa)
OSError: [Errno 113] No route to host
fgbulsoni commented 7 years ago

Seems like a valid request, possible solution in #310 .

Not every http error is being caught that way, as it is not impossible for those to happen in some other part of the code, but this should catch the errors coming from a first attempt at connecting to the appliance, usually timeout or no route to host.

llvieira commented 7 years ago

@fgbulsoni Thanks for answer and for your new PR related to this request.