def run_loadtest(repo,
                 cycles=None,
                 nodes_count=None,
                 duration=None,
                 email=None,
                 options=None,
                 distributed=True,
                 fl_result_path=None,
                 queue=None,
                 fixture_plugin=None,
                 fixture_options=None,
                 workdir=DEFAULT_WORKDIR,
                 reportsdir=DEFAULT_REPORTSDIR,
                 test=None,
                 script=None):
    if options is None:
        options = {}

    rtfeedback = options.get('feedback', None) is not None

    # loading the fixtures plugins
    for fixture in options.get('fixtures', []):
        import_string(fixture)

    job_id = os.environ.get('MARTEAU_JOBID', '')

    if options is None:
        options = {}

    if os.path.exists(repo):
        # just a local dir, lets work there
        os.chdir(repo)
        _logrun('Moved to %r' % repo)
        target = os.path.realpath(repo)
    else:
        # checking out the repo
        os.chdir(workdir)
        name = repo.split('/')[-1].split('.')[0]
        target = os.path.join(workdir, name)
        if os.path.exists(target):
            os.chdir(target)
            _logrun('Moved to %r' % target)
            run_func(queue, job_id, 'git pull')
        else:
            _logrun('Moved to %r' % workdir)
            run_func(queue,
                     job_id,
                     'git clone %s' % repo,
                     stop_on_failure=False)
            os.chdir(target)

    # now looking for the marteau config file in there
    config = read_yaml_config(os.getcwd())

    wdir = config.get('wdir')
    if wdir is not None:
        target = os.path.join(target, wdir)
        os.chdir(target)

    deps = config.get('deps', [])
    if rtfeedback and 'pyzmq' not in deps:
        deps.append('pyzmq')

    if distributed:
        # is this a distributed test ?
        if nodes_count in (None, ''):  # XXX fix later
            nodes_count = config.get('nodes', 1)
        else:
            nodes_count = int(nodes_count)

        nodes = get_nodes(nodes_count, queue, options)
        nodes_names = ','.join([node.name for node in nodes])
        os.environ['MARTEAU_NODES'] = nodes_names
        workers = '--distribute-workers=%s' % nodes_names
        cmd = '%s --distribute %s' % (run_bench, workers)
        if deps != []:
            cmd += ' --distributed-packages="%s"' % ' '.join(deps)
        target = tempfile.mkdtemp()
        cmd += ' --distributed-log-path=%s' % target
        if 'ssh_key' in options:
            cmd += ' --distributed-key-filename=%s' % options['ssh_key']

        # asking the node to send us realtime feedback.
        if rtfeedback:
            cmd += ' --feedback'
            cmd += ' --feedback-endpoint %s' % options['feedback_endpoint']
            cmd += ' --feedback-pubsub-endpoint %s' % \
                        options['feedback_publisher']

    else:
        cmd = run_bench

    try:
        # creating a virtualenv there
        run_func(queue, job_id, 'virtualenv --no-site-packages .')
        run_func(queue, job_id, run_pip + ' install funkload')

        # install dependencies if any
        for dep in deps:
            run_func(queue, job_id, run_pip + ' install %s' % dep)

        if fl_result_path is not None:
            # in funkload this is a relative path
            target = os.path.join(target, fl_result_path)
        xml_files = os.path.join(target, '*.xml')

        if cycles is None:
            cycles = config.get('cycles')

        if cycles is not None:
            cmd += ' --cycles=%s' % cycles

        if duration is None:
            duration = config.get('duration')

        if test is None:
            test = config.get('test')

        if script is None:
            script = config.get('script')

        if duration is not None:
            cmd += ' --duration=%s' % duration

        report_dir = os.path.join(reportsdir,
                                  os.environ.get('MARTEAU_JOBID', 'report'))

        if fixture_plugin:
            _logrun('Running the %r fixture' % fixture_plugin)
            fixture_klass = get_fixture(fixture_plugin)
            if fixture_options is None:
                fixture_options = {}
            try:
                fixture = fixture_klass(**fixture_options)
            except:
                _logrun('Could not instanciate a fixture plugin instance')
                raise

            try:
                fixture.setup()
            except:
                _logrun('The fixture set up failed')
                raise

        # starting the feedback subscriberin its own thread
        if rtfeedback:
            from funkload.rtfeedback import FeedbackSubscriber
            sub = FeedbackSubscriber(
                pubsub_endpoint=options['feedback_publisher'],
                handler=_rt_handler,
                pid=os.getpid(),
                queue=queue)
            sub.start()

        try:
            _logrun('Running the loadtest')
            run_func(queue, job_id, '%s %s %s' % (cmd, script, test))
        finally:
            _logrun('Running the fixture tear_down method')
            if fixture_plugin:
                try:
                    fixture.tear_down()
                except:
                    _logrun('The fixture tear down failed')
                    raise

            if rtfeedback:
                sub.terminate()

        _logrun('Building the report')
        report = run_report + ' --skip-definitions --css %s --html -r %s  %s'
        run_func(queue, job_id, report % (CSS_FILE, report_dir, xml_files))

        # do we send an email with the result ?
        if email is None:
            email = config.get('email')

        if email is not None:
            _logrun('Sending an e-mail to %r' % email)
            try:
                res, msg = send_report(email, job_id, **options)
            except Exception, e:
                res = False
                msg = str(e)

            if not res:
                _logrun(msg)
            else:
                _logrun('Mail sent.')

        return report_dir
