コード例 #1
0
ファイル: run_test.py プロジェクト: vtapia/iperf_benchmark
def warming_run(template_file, parameters, args, credentials):
    temp = template_path + template_file

    with open(temp, 'r') as f:
        template = Template(f.read())

    output = template.render(server=parameters.IPERF_SERVER,
                             protocol=args.protocol,
                             udpflags=parameters.IPERF_C_UDP,
                             timeout=parameters.WARMING_TIME,
                             threads=args.threads)

    with open(tmp_path + 'warming_run.ps1', 'w') as f:
        f.write(output)

    # Start iperf server
    logger.debug("- Starting iperf server for warming run")
    cmd = ' '.join(['./s_iperf.sh', str(args.threads), str(args.protocol)])
    logger.debug("Executing cmd: %s" % cmd)
    os.system(cmd)

    # Start iperf client
    logger.debug("- Starting iperf client for warming run")
    output = run_ps(tmp_path + "warming_run.ps1", parameters.IPERF_CLIENT,
                    credentials, 1)
    logger.debug("PS Output: " + output[2])

    # Stop iperf server
    logger.debug("- Stopping iperf server")
    os.system("killall -9 iperf")
コード例 #2
0
ファイル: run_test.py プロジェクト: vtapia/iperf_benchmark
def validate_driver_config(credentials, guest_ip, cfg):
    logger.info("Verifying if driver configuration has been applied")
    output = run_ps(template_path + "get_driver_config.ps1", guest_ip,
                    credentials, 1)
    data = json.loads(output[1])
    for option in data:
        if cfg[option["DisplayName"]] != option["DisplayValue"]:
            logger.error['Failure during driver configuration.']
            raise SystemExit
        logger.debug('- ' + option["DisplayName"] + ' : ' +
                     option["DisplayValue"])
コード例 #3
0
ファイル: run_test.py プロジェクト: vtapia/iperf_benchmark
def setup_guest_driver(credentials, guest_ip, setup_ps1):
    # Change driver configuration
    logger.info("Configuring driver in guest")
    try:
        with Timeout(15):
            output = run_ps(setup_ps1, guest_ip, credentials, 0)
            logger.debug("PS Output: " + output[2])
    except Timeout.Timeout:
        logger.debug(
            "Driver configuration timed out, closing connection to guest.")

    signal.alarm(0)
コード例 #4
0
ファイル: run_test.py プロジェクト: vtapia/iperf_benchmark
def guest_results(credentials, parameters):
    # Render template
    temp = template_path + "get_guest_results.ps1.template"
    ps1_file = tmp_path + "get_guest_results.ps1"
    with open(temp, 'r') as f:
        template = Template(f.read())

    output = template.render(guest_log_path=parameters.GUEST_LOG_DIR)
    with open(ps1_file, 'w') as f:
        f.write(output)

    # Gather results in JSON
    results = run_ps(ps1_file, parameters.IPERF_CLIENT, credentials, 1)
    return results[1]
コード例 #5
0
ファイル: run_test.py プロジェクト: vtapia/iperf_benchmark
def main():
    logger.setLevel(logging.INFO)
    args = read_args()

    if args.verbose is True:
        logger.setLevel(logging.DEBUG)

    # Hide everything but errors
    # csv ignores verbosity parameter
    if args.csv is True:
        logger.setLevel(logging.ERROR)

    # Define VM from template
    lv = libvirt.open('qemu:///system')
    try:
        vm = lv.lookupByName(parameters.VM_NAME)
        if vm.isActive() is False:
            logger.info(parameters.VM_NAME + " is not running. Starting")
            vm.start()

    except libvirt.libvirtError:
        logger.info("VM " + parameters.VM_NAME + " doesn't exist.")

    # Set WinRM credentials
    credentials = (parameters.USERNAME, parameters.PASSWORD)

    # Render PS1 file for driver config
    logger.debug("Rendering driver config PS1")
    driver_config = render_config_file("set_driver_config.ps1.template",
                                       "driver_definitions.yml", args.driver,
                                       "set_driver_config.ps1")

    # Render PS1 file for client run
    logger.debug("Rendering client run PS1")
    render_test_file("client_iperf.ps1.template", parameters, args,
                     "client_iperf.ps1")

    # Wait until the VM finishes booting
    winrm_port_online(parameters.IPERF_CLIENT, parameters.VM_NAME)

    # Change driver configuration
    setup_guest_driver(credentials, parameters.IPERF_CLIENT,
                       tmp_path + "set_driver_config.ps1")

    # Verify that the configuration has been applied
    validate_driver_config(credentials, parameters.IPERF_CLIENT, driver_config)

    # Remove old log files
    host_log_path = parameters.HOST_LOG_DIR + '/'
    cmd = ' '.join(['rm', host_log_path + 'server*.csv'])
    os.system(cmd)

    # Warming up run
    logger.info("Warm up run")
    warming_run("warming_run.ps1.template", parameters, args, credentials)

    iteration = 1
    throughput = []
    while iteration <= args.iterations:
        logger.info("Running iteration " + str(iteration))
        iteration += 1

        # Start iperf server
        logger.info("- Starting iperf server")
        cmd = ' '.join(['./s_iperf.sh', str(args.threads), str(args.protocol)])
        logger.debug("Executing cmd: %s" % cmd)
        os.system(cmd)

        # Start iperf client
        logger.info("- Starting iperf client")
        output = run_ps(tmp_path + "client_iperf.ps1", parameters.IPERF_CLIENT,
                        credentials, 1)
        logger.debug("PS Output: " + output[2])

        # Gather guest results
        logger.debug("Gathering test results from guest")
        gresults = guest_results(credentials, parameters)
        logger.debug(gresults)

        # Gather host results
        # host_results(host_log_path)

        # Stop iperf server
        logger.info("- Stopping iperf server")
        os.system("killall -9 iperf")

        if args.csv is True:
            # Show CSV from guest results
            print_csv(args.driver, iteration - 1, args.threads, gresults)

        else:
            # Show human readable results
            iteration_tp = parse_results(args.threads, gresults)
            throughput.append(iteration_tp)

    if args.csv is not True:
        run_tp = sum(throughput) / args.iterations
        run_std = numpy.std(throughput)
        logger.info("Run average throughput: " + readable(run_tp))
        logger.info("Std dev for this run: %s (%.2f%%)", readable(run_std),
                    (100 * run_std / run_tp))