Skip to content

Commit 5155c44

Browse files
refactor(linstorjournaler,linstorvolumemanager): rebuild cache on connection error
Signed-off-by: Mathieu Labourier <[email protected]>
1 parent 21f7a62 commit 5155c44

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

drivers/linstorjournaler.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717

1818

1919
from linstorvolumemanager import \
20-
get_controller_uri, LinstorVolumeManager, LinstorVolumeManagerError
20+
get_controller_uri, LinstorVolumeManager, LinstorVolumeManagerError, build_controller_uri_cache, \
21+
delete_controller_uri_cache
2122
import linstor
2223
import re
2324
import util
@@ -160,8 +161,10 @@ def connect(uri):
160161

161162
try:
162163
return connect(uri)
163-
except (linstor.errors.LinstorNetworkError, LinstorVolumeManagerError):
164+
except LinstorVolumeManagerError:
164165
pass
166+
except linstor.errors.LinstorNetworkError:
167+
delete_controller_uri_cache()
165168

166169
return util.retry(
167170
lambda: connect(None),

drivers/linstorvolumemanager.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ def get_cached_controller_uri():
213213
))
214214
return None
215215

216+
def delete_controller_uri_cache():
217+
try:
218+
os.remove(CONTROLLER_CACHE_PATH)
219+
except Exception as e:
220+
util.SMlog('Unable to write controller uri cache file at {}/{} : {}'.format(
221+
CONTROLLER_CACHE_DIRECTORY,
222+
CONTROLLER_CACHE_FILE,
223+
e
224+
))
216225

217226
def write_controller_uri_cache(uri):
218227
try:
@@ -2664,7 +2673,7 @@ def _get_error_str(cls, result):
26642673

26652674
@classmethod
26662675
def _create_linstor_instance(
2667-
cls, uri, keep_uri_unmodified=False, attempt_count=30
2676+
cls, uri, keep_uri_unmodified=False, keep_cache_on_error=False, attempt_count=30
26682677
):
26692678
retry = False
26702679

@@ -2681,8 +2690,11 @@ def connect(uri):
26812690

26822691
try:
26832692
return connect(uri)
2684-
except (linstor.errors.LinstorNetworkError, LinstorVolumeManagerError):
2693+
except LinstorVolumeManagerError:
26852694
pass
2695+
except linstor.errors.LinstorNetworkError:
2696+
if not keep_cache_on_error:
2697+
build_controller_uri_cache()
26862698

26872699
if not keep_uri_unmodified:
26882700
uri = None

0 commit comments

Comments
 (0)