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.6] Dev: utils: Introduced detect_duplicate_device_path function in utils #1582

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 @@ -321,6 +321,7 @@
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)

Check warning on line 324 in crmsh/sbd.py

View check run for this annotation

Codecov / codecov/patch

crmsh/sbd.py#L324

Added line #L324 was not covered by tests

def _no_overwrite_check(self, dev):
"""
Expand Down
14 changes: 14 additions & 0 deletions crmsh/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import bz2
import lzma
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 @@ -2563,6 +2564,19 @@
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}")

Check warning on line 2577 in crmsh/utils.py

View check run for this annotation

Codecov / codecov/patch

crmsh/utils.py#L2571-L2577

Added lines #L2571 - L2577 were not covered by tests


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