예제 #1
0
파일: conftest.py 프로젝트: vadfabi/switchy
    def factory(userpart, port=5080, limit=1, rate=1, offer=1, **kwargs):
        orig = switchy.get_originator(fsip,
                                      limit=limit,
                                      rate=rate,
                                      max_offered=offer,
                                      **kwargs)

        # each profile should originate calls back to itself
        # to avoid dependency on another server
        orig.pool.evals(
            ("""client.set_orig_cmd('{}@{}:{}'.format(
             userpart, client.host, port), app_name='park')"""),
            userpart=userpart,
            port=port,
        )
        origs.append(orig)
        return orig
예제 #2
0
    def factory(userpart, port=5080, limit=1, rate=1, offer=1, **kwargs):
        orig = get_originator(
            fsip,
            limit=limit,
            rate=rate,
            max_offered=offer,
            **kwargs
        )

        # each slave profile should call originate calls to itself
        # to avoid dependency on another server
        orig.pool.evals(
            ("""client.set_orig_cmd('{}@{}:{}'.format(
             userpart, client.server, port))"""),
            userpart=userpart,
            port=port,
        )
        origs.append(orig)
        return orig
예제 #3
0
def get_orig(request, fsip):
    '''Deliver an `Originator` app which drives a single
    FreeSWITCH slave process.
    '''
    apps = request.node.get_marker('apps')
    orig = get_originator(fsip, apps=apps.kwargs.values())

    def conf_orig(userpart, port=5080, limit=1, rate=1, offer=1):
        # each slave profile should call originate calls to itself
        # to avoid dependency on another server
        orig.pool.evals(
            ("""client.set_orig_cmd('{}@{}:{}'.format(
             userpart, client.server, port), app_name='park')"""),
            userpart=userpart,
            port=port,
        )
        # dut should provide these values based on hw resources
        orig.limit = limit
        orig.rate = rate
        orig.max_offered = offer
        return orig
    yield conf_orig
    orig.shutdown()
예제 #4
0
def get_orig(request, fsip):
    '''Deliver an `Originator` app which drives a single
    FreeSWITCH slave process.
    '''
    apps = request.node.get_marker('apps')
    orig = get_originator(fsip, apps=apps.kwargs.values())

    def conf_orig(userpart, port=5080, limit=1, rate=1, offer=1):
        # each slave profile should call originate calls to itself
        # to avoid dependency on another server
        orig.pool.evals(
            ("""client.set_orig_cmd('{}@{}:{}'.format(
             userpart, client.server, port), app_name='park')"""),
            userpart=userpart,
            port=port,
        )
        # dut should provide these values based on hw resources
        orig.limit = limit
        orig.rate = rate
        orig.max_offered = offer
        return orig

    yield conf_orig
    orig.shutdown()
예제 #5
0
파일: cli.py 프로젝트: ncorbic/switchy
def run(slaves, proxy, profile, rate, limit, max_offered,
        duration, interactive, debug, app, metrics_file):
    log = switchy.utils.log_to_stderr("INFO")

    # Check if the specified (or default) app is valid
    switchy.apps.load()
    cls = switchy.apps.get(app)
    if not cls:
        raise click.ClickException('Unknown app {}. Use list-apps command '
                                   'to list available apps'.format(app))

    # TODO: get_originator() receives an apps tuple (defaults to Bert) to
    # select the application we should accept --app multi argument list to
    # set multiple apps
    o = switchy.get_originator(
        slaves,
        apps=(cls,),
        rate=int(rate) if rate else None,
        limit=int(limit) if limit else None,
        max_offered=int(max_offered) if max_offered else None,
        duration=int(duration) if duration else None,
        auto_duration=True if not duration else False,
    )

    # Prepare the originate string for each slave
    # depending on the profile name and network settings
    # configured for that profile in that particular slave
    p = re.compile('.+?BIND-URL\s+?.+?@(.+?):(\d+).+?\s+',
                   re.IGNORECASE | re.DOTALL)
    for c in o.pool.clients:
        status = c.client.api('sofia status profile {}'
                              .format(profile)).getBody()
        m = p.match(status)
        if not m:
            raise click.ClickException('Slave {} does not have a profile '
                                       'named \'{}\' running'
                                       .format(c.host, profile))
        ip = m.group(1)
        port = m.group(2)
        # The originate cmd must route the call back to us using the specified
        # proxy (the device under test)
        log.info('Slave {} SIP address is at {}:{}'.format(c.host, ip, port))
        c.set_orig_cmd(dest_url='switchy@{}:{}'.format(ip, port),
                       profile=profile, app_name='park',
                       proxy='{}'.format(proxy))

    log.info('Starting load test for server {} at {}cps using {} slaves'
               .format(proxy, o.rate, len(slaves)))
    click.echo(o)
    if interactive:
        try:
            import IPython
            IPython.embed()
        except ImportError:
            try:
                # optional, will allow Up/Down/History in the console
                import readline
            except ImportError:
                pass
            import code
            vars = globals().copy()
            vars.update(locals())
            shell = code.InteractiveConsole(vars)
            shell.interact()

        o.shutdown()
        click.echo(o)
    else:
        o.start()
        while o.state != 'STOPPED':
            try:
                time.sleep(1)
                click.echo(o)
            except KeyboardInterrupt:
                o.shutdown()
                click.echo(o)

    while True:
        active_calls = o.count_calls()
        if active_calls <= 0:
            break
        click.echo('Waiting on {} active calls to finish'.format(active_calls))
        time.sleep(1)

    if metrics_file:
        click.echo('Storing test metrics at {}'.format(metrics_file))
        o.metrics.dump(metrics_file)

    click.echo('Load test finished!')
