示例#1
0
def cmd_test(metasync, args, opts):
    "quick test (e.g., metasync test {%s})"

    # invoke pdb when failed in testing
    util.install_pdb()

    tmpdir = tempfile.mkdtemp()
    root = os.path.join(tmpdir, "repo")
    util.mkdirs(root)
    metasync = MetaSync(root)

    # opts for sub test routines
    opts.root = root
    opts.tmpdir = tmpdir
    opts.encrypt_key = "testkey" if opts.encrypt else ""

    dbg.info("root: %s" % root)
    dbg.info("args: %s" % args)
    dbg.info("opts: ")
    for (k, v) in vars(opts).iteritems():
        dbg.info("  %-12s = %s" % (k, v))

    alltests = dict(test.get_all_tests())
    if any(case not in alltests for case in args):
        dbg.err("no such a test case: %s" % args)
        alltests["help"](metasync, opts)
        exit(1)
示例#2
0
def cmd_test(metasync, args, opts):
    "quick test (e.g., metasync test {%s})"

    # invoke pdb when failed in testing
    util.install_pdb()

    tmpdir = tempfile.mkdtemp()
    root = os.path.join(tmpdir, "repo")
    util.mkdirs(root)
    metasync = MetaSync(root)

    # opts for sub test routines
    opts.root = root
    opts.tmpdir = tmpdir
    opts.encrypt_key = "testkey" if opts.encrypt else ""

    dbg.info("root: %s" % root)
    dbg.info("args: %s" % args)
    dbg.info("opts: ")
    for (k, v) in vars(opts).iteritems():
        dbg.info("  %-12s = %s" % (k, v))

    alltests = dict(test.get_all_tests())
    if any(case not in alltests for case in args):
        dbg.err("no such a test case: %s" % args)
        alltests["help"](metasync, opts)
        exit(1)

    # print help if no test case is provided
    if len(args) == 0:
        args = ["help"]

    for case in args:
        dbg.info("#R<testing %s#> (%s)" % (case, alltests[case].__doc__))
        alltests[case](metasync, opts)

    # poorman's tree
    def tree(path):
        for root, dirs, files in os.walk(path):
            base = os.path.basename(root)
            idnt = '    ' * (root.replace(path, '').count(os.sep))
            print('%s%s/' % (idnt, base))
            for f in files:
                pn = os.path.join(root, f)
                print('    %s%s [%s]' % (idnt, f, os.stat(pn).st_size))

                # dump some content of blobs
                if opts.dump and "objects" == base:
                    print(util.hexdump(util.read_file(pn, 32*2)))
                    print

    # dump root
    if not opts.notree:
        tree(tmpdir)

    # cleanup tmpdir
    if not opts.keep:
        shutil.rmtree(tmpdir)
示例#3
0
def main():
    # do all the dirty works on command args
    parser = argparse.ArgumentParser(prog='MetaSync')
    parser.add_argument('--version',
                        action='version',
                        version='%(prog)s ' + VERSION)
    parser.add_argument('--quite', action='store_true', default=False)
    parser.add_argument('--debug', action='store_true', default=False)
    parser.add_argument('--authdir', default=None)
    parser.add_argument('--nthreads', default=2, type=int)
    parser.add_argument('--metasync',
                        help="root of metasync repo",
                        default=".")

    # add subparser for each command
    sub_parser = {}
    sub = parser.add_subparsers(dest="cmd")
    for (k, f) in get_all_cmds():
        p = sub.add_parser(k, help=f.__doc__)
        p.add_argument('args', nargs='*')
        sub_parser[k] = p

    # sub command specific option other than args
    sub_parser["test"].add_argument('--dump',
                                    help="hexdump of /objects",
                                    action="store_true",
                                    default=False)

    sub_parser["test"].add_argument('--keep',
                                    help="keep test dir",
                                    action="store_true",
                                    default=False)

    sub_parser["test"].add_argument('--slow',
                                    help="slow path for testing",
                                    action="store_true",
                                    default=False)

    sub_parser["test"].add_argument('--encrypt',
                                    help="enable encryption",
                                    action="store_true",
                                    default=False)

    sub_parser["test"].add_argument('--notree',
                                    help="do not dump the root tree",
                                    action="store_true",
                                    default=False)

    sub_parser["daemon"].add_argument('--nocheckin',
                                      action="store_true",
                                      default=False)

    # in case of not getting any arg
    if len(sys.argv) < 2:
        sys.argv.append('--help')

    args = parser.parse_args()
    # set quite
    dbg.quiet(["info", "err"])

    if args.debug:
        util.install_pdb()
        dbg.quiet(["info", "err", "dbg", "time"])
    import services
    services.auth_dir = args.authdir

    # invoke & exit
    exit(invoke_cmd(args.cmd, MetaSync(args.metasync, args), args))
