def test_fail_missing_config_key(self): with self.assertRaises(dataspace.DataSpaceConfigurationError): with mock.patch.object(dataspace.DataSourceLoader, "create_datasource") as source: source.return_value = MockSource() del GLOBAL_CONFIG["dataspace"]["retention_interval_in_days"] dataspace.Reaper(GLOBAL_CONFIG)
def main(): username = pwd.getpwuid(os.getuid()).pw_name if username not in ['root', 'decisionengine']: sys.exit(f"User '{username}' is not allowed to run this script.") config_file = policies.global_config_file() global_config = ValidConfig(config_file) reaper = dataspace.Reaper(global_config) reaper.reap()
def __init__(self, global_config, channel_config_loader, server_address): xmlrpc.server.SimpleXMLRPCServer.__init__(self, server_address, logRequests=False, requestHandler=RequestHandler) self.logger = logging.getLogger("decision_engine") signal.signal(signal.SIGHUP, self.handle_sighup) self.workers = Workers() self.channel_config_loader = channel_config_loader self.global_config = global_config self.dataspace = dataspace.DataSpace(self.global_config) self.reaper = dataspace.Reaper(self.global_config) self.logger.info("DecisionEngine started on {}".format(server_address))
def __init__(self, cfg, server_address, RequestHandlerClass): SimpleXMLRPCServer.SimpleXMLRPCServer.__init__( self, server_address, logRequests=False, requestHandler=RequestHandlerClass) self.logger = logging.getLogger("decision_engine") signal.signal(signal.SIGHUP, self.handle_sighup) self.task_managers = {} self.config_manager = cfg self.dataspace = dataspace.DataSpace( self.config_manager.get_global_config()) self.reaper = dataspace.Reaper(self.config_manager.get_global_config()) self.logger.info("DecisionEngine started on {}".format(server_address))
#!/usr/bin/env python3 """ A stand-alone script purges data in database older than specified in configuration. Configuration file has to have this bit added: { "dataspace" : { "retention_interval_in_days" : 365, "datasource" : { ... } } } Can be used in a cron job. """ import os import pwd import sys import decisionengine.framework.configmanager.ConfigManager as config import decisionengine.framework.dataspace.dataspace as dataspace if __name__ == "__main__": ALLOWED_USERS = ("root", "decisionengine") username = pwd.getpwuid(os.getuid()).pw_name if username not in ALLOWED_USERS: sys.stderr.write( "User '{}' is not allowed to run this script.\n".format(username)) sys.exit(1) conf_manager = config.ConfigManager() conf_manager.load() reaper = dataspace.Reaper(conf_manager.get_global_config()) reaper.reap()
def setUp(self): with mock.patch.object(dataspace.DataSourceLoader, "create_datasource") as source: source.return_value = MockSource() GLOBAL_CONFIG["dataspace"]["retention_interval_in_days"] = 365 self.reaper = dataspace.Reaper(GLOBAL_CONFIG)