예제 #6
0
파일: dialer.py 프로젝트: ncorbic/switchy
def main(
    # Specify FreeSWITCH or Sangoma NSG IP information.
    # In this example the sample app is running on
    # Sangoma NSG appliance hence the use of local loopback address
    host="127.0.0.1",
    port=8821,
    # Specify campaign settings
    max_calls_per_campaign=1,
    max_call_attempts_per_sec=1,
    max_campaigns=1,
):
    """Run an auto-dialer and manage campaigns.

    Create an 'originator' to use as an auto-dialer.
    You can tell it how many calls to make and at what frequency.
    After the first batch of calls are complete, you can choose to start
    dialing again.

    There are 3 configurable dialer variables:
     - max_calls_per_campaign
     - max_call_attempts_per_sec
     - max_campaigns

    In this example the dialer will by default make 1 outbound call on the
    first campaign. The `max_campaigns` variable, determines the number of
    times the dialer will repeat campaigns.
    """
    # Enable logging to stderr
    # Debug levels: 'INFO' for production, 'DEBUG' for development
    loglevel = "INFO"
    log = switchy.utils.log_to_stderr(loglevel)

    # create an auto-dialer and load our IVRCallLogic switchy app
    originator = get_originator([(host, port)], apps=(IVRCallLogic,), auto_duration=False, rep_fields_func=create_url)

    # Initialize dial variables in order for switchy to trigger create_url()
    # function above.
    # The create_url function is a callback which has the task of specifying
    # the dial information per call (i.e. it is called once for each call).
    originator.pool.evals(
        (
            """client.set_orig_cmd(
         dest_url='{dest_url}',
         profile='{dest_profile}',
         endpoint='{dest_endpoint}',
         app_name='park')"""
        )
    )

    # Enables debugging on NetBorder VoIP Gateway
    if loglevel == "DEBUG":
        originator.pool.evals(("""client.set_loglevel('DEBUG')"""))

    # Setup calls per sec
    originator.rate = max_call_attempts_per_sec

    # Setup maximum number of calls to make
    # max erlangs / simultaneous calls
    originator.limit = max_calls_per_campaign

    # Maximum number of calls to dial out
    originator.max_offered = max_calls_per_campaign

    # Start the initial campaign - Originator will start making outbound calls
    originator.start()

    # Keeps a count of campaigns
    campaign_cnt = 0

    # Here is an example of how to keep an eye on the campaign.
    # After the campaign is over, check to see if another campaign should start
    while True:
        if originator.stopped() and originator.count_calls() == 0:

            log.info(originator)  # log state info and current load

            # Check to see if we should run another camapign
            campaign_cnt += 1
            if campaign_cnt >= max_campaigns:
                break

            log.info("Starting new campaign\n")

            # We must increase the max allowed calls in order
            # for dialer to initiate another max_calls_per_campaign
            originator.max_offered += max_calls_per_campaign
            originator.start()

        time.sleep(1)

    log.info("All campaigns done: stopping...\n")
    originator.shutdown()