示例#4
0
#!/usr/bin/python

import util, ctrl, mgrapi, mgrutil, copy, optparse
import zoobarmgr

util.install_pdb()


def load_graph(logdir):
    zoobarmgr.set_logdir(logdir)
    zoobarmgr.load(None, None)


def pick_attack_nodes():
    ckpts = {}
    for o in mgrapi.RegisteredObject.all():
        if not isinstance(o, mgrutil.BufferNode) or \
           o.name[-1] != 'htargs' or o.data is None or \
           'hint=attack' not in o.data['env'].get('QUERY_STRING', ''):
            continue

        attack_req = mgrapi.RegisteredObject.by_name_load(o.name)
        nd = copy.deepcopy(attack_req.data)
        nd['env']['REQUEST_METHOD'] = 'GET'
        nd['env']['QUERY_STRING'] = ''
        nd['post'] = ''
        tr = min(attack_req.readers).tic
        tw = min(attack_req.writers).tic
        attack_data = mgrutil.BufferCheckpoint(o.name + ('repair_cp', ),
                                               min(tr, tw), nd)
示例#5
0
def main():
    # do all the dirty works on command args
    parser = argparse.ArgumentParser(prog='MetaSync')
    parser.add_argument('--version', action='version', version='%(prog)s ' + VERSION)
    parser.add_argument('--quite', action='store_true', default=False)
    parser.add_argument('--debug', action='store_true', default=False)
    parser.add_argument('--authdir', default=None)
    parser.add_argument('--nthreads', default=2, type=int)
    parser.add_argument('--metasync',
                        help="root of metasync repo",
                        default=".")

    # add subparser for each command
    sub_parser = {}
    sub = parser.add_subparsers(dest="cmd")
    for (k, f) in get_all_cmds():
        p = sub.add_parser(k, help=f.__doc__)
        p.add_argument('args', nargs='*')
        sub_parser[k] = p

    # sub command specific option other than args
    sub_parser["test"].add_argument('--dump',
                                    help="hexdump of /objects",
                                    action="store_true",
                                    default=False)

    sub_parser["test"].add_argument('--keep',
                                    help="keep test dir",
                                    action="store_true",
                                    default=False)

    sub_parser["test"].add_argument('--slow',
                                    help="slow path for testing",
                                    action="store_true",
                                    default=False)

    sub_parser["test"].add_argument('--encrypt',
                                    help="enable encryption",
                                    action="store_true",
                                    default=False)

    sub_parser["test"].add_argument('--notree',
                                    help="do not dump the root tree",
                                    action="store_true",
                                    default=False)

    sub_parser["daemon"].add_argument('--nocheckin',
                                    action="store_true",
                                    default=False)

    # in case of not getting any arg
    if len(sys.argv) < 2:
        sys.argv.append('--help')

    args = parser.parse_args()
    # set quite
    dbg.quiet(["info", "err"])

    if args.debug:
        util.install_pdb()
        dbg.quiet(["info", "err","dbg","time"])
    import services
    services.auth_dir = args.authdir


    # invoke & exit
    exit(invoke_cmd(args.cmd, MetaSync(args.metasync, args), args))