def assert_environ_produces_modified_pcsd_env( self, environ=None, specific_env_values=None, errors=None, warnings=None ): pcsd_dir = partial(join_path, settings.pcsd_exec_location) default_env_values = { env.PCSD_PORT: settings.pcsd_default_port, env.PCSD_SSL_CIPHERS: settings.default_ssl_ciphers, env.PCSD_SSL_OPTIONS: env.str_to_ssl_options( settings.default_ssl_options, [] ), env.PCSD_BIND_ADDR: {None}, env.NOTIFY_SOCKET: None, env.PCSD_DEBUG: False, env.PCSD_DISABLE_GUI: False, env.PCSD_SESSION_LIFETIME: settings.gui_session_lifetime_seconds, env.GEM_HOME: pcsd_dir(settings.pcsd_gem_path), env.PCSD_CMDLINE_ENTRY: pcsd_dir(env.PCSD_CMDLINE_ENTRY_RB_SCRIPT), env.PCSD_STATIC_FILES_DIR: pcsd_dir(env.PCSD_STATIC_FILES_DIR_NAME), env.HTTPS_PROXY: None, env.NO_PROXY: None, env.PCSD_DEV: False, "has_errors": False, } if specific_env_values is None: specific_env_values = {} # compare as dict because of clearer error report self.assertEqual( dict(env.prepare_env(environ or {}, self.logger)._asdict()), {**default_env_values, **specific_env_values} ) self.assertEqual(self.logger.errors, errors or []) self.assertEqual(self.logger.warnings, warnings or [])
def main(): signal.signal(signal.SIGTERM, handle_signal) signal.signal(signal.SIGINT, handle_signal) Path(settings.pcsd_log_location).touch(mode=0o600, exist_ok=True) log.setup(settings.pcsd_log_location) env = prepare_env(os.environ, log.pcsd) if env.has_errors: raise SystemExit(1) if env.PCSD_DEBUG: log.enable_debug() sync_config_lock = Lock() ruby_pcsd_wrapper = ruby_pcsd.Wrapper( settings.pcsd_ruby_socket, debug=env.PCSD_DEBUG, ) make_app = configure_app( session.Storage(env.PCSD_SESSION_LIFETIME), ruby_pcsd_wrapper, sync_config_lock, env.PCSD_STATIC_FILES_DIR, disable_gui=env.PCSD_DISABLE_GUI, debug=env.PCSD_DEV, ) pcsd_ssl = ssl.PcsdSSL( server_name=socket.gethostname(), cert_location=settings.pcsd_cert_location, key_location=settings.pcsd_key_location, ssl_options=env.PCSD_SSL_OPTIONS, ssl_ciphers=env.PCSD_SSL_CIPHERS, ) try: SignalInfo.server_manage = HttpsServerManage( make_app, port=env.PCSD_PORT, bind_addresses=env.PCSD_BIND_ADDR, ssl=pcsd_ssl, ).start() except socket.gaierror as e: log.pcsd.error("Unable to bind to specific address(es), exiting: %s ", e) raise SystemExit(1) except OSError as e: log.pcsd.error("Unable to start pcsd daemon, exiting: %s ", e) raise SystemExit(1) except ssl.SSLCertKeyException as e: for error in e.args: log.pcsd.error(error) log.pcsd.error("Invalid SSL certificate and/or key, exiting") raise SystemExit(1) ioloop = IOLoop.current() ioloop.add_callback(sign_ioloop_started) if is_systemd() and env.NOTIFY_SOCKET: ioloop.add_callback(systemd.notify, env.NOTIFY_SOCKET) ioloop.add_callback(config_sync(sync_config_lock, ruby_pcsd_wrapper)) ioloop.start()
def main(): signal.signal(signal.SIGTERM, handle_signal) signal.signal(signal.SIGINT, handle_signal) Path(settings.pcsd_log_location).touch(mode=0o600, exist_ok=True) log.setup(settings.pcsd_log_location) env = prepare_env(os.environ, log.pcsd) if env.has_errors: raise SystemExit(1) if env.PCSD_DEBUG: log.enable_debug() sync_config_lock = Lock() ruby_pcsd_wrapper = ruby_pcsd.Wrapper( pcsd_cmdline_entry=env.PCSD_CMDLINE_ENTRY, gem_home=env.GEM_HOME, debug=env.PCSD_DEBUG, ruby_executable=settings.ruby_executable, https_proxy=env.HTTPS_PROXY, no_proxy=env.NO_PROXY, ) make_app = configure_app( session.Storage(env.PCSD_SESSION_LIFETIME), ruby_pcsd_wrapper, sync_config_lock, env.PCSD_STATIC_FILES_DIR, disable_gui=env.PCSD_DISABLE_GUI, debug=env.PCSD_DEV, ) pcsd_ssl = ssl.PcsdSSL( server_name=socket.gethostname(), cert_location=settings.pcsd_cert_location, key_location=settings.pcsd_key_location, ssl_options=env.PCSD_SSL_OPTIONS, ssl_ciphers=env.PCSD_SSL_CIPHERS, ) try: SignalInfo.server_manage = HttpsServerManage( make_app, port=env.PCSD_PORT, bind_addresses=env.PCSD_BIND_ADDR, ssl=pcsd_ssl, ).start() except socket.gaierror as e: log.pcsd.error( "Unable to bind to specific address(es), exiting: %s ", e ) raise SystemExit(1) except OSError as e: log.pcsd.error("Unable to start pcsd daemon, exiting: %s ", e) raise SystemExit(1) except ssl.SSLCertKeyException as e: for error in e.args: log.pcsd.error(error) log.pcsd.error("Invalid SSL certificate and/or key, exiting") raise SystemExit(1) ioloop = IOLoop.current() ioloop.add_callback(sign_ioloop_started) if is_systemd() and env.NOTIFY_SOCKET: ioloop.add_callback(systemd.notify, env.NOTIFY_SOCKET) ioloop.add_callback(config_sync(sync_config_lock, ruby_pcsd_wrapper)) ioloop.start()