예제 #7
0
파일: cli.py 프로젝트: vadfabi/switchy
def dial(hosts, proxy, dest_url, profile, gateway, rate, limit, max_offered,
         duration, interactive, app, metrics_file, loglevel, password):
    """Spin up an auto-dialer.
    """
    log = switchy.utils.log_to_stderr(loglevel)
    log.propagate = False

    dialer = switchy.get_originator(
        hosts,
        rate=int(rate) if rate else None,
        limit=int(limit) if limit else None,
        max_offered=int(max_offered) if max_offered else None,
        duration=int(duration) if duration else None,
        auto_duration=True if not duration else False,
        auth=password,
    )
    apps = get_apps(app)
    for cls, args in apps:
        dialer.load_app(cls, ppkwargs=args)

    # Prepare the originate string for each slave
    # depending on the profile name and network settings
    # configured for that profile in that particular slave
    p = re.compile('.+?BIND-URL\s+?.+?@(.+?):(\d+).+?\s+',
                   re.IGNORECASE | re.DOTALL)
    for client in dialer.pool.clients:
        status = client.client.api(
            'sofia status profile {}'.format(profile)).getBody()
        m = p.match(status)
        if not m:
            raise click.ClickException('Slave {} does not have a profile '
                                       'named \'{}\' running'.format(
                                           client.host, profile))
        # configure originate cmd(s)
        ip = m.group(1)
        port = m.group(2)
        if dest_url is None:
            dest_url = 'switchy@{}:{}'.format(ip, port)
        # The originate cmd must route the call back to us using the specified
        # proxy (the device under test)
        if proxy is None:
            proxy = dest_url
        log.info('Slave {} SIP address is at {}:{}'.format(
            client.host, ip, port))
        client.set_orig_cmd(dest_url=dest_url,
                            profile=profile,
                            gateway=gateway,
                            app_name='park',
                            proxy='{}'.format(proxy))

    log.info('Starting load test for server {} at {}cps using {} hosts'.format(
        proxy, dialer.rate, len(hosts)))
    click.echo(dialer)
    if interactive:
        try:
            import IPython
            IPython.start_ipython(argv=[], user_ns=locals())
        except ImportError:
            try:
                # optional, will allow Up/Down/History in the console
                import readline
            except ImportError:
                pass

            # load built-in console
            import code
            vars = globals().copy()
            vars.update(locals())
            shell = code.InteractiveConsole(vars)
            shell.interact()

        dialer.shutdown()
        click.echo(dialer)
    else:
        dialer.start()
        while dialer.state != 'STOPPED':
            try:
                time.sleep(1)
                click.echo(dialer)
            except KeyboardInterrupt:
                dialer.shutdown()
                click.echo(dialer)

    try:
        while True:
            active_calls = dialer.count_calls()
            if active_calls <= 0:
                break
            click.echo(
                'Waiting on {} active calls to finish'.format(active_calls))
            time.sleep(1)
    except KeyboardInterrupt:
        dialer.shutdown()

    if metrics_file:
        click.echo('Storing test metrics at {}'.format(metrics_file))
        dialer.measurers.to_store(metrics_file)

    click.echo('Dialing session completed!')
