diff --git a/lib/charms/opensearch/v0/opensearch_plugin_manager.py b/lib/charms/opensearch/v0/opensearch_plugin_manager.py index 6ef2ff12f..dc362df6d 100644 --- a/lib/charms/opensearch/v0/opensearch_plugin_manager.py +++ b/lib/charms/opensearch/v0/opensearch_plugin_manager.py @@ -13,7 +13,6 @@ import logging from typing import Any, Dict, List, Optional -from charms.opensearch.v0.opensearch_backups import OpenSearchBackupPlugin from charms.opensearch.v0.opensearch_exceptions import ( OpenSearchCmdError, OpenSearchNotFullyReadyError, @@ -53,11 +52,6 @@ "config": "plugin_opensearch_knn", "relation": None, }, - "repository-s3": { - "class": OpenSearchBackupPlugin, - "config": None, - "relation": "s3-credentials", - }, } @@ -163,7 +157,12 @@ def run(self) -> bool: restart_needed, ] ) - except OpenSearchPluginMissingConfigError as e: + except ( + OpenSearchPluginMissingDepsError, + OpenSearchPluginMissingConfigError, + OpenSearchPluginInstallError, + OpenSearchPluginRemoveError, + ) as e: # This is a more serious issue, as we are missing some input from # the user. The charm should block. raise e @@ -183,9 +182,7 @@ def _install_plugin(self, plugin: OpenSearchPlugin) -> bool: if plugin.dependencies: missing_deps = [dep for dep in plugin.dependencies if dep not in installed_plugins] if missing_deps: - raise OpenSearchPluginMissingDepsError( - f"Failed to install {plugin.name}, missing dependencies: {missing_deps}" - ) + raise OpenSearchPluginMissingDepsError(plugin.name, missing_deps) # Add the plugin try: @@ -198,9 +195,7 @@ def _install_plugin(self, plugin: OpenSearchPlugin) -> bool: # Check for dependencies missing_deps = [dep for dep in plugin.dependencies if dep not in installed_plugins] if missing_deps: - raise OpenSearchPluginMissingDepsError( - f"Failed to install {plugin.name}, missing dependencies: {missing_deps}" - ) + raise OpenSearchPluginMissingDepsError(plugin.name, missing_deps) self._opensearch.run_bin("opensearch-plugin", f"install --batch {plugin.name}") except KeyError as e: @@ -210,7 +205,7 @@ def _install_plugin(self, plugin: OpenSearchPlugin) -> bool: logger.info(f"Plugin {plugin.name} already installed, continuing...") # Nothing installed, as plugin already exists return False - raise OpenSearchPluginInstallError(f"Failed to install plugin {plugin.name}: {e}") + raise OpenSearchPluginInstallError(plugin.name) # Install successful return True @@ -240,7 +235,7 @@ def _configure_if_needed(self, plugin: OpenSearchPlugin) -> bool: return False return self.apply_config(plugin.config()) except KeyError as e: - raise OpenSearchPluginMissingConfigError(e) + raise OpenSearchPluginMissingConfigError(plugin.name, configs=[f"{e}"]) def _disable_if_needed(self, plugin: OpenSearchPlugin) -> bool: """If disabled, removes plugin configuration or sets it to other values.""" @@ -255,7 +250,7 @@ def _disable_if_needed(self, plugin: OpenSearchPlugin) -> bool: return False return self.apply_config(plugin.disable()) except KeyError as e: - raise OpenSearchPluginMissingConfigError(e) + raise OpenSearchPluginMissingConfigError(plugin.name, configs=[f"{e}"]) def apply_config(self, config: OpenSearchPluginConfig) -> bool: """Runs the configuration changes as passed via OpenSearchPluginConfig. @@ -373,7 +368,7 @@ def _remove_plugin(self, plugin: OpenSearchPlugin) -> bool: if "not found" in str(e): logger.info(f"Plugin {plugin.name} to be deleted, not found. Continuing...") return False - raise OpenSearchPluginRemoveError(f"Failed to remove plugin {plugin.name}: {e}") + raise OpenSearchPluginRemoveError(plugin.name) return True def _installed_plugins(self) -> List[str]: diff --git a/lib/charms/opensearch/v0/opensearch_plugins.py b/lib/charms/opensearch/v0/opensearch_plugins.py index 8d2f63f9d..56735f336 100644 --- a/lib/charms/opensearch/v0/opensearch_plugins.py +++ b/lib/charms/opensearch/v0/opensearch_plugins.py @@ -301,14 +301,24 @@ def __init__(self, msg): class OpenSearchPluginMissingDepsError(OpenSearchPluginError): """Exception thrown when an opensearch plugin misses installed dependencies.""" + def __init__(self, name, deps): + super().__init__(f"Failed to install plugin: {name} - missing dependencies {deps}") + self.deps = deps + class OpenSearchPluginInstallError(OpenSearchPluginError): """Exception thrown when opensearch plugin installation fails.""" + def __init__(self, name): + super().__init__("Failed to install plugin: {}".format(name)) + class OpenSearchPluginRemoveError(OpenSearchPluginError): """Exception thrown when opensearch plugin removal fails.""" + def __init__(self, name): + super().__init__("Failed to remove plugin: {}".format(name)) + class OpenSearchPluginMissingConfigError(OpenSearchPluginError): """Exception thrown when config() or disable() fails to find a config key. @@ -316,6 +326,10 @@ class OpenSearchPluginMissingConfigError(OpenSearchPluginError): The plugin itself should raise a KeyError, to avoid burden in the plugin development. """ + def __init__(self, name, configs: List[str]): + super().__init__(f"Plugin {name} is missing configs: {configs}") + self.configs = configs + class OpenSearchPluginEventScope(BaseStrEnum): """Defines the scope of the plugin manager.""" @@ -472,7 +486,12 @@ def config(self) -> OpenSearchPluginConfig: """ if not self._extra_config.get("access-key") or not self._extra_config.get("secret-key"): raise OpenSearchPluginMissingConfigError( - "Missing AWS access-key and secret-key configuration" + self.name, + [ + conf + for conf in ["access-key", "secret-key"] + if not self._extra_config.get(conf) + ], ) return OpenSearchPluginConfig(