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-5628 Skip set unknown config keys #532

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
42 changes: 21 additions & 21 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,6 @@ def _on_config_changed(self, _) -> None:
# the upgrade already restart the daemon
return

# restart not required if mysqld is not running
mysqld_running = self._mysql.is_mysqld_running()

previous_config = self.mysql_config.custom_config
if not previous_config:
# empty config means not initialized, skipping
Expand All @@ -298,30 +295,33 @@ def _on_config_changed(self, _) -> None:

changed_config = compare_dictionaries(previous_config, new_config_dict)

if self.mysql_config.keys_requires_restart(changed_config):
# there are static configurations in changed keys
logger.info("Persisting configuration changes to file")
# persist config to file
self._mysql.write_content_to_file(
path=MYSQLD_CUSTOM_CONFIG_FILE, content=new_config_content
)
if mysqld_running:
logger.info("Configuration change requires restart")
logger.info("Persisting configuration changes to file")
# always persist config to file
self._mysql.write_content_to_file(
path=MYSQLD_CUSTOM_CONFIG_FILE, content=new_config_content
)

if "loose-audit_log_format" in changed_config:
# plugins are manipulated running daemon
if self.config.plugin_audit_enabled:
self._mysql.install_plugins(["audit_log", "audit_log_filter"])
else:
self._mysql.uninstall_plugins(["audit_log", "audit_log_filter"])
if (
self.mysql_config.keys_requires_restart(changed_config)
and self._mysql.is_mysqld_running()
):
logger.info("Configuration change requires restart")
if "loose-audit_log_format" in changed_config:
# plugins are manipulated on running daemon
if self.config.plugin_audit_enabled:
self._mysql.install_plugins(["audit_log", "audit_log_filter"])
else:
self._mysql.uninstall_plugins(["audit_log", "audit_log_filter"])

self.on[f"{self.restart.name}"].acquire_lock.emit()
return
self.on[f"{self.restart.name}"].acquire_lock.emit()

if dynamic_config := self.mysql_config.filter_static_keys(changed_config):
elif dynamic_config := self.mysql_config.filter_static_keys(changed_config):
# if only dynamic config changed, apply it
logger.info("Configuration does not requires restart")
for config in dynamic_config:
if config not in new_config_dict:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these 3 lines are the main part

# skip removed configs
continue
self._mysql.set_dynamic_variable(config, new_config_dict[config])

def _on_start(self, event: StartEvent) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import asyncio
import logging
import subprocess
from time import sleep

import pytest
Expand Down Expand Up @@ -71,7 +72,37 @@ async def test_refresh_without_pre_upgrade_check(ops_test: OpsTest):
# 2. Rolling restart, if there's a configuration change
# for both, operations should continue to work
# and there's a mismatch between the charm and the snap
logger.info("Wait for rolling restart OR continue to writes")
logger.info("Wait (120s) for rolling restart OR continue to writes")
count = 0
while count < 2 * 60:
if "maintenance" in {unit.workload_status for unit in application.units}:
# Case when refresh triggers a rolling restart
logger.info("Waiting for rolling restart to complete")
await ops_test.model.wait_for_idle(
apps=[MYSQL_APP_NAME], status="active", idle_period=30, timeout=TIMEOUT
)
break
else:
count += 1
sleep(1)

await ensure_all_units_continuous_writes_incrementing(ops_test)


@pytest.mark.group(1)
@markers.amd64_only # TODO: remove after arm64 stable release
async def test_rollback_without_pre_upgrade_check(ops_test: OpsTest):
"""Test refresh back to stable channel."""
application = ops_test.model.applications[MYSQL_APP_NAME]

logger.info("Refresh the charm back to stable channel")
# pylibjuju refresh dont work for switch:
# https://github.com/juju/python-libjuju/issues/924
subprocess.check_output(
f"juju refresh {MYSQL_APP_NAME} --switch ch:{MYSQL_APP_NAME} --channel 8.0/stable".split()
)

logger.info("Wait (120s) for rolling restart OR continue to writes")
count = 0
while count < 2 * 60:
if "maintenance" in {unit.workload_status for unit in application.units}:
Expand All @@ -85,5 +116,4 @@ async def test_refresh_without_pre_upgrade_check(ops_test: OpsTest):
count += 1
sleep(1)

logger.info("Ensure continuous_writes")
await ensure_all_units_continuous_writes_incrementing(ops_test)
Loading