예제 #1
0
파일: profiles.py 프로젝트: yiu31802/ave
def t12():
    pretty = '%s t12' % __file__
    print(pretty)

    profiles = [[{
        'type': 'handset'
    }, {
        'type': 'relay'
    }], [{
        'type': 'hanset'
    }, {
        'type': 'workspace'
    }]]
    expected = [({
        u'type': u'handset'
    }, {
        u'type': u'relay'
    }), ({
        u'type': u'hanset'
    }, {
        u'type': u'workspace'
    })]
    try:
        vcsjob.set_profiles(profiles)
    except Exception, e:
        print('FAIL %s: could not set profiles: %s' % (pretty, e))
        return False
예제 #2
0
파일: profiles.py 프로젝트: yiu31802/ave
def t3():
    pretty = '%s t3' % __file__
    print(pretty)

    profiles = [{'type': 'something'}, {'type': 'else', 'more': 'junk'}]
    try:
        vcsjob.set_profiles(profiles)
    except Exception, e:
        print('FAIL %s: could not set profiles: %s' % (pretty, e))
        return False
예제 #3
0
파일: profiles.py 프로젝트: yiu31802/ave
def t2():
    pretty = '%s t2' % __file__
    print(pretty)

    profiles = [{'type': 'something'}]
    try:
        vcsjob.set_profiles(profiles)
    except Exception, e:
        print('FAIL %s: could not set profile: %s' % (pretty, e))
        return False
예제 #4
0
파일: profiles.py 프로젝트: yiu31802/ave
def t1():
    pretty = '%s t1' % __file__
    print(pretty)

    try:
        vcsjob.set_profiles(123)
        print('FAIL %s: could set integer as profile' % pretty)
        return False
    except Exception, e:
        if 'profiles must be a list' not in str(e):
            print('FAIL %s: wrong error 1: %s' % (pretty, e))
            return False
예제 #5
0
파일: profiles.py 프로젝트: yiu31802/ave
def t6():
    pretty = '%s t6' % __file__
    print(pretty)

    # with u prefixes for the string literals
    profiles = [{u'type': u'sömething', u'är': u'"lurt"'}, {u'type': u'också'}]
    vcsjob.set_profiles(profiles)

    try:
        hints = vcsjob.get_profiles()
    except Exception, e:
        print('FAIL %s: could not get hints: %s' % (pretty, e))
        return False
예제 #6
0
파일: profiles.py 프로젝트: yiu31802/ave
def t5():
    pretty = '%s t5' % __file__
    print(pretty)

    vcsjob.set_profiles(None)

    profiles = [{'type': 'something'}, {'type': 'else', 'more': 'junk'}]
    vcsjob.set_profiles(profiles)

    try:
        hints = vcsjob.get_profiles()
    except Exception, e:
        print('FAIL %s: could not get hint: %s' % (pretty, e))
        return False
예제 #7
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
예제 #8
0
파일: profiles.py 프로젝트: yiu31802/ave
def t4():
    pretty = '%s t4' % __file__
    print(pretty)

    vcsjob.set_profiles(None)

    if 'VCSJOB_PROFILES' in os.environ:
        print(
            'FAIL %s: set_profiles() did not clear environment variable: %s' %
            (pretty, os.environ['VCSJOB_PROFILES']))
        return False

    try:
        vcsjob.get_profiles()
        print('FAIL %s: could get profiles' % pretty)
        return False
    except Exception, e:
        if 'no profiles' not in str(e):
            print('FAIL %s: wrong error 1: %s' % (pretty, e))
            return False
예제 #9
0
파일: profiles.py 프로젝트: yiu31802/ave
# check error messages for vcsjob.set_profiles()
def t1():
    pretty = '%s t1' % __file__
    print(pretty)

    try:
        vcsjob.set_profiles(123)
        print('FAIL %s: could set integer as profile' % pretty)
        return False
    except Exception, e:
        if 'profiles must be a list' not in str(e):
            print('FAIL %s: wrong error 1: %s' % (pretty, e))
            return False

    try:
        vcsjob.set_profiles([123])
        print('FAIL %s: could set list of integer as profile' % pretty)
        return False
    except Exception, e:
        if 'profile is not a dictionary' not in str(e):
            print('FAIL %s: wrong error 2: %s' % (pretty, e))
            return False

    try:
        vcsjob.set_profiles([{
            'type': 'ok'
        }, {
            'no': 'type',
            'field': 'present'
        }])
        print('FAIL %s: could set profile without type' % pretty)