From 0e92a480bf6063aa7bf4a108b0915af84ba03a93 Mon Sep 17 00:00:00 2001 From: chihyuwu Date: Wed, 30 Oct 2019 07:10:38 +0000 Subject: [PATCH] Synology: Improve session expired error handling Session may not reconnect when current session is expired because error handling only handles Error Code 105 (No Permission) but 119 (SID Not Found) is needed as well. Change-Id: Ida093a1ebf3395a73298cb087c28290229fbb92e Closes-Bug: #1850601 --- .../unit/volume/drivers/synology/test_synology_common.py | 7 +++++-- cinder/volume/drivers/synology/synology_common.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cinder/tests/unit/volume/drivers/synology/test_synology_common.py b/cinder/tests/unit/volume/drivers/synology/test_synology_common.py index 93755fbb69f..94c7425dfb4 100644 --- a/cinder/tests/unit/volume/drivers/synology/test_synology_common.py +++ b/cinder/tests/unit/volume/drivers/synology/test_synology_common.py @@ -23,6 +23,7 @@ from unittest import mock from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives.asymmetric import padding from cryptography.hazmat.primitives.asymmetric import rsa +import ddt from oslo_utils import units import requests from six.moves import http_client @@ -323,6 +324,7 @@ class SynoSessionTestCase(test.TestCase): ) +@ddt.ddt class SynoAPIRequestTestCase(test.TestCase): @mock.patch('requests.post') def setUp(self, _mock_post): @@ -427,7 +429,8 @@ class SynoAPIRequestTestCase(test.TestCase): {'http_status': http_client.INTERNAL_SERVER_ERROR}, result) @mock.patch.object(common.LOG, 'debug') - def test_request_auth_error(self, _log): + @ddt.data(105, 119) + def test_request_auth_error(self, _code, _log): version = 1 self.request._start = mock.Mock(return_value='fake.cgi') @@ -435,7 +438,7 @@ class SynoAPIRequestTestCase(test.TestCase): self.request.new_session = mock.Mock() requests.post = mock.Mock(return_value= MockResponse({ - 'error': {'code': 105}, + 'error': {'code': _code}, 'success': False }, http_client.OK)) diff --git a/cinder/volume/drivers/synology/synology_common.py b/cinder/volume/drivers/synology/synology_common.py index 655ccba0095..d467290760e 100644 --- a/cinder/volume/drivers/synology/synology_common.py +++ b/cinder/volume/drivers/synology/synology_common.py @@ -398,7 +398,7 @@ class APIRequest(object): reason=reason) if ('error' in result and 'code' in result["error"] - and result['error']['code'] == 105): + and result['error']['code'] in [105, 119]): raise SynoAuthError(reason=_('Session might have expired.')) return result