예제 #1
0
파일: cli.py 프로젝트: yiu31802/ave
def t17(executable, sources):
    pretty = '%s t17' % __file__
    print(pretty)

    if sources:
        sources = ' -s ' + ','.join(sources)
    else:
        sources = ''

    w = Workspace(uid='vcsjob-cli-t17')

    # pull the tree into a temporary directory
    valid  = 'git://review.sonyericsson.net/semctools/ave/vcsjob'
    target = w.make_tempdir()
    for i in range(5):
        cmd = '%s %s fetch -s %s -d %s -r master' % (
            executable, sources, valid, target
        )
        (s, o, e) = ave.cmd.run(cmd)
        if s != 0:
            print(o)
            print(e)
            print('FAIL %s: wrong return code: %s' % (pretty, s))
            return

    w.delete()
예제 #2
0
파일: cli.py 프로젝트: yiu31802/ave
def t18(executable, sources):
    pretty = '%s t18' % __file__
    print(pretty)

    if sources:
        sources = ' -s ' + ','.join(sources)
    else:
        sources = ''

    w = Workspace(uid='vcsjob-cli-t4')

    sys.path.insert(0, os.getcwd())

    # pull the tree into a temporary directory, check that all remotes are
    # also locals afterwards
    valid  = 'git://review.sonyericsson.net/semctools/ave/vcsjob'
    target = w.make_tempdir()
    cmd = '%s %s fetch -s %s -d %s -r master' % (
        executable, sources, valid, target
    )
    (s, o, e) = ave.cmd.run(cmd)
    if s != 0:
        print('FAIL %s: could not fetch master:\n%s\n%s' % (pretty, o, e))
        return
    (local, remote) = ave.git.list_branches(target)
    if local != remote:
        print(
            'FAIL %s: list of remote and local branches not equal: %s != %s'
            % (pretty, local, remote)
        )

    w.delete()
예제 #3
0
파일: cli.py 프로젝트: yiu31802/ave
def t7(executable, sources):
    pretty = '%s t7' % __file__
    print(pretty)

    if sources:
        sources = ' -s ' + ','.join(sources)
    else:
        sources = ''

    w = Workspace(uid='vcsjob-cli-t7')

    # create a broken .vcsjob file
    target = w.make_tempdir()
    f = open(os.path.join(target, '.vcsjob'), 'w')
    f.write('{ "executables": [ { "path": "does_not_exist" } ] }')
    f.close()

    # put in a tags filter that doesn't include any tests
    cmd = '%s %s execute --jobs=%s --tags=NONSENSE' % (
        executable, sources, target
    )
    (s, o, e) = ave.cmd.run(cmd)
    if s == 0:
        print('FAIL %s: wrong return code: %s' % (pretty, s))
        return
    if not o.splitlines()[0].startswith('ERROR: no such file: '):
        print('FAIL %s: help not shown:\n%s' % (pretty, o))
        return
    if e:
        print('FAIL %s: stderr set:\n%s' % (pretty, e))
        return

    w.delete()
예제 #4
0
파일: cli.py 프로젝트: yiu31802/ave
def t15(executable, sources):
    pretty = '%s t15' % __file__
    print(pretty)

    if sources:
        sources = ' -s ' + ','.join(sources)
    else:
        sources = ''

    w = Workspace(uid='vcsjob-cli-t15')

    dst = w.make_tempdir()
    (s, o, e) = ave.cmd.run(
        '%s %s fetch --source=git://no.such.host/tree -d %s -r y'
        % (executable, sources, dst)
    )
    if s == 0:
        print('FAIL %s: wrong return code: %s' % (pretty, s))
        return
    if 'failed to clone from git://no.such.host/tree' not in o:
        print('FAIL %s: error not shown:\n%s' % (pretty, o))
        return
    if e:
        print('FAIL %s: stderr set:\n%s' % (pretty, e))
        return
    if os.path.exists(dst):
        print(
            'FAIL %s: failing a clone to an empty dir should cause the dir to '
            'be deleted.'
        )
        return

    w.delete()
예제 #5
0
def t18():
    pretty = '%s t18' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t18')

    src = 'git://review.sonyericsson.net/semctools/ave/vcsjob.git'
    dst = w.make_tempdir()

    # fetch the source into the destination
    try:
        vcsjob.fetch(src, dst, 'master', depth='2')
        cmd = [
            'git',
            '--git-dir=%s/.git' % dst, '--work-tree=' + dst, 'rev-list',
            'HEAD', '--count'
        ]
        (s, o, e) = ave.cmd.run(cmd, timeout=100, debug=False)
        if int(o) != 2:
            print(
                'FAIL %s: git clone parameter --depth is ignored in clones.' %
                pretty)
    except Exception, e:
        print('FAIL %s: fetch failed: %s' % (pretty, str(e)))
        return False
