mirror of
https://github.com/samba-team/samba.git
synced 2024-12-25 23:21:54 +03:00
Testing: IP allocation simulation - fix nondeterminism in do_something_random().
The current code makes random choices from unsorted lists. This ensures the lists are sorted. Also, make the code easier to read by doing the random selction from lists of PNNs rather than lists of Node objects. Signed-off-by: Martin Schwenke <martin@meltin.net> (This used to be ctdb commit a01244499dc3567f5aa934b1864b9bc183a6c242)
This commit is contained in:
parent
eac5edf322
commit
ae0f339173
@ -193,17 +193,19 @@ class Cluster(object):
|
||||
unhealthy."""
|
||||
|
||||
num_nodes = len(self.nodes)
|
||||
healthy_nodes = [n for n in self.nodes if n.healthy]
|
||||
num_healthy = len(healthy_nodes)
|
||||
healthy_pnns = [i for (i,n) in enumerate(self.nodes) if n.healthy]
|
||||
num_healthy = len(healthy_pnns)
|
||||
|
||||
if num_nodes == num_healthy:
|
||||
self.unhealthy(random.randint(0, num_nodes-1))
|
||||
elif num_healthy == 0:
|
||||
self.healthy(random.randint(0, num_nodes-1))
|
||||
elif random.randint(1, 4) == 1:
|
||||
self.unhealthy(self.nodes.index(random.choice(healthy_nodes)))
|
||||
self.unhealthy(random.choice(healthy_pnns))
|
||||
else:
|
||||
self.healthy(self.nodes.index(random.choice(list(set(self.nodes) - set(healthy_nodes)))))
|
||||
all_pnns = range(num_nodes)
|
||||
unhealthy_pnns = sorted(list(set(all_pnns) - set(healthy_pnns)))
|
||||
self.healthy(random.choice(unhealthy_pnns))
|
||||
|
||||
def random_iterations(self):
|
||||
i = 1
|
||||
|
Loading…
Reference in New Issue
Block a user