Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion PyPowerFlex/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,11 @@ def get_api_version(self):
dict: The JSON response containing the API version.
"""
request_url = self.base_url + '/version'
self._login()
try:
self._appliance_login()
except exceptions.PowerFlexClientException as e:
LOG.error("Failed to login: %s. Revert to 3.x authentication.", e)
self._login()
r = requests.get(request_url,
auth=(
self.configuration.username,
Expand Down
13 changes: 9 additions & 4 deletions tests/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def decorator(subclass):
'/login': 'token',
VERSION_API_PATH: '4.5',
'/logout': '',
'/rest/auth/login': {"access_token": "token", "refresh_token": "refresh_token"},
},
RESPONSE_MODE.Invalid: {
VERSION_API_PATH: '2.5',
Expand All @@ -127,6 +128,12 @@ def decorator(subclass):
'message': 'Test login bad status',
}, 400
),
'/rest/auth/login': MockResponse(
{
'errorCode': 1,
'message': 'Test login bad status',
}, 400
),
'/version': MockResponse(
{
'errorCode': 2,
Expand Down Expand Up @@ -244,10 +251,8 @@ def get_mock_response(self, url, request_url=None, mode=None, *args, **kwargs):

api_path = self.extract_path_segment(url, request_url)
try:
if api_path == "/login":
response = self.RESPONSE_MODE.Valid[0]
elif api_path == "/logout":
response = self.RESPONSE_MODE.Valid[2]
if api_path in {"/login", "/rest/auth/login", "/logout"}:
response = self.DEFAULT_MOCK_RESPONSES[self.RESPONSE_MODE.Valid][api_path]
else:
response = self.MOCK_RESPONSES[mode][api_path]
except KeyError as e:
Expand Down
4 changes: 2 additions & 2 deletions tests/gen1/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_system_api_version(self):
Test the API version.
"""
self.client.system.api_version()
self.assertEqual(8, self.get_mock.call_count)
self.assertEqual(6, self.get_mock.call_count)

def test_system_api_version_bad_status(self):
"""
Expand All @@ -127,7 +127,7 @@ def test_system_api_version_cached(self):
self.client.system.api_version()
self.client.system.api_version()
self.client.system.api_version()
self.assertEqual(8, self.get_mock.call_count)
self.assertEqual(6, self.get_mock.call_count)

def test_system_remove_cg_snapshots(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions tests/gen2/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_system_api_version(self):
Test the API version.
"""
self.client.system.api_version()
self.assertEqual(8, self.get_mock.call_count)
self.assertEqual(6, self.get_mock.call_count)

def test_system_api_version_bad_status(self):
"""
Expand All @@ -124,7 +124,7 @@ def test_system_api_version_cached(self):
self.client.system.api_version()
self.client.system.api_version()
self.client.system.api_version()
self.assertEqual(8, self.get_mock.call_count)
self.assertEqual(6, self.get_mock.call_count)

def test_system_remove_cg_snapshots(self):
"""
Expand Down