From ad7de14ea6fbc7bc0b354ac3a2dc2158167a5b46 Mon Sep 17 00:00:00 2001 From: Alex Talker Date: Tue, 8 Jan 2019 18:39:32 +0300 Subject: [PATCH] Introduce order in detect_scan command (#52) --- chroma_agent/action_plugins/detect_scan.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/chroma_agent/action_plugins/detect_scan.py b/chroma_agent/action_plugins/detect_scan.py index 7551793..6714b99 100644 --- a/chroma_agent/action_plugins/detect_scan.py +++ b/chroma_agent/action_plugins/detect_scan.py @@ -31,7 +31,7 @@ def __init__(self, target_devices): # when we see a combined MGS+MDT uuid_name_to_target = {} - for device in target_devices: + for device in sorted(target_devices, cmp=LocalTargets.comparator): block_device = BlockDevice(device["type"], device["path"]) # If the target_device has no uuid then it doesn't have a filesystem and is of no use to use, but @@ -80,6 +80,18 @@ def __init__(self, target_devices): self.targets = uuid_name_to_target.values() + @classmethod + def comparator(cls, a, b): + value = cmp(a["type"], b["type"]) + + if value == 0: + value = cmp(a["uuid"], b["uuid"]) + + if value == 0: + value = cmp(a["path"], b["path"]) + + return value + class MgsTargets(object): TARGET_NAME_REGEX = "([\w-]+)-(MDT|OST)\w+"