def _monitor_conf_updates(self): """ Monitor all config files for any change """ LOG.info(_("Started configuration updates monitor")) old_timestamp = {} config_files = CONF.config_file try: for config_file in config_files: old_timestamp[config_file] = self.\ _get_lastmodifiedtime(config_file) while self.state not in (State.STOPPED, State.STOPPING): try: for config_file in config_files: current_timestamp = self.\ _get_lastmodifiedtime(config_file) if current_timestamp != old_timestamp[config_file]: LOG.info(_("%s updated.") % config_file) # reload all oslo config files LOG.debug(_("Reloading oslo-config opts.")) config.parse(["--config-file=%s" % f for f in config_files]) old_timestamp[config_file] = current_timestamp eventlet.spawn_n(self._handle_conf_updates) except OSError as e: LOG.error(_("Failed to monitor file %(config_file)s." "Cause %(error)s "), {'config_file': config_file, 'error': e}) time.sleep(CONF.conf_file_poll_interval) except OSError as e: LOG.error(_("Failed to monitor file %(config_file)s." "Cause %(error)s "), {'config_file': config_file, 'error': e})
def test_parse(self): config_file = os.path.join(self.temp_dir, "ovsvapp_agent.ini") with open(config_file, 'w') as fd: fd.write("[DEFAULT]\ntest_arg=test_val") argv = ['test_config', '--config-file=%s' % config_file] config.parse(argv[1:]) test_opts = [cfg. StrOpt('test_arg', help=_("Test CONF item"), default=_("test_val_def"))] CONF.register_opts(test_opts) self.assertEqual(CONF.test_arg, "test_val")
def main(): signal.signal(signal.SIGTERM, signal_handler) signal.signal(signal.SIGINT, signal_handler) eventlet.monkey_patch() config.parse(sys.argv[1:]) if not CONF.config_file: sys.exit(_("ERROR: Unable to find configuration file")) agent_obj = None try: config.setup_logging() LOG.info(_("Loading agent %s"), CONF.agent_driver) agent_obj = utils.load_object(CONF.agent_driver, agent.Agent) agent_obj.start() except Exception as e: LOG.exception(_("Error in L2 agent service")) if agent_obj: agent_obj.stop() sys.exit(_("ERROR: %s") % e)