Fix persistent config file not update bug

When ceph doing the version upgrade, it will check the previous ceph
from the `source` config variable which store in persistent file.
But the persistent file update is broken. It is because we use hookenv.Config
from ops framework, but the hookenv._run_atexit, which
save the change to file, is not been called.

Partial-Bug: #2007976
Change-Id: Ibf12a2b87736cb1d32788672fb390e027f15b936
func-test-pr: https://github.com/openstack-charmers/zaza-openstack-tests/pull/1047
This commit is contained in:
jneo8 2023-04-27 14:31:39 +08:00
parent 357421f391
commit e99c38ae4c
3 changed files with 15 additions and 0 deletions

View File

@ -157,6 +157,13 @@ class CephMonCharm(ops_openstack.core.OSBaseCharm):
def on_commit(self, _event):
self.ceph_status.assess_status()
def on_pre_commit(self, _event):
# Fix bug: https://bugs.launchpad.net/charm-ceph-mon/+bug/2007976
# The persistent config file doesn't update because the config save
# function handled by atexit is not triggered.
# Trigger it manually here.
hooks.hookenv._run_atexit()
# Actions.
def _observe_action(self, on_action, callable):
@ -273,6 +280,8 @@ class CephMonCharm(ops_openstack.core.OSBaseCharm):
fw.observe(self.on.notify_clients, self.notify_clients)
fw.observe(self.on.framework.on.pre_commit, self.on_pre_commit)
def ready_for_service(self):
return hooks.ready_for_service()

View File

@ -26,6 +26,7 @@ tests:
- zaza.openstack.charm_tests.ceph.tests.CephPrometheusTest
# Charm upgrade, then re-run tests
- zaza.charm_tests.lifecycle.tests.UpgradeCharmsToPath;ceph-mon
- zaza.openstack.charm_tests.ceph.tests.CephMonJujuPersistent
- zaza.openstack.charm_tests.ceph.tests.CheckPoolTypes
- zaza.openstack.charm_tests.ceph.tests.CephLowLevelTest
- zaza.openstack.charm_tests.ceph.tests.CephTest

View File

@ -63,3 +63,8 @@ class TestCephCharm(unittest.TestCase):
fatal=True,
)
apt_update.assert_called()
@patch("charm.hooks")
def test_on_pre_commit(self, hooks):
self.harness.charm.on.framework.on.pre_commit.emit()
hooks.hookenv._run_atexit.assert_called()