def _update_component_dependencies_pv(self, name): # Updates PV with list of configs that depend on a component configs = [] if name in self._comp_dependencies.keys(): configs = self._comp_dependencies[name] if name in self._component_metas.keys(): # Check just in case component failed to load pv_name = BlockserverPVNames.get_dependencies_pv(self._component_metas[name].pv) self._update_pv_value(pv_name, compress_and_hex(json.dumps(configs)))
def delete(self, delete_list, are_comps=False): """Takes a list of configurations and removes them from the file system and any relevant PVs. Args: delete_list (list): The configurations/components to delete are_comps (bool): Whether they are components or not """ with self._lock: # TODO: clean this up? print_and_log("Deleting: " + ", ".join(list(delete_list)), "INFO") lower_delete_list = set([x.lower() for x in delete_list]) unable_to_remove_text = "Unable to remove %s from version control: %s" if not are_comps: if self.active_config_name.lower() in lower_delete_list: raise InvalidDeleteException("Cannot delete currently active configuration") if not lower_delete_list.issubset(self._config_metas.keys()): raise InvalidDeleteException("Delete list contains unknown configurations") for config in delete_list: self._delete_pv(BlockserverPVNames.get_config_details_pv(self._config_metas[config.lower()].pv)) del self._config_metas[config.lower()] self._remove_config_from_dependencies(config) try: self._update_version_control_post_delete(self._conf_path, delete_list) # Git is case sensitive except Exception as err: print_and_log(unable_to_remove_text % ("configuration", str(err)), "MINOR") else: if DEFAULT_COMPONENT.lower() in lower_delete_list: raise InvalidDeleteException("Cannot delete default component") # Only allow comps to be deleted if they appear in no configs for comp in lower_delete_list: if self._comp_dependencies.get(comp): raise InvalidDeleteException( comp + " is in use in: " + ", ".join(self._comp_dependencies[comp]) ) if not lower_delete_list.issubset(self._component_metas.keys()): raise InvalidDeleteException("Delete list contains unknown components") for comp in lower_delete_list: self._delete_pv(BlockserverPVNames.get_component_details_pv(self._component_metas[comp].pv)) self._delete_pv(BlockserverPVNames.get_dependencies_pv(self._component_metas[comp].pv)) del self._component_metas[comp] try: self._update_version_control_post_delete(self._comp_path, delete_list) except Exception as err: print_and_log(unable_to_remove_text % ("component", str(err)), "MINOR") self.update_monitors()