Пример #1
0
def text_result(job_id=None):
    """
    Returns a text version of the result.
    :param job_id: id of the job.
    :return: Text version of the report (unicode).
    """

    session = create_session(DB_URL)
    if not job_id:
        return

    result = u''
    job = get_job(session, job_id)
    if job.status:
        result = u"Passed.\n\n"
    else:
        result = u"Failed.\n\n"

    for res in job.results:
        result += u'command: %s\nstatus: %s\n' % (res.command, res.status)
        result += u'\n\n'

    return result
Пример #2
0
def text_result(job_id=None):
    """
    Returns a text version of the result.
    :param job_id: id of the job.
    :return: Text version of the report (unicode).
    """

    session = create_session(DB_URL)
    if not job_id:
        return

    result = u''
    job = get_job(session, job_id)
    if job.status:
        result = u"Passed.\n\n"
    else:
        result= u"Failed.\n\n"

    for res in job.results:
        result += u'command: %s\nstatus: %s\n' % (res.command, res.status)
        result += u'\n\n'

    return result
Пример #3
0
def run_job(args,
            jobpath,
            job_name='',
            config=None,
            container=None,
            port=None):
    """
    Runs the given command using fabric.

    :param args: Command line arguments.
    :param jobpath: Path to the job file.
    :param job_name: string job name.
    :param config: Configuration of the given job
    :param container: Docker object for a Docker job.
    :param port: The port number to connect in case of a vm.
    :return: None
    """
    if not os.path.exists(jobpath):
        print "Missing job file."
        return

    # Now read the commands inside the job file
    # and execute them one by one, we need to save
    # the result too.
    commands = []
    status = True
    session = None
    if not args.stateless:
        session = create_session(DB_URL)

    with open(jobpath) as fobj:
        commands = fobj.readlines()

    try:
        job = None
        if not args.stateless:
            job = add_job(session,
                          name=job_name,
                          image=config['image'],
                          ram=config.get('ram', 0),
                          user=config.get('user', 'root'),
                          password=config.get('password', 'none'))
            print "Starting Job: %s" % job.id
        else:
            print "Starting a stateless job."

        config['host_string'] = '127.0.0.1'
        if config['type'] == 'vm':
            config['port'] = port
        elif config['type'] == 'bare':
            config['host_string'] = config['image']
        elif config['type'] == 'docker':
            # Now we will convert this job as a bare metal :)
            config['type'] = 'bare'
            config['port'] = int(container.port)
        for command in commands:
            negative = False
            result = ''
            command = command.strip('\n')
            if command.startswith('SLEEP'):  # We will have to sleep
                word = command.split(' ')[1]
                print "Sleeping for %s." % word
                time.sleep(int(word))
                continue
            print "Executing command: %s" % command

            result, negative = execute(config, command)
            status = update_result(result, session, job, command, negative,
                                   args.stateless)
            if not status:
                break

        # If we are here, that means all commands ran successfully.
        if status:
            if not args.stateless:
                update_job(session, job)
    finally:
        # Now for stateless jobs
        if args.stateless:
            print "\n\nJob status: %s\n\n" % status

            for key, value in STR.iteritems():
                print "command: %s" % value['command']
                print "status: %s\n" % value['status']
                print value['result']
                print "\n"
Пример #4
0
def run_job(args, jobpath, job_name='', config=None, container=None):
    """
    Runs the given command using fabric.

    :param args: Command line arguments.
    :param jobpath: Path to the job file.
    :param job_name: string job name.
    :param config: Configuration of the given job
    :param container: Docker object for a Docker job.
    :return: None
    """
    if not os.path.exists(jobpath):
        print "Missing job file."
        return

    # Now read the commands inside the job file
    # and execute them one by one, we need to save
    # the result too.
    commands = []
    status = True
    session = None
    if not args.stateless:
        session = create_session(DB_URL)

    with open(jobpath) as fobj:
        commands = fobj.readlines()


    try:
        job = None
        if not args.stateless:
            job = add_job(session, name=job_name, image=config['image'],
                          ram=config.get('ram', 0), user=config.get('user', 'root'), password=config.get('password', 'none'))
            print "Starting Job: %s" % job.id
        else:
            print "Starting a stateless job."

        for command in commands:
            negative = False
            result = ''
            command = command.strip('\n')
            if command.startswith('SLEEP'): # We will have to sleep
                word = command.split(' ')[1]
                print "Sleeping for %s." % word
                time.sleep(int(word))
                continue
            if config['type'] == 'docker':
                # We want to run a container and use that.
                result, negative = execute('docker', command, container)
                status = update_result(result, session, job, command, negative, args.stateless)
                if not status:
                    break
            else:
                host_string = 'localhost:2222'
                user = '******'
                password = '******'
                if config['type'] == 'bare':
                    host_string = config['image']
                    user = config['user']
                    password = config['password']

                with settings(host_string=host_string, user=user, password=password,
                                  warn_only=True):
                    result, negative = execute(config['type'], command)
                    status = update_result(result, session, job, command, negative, args.stateless)
                    if not status:
                        break

        # If we are here, that means all commands ran successfully.
        if status:
            if not args.stateless:
                update_job(session, job)
    finally:
        disconnect_all()
        os.system('stty sane')

        # Now for stateless jobs
        if args.stateless:
            print "\n\nJob status: %s\n\n" % status

            for key, value in STR.iteritems():
                print "command: %s" % value['command']
                print "status: %s\n" % value['status']
                print value['result']
                print "\n"