From 4d3ff90e8676e2403f0a0ca2f968aa49aab9bbdd Mon Sep 17 00:00:00 2001 From: Daniel Pivonka Date: Tue, 20 Apr 2021 15:30:28 -0400 Subject: [PATCH] python-common: use OrderedDict instead of Set to remove duplicates from host labels list this preserves the order of the list instead of randomizing the order Signed-off-by: Daniel Pivonka --- src/python-common/ceph/deployment/hostspec.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/python-common/ceph/deployment/hostspec.py b/src/python-common/ceph/deployment/hostspec.py index df9aa42ad78..cb86822d94c 100644 --- a/src/python-common/ceph/deployment/hostspec.py +++ b/src/python-common/ceph/deployment/hostspec.py @@ -1,3 +1,4 @@ +from collections import OrderedDict import errno try: from typing import Optional, List, Any @@ -45,7 +46,7 @@ class HostSpec(object): return { 'hostname': self.hostname, 'addr': self.addr, - 'labels': list(set((self.labels))), + 'labels': list(OrderedDict.fromkeys((self.labels))), 'status': self.status, } @@ -54,7 +55,8 @@ class HostSpec(object): host_spec = cls.normalize_json(host_spec) _cls = cls(host_spec['hostname'], host_spec['addr'] if 'addr' in host_spec else None, - list(set(host_spec['labels'])) if 'labels' in host_spec else None, + list(OrderedDict.fromkeys( + host_spec['labels'])) if 'labels' in host_spec else None, host_spec['status'] if 'status' in host_spec else None) return _cls -- 2.39.5