X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_policy_module%2Fcmd%2Fpolicy_module_agent.py;h=43dbc343c54b8b5e7d6eedc00c445b1b7dc405aa;hb=3fbf2fbf60e3aed3ec7ca0134839f19bc0d733d4;hp=050cf32021d063243b4835697adb31decbfcb8d1;hpb=a14cf16181c8b39f12c872c486e0b292c0068944;p=osm%2FPOL.git diff --git a/osm_policy_module/cmd/policy_module_agent.py b/osm_policy_module/cmd/policy_module_agent.py index 050cf32..43dbc34 100644 --- a/osm_policy_module/cmd/policy_module_agent.py +++ b/osm_policy_module/cmd/policy_module_agent.py @@ -25,6 +25,7 @@ import argparse import asyncio import logging import sys +import os from osm_policy_module.core.agent import PolicyModuleAgent from osm_policy_module.core.config import Config @@ -32,24 +33,30 @@ from osm_policy_module.core.database import DatabaseManager def main(): - parser = argparse.ArgumentParser(prog='osm-policy-agent') - parser.add_argument('--config-file', nargs='?', help='POL configuration file') + # Cleanup old temp health file + if os.path.exists("/tmp/osm_pol_agent_health_flag"): + os.remove("/tmp/osm_pol_agent_health_flag") + + parser = argparse.ArgumentParser(prog="osm-policy-agent") + parser.add_argument("--config-file", nargs="?", help="POL configuration file") args = parser.parse_args() cfg = Config(args.config_file) root = logging.getLogger() - root.setLevel(logging.getLevelName(cfg.get('global', 'loglevel'))) + root.setLevel(logging.getLevelName(cfg.get("global", "loglevel"))) ch = logging.StreamHandler(sys.stdout) - ch.setLevel(logging.getLevelName(cfg.get('global', 'loglevel'))) - formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s', '%m/%d/%Y %I:%M:%S %p') + ch.setLevel(logging.getLevelName(cfg.get("global", "loglevel"))) + formatter = logging.Formatter( + "%(asctime)s - %(name)s - %(levelname)s - %(message)s", "%m/%d/%Y %I:%M:%S %p" + ) ch.setFormatter(formatter) root.addHandler(ch) log = logging.getLogger(__name__) log.debug("Config: %s", cfg.conf) log.info("Initializing database...") - db_manager = DatabaseManager() - db_manager.init_db(cfg) + db_manager = DatabaseManager(cfg) + db_manager.create_tables() log.info("Database initialized correctly.") log.info("Starting policy module agent...") loop = asyncio.get_event_loop() @@ -57,5 +64,5 @@ def main(): agent.run() -if __name__ == '__main__': +if __name__ == "__main__": main()