def run_scenario(scenario):
 seed = scenario['random_seed']
 rb = builder.RingBuilder(scenario['part_power'], scenario['replicas'], 1)
 rb.set_overload(scenario['overload'])
 command_map = {'add': rb.add_dev, 'remove': rb.remove_dev, 'set_weight': rb.set_dev_weight, 'save': rb.save}
 for (round_index, commands) in enumerate(scenario['rounds']):
  print ('Round %d' % (round_index + 1))
  for command in commands:
   key = command.pop(0)
   try:
    command_f = command_map[key]
   except KeyError:
    raise ValueError(('unknown command %r' % key))
   command_f(*command)
  rebalance_number = 1
  (parts_moved, old_balance, removed_devs) = rb.rebalance(seed=seed)
  rb.pretend_min_part_hours_passed()
  print (' DCTB Rebalance 1: moved %d parts, balance is %.6f, %d removed devs' % (parts_moved, old_balance, removed_devs))
  while True:
   rebalance_number += 1
   (parts_moved, new_balance, removed_devs) = rb.rebalance(seed=seed)
   rb.pretend_min_part_hours_passed()
   print (' DCTB Rebalance %d: moved %d parts, balance is %.6f, %d removed devs' % (rebalance_number, parts_moved, new_balance, removed_devs))
   if ((parts_moved == 0) and (removed_devs == 0)):
    break
   if ((abs((new_balance - old_balance)) < 1) and (not ((old_balance == builder.MAX_BALANCE) and (new_balance == builder.MAX_BALANCE)))):
    break
   old_balance = new_balance

def run_scenario ( scenario ) : seed = scenario [ 'random_seed' ] rb = builder . RingBuilder ( scenario [ 'part_power' ] , scenario [ 'replicas' ] , 1 ) rb . set_overload ( scenario [ 'overload' ] ) command_map = { 'add' : rb . add_dev , 'remove' : rb . remove_dev , 'set_weight' : rb . set_dev_weight , 'save' : rb . save } for ( round_index , commands ) in enumerate ( scenario [ 'rounds' ] ) : print ( 'Round %d' % ( round_index + 1 ) ) for command in commands : key = command . pop ( 0 ) try : command_f = command_map [ key ] except KeyError : raise ValueError ( ( 'unknown command %r' % key ) ) command_f ( * command ) rebalance_number = 1 ( parts_moved , old_balance , removed_devs ) = rb . rebalance ( seed = seed ) rb . pretend_min_part_hours_passed ( ) print ( ' DCTB Rebalance 1: moved %d parts, balance is %.6f, %d removed devs' % ( parts_moved , old_balance , removed_devs ) ) while True : rebalance_number += 1 ( parts_moved , new_balance , removed_devs ) = rb . rebalance ( seed = seed ) rb . pretend_min_part_hours_passed ( ) print ( ' DCTB Rebalance %d: moved %d parts, balance is %.6f, %d removed devs' % ( rebalance_number , parts_moved , new_balance , removed_devs ) ) if ( ( parts_moved == 0 ) and ( removed_devs == 0 ) ) : break if ( ( abs ( ( new_balance - old_balance ) ) < 1 ) and ( not ( ( old_balance == builder . MAX_BALANCE ) and ( new_balance == builder . MAX_BALANCE ) ) ) ) : break old_balance = new_balance
runs a django scenario and returns its output vars .