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

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

    # 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)

    if opt.showcodesflags:
        codes = cdict.keys()
        codes.sort()
        for c in codes:
            print(c, "FLAGS:", ', '.join(cdict[c].flags_list))
        sys.exit(0)

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

    if not server_list:
        p.error("%s not a valid server name" % url)

    opt.server, opt.port = server_list[0]

    if not opt.port:
        opt.port = 2049
    else:
        opt.port = int(opt.port)
    if not opt.path:
        opt.path = []
    else:
        opt.path = unixpath2comps(opt.path)

    # Check --use* options are valid
    for attr in dir(opt):
        if 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 = unixpath2comps(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)
        print(sys.exc_info()[1])
        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:
            nfail = testmod.printresults(tests, opt)
    try:
        fail = False
        env.finish()
    except Exception as e:
        fail = True
    nfail = testmod.printresults(tests, opt)
    if fail:
        print("\nWARNING: could not clean testdir due to:\n%s\n" % str(e))

    if opt.xmlout is not None:
        testmod.xml_printresults(tests, opt.xmlout)
    if nfail < 0:
        sys.exit(3)
    if nfail > 0:
        sys.exit(2)
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
        print sys.exc_info()[1]
        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')