Skip to content

Commit ee9d128

Browse files
committed
fix(linstor): fix bad JSON parsing for get_remote_host_ip
The JSON format has changed between several DRBD versions. Now we log if we suspect a change that causes incorrect parsing. Signed-off-by: Ronan Abhamon <ronan.abhamon@vates.tech>
1 parent f0e6601 commit ee9d128

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

drivers/linstorvolumemanager.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
DATABASE_MKFS = 'mkfs.ext4'
4040

4141
REG_DRBDADM_PRIMARY = re.compile("([^\\s]+)\\s+role:Primary")
42-
REG_DRBDSETUP_IP = re.compile('[^\\s]+\\s+(.*):.*$')
4342

4443
DRBD_BY_RES_PATH = '/dev/drbd/by-res/'
4544

@@ -139,17 +138,18 @@ def get_remote_host_ip(node_name):
139138
conf = json.loads(stdout)
140139
if not conf:
141140
return
141+
except Exception as e:
142+
util.SMlog(f"Failed to read DRBD configuration as JSON: `{e}`.")
143+
return ""
142144

143-
for connection in conf[0]['connections']:
144-
if connection['net']['_name'] == node_name:
145-
value = connection['path']['_remote_host']
146-
res = REG_DRBDSETUP_IP.match(value)
147-
if res:
148-
return res.groups()[0]
149-
break
150-
except Exception:
151-
pass
152-
145+
try:
146+
for connection in conf[0]["connections"]:
147+
if connection["net"]["_name"] == node_name:
148+
return connection["paths"][0]["remote_host"]["address"]
149+
except KeyError as e:
150+
util.SMlog(f"The key `{e}` could not be found in the DRBD configuration. The JSON format may have changed.")
151+
except Exception as e:
152+
util.SMlog(f"Failed to parse DRBD configuration: `{e}`. The JSON format may have changed.")
153153

154154
def _get_controller_uri():
155155
PLUGIN_CMD = 'hasControllerRunning'

0 commit comments

Comments
 (0)