Merge "Use a different name for the local key/value store"
This commit is contained in:
commit
7ea8cf6a35
26
src/charm.py
26
src/charm.py
|
@ -1,5 +1,7 @@
|
||||||
#! /usr/bin/python3
|
#! /usr/bin/python3
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
|
||||||
from ops.main import main
|
from ops.main import main
|
||||||
|
|
||||||
|
@ -47,6 +49,8 @@ class CephMonCharm(ops_openstack.core.OSBaseCharm):
|
||||||
'radosgw', 'lvm2', 'parted', 'smartmontools',
|
'radosgw', 'lvm2', 'parted', 'smartmontools',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
NEW_DB_PATH = '.charmhelpers-unit-state.db'
|
||||||
|
|
||||||
on = CephCharmEvents()
|
on = CephCharmEvents()
|
||||||
|
|
||||||
# General charm control callbacks.
|
# General charm control callbacks.
|
||||||
|
@ -83,12 +87,29 @@ class CephMonCharm(ops_openstack.core.OSBaseCharm):
|
||||||
if hooks.config_changed():
|
if hooks.config_changed():
|
||||||
self.on.notify_clients.emit()
|
self.on.notify_clients.emit()
|
||||||
|
|
||||||
|
def make_db_path(self, suffix):
|
||||||
|
return os.path.join(os.environ.get('CHARM_DIR', ''), suffix)
|
||||||
|
|
||||||
|
def migrate_db(self):
|
||||||
|
"""
|
||||||
|
Migrate the Key/Value database into a new location.
|
||||||
|
This is done to avoid conflicts between charmhelpers and
|
||||||
|
the ops library, since they both use the same path and
|
||||||
|
with excluding lock semantics.
|
||||||
|
"""
|
||||||
|
db_path = self.make_db_path('.unit-state.db')
|
||||||
|
new_db_path = self.make_db_path(self.NEW_DB_PATH)
|
||||||
|
if os.path.exists(db_path) and not os.path.exists(new_db_path):
|
||||||
|
# The new DB doesn't exist yet. Copy it over.
|
||||||
|
shutil.copy(db_path, new_db_path)
|
||||||
|
|
||||||
def on_pre_series_upgrade(self, event):
|
def on_pre_series_upgrade(self, event):
|
||||||
hooks.pre_series_upgrade()
|
hooks.pre_series_upgrade()
|
||||||
|
|
||||||
def on_upgrade(self, event):
|
def on_upgrade(self, event):
|
||||||
self._initialise_config()
|
self._initialise_config()
|
||||||
self.metrics_endpoint.update_alert_rules()
|
self.metrics_endpoint.update_alert_rules()
|
||||||
|
self.migrate_db()
|
||||||
hooks.upgrade_charm()
|
hooks.upgrade_charm()
|
||||||
self.on.notify_clients.emit()
|
self.on.notify_clients.emit()
|
||||||
|
|
||||||
|
@ -175,6 +196,11 @@ class CephMonCharm(ops_openstack.core.OSBaseCharm):
|
||||||
"Not running hook, CMR detected and not supported")
|
"Not running hook, CMR detected and not supported")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Make the charmhelpers lib use a different DB path. This is done
|
||||||
|
# so as to avoid conflicts with what the ops framework uses.
|
||||||
|
# See: https://bugs.launchpad.net/charm-ceph-mon/+bug/2005137
|
||||||
|
os.environ['UNIT_STATE_DB'] = self.make_db_path(self.NEW_DB_PATH)
|
||||||
|
|
||||||
fw = self.framework
|
fw = self.framework
|
||||||
|
|
||||||
self.clients = ceph_client.CephClientProvides(self)
|
self.clients = ceph_client.CephClientProvides(self)
|
||||||
|
|
Loading…
Reference in New Issue