From: Daniel Pivonka Date: Tue, 20 Apr 2021 19:30:28 +0000 (-0400) Subject: python-common: use OrderedDict instead of Set to remove duplicates from host labels... X-Git-Tag: v16.2.5~39^2~4^2^2~29 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=7af77b8969b42152f8197fbae2808197fce42578;p=ceph.git 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 (cherry picked from commit 4d3ff90e8676e2403f0a0ca2f968aa49aab9bbdd) --- 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