コード例 #2
0
ファイル: job.py プロジェクト: whitmo/marteau
def run_loadtest(
    repo, cycles=None, nodes_count=None, duration=None, email=None, options=None, distributed=True, queue=None
):

    job_id = os.environ.get("MARTEAU_JOBID", "")

    if options is None:
        options = {}

    if os.path.exists(repo):
        # just a local dir, lets work there
        os.chdir(repo)
        target = os.path.realpath(repo)
    else:
        # checking out the repo
        os.chdir(workdir)
        name = repo.split("/")[-1].split(".")[0]
        target = os.path.join(workdir, name)
        if os.path.exists(target):
            os.chdir(target)
            run_func(queue, job_id, "git pull")
        else:
            run_func(queue, job_id, "git clone %s" % repo, stop_on_failure=False)
            os.chdir(target)

    # now looking for the marteau config file in there
    config = read_yaml_config(os.getcwd())

    wdir = config.get("wdir")
    if wdir is not None:
        target = os.path.join(target, wdir)
        os.chdir(target)

    # creating a virtualenv there
    run_func(queue, job_id, "virtualenv --no-site-packages .")
    run_func(queue, job_id, run_pip + " install funkload")

    # install dependencies if any
    deps = config.get("deps", [])
    for dep in deps:
        run_func(queue, job_id, run_pip + " install %s" % dep)

    if distributed:
        # is this a distributed test ?
        if nodes_count is None:
            nodes_count = config.get("nodes", 1)

        # we want to pick up the number of nodes asked
        nodes = [node for node in queue.get_nodes() if node.status == "idle" and node.enabled]

        if len(nodes) < nodes_count:
            # XXX we want to pile this one back !
            raise ValueError("Sorry could not find enough free nodes")

        # then pick random ones
        random.shuffle(nodes)
        nodes = nodes[:nodes_count]

        # save the nodes status
        for node in nodes:
            node.status = "working"
            queue.save_node(node)

        workers = ",".join([node.name for node in nodes])
        os.environ["MARTEAU_NODES"] = workers

        workers = "--distribute-workers=%s" % workers
        cmd = "%s --distribute %s" % (run_bench, workers)
        if deps != []:
            cmd += " --distributed-packages=%s" % " ".join(deps)
        target = tempfile.mkdtemp()
        cmd += " --distributed-log-path=%s" % target
    else:
        cmd = run_bench

    xml_files = os.path.join(target, "*.xml")

    if cycles is None:
        cycles = config.get("cycles")

    if cycles is not None:
        cmd += " --cycles=%s" % cycles

    if duration is None:
        duration = config.get("duration")

    if duration is not None:
        cmd += " --duration=%s" % duration

    report_dir = os.path.join(reportsdir, os.environ.get("MARTEAU_JOBID", "report"))

    _logrun("Running the loadtest")
    run_func(queue, job_id, "%s %s %s" % (cmd, config["script"], config["test"]))

    _logrun("Building the report")

    report = run_report + " --skip-definitions --css %s --html -r %s  %s"
    run_func(queue, job_id, report % (CSS_FILE, report_dir, xml_files))

    # do we send an email with the result ?
    if email is None:
        email = config.get("email")

    if email is not None:
        _logrun("Sending an e-mail to %r" % email)
        try:
            res, msg = send_report(email, job_id, **options)
        except Exception, e:
            res = False
            msg = str(e)

        if not res:
            _logrun(msg)
        else:
            _logrun("Mail sent.")
