def main_default(type_, local_type=None, trace_=False, **kwargs): """ Default main() method. Parses cmdline args, setups up signal handling, logging, creates the appropriate object and runs it. :param type type_: Primary type to instantiate. :param type local_type: If not `None`, load the topology to check if this is a core or local AS. If it's a core AS, instantiate the primary type, otherwise the local type. :param bool trace_: Should a periodic thread stacktrace report be created? """ handle_signals() parser = argparse.ArgumentParser() parser.add_argument('--log_dir', default="logs/", help='Log dir (Default: logs/)') parser.add_argument( '--spki_cache_dir', default="gen-cache/", help='Cache dir for SCION TRCs and cert chains (Default: gen-cache/)') parser.add_argument('--prom', type=str, help='Address to export prometheus metrics on') parser.add_argument('server_id', help='Server identifier') parser.add_argument('conf_dir', nargs='?', default='.', help='Configuration directory (Default: ./)') args = parser.parse_args() init_logging(os.path.join(args.log_dir, args.server_id)) if local_type is None: inst = type_(args.server_id, args.conf_dir, prom_export=args.prom, spki_cache_dir=args.spki_cache_dir, **kwargs) else: # Load the topology to check if this is a core AD or not topo = Topology.from_file(os.path.join(args.conf_dir, TOPO_FILE)) if topo.is_core_as: inst = type_(args.server_id, args.conf_dir, prom_export=args.prom, spki_cache_dir=args.spki_cache_dir, **kwargs) else: inst = local_type(args.server_id, args.conf_dir, prom_export=args.prom, spki_cache_dir=args.spki_cache_dir, **kwargs) if trace_: trace(inst.id) logging.info("Started %s", args.server_id) inst.run()
def test_basic(self, join, trace_start): join.return_value = "Path" trace(3) join.assert_any_call(TRACE_DIR, "3.trace.html") trace_start.assert_called_once_with("Path")