Exemplo n.º 1
0
def main():
    """
    Entry point for GNS3 server
    """

    level = logging.INFO
    args = parse_arguments(sys.argv[1:],
                           Config.instance().get_section_config("Server"))
    if args.debug:
        level = logging.DEBUG

    user_log = init_logger(level, quiet=args.quiet)
    user_log.info("GNS3 server version {}".format(__version__))
    current_year = datetime.date.today().year
    user_log.info(
        "Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year))

    for config_file in Config.instance().get_config_files():
        user_log.info("Config file {} loaded".format(config_file))

    set_config(args)
    server_config = Config.instance().get_section_config("Server")
    if server_config.getboolean("local"):
        log.warning(
            "Local mode is enabled. Beware, clients will have full control on your filesystem"
        )

    # we only support Python 3 version >= 3.3
    if sys.version_info < (3, 3):
        raise RuntimeError("Python 3.3 or higher is required")

    user_log.info(
        "Running with Python {major}.{minor}.{micro} and has PID {pid}".format(
            major=sys.version_info[0],
            minor=sys.version_info[1],
            micro=sys.version_info[2],
            pid=os.getpid()))

    # check for the correct locale (UNIX/Linux only)
    locale_check()

    try:
        os.getcwd()
    except FileNotFoundError:
        log.critical("The current working directory doesn't exist")
        return

    Project.clean_project_directory()

    CrashReport.instance()
    host = server_config["host"]
    port = int(server_config["port"])
    server = Server.instance(host, port)
    try:
        server.run()
    except Exception as e:
        log.critical("Critical error while running the server: {}".format(e),
                     exc_info=1)
        CrashReport.instance().capture_exception()
        return
Exemplo n.º 2
0
def main():
    """
    Entry point for GNS3 server
    """

    level = logging.INFO
    args = parse_arguments(sys.argv[1:], Config.instance().get_section_config("Server"))
    if args.debug:
        level = logging.DEBUG

    user_log = init_logger(level, logfile=args.log, quiet=args.quiet)
    user_log.info("GNS3 server version {}".format(__version__))
    current_year = datetime.date.today().year
    user_log.info("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year))

    for config_file in Config.instance().get_config_files():
        user_log.info("Config file {} loaded".format(config_file))

    set_config(args)
    server_config = Config.instance().get_section_config("Server")
    if server_config.getboolean("local"):
        log.warning("Local mode is enabled. Beware, clients will have full control on your filesystem")

    # we only support Python 3 version >= 3.3
    if sys.version_info < (3, 3):
        raise RuntimeError("Python 3.3 or higher is required")

    user_log.info("Running with Python {major}.{minor}.{micro} and has PID {pid}".format(
                  major=sys.version_info[0], minor=sys.version_info[1],
                  micro=sys.version_info[2], pid=os.getpid()))

    # check for the correct locale (UNIX/Linux only)
    locale_check()

    try:
        os.getcwd()
    except FileNotFoundError:
        log.critical("The current working directory doesn't exist")
        return

    Project.clean_project_directory()

    CrashReport.instance()
    host = server_config["host"]
    port = int(server_config["port"])
    server = Server.instance(host, port)
    try:
        server.run()
    except OSError as e:
        # This is to ignore OSError: [WinError 0] The operation completed successfully exception on Windows.
        if not sys.platform.startswith("win") and not e.winerror == 0:
            raise
    except Exception as e:
        log.critical("Critical error while running the server: {}".format(e), exc_info=1)
        CrashReport.instance().capture_exception()
        return
Exemplo n.º 3
0
def test_init_logger_quiet(caplog):

    logger = init_logger(logging.DEBUG, quiet=True)
    logger.debug("DEBUG1")
    assert "DEBUG1" not in caplog.text
    logger.info("INFO1")
    assert "INFO1" not in caplog.text
    logger.warn("WARN1")
    assert "WARN1" not in caplog.text
    logger.error("ERROR1")
    assert "ERROR1" not in caplog.text
    logger.critical("CRITICAL1")
    assert "CRITICAL1" not in caplog.text
Exemplo n.º 4
0
def test_init_logger(caplog):

    logger = init_logger(logging.DEBUG)
    logger.debug("DEBUG1")
    assert "DEBUG1" in caplog.text()
    logger.info("INFO1")
    assert "INFO1" in caplog.text()
    logger.warn("WARN1")
    assert "WARN1" in caplog.text()
    logger.error("ERROR1")
    assert "ERROR1" in caplog.text()
    logger.critical("CRITICAL1")
    assert "CRITICAL1" in caplog.text()
Exemplo n.º 5
0
def run():
    args = parse_arguments(sys.argv[1:])

    if args.daemon and sys.platform.startswith("win"):
        log.critical("Daemon is not supported on Windows")
        sys.exit(1)

    if args.pid:
        pid_lock(args.pid)
        kill_ghosts()

    level = logging.INFO
    if args.debug:
        level = logging.DEBUG

    user_log = init_logger(level, logfile=args.log, quiet=args.quiet)
    user_log.info("GNS3 server version {}".format(__version__))
    current_year = datetime.date.today().year
    user_log.info("Copyright (c) 2007-{} GNS3 Technologies Inc.".format(current_year))

    for config_file in Config.instance().get_config_files():
        user_log.info("Config file {} loaded".format(config_file))

    set_config(args)
    server_config = Config.instance().get_section_config("Server")

    if server_config.getboolean("local"):
        log.warning("Local mode is enabled. Beware, clients will have full control on your filesystem")

    # we only support Python 3 version >= 3.5
    if sys.version_info < (3, 5, 3):
        raise SystemExit("Python 3.5.3 or higher is required")

    user_log.info("Running with Python {major}.{minor}.{micro} and has PID {pid}".format(
                  major=sys.version_info[0], minor=sys.version_info[1],
                  micro=sys.version_info[2], pid=os.getpid()))

    # check for the correct locale (UNIX/Linux only)
    locale_check()

    try:
        os.getcwd()
    except FileNotFoundError:
        log.critical("The current working directory doesn't exist")
        return

    CrashReport.instance()
    host = server_config["host"]

    port = int(server_config["port"])

    server = WebServer.instance(host, port)
    try:
        server.run()
    except OSError as e:
        # This is to ignore OSError: [WinError 0] The operation completed successfully exception on Windows.
        if not sys.platform.startswith("win") and not e.winerror == 0:
            raise
    except Exception as e:
        log.critical("Critical error while running the server: {}".format(e), exc_info=1)
        CrashReport.instance().capture_exception()
        return

    if args.pid:
        log.info("Remove PID file %s", args.pid)
        try:
            os.remove(args.pid)
        except OSError as e:
            log.critical("Can't remove pid file %s: %s", args.pid, str(e))