From 7149b14d36103d49cabb70f2565c5554e2adb69f Mon Sep 17 00:00:00 2001 From: Luciano Lo Giudice Date: Mon, 13 Mar 2023 18:18:55 -0300 Subject: [PATCH 1/2] Conditionally change the local DB file name This PR tests whether the ops library is present in the system to decide the final file name for the local key/value database, in order to avoid conflicts between that library and charmhelpers. --- charmhelpers/core/unitdata.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/charmhelpers/core/unitdata.py b/charmhelpers/core/unitdata.py index ab554327b..ae2861aa2 100644 --- a/charmhelpers/core/unitdata.py +++ b/charmhelpers/core/unitdata.py @@ -173,12 +173,24 @@ class Storage(object): """ def __init__(self, path=None): self.db_path = path + # The following is a hack to work around a bug in which both the + # ops framework libraries and charmhelpers end up using the same + # DB path, which leads to conflicts. + # See: https://bugs.launchpad.net/charm-ceph-mon/+bug/2005137 + db_suffix = '.unit-state.db' + try: + import ops + db_suffix = '.unit-state2.db' + ops = None # Don't hold an unneeded reference. + except: + pass + if path is None: if 'UNIT_STATE_DB' in os.environ: self.db_path = os.environ['UNIT_STATE_DB'] else: self.db_path = os.path.join( - os.environ.get('CHARM_DIR', ''), '.unit-state.db') + os.environ.get('CHARM_DIR', ''), db_suffix) if self.db_path != ':memory:': with open(self.db_path, 'a') as f: os.fchmod(f.fileno(), 0o600) From 43f5c619485d75b9924750d9c069fed3298b93c2 Mon Sep 17 00:00:00 2001 From: Luciano Lo Giudice Date: Thu, 16 Mar 2023 12:28:33 -0300 Subject: [PATCH 2/2] Fix pep8 error --- charmhelpers/core/unitdata.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charmhelpers/core/unitdata.py b/charmhelpers/core/unitdata.py index 2d56bd9f2..eb7245309 100644 --- a/charmhelpers/core/unitdata.py +++ b/charmhelpers/core/unitdata.py @@ -181,7 +181,7 @@ def __init__(self, path=None, keep_revisions=False): try: import ops db_suffix = '.unit-state2.db' - ops = None # Don't hold an unneeded reference. + del ops # Don't hold an unneeded reference. except: pass