def create_dummy_status_server(self, p_process_handlers=None): # TODO: Add rule set configs as parameters again and migrate them into the datamodel if p_process_handlers is None: p_process_handlers = {} _persistence = test_persistence.TestPersistence.create_dummy_persistence( self._logger) _rule_handler = test_rule_handler.TestRuleHandler.create_dummy_rule_handler( p_persistence=_persistence) master_connector_config = master_connector.MasterConnectorConfigModel() _master_connector = master_connector.MasterConnector( p_config=master_connector_config) app_control_config = app_control.AppControlConfigModel() _app_control = app_control.AppControl( p_config=app_control_config, p_debug_mode=False, p_process_handlers=p_process_handlers, p_device_handler=None, p_prometheus_client=None, p_persistence=_persistence, p_rule_handler=_rule_handler, p_notification_handlers=[], p_master_connector=_master_connector, p_login_mapping=test_data.LOGIN_MAPPING, p_locale_helper=locale_helper.LocaleHelper()) status_server_config = status_server.StatusServerConfigModel() status_server_config.admin_username = ADMIN_USERNAME status_server_config.admin_password = ADMIN_PASSWORD status_server_config.app_secret = "secret!" status_server_config.port = int(os.getenv("STATUS_SERVER_PORT", "5555")) user_handler_config = unix_user_handler.BaseUserHandlerConfigModel() user_handler_config.admin_username = ADMIN_USERNAME user_handler_config.admin_password = ADMIN_PASSWORD user_handler = unix_user_handler.UnixUserHandler( p_config=user_handler_config) _status_server = status_server.StatusServer( p_config=status_server_config, p_package_name=app.PACKAGE_NAME, p_app_control=_app_control, p_master_connector=_master_connector, p_persistence=_persistence, p_is_master=True, p_user_handler=user_handler, p_locale_helper=locale_helper.LocaleHelper()) return _status_server
def test_retrieve_user_mappings(self): config = app_control.AppControlConfigModel() ac = app_control.AppControl(p_config=config, p_debug_mode=False, p_persistence=test_persistence. TestPersistence.create_dummy_persistence( self._logger)) ac.retrieve_user_mappings()
def test_constructor(self): config = app_control.AppControlConfigModel() ac = app_control.AppControl(p_config=config, p_debug_mode=False, p_persistence=test_persistence. TestPersistence.create_dummy_persistence( self._logger)) self.assertIsNotNone(ac)
def test_get_number_of_monitored_users_function(self): config = app_control.AppControlConfigModel() ac = app_control.AppControl(p_config=config, p_debug_mode=False, p_persistence=test_persistence. TestPersistence.create_dummy_persistence( self._logger)) func = ac.get_number_of_monitored_users_function() self.assertIsNotNone(func) self.assertEqual(func(), 0)
def test_is_master(self): mc_config = master_connector.MasterConnectorConfigModel() config = app_control.AppControlConfigModel() mc = master_connector.MasterConnector(p_config=mc_config) ac = app_control.AppControl(p_config=config, p_debug_mode=False, p_master_connector=mc, p_persistence=test_persistence. TestPersistence.create_dummy_persistence( self._logger)) self.assertTrue(ac.is_master())
def test_check_interval(self): config = app_control.AppControlConfigModel() config.check_interval = 123 ac = app_control.AppControl(p_config=config, p_debug_mode=False, p_persistence=test_persistence. TestPersistence.create_dummy_persistence( self._logger)) self.assertIsNotNone(ac) check_interval = ac.check_interval self.assertEqual(check_interval, 123)
def test_is_slave(self): mc_config = master_connector.MasterConnectorConfigModel() mc_config.host_url = "http://master.domain/" config = app_control.AppControlConfigModel() mc = master_connector.MasterConnector(p_config=mc_config) ac = app_control.AppControl(p_config=config, p_debug_mode=False, p_master_connector=mc, p_persistence=test_persistence. TestPersistence.create_dummy_persistence( self._logger)) self.assertFalse(ac.is_master())
def load_configuration(self, p_configuration): app_control_section = app_control.AppControlConfigModel() p_configuration.add_section(app_control_section) audio_handler_section = audio_handler.AudioHandlerConfigModel() p_configuration.add_section(audio_handler_section) popup_handler_section = popup_handler.PopupHandlerConfigModel() p_configuration.add_section(popup_handler_section) persistence_section = persistence.PersistenceConfigModel() p_configuration.add_section(persistence_section) rule_handler_section = rule_handler.RuleHandlerConfigModel() p_configuration.add_section(rule_handler_section) self._rule_set_section_handler = rule_handler.RuleSetSectionHandler() p_configuration.register_section_handler( p_section_handler=self._rule_set_section_handler) client_process_handler_section = client_process_handler.ClientProcessHandlerConfigModel( ) p_configuration.add_section(client_process_handler_section) client_device_handler_section = client_device_handler.ClientDeviceHandlerConfigModel( ) p_configuration.add_section(client_device_handler_section) self._client_device_section_handler = client_device_handler.ClientDeviceSectionHandler( ) p_configuration.register_section_handler( p_section_handler=self._client_device_section_handler) status_server_section = status_server.StatusServerConfigModel() p_configuration.add_section(status_server_section) master_connector_section = master_connector.MasterConnectorConfigModel( ) p_configuration.add_section(master_connector_section) self.app_config = AppConfigModel() p_configuration.add_section(self.app_config) return super(App, self).load_configuration(p_configuration=p_configuration)
def create_dummy_status_server(p_process_handlers=None, p_ruleset_configs=None): if p_process_handlers is None: p_process_handlers = {} if p_ruleset_configs is None: p_ruleset_configs = {} _persistence = test_persistence.TestPersistence.create_dummy_persistence( ) _rule_handler = test_rule_handler.TestRuleHandler.create_dummy_rule_handler( p_ruleset_configs=p_ruleset_configs) master_connector_config = master_connector.MasterConnectorConfigModel() _master_connector = master_connector.MasterConnector( p_config=master_connector_config) app_control_config = app_control.AppControlConfigModel() _app_control = app_control.AppControl( p_config=app_control_config, p_debug_mode=False, p_process_handlers=p_process_handlers, p_persistence=_persistence, p_rule_handler=_rule_handler, p_notification_handlers=[], p_rule_set_configs=p_ruleset_configs, p_master_connector=_master_connector, p_username_map=test_data.USERNAME_MAP) status_server_config = status_server.StatusServerConfigModel() status_server_config.admin_username = ADMIN_USERNAME status_server_config.admin_password = ADMIN_PASSWORD status_server_config.app_secret = "secret!" status_server_config.port = int(os.getenv("STATUS_SERVER_PORT", "5555")) _status_server = status_server.StatusServer( p_config=status_server_config, p_package_name=app.PACKAGE_NAME, p_app_control=_app_control, p_master_connector=_master_connector, p_is_master=True) return _status_server
def test_constructor2(self): config = app_control.AppControlConfigModel() config.hostname = HOSTNAME rule_set_configs = test_rule_handler.TestRuleHandler.create_dummy_ruleset_configs( ) dummy_persistence = p_persistence = test_persistence.TestPersistence.create_dummy_persistence( self._logger) ac = app_control.AppControl( p_config=config, p_debug_mode=False, p_rule_handler=test_rule_handler.TestRuleHandler. create_dummy_rule_handler(p_persistence=dummy_persistence), p_persistence=dummy_persistence) self.assertIsNotNone(ac)
def test_set_metrics(self): pc_config = prometheus.PrometheusClientConfigModel() config = app_control.AppControlConfigModel() pc = prometheus.PrometheusClient(p_logger=self._logger, p_config=pc_config) ac = app_control.AppControl(p_config=config, p_debug_mode=False, p_prometheus_client=pc, p_persistence=test_persistence. TestPersistence.create_dummy_persistence( self._logger)) ac.set_prometheus_http_requests_summary(p_duration=1.0, p_hostname=HOSTNAME, p_service="/app") ac.set_metrics() pc.stop()
def prepare_configuration(self, p_configuration): app_control_section = app_control.AppControlConfigModel() p_configuration.add_section(app_control_section) audio_handler_section = audio_handler.AudioHandlerConfigModel() audio_handler_section.spool_dir = os.path.join("/var/spool", constants.DIR_NAME) p_configuration.add_section(audio_handler_section) popup_handler_section = popup_handler.PopupHandlerConfigModel() p_configuration.add_section(popup_handler_section) persistence_section = persistence.PersistenceConfigModel() persistence_section.sqlite_dir = os.path.join("/var/spool", constants.DIR_NAME) p_configuration.add_section(persistence_section) rule_handler_section = rule_handler.RuleHandlerConfigModel() p_configuration.add_section(rule_handler_section) self._rule_set_section_handler = rule_handler.RuleSetSectionHandler() p_configuration.register_section_handler( p_section_handler=self._rule_set_section_handler) client_process_handler_section = client_process_handler.ClientProcessHandlerConfigModel( ) p_configuration.add_section(client_process_handler_section) client_device_handler_section = client_device_handler.ClientDeviceHandlerConfigModel( ) p_configuration.add_section(client_device_handler_section) self._client_device_section_handler = client_device_handler.ClientDeviceSectionHandler( ) p_configuration.register_section_handler( p_section_handler=self._client_device_section_handler) status_server_section = status_server.StatusServerConfigModel() p_configuration.add_section(status_server_section) master_connector_section = master_connector.MasterConnectorConfigModel( ) p_configuration.add_section(master_connector_section) prometheus_client_section = prometheus.PrometheusClientConfigModel() p_configuration.add_section(prometheus_client_section) self.app_config = AppConfigModel() p_configuration.add_section(self.app_config) user_handler_section = unix_user_handler.BaseUserHandlerConfigModel() p_configuration.add_section(user_handler_section) self._login_mapping_section_handler = login_mapping.LoginMappingSectionHandler( ) p_configuration.register_section_handler( p_section_handler=self._login_mapping_section_handler) return super( App, self).prepare_configuration(p_configuration=p_configuration)