def watcher_parser(config_file, logname, prom_client): """Return Watcher instances from config.""" conf, _ = config_parser_util.read_config(config_file, logname) conf_hash = config_parser_util.config_file_hash(config_file) faucet_config_files, faucet_conf_hashes, result = _watcher_parser_v2( conf, logname, prom_client) return conf_hash, faucet_config_files, faucet_conf_hashes, result
def _check_hashes(self): """Verify and return faucet_config_hash_info labels""" labels = self._get_info(metric=self.metrics.faucet_config_hash, name='faucet_config_hash_info') files = labels['config_files'].split(',') hashes = labels['hashes'].split(',') self.assertTrue(len(files) == len(hashes) == 1) self.assertEqual(files[0], self.config_file, 'wrong config file') hash_value = config_parser_util.config_file_hash(self.config_file) self.assertEqual(hashes[0], hash_value, 'hash validation failed') return labels
def _config_changed(self, new_config_file): """Return True if configuration has changed. Args: new_config_file (str): name, possibly new, of FAUCET config file. Returns: bool: True if the file, or any file it includes, has changed. """ if new_config_file != self.config_file: return True for config_file, config_hash in list(self.config_hashes.items()): config_file_exists = os.path.isfile(config_file) # Config file not loaded but exists = reload. if config_hash is None and config_file_exists: return True # Config file loaded but no longer exists = reload. if config_hash and not config_file_exists: return True # Config file hash has changed = reload. new_config_hash = config_file_hash(config_file) if new_config_hash != config_hash: return True return False