コード例 #3
0
ファイル: job.py プロジェクト: anentropic/marteau
def run_loadtest(repo, cycles=None, nodes_count=None, duration=None,
                 email=None, options=None, distributed=True,
                 queue=None, fixture_plugin=None, fixture_options=None,
                 workdir=DEFAULT_WORKDIR, reportsdir=DEFAULT_REPORTSDIR,
                 test=None, script=None):

    if options is None:
        options = {}

    # loading the fixtures plugins
    for fixture in options.get('fixtures', []):
        import_string(fixture)

    job_id = os.environ.get('MARTEAU_JOBID', '')

    if options is None:
        options = {}

    if os.path.exists(repo):
        # just a local dir, lets work there
        os.chdir(repo)
        _logrun('Moved to %r' % repo)
        target = os.path.realpath(repo)
    else:
        # checking out the repo
        os.chdir(workdir)
        name = repo.split('/')[-1].split('.')[0]
        target = os.path.join(workdir, name)
        if os.path.exists(target):
            os.chdir(target)
            _logrun('Moved to %r' % target)
            run_func(queue, job_id, 'git pull')
        else:
            _logrun('Moved to %r' % workdir)
            run_func(queue, job_id,
                     'git clone %s' % repo, stop_on_failure=False)
            os.chdir(target)

    # now looking for the marteau config file in there
    config = read_yaml_config(os.getcwd())

    wdir = config.get('wdir')
    if wdir is not None:
        target = os.path.join(target, wdir)
        os.chdir(target)

    deps = config.get('deps', [])
    if distributed:
        # is this a distributed test ?
        if nodes_count in (None, ''):    # XXX fix later
            nodes_count = config.get('nodes', 1)
        else:
            nodes_count = int(nodes_count)

        # we want to pick up the number of nodes asked
        nodes = queue.get_nodes(check_available=True)

        if len(nodes) < nodes_count:
            # we want to pile this one back and sleep a bit here
            _logrun('Sleeping for 30 s.')
            time.sleep(30)
            raise ValueError("Sorry could not find enough free nodes")

        # then pick random ones
        random.shuffle(nodes)
        nodes = nodes[:nodes_count]

        # save the nodes status
        for node in nodes:
            node.status = 'working'
            queue.save_node(node)

        workers = ','.join([node.name for node in nodes])
        os.environ['MARTEAU_NODES'] = workers

        workers = '--distribute-workers=%s' % workers
        cmd = '%s --distribute %s' % (run_bench, workers)
        if deps != []:
            cmd += ' --distributed-packages="%s"' % ' '.join(deps)
        target = tempfile.mkdtemp()
        cmd += ' --distributed-log-path=%s' % target
    else:
        cmd = run_bench

    # creating a virtualenv there
    run_func(queue, job_id, 'virtualenv --no-site-packages .')
    run_func(queue, job_id, run_pip + ' install funkload')

    # install dependencies if any
    for dep in deps:
        run_func(queue, job_id, run_pip + ' install %s' % dep)

    xml_files = os.path.join(target, '*.xml')

    if cycles is None:
        cycles = config.get('cycles')

    if cycles is not None:
        cmd += ' --cycles=%s' % cycles

    if duration is None:
        duration = config.get('duration')

    if test is None:
        test = config.get('test')

    if script is None:
        script = config.get('script')

    if duration is not None:
        cmd += ' --duration=%s' % duration

    report_dir = os.path.join(reportsdir,
                              os.environ.get('MARTEAU_JOBID', 'report'))

    if fixture_plugin:
        _logrun('Running the %r fixture' % fixture_plugin)
        fixture_klass = get_fixture(fixture_plugin)
        if fixture_options is None:
            fixture_options = {}
        try:
            fixture = fixture_klass(**fixture_options)
        except:
            _logrun('Could not instanciate a fixture plugin instance')
            raise

        try:
            fixture.setup()
        except:
            _logrun('The fixture set up failed')
            raise

    try:
        _logrun('Running the loadtest')
        run_func(queue, job_id, '%s %s %s' % (cmd, script, test))
    finally:
        _logrun('Running the fixture tear_down method')
        if fixture_plugin:
            try:
                fixture.tear_down()
            except:
                _logrun('The fixture tear down failed')
                raise

    _logrun('Building the report')

    report = run_report + ' --skip-definitions --css %s --html -r %s  %s'
    run_func(queue, job_id, report % (CSS_FILE, report_dir, xml_files))

    # do we send an email with the result ?
    if email is None:
        email = config.get('email')

    if email is not None:
        _logrun('Sending an e-mail to %r' % email)
        try:
            res, msg = send_report(email, job_id, **options)
        except Exception, e:
            res = False
            msg = str(e)

        if not res:
            _logrun(msg)
        else:
            _logrun('Mail sent.')
コード例 #4
0
ファイル: job.py プロジェクト: mozilla-services/marteau
def run_loadtest(repo, cycles=None, nodes_count=None, duration=None,
                 email=None, options=None, distributed=True,
                 fl_result_path=None, queue=None, fixture_plugin=None,
                 fixture_options=None, workdir=DEFAULT_WORKDIR,
                 reportsdir=DEFAULT_REPORTSDIR, test=None, script=None):
    if options is None:
        options = {}

    rtfeedback = options.get('feedback', None) is not None

    # loading the fixtures plugins
    for fixture in options.get('fixtures', []):
        import_string(fixture)

    job_id = os.environ.get('MARTEAU_JOBID', '')

    if options is None:
        options = {}

    if os.path.exists(repo):
        # just a local dir, lets work there
        os.chdir(repo)
        _logrun('Moved to %r' % repo)
        target = os.path.realpath(repo)
    else:
        # checking out the repo
        os.chdir(workdir)
        name = repo.split('/')[-1].split('.')[0]
        target = os.path.join(workdir, name)
        if os.path.exists(target):
            os.chdir(target)
            _logrun('Moved to %r' % target)
            run_func(queue, job_id, 'git pull')
        else:
            _logrun('Moved to %r' % workdir)
            run_func(queue, job_id,
                     'git clone %s' % repo, stop_on_failure=False)
            os.chdir(target)

    # now looking for the marteau config file in there
    config = read_yaml_config(os.getcwd())

    wdir = config.get('wdir')
    if wdir is not None:
        target = os.path.join(target, wdir)
        os.chdir(target)

    deps = config.get('deps', [])
    if rtfeedback and 'pyzmq' not in deps:
        deps.append('pyzmq')

    if distributed:
        # is this a distributed test ?
        if nodes_count in (None, ''):    # XXX fix later
            nodes_count = config.get('nodes', 1)
        else:
            nodes_count = int(nodes_count)

        nodes = get_nodes(nodes_count, queue, options)
        nodes_names = ','.join([node.name for node in nodes])
        os.environ['MARTEAU_NODES'] = nodes_names
        workers = '--distribute-workers=%s' % nodes_names
        cmd = '%s --distribute %s' % (run_bench, workers)
        if deps != []:
            cmd += ' --distributed-packages="%s"' % ' '.join(deps)
        target = tempfile.mkdtemp()
        cmd += ' --distributed-log-path=%s' % target
        if 'ssh_key' in options:
            cmd += ' --distributed-key-filename=%s' % options['ssh_key']

        # asking the node to send us realtime feedback.
        if rtfeedback:
            cmd += ' --feedback'
            cmd += ' --feedback-endpoint %s' % options['feedback_endpoint']
            cmd += ' --feedback-pubsub-endpoint %s' % \
                        options['feedback_publisher']

    else:
        cmd = run_bench

    try:
        # creating a virtualenv there
        run_func(queue, job_id, 'virtualenv --no-site-packages .')
        run_func(queue, job_id, run_pip + ' install funkload')

        # install dependencies if any
        for dep in deps:
            run_func(queue, job_id, run_pip + ' install %s' % dep)

        if fl_result_path is not None:
            # in funkload this is a relative path
            target = os.path.join(target, fl_result_path)
        xml_files = os.path.join(target, '*.xml')

        if cycles is None:
            cycles = config.get('cycles')

        if cycles is not None:
            cmd += ' --cycles=%s' % cycles

        if duration is None:
            duration = config.get('duration')

        if test is None:
            test = config.get('test')

        if script is None:
            script = config.get('script')

        if duration is not None:
            cmd += ' --duration=%s' % duration

        report_dir = os.path.join(reportsdir,
                                os.environ.get('MARTEAU_JOBID', 'report'))

        if fixture_plugin:
            _logrun('Running the %r fixture' % fixture_plugin)
            fixture_klass = get_fixture(fixture_plugin)
            if fixture_options is None:
                fixture_options = {}
            try:
                fixture = fixture_klass(**fixture_options)
            except:
                _logrun('Could not instanciate a fixture plugin instance')
                raise

            try:
                fixture.setup()
            except:
                _logrun('The fixture set up failed')
                raise

        # starting the feedback subscriberin its own thread
        if rtfeedback:
            from funkload.rtfeedback import FeedbackSubscriber
            sub = FeedbackSubscriber(pubsub_endpoint=options['feedback_publisher'],
                                     handler=_rt_handler,
                                     pid=os.getpid(), queue=queue)
            sub.start()

        try:
            _logrun('Running the loadtest')
            run_func(queue, job_id, '%s %s %s' % (cmd, script, test))
        finally:
            _logrun('Running the fixture tear_down method')
            if fixture_plugin:
                try:
                    fixture.tear_down()
                except:
                    _logrun('The fixture tear down failed')
                    raise

            if rtfeedback:
                sub.terminate()

        _logrun('Building the report')
        report = run_report + ' --skip-definitions --css %s --html -r %s  %s'
        run_func(queue, job_id, report % (CSS_FILE, report_dir, xml_files))

        # do we send an email with the result ?
        if email is None:
            email = config.get('email')

        if email is not None:
            _logrun('Sending an e-mail to %r' % email)
            try:
                res, msg = send_report(email, job_id, **options)
            except Exception, e:
                res = False
                msg = str(e)

            if not res:
                _logrun(msg)
            else:
                _logrun('Mail sent.')

        return report_dir