GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Catch http lib related exceptions as HpOneViewExceptions during login by fgbulsoni · Pull Request #310 · HewlettPackard/python-hpOneView

This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Conversation

@fgbulsoni

@fgbulsoni fgbulsoni commented Aug 28, 2017

Copy link
Copy Markdown
Contributor

Description

Added try/except block to validateVersion in order to catch host unreachable and timeout exceptions during login attempts to appliance.

Issues Resolved

Fixes #309

Check List

  • All tests pass for Python 2.7+ & 3.4+($ tox).
  • Changes are documented in the CHANGELOG.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

llvieira reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@fgbulsoni
fgbulsoni requested a review from tmiotto August 28, 2017 13:13
@fgbulsoni
Added try/except block to validateVersion to catch host unreachable a…
56485b1
…nd timeout exceptions
@fgbulsoni
fgbulsoni force-pushed the enhancement/catch-http-lib-exceptions-as-hponeviewexceptions branch from 8ed7596 to 56485b1 Compare August 28, 2017 13:17
@fgbulsoni
Adding unit test to validate new except block
af9d839
@fgbulsoni fgbulsoni mentioned this pull request Aug 28, 2017
HPOneViewException not raised when connection with paused VM fails #309
Closed
tmiotto
tmiotto suggested changes Aug 29, 2017
View reviewed changes
Comment thread hpOneView/connection.py Outdated
if self._validateVersion is False:
self.validateVersion()
except Exception as e:
raise HPOneViewException(str(e))

@tmiotto tmiotto Aug 29, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to cover every exception?

An InterruptedException, for instance, should not be re-raised as a HPOneViewException, these are not SDK errors

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@fgbulsoni fgbulsoni Aug 29, 2017

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, what about the no route to host or timeout exceptions? Should we specifically seek those out?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@tmiotto tmiotto Aug 29, 2017

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should try:

raise HPOneViewException(str(e)) from e

But I don't know if future will handle it well.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@fgbulsoni fgbulsoni Aug 29, 2017

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just tried the raise_from from future, but it does not appear to handle it as it should:

On python2:

vagrant@ecosystem-centos7:~/dev/python-hpOneView/examples  (enhancement/catch-http-lib-exceptions-as-hponeviewexceptions)
$ python fc_networks.py
Traceback (most recent call last):
  File "fc_networks.py", line 54, in <module>
    oneview_client = OneViewClient(config)
  File "/home/vagrant/dev/python-hpOneView/hpOneView/oneview_client.py", line 119, in __init__
    self.__connection.login(config["credentials"])
  File "/home/vagrant/dev/python-hpOneView/hpOneView/connection.py", line 491, in login
    raise_from(HPOneViewException('Failure during login attempt.'), e)
  File "/usr/local/lib/python2.7/site-packages/future/utils/__init__.py", line 454, in raise_from
    raise e
HPOneViewException: Failure during login attempt.
vagrant@ecosystem-centos7:~/dev/python-hpOneView/examples  (enhancement/catch-http-lib-exceptions-as-hponeviewexceptions)

On Python3:

$ python3 fc_networks.py
Traceback (most recent call last):
  File "/home/vagrant/dev/python-hpOneView/hpOneView/connection.py", line 485, in login
    self.validateVersion()
  File "/home/vagrant/dev/python-hpOneView/hpOneView/connection.py", line 80, in validateVersion
    version = self.get(uri['version'])
  File "/home/vagrant/dev/python-hpOneView/hpOneView/connection.py", line 325, in get
    resp, body = self.do_http('GET', uri, '')
  File "/home/vagrant/dev/python-hpOneView/hpOneView/connection.py", line 127, in do_http
    conn.request(method, path, body, http_headers)
  File "/usr/local/lib/python3.5/http/client.py", line 1107, in request
    self._send_request(method, url, body, headers)
  File "/usr/local/lib/python3.5/http/client.py", line 1152, in _send_request
    self.endheaders(body)
  File "/usr/local/lib/python3.5/http/client.py", line 1103, in endheaders
    self._send_output(message_body)
  File "/usr/local/lib/python3.5/http/client.py", line 934, in _send_output
    self.send(msg)
  File "/usr/local/lib/python3.5/http/client.py", line 877, in send
    self.connect()
  File "/usr/local/lib/python3.5/http/client.py", line 1253, in connect
    super().connect()
  File "/usr/local/lib/python3.5/http/client.py", line 849, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/local/lib/python3.5/socket.py", line 712, in create_connection
    raise err
  File "/usr/local/lib/python3.5/socket.py", line 703, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "fc_networks.py", line 54, in <module>
    oneview_client = OneViewClient(config)
  File "/home/vagrant/dev/python-hpOneView/hpOneView/oneview_client.py", line 119, in __init__
    self.__connection.login(config["credentials"])
  File "/home/vagrant/dev/python-hpOneView/hpOneView/connection.py", line 487, in login
    raise_from(HPOneViewException('Failure during login attempt.'), e)
  File "/usr/local/lib/python3.5/site-packages/future/utils/__init__.py", line 398, in raise_from
    exec(execstr, myglobals, mylocals)
  File "<string>", line 1, in <module>
hpOneView.exceptions.HPOneViewException: Failure during login attempt.

Python 2 ends up having a lot less understandable trace and message in this case

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@fgbulsoni fgbulsoni Aug 30, 2017

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, after trying both the reraise method from six and the raise_from method from future.utils, both which are basically supposed to achieve PEP 3134 on Py2/Py3, I'm still seeing the same thing happening.

Py2 exception will remain not chained while Py3 has the chaining.

Do we want to keep this behavior @tmiotto ? Thoughts?

Another possibility: Specifically target OSerror as a no route to host and TimeOut Exception types, as those have been proven to be hit, and leave the rest to chance.

That way we do get better error messages, but we also do get more lines of code and still allow whatever other exception to pass through.

Both feel like tradeoffs to me, ideally the from_raise should've worked 😞

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
fgbulsoni added 2 commits August 31, 2017 13:21
@fgbulsoni
Added raise_from usage from future to improve error trace.
83adbbd
@fgbulsoni
Updated CHANGELOG and setup.py in preparation for release
d9a3f8e
tmiotto
tmiotto approved these changes Sep 1, 2017
View reviewed changes
@tmiotto
tmiotto merged commit e97fcd5 into master Sep 1, 2017
@tmiotto
tmiotto deleted the enhancement/catch-http-lib-exceptions-as-hponeviewexceptions branch September 1, 2017 13:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

1 more reviewer
@tmiotto tmiotto tmiotto approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@fgbulsoni @tmiotto
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.