Skip to content

Commit 3a32b36

Browse files
authored
[crmsh-4.5] Dev: utils: Introduced detect_duplicate_device_path function in utils (#1584)
backport from #1582
2 parents eb5e2e1 + f88204b commit 3a32b36

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

crmsh/sbd.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ def _verify_sbd_device(self, dev_list, compare_node_list=[]):
320320
if not utils.is_block_device(dev):
321321
raise ValueError("{} doesn't look like a block device".format(dev))
322322
self._compare_device_uuid(dev, compare_node_list)
323+
utils.detect_duplicate_device_path(dev_list)
323324

324325
def _no_overwrite_check(self, dev):
325326
"""

crmsh/utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import pwd
2525
import grp
2626
from pathlib import Path
27+
from collections import defaultdict
2728
from contextlib import contextmanager, closing
2829
from stat import S_ISBLK
2930
from lxml import etree
@@ -3053,6 +3054,19 @@ def is_block_device(dev):
30533054
return rc
30543055

30553056

3057+
def detect_duplicate_device_path(device_list: typing.List[str]):
3058+
"""
3059+
Resolve device path and check if there are duplicated device path
3060+
"""
3061+
path_dict = defaultdict(list)
3062+
for dev in device_list:
3063+
resolved_path = Path(dev).resolve()
3064+
path_dict[resolved_path].append(dev)
3065+
for path, dev_list in path_dict.items():
3066+
if len(dev_list) > 1:
3067+
raise ValueError(f"Duplicated device path detected: {','.join(dev_list)}. They are all pointing to {path}")
3068+
3069+
30563070
def has_stonith_running():
30573071
"""
30583072
Check if any stonith device registered

0 commit comments

Comments
 (0)