def run_scenario(scenario):
    """
    Takes a parsed scenario (like from parse_scenario()) and runs it.
    """
    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(key % "unknown command %r")
            command_f(*command)

        rebalance_number = 1
        parts_moved, old_balance, removed_devs = rb.rebalance(seed=seed)
        rb.pretend_min_part_hours_passed()
        print "\tRebalance 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 "\tRebalance %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
dataset/ETHPy150Open openstack/swift/swift/cli/ring_builder_analyzer.py/run_scenario/swapped operands of `%`