Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DPE-5540 Skip plugin install for not file found #524

Merged
merged 5 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 37 additions & 6 deletions lib/charms/mysql/v0/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def wait_until_mysql_connection(self) -> None:
# Increment this major API version when introducing breaking changes
LIBAPI = 0

LIBPATCH = 73
LIBPATCH = 74

UNIT_TEARDOWN_LOCKNAME = "unit-teardown"
UNIT_ADD_LOCKNAME = "unit-add"
Expand Down Expand Up @@ -1085,16 +1085,25 @@ def configure_mysql_users(self, password_needed: bool = True) -> None:
)
raise MySQLConfigureMySQLUsersError(e.message)

def _plugin_file_exists(self, plugin_file_name: str) -> bool:
"""Check if the plugin file exists.

Args:
plugin_file_name: Plugin file name, with the extension.

"""
path = self.get_variable_value("plugin_dir")
return self._file_exists(f"{path}/{plugin_file_name}")

def install_plugins(self, plugins: list[str]) -> None:
"""Install extra plugins."""
supported_plugins = {
"audit_log": "INSTALL PLUGIN audit_log SONAME 'audit_log.so';",
"audit_log_filter": "INSTALL PLUGIN audit_log_filter SONAME 'audit_log_filter.so';",
"audit_log": ("INSTALL PLUGIN audit_log SONAME", "audit_log.so"),
"audit_log_filter": ("INSTALL PLUGIN audit_log_filter SONAME", "audit_log_filter.so"),
}

super_read_only = self.get_variable_value("super_read_only").lower() == "on"

try:
super_read_only = self.get_variable_value("super_read_only").lower() == "on"
installed_plugins = self._get_installed_plugins()
# disable super_read_only to install plugins
for plugin in plugins:
Expand All @@ -1106,7 +1115,16 @@ def install_plugins(self, plugins: list[str]) -> None:
logger.warning(f"{plugin=} is not supported")
continue

command = supported_plugins[plugin]
command_prefix, plugin_file = (
supported_plugins[plugin][0],
supported_plugins[plugin][1],
)

if not self._plugin_file_exists(plugin_file):
logger.warning(f"{plugin=} file not found. Skip installation")
continue

command = f"{command_prefix} '{plugin_file}';"
if super_read_only:
command = (
f"SET GLOBAL super_read_only=OFF; {command}"
Expand All @@ -1123,6 +1141,10 @@ def install_plugins(self, plugins: list[str]) -> None:
f"Failed to install {plugin=}", # type: ignore
)
raise MySQLPluginInstallError
except MySQLGetVariableError:
# workaround for config changed triggered after failed upgrade
# the check fails for charms revisions not using admin address
logger.warning("Failed to get super_read_only variable. Skip plugin installation")

def uninstall_plugins(self, plugins: list[str]) -> None:
"""Uninstall plugins."""
Expand Down Expand Up @@ -3147,3 +3169,12 @@ def _run_mysqlcli_script(
timeout: (optional) time before the query should timeout
"""
raise NotImplementedError

@abstractmethod
def _file_exists(self, path: str) -> bool:
"""Check if a file exists.

Args:
path: Path to the file to check
"""
raise NotImplementedError
1 change: 1 addition & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class MySQLConfig:
"log_error",
"loose-audit_log_strategy",
"loose-audit_log_format",
"admin_address",
}

def __init__(self, config_file_path: str):
Expand Down
4 changes: 4 additions & 0 deletions src/mysql_vm_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,10 @@ def is_data_dir_initialised(self) -> bool:
except FileNotFoundError:
return False

def _file_exists(self, path: str) -> bool:
"""Check if file exists."""
return os.path.exists(path)

@staticmethod
def write_content_to_file(
path: str,
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2040,6 +2040,7 @@ def test_get_cluster_set_name(self, _get_cluster_set_status):

self.assertEqual(self.mysql.get_cluster_set_name(), self.mysql.cluster_set_name)

@patch("charms.mysql.v0.mysql.MySQLBase._file_exists", return_value=True)
@patch("charms.mysql.v0.mysql.MySQLBase.get_variable_value")
@patch("charms.mysql.v0.mysql.MySQLBase._get_installed_plugins")
@patch("charms.mysql.v0.mysql.MySQLBase._run_mysqlcli_script")
Expand All @@ -2048,6 +2049,7 @@ def test_install_plugin(
_run_mysqlcli_script,
_get_installed_plugins,
_get_variable_value,
_file_exists,
):
"""Test install_plugin."""
_get_variable_value.return_value = "ON"
Expand Down
Loading