]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
qa/tasks/mds_thrash: s/random.sample/random.choice/ 35193/head
authorKefu Chai <kchai@redhat.com>
Sat, 23 May 2020 03:29:51 +0000 (11:29 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 23 May 2020 03:29:53 +0000 (11:29 +0800)
* use list comprehension instead of concatenating two ranges for
  better readablity -- we want to skip current max_mds for changing
  it. this helps reader to understand the goal of thrashing
* random.sample() is replaced with random.choice(). the latter is a
  better alternative, if the number of samples is 1.

Signed-off-by: Kefu Chai <kchai@redhat.com>
qa/tasks/mds_thrash.py

index 11e647b8a05f073dbb23dd8f4cd1c92857ed672e..ebd9e81a30ab2caa140d786a2e1cb0f19c0a54b4 100644 (file)
@@ -246,10 +246,9 @@ class MDSThrasher(Thrasher, Greenlet):
 
             if random.random() <= self.thrash_max_mds:
                 max_mds = status.get_fsmap(self.fs.id)['mdsmap']['max_mds']
-                options = list(range(1, max_mds))+list(range(max_mds+1, self.max_mds+1))
+                options = [i for i in range(1, self.max_mds + 1) if i != max_mds]
                 if len(options) > 0:
-                    sample = random.sample(options, 1)
-                    new_max_mds = sample[0]
+                    new_max_mds = random.choice(options)
                     self.log('thrashing max_mds: %d -> %d' % (max_mds, new_max_mds))
                     self.fs.set_max_mds(new_max_mds)
                     stats['max_mds'] += 1