]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
python-common: use OrderedDict instead of Set to remove duplicates from host labels... 40944/head
authorDaniel Pivonka <dpivonka@redhat.com>
Tue, 20 Apr 2021 19:30:28 +0000 (15:30 -0400)
committerDaniel Pivonka <dpivonka@redhat.com>
Wed, 21 Apr 2021 20:31:58 +0000 (16:31 -0400)
this preserves the order of the list instead of randomizing the order

Signed-off-by: Daniel Pivonka <dpivonka@redhat.com>
src/python-common/ceph/deployment/hostspec.py

index df9aa42ad782d499e4dbb6a39177bb348f644d46..cb86822d94ca19286bbb307847d7602a2188d21d 100644 (file)
@@ -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