Testing: IP allocation simulation - add option to change odds of a failure.
authorMartin Schwenke <martin@meltin.net>
Tue, 3 Aug 2010 01:51:14 +0000 (11:51 +1000)
committerMartin Schwenke <martin@meltin.net>
Tue, 3 Aug 2010 01:51:14 +0000 (11:51 +1000)
Signed-off-by: Martin Schwenke <martin@meltin.net>
tests/takeover/ctdb_takeover.py

index f7b0175e8e0628759661f47022b432bbc95a3c85..b87e35f29ffa685aaa91d2be4bcc82511a71f172 100755 (executable)
@@ -66,6 +66,9 @@ def process_args(extra_options=[]):
                       action="store", type="int", dest="iterations",
                       default=1000,
                       help="number of iterations to run in test [default: %default]")
+    parser.add_option("-o", "--odds",
+                      action="store", type="int", dest="odds", default=4,
+                      help="make the chances of a failover 1 in ODDS [default: %default]")
 
     def seed_callback(option, opt, value, parser):
         random.seed(value)
@@ -192,8 +195,8 @@ class Cluster(object):
         """Make a random node healthy or unhealthy.
 
         If all nodes are healthy or unhealthy, then invert one of
-        them.  Otherwise, there's a 1/4 chance of making another node
-        unhealthy."""
+        them.  Otherwise, there's a 1 in options.odds chance of making
+        another node unhealthy."""
 
         num_nodes = len(self.nodes)
         healthy_pnns = [i for (i,n) in enumerate(self.nodes) if n.healthy]
@@ -203,7 +206,7 @@ class Cluster(object):
             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:
+        elif random.randint(1, options.odds) == 1:
             self.unhealthy(random.choice(healthy_pnns))
         else:
             all_pnns = range(num_nodes)