예제 #6
0
def t16(home):
    pretty = '%s t16' % __file__
    print(pretty)

    config_key = "auth"
    config_file = "jenkins.json"

    create_default(home.path)
    authkeys = load_jenkins(home.path)
    authkeys[config_key] = {JENKINS_WITH_AUTH: {'method': 'basic',
                                                'user': '******',
                                                'password': '******'}}

    path = os.path.join(home.path, '.ave', 'config', config_file)
    with open(path, 'w') as f:
        json.dump(authkeys, f, indent=4)

    w = Workspace(home=home.path)
    try:
        w.download_jenkins(JOB_ID, base=JENKINS_WITH_AUTH)
    except Exception, e:
        if "Invalid authentication to" not in str(e):
            print('FAIL %s: unexpected exception: %s' % (pretty, str(e)))
            return False
        return True
예제 #7
0
def t7():
    pretty = '%s t7' % __file__
    print(pretty)

    def make_vcsjob_tree(workspace):
        path = workspace.make_tempdir()
        f = open(os.path.join(path, '.vcsjob'), 'w')
        f.write('{ "executables": [ { "path": "job.sh", "tags":["THIS"] } ] }')
        f.close()
        f = open(os.path.join(path, 'job.sh'), 'w')
        f.write('#! /bin/bash\nprintenv\n')
        f.close()
        os.chmod(os.path.join(path, 'job.sh'), 0755)
        return path

    w = Workspace(uid='vcsjob-execute-t7')
    jobs = make_vcsjob_tree(w)
    result = vcsjob.list_jobs(jobs_dir=jobs, job_tags=['THAT'])

    if result != []:
        print(
            'FAIL %s: vcsjob.list_jobs() returned a nonempty list even though '
            'there were no jobs to list' % pretty)
        return

    w.delete()
예제 #8
0
def generate_report(pretty, json_file):
    '''
    Generates a report from a static JSON result file
    '''
    # setup workspace
    ws = Workspace('test-files-marionette')
    ws_json_file = os.path.join(ws.make_tempdir(), json_file)
    # copy static json result file to workspace
    shutil.copyfile(os.path.join(TEST_DATA_PATH, json_file), ws_json_file)
    # create a random test name for decibel
    buff = []
    for i in range(10):
        buff.append(random.randint(0, 9))
    name = ''.join(['%d' % i for i in buff])
    # create time stamp for report
    time = datetime.now()
    start_time = time.strftime("%Y-%m-%d %H:%M:%S")
    end_time = (time + timedelta(seconds=1)).strftime("%Y-%m-%d %H:%M:%S")
    # try to generate report.

    # delete workspace.
    ws.delete()
    # check if decibel reported 200 (ok) in response.

    return name, start_time, end_time
예제 #9
0
class factory(object):
    HOME = None
    processes = None

    def __init__(self):
        pass

    def __call__(self, fn):
        def decorated(*args, **kwargs):
            pretty = '%s %s' % (fn.func_code.co_filename, fn.func_name)
            print(pretty)
            self.HOME = Workspace()
            self.processes = []
            os.makedirs(os.path.join(self.HOME.path, '.ave', 'config'))
            result = fn(pretty, self, *args, **kwargs)
            for p in self.processes:
                try:
                    p.terminate()
                    p.join()
                except Exception, e:
                    print e
            self.HOME.delete()
            return result

        return decorated
예제 #10
0
파일: config.py 프로젝트: yiu31802/ave
def t18(HOME):
    pretty = '%s t18' % __file__
    print(pretty)

    cfg_path = os.path.join(HOME.path, '.ave', 'config', 'workspace.json')
    with open(cfg_path, 'w') as f:
        config = {
            'root': '~/workspaces',
            'tools': {
                'ls': '/bin/ls'
            },
            'flocker': FLOCKER,
            'wlan': {
                'ssid': 'ave-test',
                'auth': 'ave-pw'
            }
        }
        json.dump(config, f)

    w = Workspace(home=HOME.path)
    if w.get_wifi_ssid() != 'ave-test':
        print('FAIL %s: wifi ssid match failed' % pretty)
        return False
    if w.get_wifi_pw() != 'ave-pw':
        print('FAIL %s: wifi password match failed' % pretty)
        return False
    return True
예제 #11
0
 def get_workspace(self):
     if not self.HOME:
         self.HOME = Workspace()
     self.make_system()
     w = Workspace(home=self.HOME.path)
     self.make_files(w.path)
     return w
예제 #12
0
파일: decorators.py 프로젝트: yiu31802/ave
 def decorated_fn():
     w = Workspace()
     try:
         result = fn(w)
         return result
     except Exception:
         raise
     finally:
         w.delete()
