From: Sage Weil Date: Thu, 22 Apr 2021 22:42:00 +0000 (-0400) Subject: mgr/cephadm/schedule: make placement shuffle deterministic X-Git-Tag: v16.2.5~87^2~71 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c1953d525d9ade0b7e7b94353d8bde4c832b0118;p=ceph.git mgr/cephadm/schedule: make placement shuffle deterministic hash(str) is non-deterministic, probably because it is using the internal object ID or something and not the string content? In any case, explicitly hash the string content and use that instead. Also, sort the input pre-shuffle to ensure that variations in the original host list ordering don't screw with the result. Signed-off-by: Sage Weil (cherry picked from commit adceaa9b28278601c56a7db1c3f42eaa592ec4d1) --- diff --git a/src/pybind/mgr/cephadm/schedule.py b/src/pybind/mgr/cephadm/schedule.py index c583bfaa5268..de7f8a61e903 100644 --- a/src/pybind/mgr/cephadm/schedule.py +++ b/src/pybind/mgr/cephadm/schedule.py @@ -1,3 +1,4 @@ +import hashlib import logging import random from typing import List, Optional, Callable, TypeVar, Tuple, NamedTuple, Dict @@ -308,7 +309,10 @@ class HostAssignment(object): # shuffle for pseudo random selection # gen seed off of self.spec to make shuffling deterministic - seed = hash(self.spec.service_name()) - random.Random(seed).shuffle(ls) - + seed = int( + hashlib.sha1(self.spec.service_name().encode('utf-8')).hexdigest(), + 16 + ) % (2 ** 32) + final = sorted(ls) + random.Random(seed).shuffle(final) return ls