예제 #8
0
def main(
    # Specify FreeSWITCH or Sangoma NSG IP information.
    # In this example the sample app is running on
    # Sangoma NSG appliance hence the use of local loopback address
    host="127.0.0.1",
    port=8821,

    # Specify campaign settings
    max_calls_per_campaign=1,
    max_call_attempts_per_sec=1,
    max_campaigns=1,
):
    """Run an auto-dialer and manage campaigns.

    Create an 'originator' to use as an auto-dialer.
    You can tell it how many calls to make and at what frequency.
    After the first batch of calls are complete, you can choose to start
    dialing again.

    There are 3 configurable dialer variables:
     - max_calls_per_campaign
     - max_call_attempts_per_sec
     - max_campaigns

    In this example the dialer will by default make 1 outbound call on the
    first campaign. The `max_campaigns` variable, determines the number of
    times the dialer will repeat campaigns.
    """
    # Enable logging to stderr
    # Debug levels: 'INFO' for production, 'DEBUG' for development
    loglevel = 'INFO'
    log = switchy.utils.log_to_stderr(loglevel)

    # create an auto-dialer and load our IVRCallLogic switchy app
    originator = get_originator([(host, port)],
                                apps=(IVRCallLogic, ),
                                auto_duration=False,
                                rep_fields_func=create_url)

    # Initialize dial variables in order for switchy to trigger create_url()
    # function above.
    # The create_url function is a callback which has the task of specifying
    # the dial information per call (i.e. it is called once for each call).
    originator.pool.evals(("""client.set_orig_cmd(
         dest_url='{dest_url}',
         profile='{dest_profile}',
         endpoint='{dest_endpoint}',
         caller_id='{caller_id}',
         caller_id_num='{caller_id_num}',
         app_name='park')"""))

    # Enables debugging on NetBorder VoIP Gateway
    if loglevel == 'DEBUG':
        originator.pool.evals(("""client.set_loglevel('DEBUG')"""))

    # Setup calls per sec
    originator.rate = max_call_attempts_per_sec

    # Setup maximum number of calls to make
    # max erlangs / simultaneous calls
    originator.limit = max_calls_per_campaign

    # Maximum number of calls to dial out
    originator.max_offered = max_calls_per_campaign

    # Start the initial campaign - Originator will start making outbound calls
    originator.start()

    # Keeps a count of campaigns
    campaign_cnt = 0

    # Here is an example of how to keep an eye on the campaign.
    # After the campaign is over, check to see if another campaign should start
    while (True):
        if originator.stopped() and originator.count_calls() == 0:

            log.info(originator)  # log state info and current load

            # Check to see if we should run another camapign
            campaign_cnt += 1
            if campaign_cnt >= max_campaigns:
                break

            log.info("Starting new campaign\n")

            # We must increase the max allowed calls in order
            # for dialer to initiate another max_calls_per_campaign
            originator.max_offered += max_calls_per_campaign
            originator.start()

        time.sleep(1)

    log.info("All campaigns done: stopping...\n")
    originator.shutdown()
예제 #9
0
def run(slaves, proxy, profile, rate, limit, max_offered, duration,
        interactive, debug, app, metrics_file):
    log = switchy.utils.log_to_stderr("INFO")

    # Check if the specified (or default) app is valid
    switchy.apps.load()
    cls = switchy.apps.get(app)
    if not cls:
        raise click.ClickException('Unknown app {}. Use list-apps command '
                                   'to list available apps'.format(app))

    # TODO: get_originator() receives an apps tuple (defaults to Bert) to
    # select the application we should accept --app multi argument list to
    # set multiple apps
    o = switchy.get_originator(
        slaves,
        apps=(cls, ),
        rate=int(rate) if rate else None,
        limit=int(limit) if limit else None,
        max_offered=int(max_offered) if max_offered else None,
        duration=int(duration) if duration else None,
        auto_duration=True if not duration else False,
    )

    # Prepare the originate string for each slave
    # depending on the profile name and network settings
    # configured for that profile in that particular slave
    p = re.compile('.+?BIND-URL\s+?.+?@(.+?):(\d+).+?\s+',
                   re.IGNORECASE | re.DOTALL)
    for c in o.pool.clients:
        status = c.client.api(
            'sofia status profile {}'.format(profile)).getBody()
        m = p.match(status)
        if not m:
            raise click.ClickException('Slave {} does not have a profile '
                                       'named \'{}\' running'.format(
                                           c.host, profile))
        ip = m.group(1)
        port = m.group(2)
        # The originate cmd must route the call back to us using the specified
        # proxy (the device under test)
        log.info('Slave {} SIP address is at {}:{}'.format(c.host, ip, port))
        c.set_orig_cmd(dest_url='switchy@{}:{}'.format(ip, port),
                       profile=profile,
                       app_name='park',
                       proxy='{}'.format(proxy))

    log.info(
        'Starting load test for server {} at {}cps using {} slaves'.format(
            proxy, o.rate, len(slaves)))
    click.echo(o)
    if interactive:
        try:
            import IPython
            IPython.embed()
        except ImportError:
            try:
                # optional, will allow Up/Down/History in the console
                import readline
            except ImportError:
                pass
            import code
            vars = globals().copy()
            vars.update(locals())
            shell = code.InteractiveConsole(vars)
            shell.interact()

        o.shutdown()
        click.echo(o)
    else:
        o.start()
        while o.state != 'STOPPED':
            try:
                time.sleep(1)
                click.echo(o)
            except KeyboardInterrupt:
                o.shutdown()
                click.echo(o)

    while True:
        active_calls = o.count_calls()
        if active_calls <= 0:
            break
        click.echo('Waiting on {} active calls to finish'.format(active_calls))
        time.sleep(1)

    if metrics_file:
        click.echo('Storing test metrics at {}'.format(metrics_file))
        o.metrics.dump(metrics_file)

    click.echo('Load test finished!')