예제 #13
0
파일: spool.py 프로젝트: yiu31802/ave
def t3():
    pretty = '%s t3' % __file__
    print(pretty)

    w = Workspace('spool-t3')

    try:
        s = Spool(w.make_tempdir())
    except Exception, e:
        print('FAIL %s: could not create spool: %s' % (pretty, str(e)))
        return
예제 #14
0
파일: config.py 프로젝트: yiu31802/ave
 def decorated_fn():
     HOME = Workspace()
     os.makedirs(os.path.join(HOME.path, '.ave', 'config'))
     pm_config = {
         'logging': False,
         'log_path': os.path.join(HOME.path, 'pm.log'),
         'map_path': os.path.join(HOME.path, 'pm.json')
     }
     write_config(HOME.path, 'powermeter.json', json.dumps(pm_config))
     result = fn(HOME)
     HOME.delete()
     return result
예제 #15
0
def t05():
    pretty = '%s t5' % __file__
    print(pretty)

    w = Workspace()
    w.config['jenkins'] = JENKINS;

    try:
        path = w.download_jenkins(JOB_ID, dst='foo')
    except Exception, e:
        print('FAIL %s: download failed: %s' % (pretty, str(e)))
        return
예제 #16
0
 def decorated(*args, **kwargs):
     self.HOME = Workspace()
     self.make_system()
     w = Workspace(home=self.HOME.path)
     self.make_files(w.path)
     try:
         result = fn(self.HOME.path, w, *args, **kwargs)
     except:
         self.kill()
         raise
     self.kill()
     return result
예제 #17
0
 def decorated(*args, **kwargs):
     pretty = '%s %s' % (fn.func_code.co_filename, fn.func_name)
     print(pretty)
     self.HOME = Workspace()
     self.processes = []
     os.makedirs(os.path.join(self.HOME.path, '.ave', 'config'))
     result = fn(pretty, self, *args, **kwargs)
     for p in self.processes:
         try:
             p.terminate()
             p.join()
         except Exception, e:
             print e
예제 #18
0
def t07(home, w):
    pretty = '%s t07' % __file__
    print(pretty)

    w = Workspace(home=home)
    custom_key = 'friendly_prefix_%s' % time.strftime("%H:%M:%S")
    # test custome_key not existed
    meta = w.flocker_push_string('hej hej', dst='hej.txt')
    try:
        w.flocker_initial(existing_key=custom_key)
    except Exception, e:
        if 'Could not access friendly_prefix' not in str(e):
            return False
예제 #19
0
파일: setup.py 프로젝트: yiu31802/ave
 def decorated(*args, **kwargs):
     pretty = '%s %s' % (fn.func_code.co_filename, fn.func_name)
     print(pretty)
     self.HOME = Workspace()
     self.processes = []
     os.makedirs(os.path.join(self.HOME.path, '.ave','config'))
     try:
         result = fn(pretty, self, *args, **kwargs)
     except:
         raise
     finally:
         self.kill()
         self.HOME.delete()
     return result
예제 #20
0
def t4():
    pretty = '%s t4' % __file__
    print(pretty)

    w = Workspace(uid='vcsjob-execute-t4')

    # create the jobs tree
    def make_vcsjob_tree():
        path = w.make_tempdir()
        f = open(os.path.join(path, '.vcsjob'), 'w')
        f.write('{ "executables": [ { "path": "printenv.sh" } ] }')
        f.close()
        f = open(os.path.join(path, 'printenv.sh'), 'w')
        f.write('#! /bin/bash\nprintenv\n')
        f.close()
        os.chmod(os.path.join(path, 'printenv.sh'), 0755)
        return path

    jobs = make_vcsjob_tree()

    env = backup_env()

    # set some environment variables
    os.environ['FOO'] = 'BAR'
    os.environ['COW'] = 'MOO'

    cwd_bak = os.getcwd()
    (strio, backup) = redirect()
    result = vcsjob.job.main(['--jobs=' + jobs, '--env=FOO'], )
    undirect(backup)
    os.chdir(cwd_bak)
    restore_env(env)

    # check that FOO appeared in the set of environment variables that the
    # test job could see, but not COW
    found_foo = False
    found_cow = False
    for line in strio.getvalue().splitlines():
        if line == 'FOO=BAR':
            found_foo = True
        elif line == 'COW=MOO':
            found_cow = True
    if not found_foo:
        print('FAIL %s: FOO was not set: %s' % (pretty, strio.getvalue()))
        return
    if found_cow:
        print('FAIL %s: COW was set: %s' % (pretty, strio.getvalue()))
        return

    w.delete()
예제 #21
0
def t10():
    pretty = '%s t10' % __file__
    print(pretty)

    w   = Workspace()
    w.config['jenkins'] = JENKINS;
    dst = 'downloads'

    sameBase = w.config['jenkins']

    try:
        path = w.download_jenkins(JOB_ID, base=sameBase,  dst=dst)
    except Exception, e:
        print('FAIL %s: download failed: %s' % (pretty, str(e)))
        return
예제 #22
0
def t15(home):
    pretty = '%s t15' % __file__
    print(pretty)

    # Making sure that we don't actually use real config that might have access
    create_default(home.path)
    w = Workspace(home=home.path)
    try:
        w.download_jenkins(JOB_ID, base=JENKINS_WITH_AUTH)
    except Exception, e:
        if "requires authentication" not in str(e) \
                or "please add to jenkins.json" not in str(e):
            print('FAIL %s: unexpected exception: %s' % (pretty, str(e)))
            return False
        return True
예제 #23
0
def t09():
    pretty = '%s t9' % __file__
    print(pretty)

    w = Workspace()
    w.config['jenkins'] = JENKINS;
    job = JenkinsJob(w.config['jenkins'], JOB_ID)

    try:
        job.load()
        build = job.last_completed()
    except Exception, e:
        print('FAIL %s: got exception: %s' % (pretty, str(e)))
        w.delete()
        return
예제 #24
0
def t12():
    pretty = '%s t12' % __file__
    print(pretty)

    w   = Workspace()
    dst = 'downloads'

    # Faulty base
    bananaBase = 'http://android-ci.bananas.net'
    nap = 5

    exc = None
    try:
        path = w.download_jenkins(JOB_ID, base=bananaBase, dst=dst, timeout=nap)
    except Exception, e:
        exc = e
예제 #25
0
def t16():
    pretty = '%s t16' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t16')

    # set up source and destination in temporary directories
    src = make_vcsjob_tree(w)
    dst = w.make_tempdir()

    # fetch the source into the destination
    exc = None
    try:
        result = vcsjob.fetch(src, dst, 'no_such_branch')
    except Exception, e:
        exc = e
예제 #26
0
def t7():
    pretty = '%s t7' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t7')

    # set up source and destination in temporary directories
    src = make_vcsjob_tree(w)
    dst = w.make_tempdir()

    # fetch the source into the destination
    try:
        vcsjob.fetch(src, dst, 'master')
    except Exception, e:
        print('FAIL %s: fetch failed: %s' % (pretty, str(e)))
        return
예제 #27
0
def t9():
    pretty = '%s t9' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t9')

    src = make_vcsjob_tree(w)
    dst = w.make_tempdir()

    # pull the tree into a temporary directory, check that the current branch
    # is "master".
    try:
        result = vcsjob.fetch(src, dst, 'master')
    except Exception, e:
        print('FAIL %s: fetch failed: %s' % (pretty, str(e)))
        return
예제 #28
0
def t14():
    pretty = '%s t14' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t14')

    src = make_vcsjob_tree(w)

    # pull "master"
    dst = w.make_tempdir()

    try:
        result = vcsjob.fetch(src, dst, 'master')
    except Exception, e:
        print('FAIL %s: first fetch failed: %s' % (pretty, str(e)))
        return
예제 #29
0
파일: spool.py 프로젝트: yiu31802/ave
def t5():
    pretty = '%s t5' % __file__
    print(pretty)

    def proc(fd):
        time.sleep(0.5)
        os.write(fd, 'will be caught')
        time.sleep(0.5)
        os.write(fd, 'will be missed')
        os.close(fd)

    w = Workspace('spool-t5')
    s = make_spool(os.path.join(w.path, 'a_spool'))
    pr, pw = os.pipe()
    s.register(pr)
    p = multiprocessing.Process(target=proc, args=(pw, ))
    p.start()

    # first read times out
    try:
        result = s.read(1)
        print('FAIL %s: read(1) did not throw exception' % pretty)
        os.kill(p.pid, signal.SIGKILL)
        return
    except Exception, e:
        if str(e) != 'time out':
            print('FAIL %s: wrong error message: %s' % (pretty, str(e)))
            os.kill(p.pid, signal.SIGKILL)
            return
예제 #30
0
def t20():
    pretty = '%s t20' % __file__
    print(pretty)

    w = Workspace('vcsjob-fetch-t20')

    src = 'git://review.sonyericsson.net/platform/prebuilts/misc.git'
    dst = w.make_tempdir()

    # fetch the source into the destination
    try:
        vcsjob.fetch(src, dst, 'oss/tools_r22.2')
    except Exception, e:
        print('FAIL %s: fetch failed: %s' % (pretty, str(e)))
        w.delete()
        return False