def METHOD_NAME():
    args = parse_args()
    logging.basicConfig(
        level=logging.DEBUG,
        format="%(asctime)s %(levelname)-7s (%(threadName)s) %(message)s")
    old_master = args.old_master
    new_master = args.new_master
    cli = client.connect("localhost", 54321)
    with closing(cli):
        if args.master_version:
            master_ver = args.master_version
        else:
            pool_info = cli.StoragePool.getInfo(storagepoolID=args.pool_id)
            master_ver = int(pool_info['info']['master_ver']) + 1
        for i in range(1, args.iterations + 1):
            log.info("Cycle %s/%s, switching master from %s to %s version %s",
                     i, args.iterations, old_master, new_master, master_ver)
            task_id = cli.StoragePool.switchMaster(
                storagepoolID=args.pool_id,
                oldMasterUUID=old_master,
                newMasterUUID=new_master,
                masterVersion=master_ver)
            log.info("Task id: %s", task_id)
            # Example Task.getStatus response:
            # {'taskID': '5e7b6cd0-d9d7-4e48-b525-7f1f0a612ff7',
            # 'taskState': 'running', 'taskResult': '', 'code': 0,
            # 'message': 'running job 1 of 1'}
            while True:
                time.sleep(5)
                status = cli.Task.getStatus(taskID=task_id)
                log.debug("Task status: %s", status)
                if status["taskState"] != "running":
                    break
            log.debug("Clearing task %s", task_id)
            cli.Task.clear(taskID=task_id)
            if status["code"] != 0:
                raise RuntimeError("Task failed: %s", status["message"])
            pool_info = cli.StoragePool.getInfo(storagepoolID=args.pool_id)
            if pool_info['info']['master_ver'] != master_ver:
                raise RuntimeError(
                    "Unexpected master_ver value: expecting: {} actual: {}"
                    .format(master_ver, pool_info['info']['master_ver']))
            if pool_info['info']['master_uuid'] != new_master:
                raise RuntimeError(
                    "Unexpected master_uuid value: expecting: {} actual: {}"
                    .format(new_master, pool_info['info']['master_uuid']))
            new_master_info = cli.StorageDomain.getInfo(
                storagedomainID=new_master)
            if new_master_info['role'] != "Master":
                raise RuntimeError(
                    "Role for new master domain didn't change to Master")
            old_master_info = cli.StorageDomain.getInfo(
                storagedomainID=old_master)
            if old_master_info['role'] != "Regular":
                raise RuntimeError(
                    "Role for old master domain didn't change to Regular")
            log.info("Master switched successfully")
            new_master, old_master = old_master, new_master
            master_ver += 1