Exemple #1
0
def main():
    p = OptionParser("%prog SERVER:/PATH [options] flags|testcodes\n"
                     "       %prog --help\n"
                     "       %prog SHOWOPTION",
                     formatter=IndentedHelpFormatter(2, 25)
                     )
    opt, args = scan_options(p)

    # Create test database
    tests, fdict, cdict = testmod.createtests('client41tests')

    # Deal with any informational options
    if opt.showflags:
        printflags(fdict.keys())
        sys.exit(0)

    if opt.showcodes:
        codes = cdict.keys()
        codes.sort()
        for c in codes:
            print(c)
        sys.exit(0)

    # Grab server info and set defaults
    if not args:
        p.error("Need a server")
    url = args.pop(0)
    print("url", url)
    opt.path = nfs4lib.path_components(url)
    print("Set opt.path", opt.path)

    # Check --use* options are valid
    for attr in dir(opt):
        if attr == 'useparams':
            opt.useparams = parse_useparams(opt.useparams)
        elif attr.startswith('use') and attr != "usefh":
            path = getattr(opt, attr)
            #print(attr, path)
            if path is None:
                path = opt.path + ['tree', attr[3:]]
            else:
                # FIXME - have funct that checks path validity
                if path[0] != '/':
                    p.error("Need to use absolute path for --%s" % attr)
                # print(path)
                if path[-1] == '/' and attr != 'usedir':
                    p.error("Can't use dir for --%s" %attr)
                try:
                    path = nfs4lib.path_components(path)
                except Exception as e:
                    p.error(e)
            setattr(opt, attr, [comp for comp in path if comp])

    #opt.path += ['tmp']

##     # Check that --security option is valid
##     # sets --flavor to a rpc.SecAuth* class, and sets flags for its options
##     valid = rpc.supported.copy()
##     # FIXME - STUB - the only gss mech available is krb5
##     if 'gss' in valid:
##         valid['krb5'] =  valid['krb5i'] =  valid['krb5p'] = valid['gss']
##         del valid['gss']
##     if opt.security not in valid:
##         p.error("Unknown security: %s\nValid flavors are %s" %
##                 (opt.security, str(valid.keys())))
##     opt.flavor = valid[opt.security]
##     opt.service = {'krb5':1, 'krb5i':2, 'krb5p':3}.get(opt.security, 0)
               
    # Make sure args are valid
    opt.args = []
    for a in args:
        if a.lower().startswith('no'):
            include = False
            a = a[2:]
        else:
            include = True
        if a in fdict:
            opt.args.append(Argtype(fdict[a], include))
        elif a in cdict:
            opt.args.append(Argtype(cdict[a], include, flag=False))
        else:
            p.error("Unknown code or flag: %s" % a)

    # DEBUGGING
    environment.debug_fail = opt.debug_fail

    # Place tests in desired order
    tests.sort() # FIXME - add options for random sort

    # Run the tests and save/print(results)
    try:
        env = environment.Environment(opt)
        env.init()
    except socket.gaierror as e:
        if e.args[0] == -2:
            print("Unknown server '%s'" % opt.server)
        sys.exit(1)
    except Exception as e:
        print("Initialization failed, no tests run.")
        if not opt.maketree:
            print("Perhaps you need to use the --maketree option")
        raise
        print(sys.exc_info()[1])
        sys.exit(1)
    if opt.outfile is not None:
        fd = open(opt.outfile, 'w')
    try:
        clean_finish = False
        testmod.runtests(tests, opt, env, run_filter)
        clean_finish = True
    finally:
        if opt.outfile is not None:
            pickle.dump(tests, fd, 0)
        if not clean_finish:
            testmod.printresults(tests, opt)
    try:
        fail = False
        env.finish()
    except Exception as e:
        fail = True
    testmod.printresults(tests, opt)
    if fail:
        print("\nWARNING: could not clean testdir due to:\n%s\n" % str(e))
Exemple #2
0
        if a in fdict:
            opt.args.append(Argtype(fdict[a], include))
        elif a in cdict:
            opt.args.append(Argtype(cdict[a], include, flag=False))
        else:
            p.error("Unknown code or flag: %s" % a)

    # DEBUGGING
    environment.debug_fail = opt.debug_fail

    # Place tests in desired order
    tests.sort()  # FIXME - add options for random sort

    # Run the tests and save/print results
    try:
        env = environment.Environment(opt)
        env.init()
    except socket.gaierror, e:
        if e.args[0] == -2:
            print "Unknown server '%s'" % opt.server
        sys.exit(1)
    except Exception, e:
        print "Initialization failed, no tests run."
        if not opt.maketree:
            print "Perhaps you need to use the --maketree option"
        raise
        print sys.exc_info()[1]
        sys.exit(1)
    if opt.outfile is not None:
        fd = file(opt.outfile, 'w')
    try: