Пример #1
0
    def load(self, filename, server_obj):
        """ Read dataservers from configuration file:
        where each line has format e.g. server[:[port][/path]]
        """
        with open(filename) as fd:
            for line in fd:
                line = line.strip()
                if not line or line.startswith('#'):
                    continue
                log.info("Analyzing: %r" % line)
                try:
                    server_list, path = nfs4lib.parse_nfs_url(line)
                except:
                    log.critical("Could not parse line: %r" % line)
                    sys.exit(1)

                # for now, just use the last path for local connections
                server, port = server_list[-1]
                server_list = server_list[:-1]
                try:
                    log.info("Adding dataserver ip:%s port:%s path:%s" %
                             (server, port, '/'.join(path)))
                    ds = DataServer41(server, port, path, mdsds=self.mdsds,
                                    multipath_servers=server_list,
                                    summary=server_obj.summary)
                    self.list.append(ds)
                except socket.error:
                    log.critical("cannot access %s:%i/%s" %
                                 (server, port, '/'.join(path)))
                    sys.exit(1)
        self.active = 1
        self.address_body = self._get_address_body()
Пример #2
0
    def load(self, filename, server_obj):
        """ Read dataservers from configuration file:
        where each line has format e.g. server[:[port][/path]]
        """
        with open(filename) as fd:
            for line in fd:
                line = line.strip()
                if not line or line.startswith('#'):
                    continue
                log.info("Analyzing: %r" % line)
                try:
                    server_list, path = nfs4lib.parse_nfs_url(line)
                except:
                    log.critical("Could not parse line: %r" % line)
                    sys.exit(1)

                # for now, just use the last path for local connections
                server, port = server_list[-1]
                server_list = server_list[:-1]
                try:
                    log.info("Adding dataserver ip:%s port:%s path:%s" %
                             (server, port, '/'.join(path)))
                    ds = DataServer41(server,
                                      port,
                                      path,
                                      mdsds=self.mdsds,
                                      multipath_servers=server_list,
                                      summary=server_obj.summary)
                    self.list.append(ds)
                except socket.error:
                    log.critical("cannot access %s:%i/%s" %
                                 (server, port, '/'.join(path)))
                    sys.exit(1)
        self.active = 1
        self.address_body = self._get_address_body()
Пример #3
0
def main():
    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)
    environment.nfs4client.SHOW_TRAFFIC = opt.showtraffic

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

    # 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)
    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 args:
        p.error("No tests given")

    # 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 = nfs4lib.path_components(path)
                except Exception, e:
                    p.error(e)
            setattr(opt, attr, [comp for comp in path if comp])
Пример #4
0
def main():
    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)
    environment.nfs4client.SHOW_TRAFFIC = opt.showtraffic

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

    # 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)
    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 args:
        p.error("No tests given")

    # 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 = nfs4lib.path_components(path)
                except Exception, e:
                    p.error(e)
            setattr(opt, attr, [comp for comp in path if comp])
Пример #5
0
def main():
    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)
    environment.nfs4client.SHOW_TRAFFIC = opt.showtraffic

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

    # 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 args:
        p.error("No tests given")

    # 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 = nfs4lib.path_components(path)
                except Exception as e:
                    p.error(e)
            setattr(opt, attr, [comp for comp in path if comp])

    # Check that --security option is valid
    # FIXME STUB
    tempd = {
        'none': (rpc.AUTH_NONE, 0),
        'sys': (rpc.AUTH_SYS, 0),
        'krb5': (rpc.RPCSEC_GSS, 1),
        'krb5i': (rpc.RPCSEC_GSS, 2),
        'krb5p': (rpc.RPCSEC_GSS, 3),
    }
    if opt.security not in tempd:
        p.error("Unknown security: %s\nValid flavors are %s" %
                (opt.security, str(tempd.keys())))

    # flavor has changed from class to int
    opt.flavor, opt.service = tempd[opt.security]

    if opt.flavor not in rpc.security.supported:
        if opt.flavor == rpc.RPCSEC_GSS:
            p.error("RPCSEC_GSS not supported,"
                    " could not find compile gssapi module")
        else:
            p.error("Unsupported security flavor")

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

    if opt.xmlout is not None:
        testmod.xml_printresults(tests, opt.xmlout)
Пример #6
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)
Пример #7
0
def usage():
    print "Usage: %s [nfs://]host[:[port]]<prefix>" % sys.argv[0]
    print "Creates tree contents on server for nfs4st testing"
    print "Directories and files will be created"
    print "under <server><prefix>/nfs4st/"
    print
    print "<prefix> defaults to /, e.g. the directory nfs4st is"
    print "created directly under the server root"
    sys.exit(1)


if __name__ == "__main__":
    if len(sys.argv) < 2:
        usage()

    parse_result = nfs4lib.parse_nfs_url(sys.argv[1])
    if not parse_result:
        usage()

    (host, portstring, directory) = parse_result

    if portstring:
        port = int(portstring)
    else:
        port = nfs4lib.NFS_PORT

    if not directory:
        directory = "/"

    directory = os.path.join(directory, "nfs4st_tree")
Пример #8
0
                sys.exit()
        if o in ("-p", "--pythonmode"):
            pythonmode = 1
        if o in ("-c", "--commandstring"):
            commandstring = a
        if o == "--uid":
            kwargs["uid"] = int(a)
        if o == "--gid":
            kwargs["gid"] = int(a)

    # By now, there should only be one argument left.
    if len(args) != 1:
        print >> sys.stderr, "the number of non-option arguments is not one"
        usage()
    else:
        parse_result = nfs4lib.parse_nfs_url(args[0])
        if not parse_result:
            usage()

        (host, portstring, directory) = parse_result

        if portstring:
            port = int(portstring)
        else:
            port = nfs4lib.NFS_PORT

        if not directory:
            directory = "/"

    ncl = nfs4lib.create_client(host, port, transport, **kwargs)
    c = ClientApp(ncl, directory, pythonmode, debuglevel)
Пример #9
0
                sys.exit()
        if o in ("-p", "--pythonmode"):
            pythonmode = 1
        if o in ("-c", "--commandstring"):
            commandstring = a
        if o == "--uid":
            kwargs["uid"] = int(a)
        if o == "--gid":
            kwargs["gid"] = int(a)

    # By now, there should only be one argument left.
    if len(args) != 1:
        print >> sys.stderr, "the number of non-option arguments is not one"
        usage()
    else:
        parse_result = nfs4lib.parse_nfs_url(args[0])
        if not parse_result:
            usage()

        (host, portstring, directory) = parse_result

        if portstring:
            port = int(portstring)
        else:
            port = nfs4lib.NFS_PORT

        if not directory:
            directory = "/"

    ncl = nfs4lib.create_client(host, port, transport, **kwargs)
    c = ClientApp(ncl, directory, pythonmode, debuglevel)
Пример #10
0
def main():
    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)
    environment.nfs4client.SHOW_TRAFFIC = opt.showtraffic

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

    # 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 args:
        p.error("No tests given")

    # 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 = nfs4lib.path_components(path)
                except Exception as e:
                    p.error(e)
            setattr(opt, attr, [comp for comp in path if comp])

    # Check that --security option is valid
    # FIXME STUB
    tempd = {'none' : (rpc.AUTH_NONE, 0),
             'sys'  : (rpc.AUTH_SYS, 0),
             'krb5' : (rpc.RPCSEC_GSS, 1),
             'krb5i': (rpc.RPCSEC_GSS, 2),
             'krb5p': (rpc.RPCSEC_GSS, 3),
             }
    if opt.security not in tempd:
        p.error("Unknown security: %s\nValid flavors are %s" %
                (opt.security, str(tempd.keys())))

    # flavor has changed from class to int
    opt.flavor, opt.service = tempd[opt.security]

    if opt.flavor not in rpc.security.supported:
        if opt.flavor == rpc.RPCSEC_GSS:
            p.error("RPCSEC_GSS not supported,"
                    " could not find compile gssapi module")
        else:
            p.error("Unsupported security flavor")

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

    if opt.xmlout is not None:
        testmod.xml_printresults(tests, opt.xmlout)
Пример #11
0
def usage():
    print "Usage: %s [nfs://]host[:[port]]<prefix>" % sys.argv[0]
    print "Creates tree contents on server for nfs4st testing"
    print "Directories and files will be created"
    print "under <server><prefix>/nfs4st/"
    print
    print "<prefix> defaults to /, e.g. the directory nfs4st is"
    print "created directly under the server root"
    sys.exit(1)

if __name__ == "__main__":
    if len(sys.argv) < 2:
        usage()

    parse_result = nfs4lib.parse_nfs_url(sys.argv[1])
    if not parse_result:
        usage()

    (host, portstring, directory) = parse_result

    if portstring:
        port = int(portstring)
    else:
        port = nfs4lib.NFS_PORT

    if not directory:
        directory = "/"

    directory = os.path.join(directory, "nfs4st")
        
Пример #12
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)