Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
Merge pull request #310 from HewlettPackard/enhancement/catch-http-li…
Browse files Browse the repository at this point in the history
…b-exceptions-as-hponeviewexceptions

Catch http lib related exceptions as HpOneViewExceptions during login
  • Loading branch information
tmiotto authored Sep 1, 2017
2 parents b219f1a + d9a3f8e commit e97fcd5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# v4.1.0 (Unreleased)
# v4.1.0

#### New Resources:
- Appliance node information

#### Bug fixes & Enhancements
- [#309](https://github.com/HewlettPackard/python-hpOneView/issues/309) HPOneViewException not raised when connection with paused VM fails

# v4.0.0
#### Notes
Major release which extends support of the SDK to OneView Rest API version 500 (OneView v3.10).
Expand Down
8 changes: 6 additions & 2 deletions hpOneView/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from builtins import open
from builtins import str
from future import standard_library
from future.utils import raise_from

standard_library.install_aliases()

Expand Down Expand Up @@ -479,8 +480,11 @@ def change_initial_password(self, newPassword):
# Login/Logout to/from appliance
###########################################################################
def login(self, cred, verbose=False):
if self._validateVersion is False:
self.validateVersion()
try:
if self._validateVersion is False:
self.validateVersion()
except Exception as e:
raise_from(HPOneViewException('Failure during login attempt.'), e)

self._cred = cred
try:
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@
from setuptools import setup

setup(name='hpOneView',
version='4.0.0',
version='4.1.0',
description='HPE OneView Python Library',
url='https://github.com/HewlettPackard/python-hpOneView',
download_url="https://github.com/HewlettPackard/python-hpOneView/tarball/v4.0.0",
download_url="https://github.com/HewlettPackard/python-hpOneView/tarball/v4.1.0",
author='Hewlett Packard Enterprise Development LP',
author_email='[email protected]',
license='MIT',
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,13 @@ def test_login(self, mock_post, mock_get):
self.assertEqual(self.connection.get_session_id(), '123')
self.assertEqual(self.connection.get_session(), True)

@patch.object(connection, 'get')
def test_login_catches_exceptions_as_hpOneView(self, mock_get):
mock_get.side_effect = [Exception('test')]

with self.assertRaises(HPOneViewException):
self.connection.login({})

@patch.object(connection, 'get')
@patch.object(connection, 'post')
def test_login_with_exception_in_post(self, mock_post, mock_get):
Expand Down

0 comments on commit e97fcd5

Please sign in to comment.