Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[crmsh-4.4] Dev: utils: Introduced detect_duplicate_device_path function in utils #1583

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crmsh/sbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ def _verify_sbd_device(self, dev_list, compare_node_list=[]):
if not utils.is_block_device(dev):
raise ValueError("{} doesn't look like a block device".format(dev))
self._compare_device_uuid(dev, compare_node_list)
utils.detect_duplicate_device_path(dev_list)

def _get_sbd_device_interactive(self):
"""
Expand Down
15 changes: 15 additions & 0 deletions crmsh/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import errno
import os
import sys
import typing
from tempfile import mkstemp
import subprocess
import re
Expand All @@ -20,6 +21,7 @@
import random
import string
from pathlib import Path
from collections import defaultdict
from contextlib import contextmanager, closing
from stat import S_ISBLK
from lxml import etree
Expand Down Expand Up @@ -2770,6 +2772,19 @@ def is_block_device(dev):
return rc


def detect_duplicate_device_path(device_list: typing.List[str]):
"""
Resolve device path and check if there are duplicated device path
"""
path_dict = defaultdict(list)
for dev in device_list:
resolved_path = Path(dev).resolve()
path_dict[resolved_path].append(dev)
for path, dev_list in path_dict.items():
if len(dev_list) > 1:
raise ValueError(f"Duplicated device path detected: {','.join(dev_list)}. They are all pointing to {path}")


def has_stonith_running():
"""
Check if any stonith device registered
Expand Down
Loading