diff --git a/PyPowerFlex/base_client.py b/PyPowerFlex/base_client.py index 352d343..7a30d4d 100644 --- a/PyPowerFlex/base_client.py +++ b/PyPowerFlex/base_client.py @@ -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, diff --git a/tests/common/__init__.py b/tests/common/__init__.py index 7e4b68b..ef0c676 100644 --- a/tests/common/__init__.py +++ b/tests/common/__init__.py @@ -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', @@ -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, @@ -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: diff --git a/tests/gen1/test_system.py b/tests/gen1/test_system.py index 9228d85..193bfed 100644 --- a/tests/gen1/test_system.py +++ b/tests/gen1/test_system.py @@ -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): """ @@ -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): """ diff --git a/tests/gen2/test_system.py b/tests/gen2/test_system.py index 26bcbab..1bd3b18 100644 --- a/tests/gen2/test_system.py +++ b/tests/gen2/test_system.py @@ -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): """ @@ -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): """