Esempio n. 1
0
File: guid.py Progetto: yiu31802/ave
def t2():
    pretty = '%s t2' % __file__
    print(pretty)

    # unicode version
    vcsjob.set_guid(u'super_valid_"åäö_@%&#"')
    try:
        val = vcsjob.get_guid()
    except Exception, e:
        print('FAIL %s: could not get unicode guid: %s' % (pretty, e))
        return False
Esempio n. 2
0
File: guid.py Progetto: yiu31802/ave
def t1():
    pretty = '%s t1' % __file__
    print(pretty)

    try:
        vcsjob.set_guid(123)
        print('FAIL %s: could set integer as guid' % pretty)
        return False
    except Exception, e:
        if 'guid is not a string' not in str(e):
            print('FAIL %s: wrong error 1: %s' % (pretty, e))
            return False
Esempio n. 3
0
def _execute(jobs_dir, path, env, profiles, log_file, guid, timeout=0):
    exe_path = os.path.realpath(os.path.join(jobs_dir, path))
    log_path = None
    if hasattr(log_file, 'name'): # logging to file, not stdout or stderr
        if log_file.name not in ['<stdout>', '<stderr>']:
            log_path = log_file.name
    info = {
        'exe'        : exe_path,
        'environment': dict(env),
        'profiles'   : profiles,
        'guid'       : guid
    }
    log_file.write('vcsjob: %s\n' % json.dumps(info, sort_keys=True))
    log_file.flush()

    vcsjob.set_profiles(profiles) # sets $VCSJOB_PROFILES
    vcsjob.set_log_path(log_path) # sets $VCSJOB_LOG_PATH
    vcsjob.set_guid(guid)         # sets $VCSJOB_GUID

    if timeout > 0:
        limit = time.time() + timeout
    else:
        limit = None

    pid, fd = ave.cmd.run_bg([exe_path], False)

    #if limit:
    while True:
        if limit:
            if time.time() > limit:
                os.kill(pid, signal.SIGKILL)
                os.waitpid(pid, 0)
                os.close(fd)
                return vcsjob.TIMEOUT

            try:
                timeout = max(0, limit - time.time())
                r, w, x = select.select([fd], [], [], timeout)
                if r:
                    tmp = os.read(fd, 4096)
                else:
                    continue
            except OSError, e:# child closed its pseudoterminal
                tmp = None
        else:
            try:
                tmp = os.read(fd, 4096)
            except OSError, e:
                tmp = None
Esempio n. 4
0
File: guid.py Progetto: yiu31802/ave
def t5(w):
    pretty = '%s t5' % __file__
    print(pretty)

    # cook a job, preserving sys.path for UNIT/ACCEPTANCE differences
    job = {'path': 'job', 'tags': ['TAG']}
    exe = '#! /usr/bin/python2\n'
    make_job(w, [job], exe)

    vcsjob.set_guid('previous_value')
    log_path = w.make_tempfile()  # store output from the job somewhere
    vcsjob.execute_job(w.path, job, log_path=log_path, guid='abc_123')

    try:
        value = vcsjob.get_guid()
    except Exception, e:
        print('FAIL %s: %s' % (pretty, e))
        return False
Esempio n. 5
0
File: guid.py Progetto: yiu31802/ave
def t4(w):
    pretty = '%s t4' % __file__
    print(pretty)

    # cook a job, preserving sys.path for UNIT/ACCEPTANCE differences
    job = {'path': 'job', 'tags': ['TAG']}
    exe = '#! /usr/bin/python2\n'
    make_job(w, [job], exe)

    vcsjob.set_guid(None)  # reset $VCSJOB_GUID
    log_path = w.make_tempfile()  # store output from the job somewhere
    vcsjob.execute_job(w.path, job, log_path=log_path, guid='abc_123')

    try:
        value = vcsjob.get_guid()
        print('FAIL %s: VCSJOB_GUID remains set: %s' % (pretty, value))
        return False
    except:
        pass

    return True
Esempio n. 6
0
    # make some Control based server for the client to call. then ask it to
    # raise an exception over RPC. no GUID has been set on the client side, so
    # no exception log should be posted to panotti by the client.
    c = factory.make_control(factory.HOME.path)
    try:
        c.raise_ave_exception({'message': 'foo', 'extras': 'bar'})
    except AveException, e:
        pass  # expected
    except Exception, e:
        print('FAIL %s: could not raise RPC exception: %s' % (pretty, e))
        return False

    # set the client side GUID and make another failed call. this exception
    # should be logged to panotti.
    vcsjob.set_guid('example_guid')
    c = RemoteControl(c.address, None, 1, home=factory.HOME.path)

    exc = None
    try:
        c.raise_ave_exception({'message': 'cow', 'extras': 'cat'})
    except AveException, e:
        exc = e  # expected
    except Exception, e:
        print('FAIL %s: could not raise RPC exception: %s' % (pretty, e))
        return False

    time.sleep(1)  # give asynchronous events some time to settle

    # expect to find the same exception in the panotti server log, with the
    # guid and time stamp patched in
Esempio n. 7
0
File: guid.py Progetto: yiu31802/ave
# check basic set functionality
def t1():
    pretty = '%s t1' % __file__
    print(pretty)

    try:
        vcsjob.set_guid(123)
        print('FAIL %s: could set integer as guid' % pretty)
        return False
    except Exception, e:
        if 'guid is not a string' not in str(e):
            print('FAIL %s: wrong error 1: %s' % (pretty, e))
            return False

    try:  # unicode version
        vcsjob.set_guid(u'super_valid_"åäö_@%&#"')
    except Exception, e:
        print('FAIL %s: could not set valid unicode guid: %s' % (pretty, e))
        return False
    if 'VCSJOB_GUID' not in os.environ:
        print('FAIL %s: could not set environment with unicode string' %
              pretty)
        return False
    del os.environ['VCSJOB_GUID']

    try:  # ascii version
        vcsjob.set_guid('super_valid_"åäö_@%&#"')
    except Exception, e:
        print('FAIL %s: could not set valid ascii guid: %s' % (pretty, e))
        return False
    if 'VCSJOB_GUID' not in os.environ: