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

Conditionally change the local DB file name #759

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion charmhelpers/core/unitdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,25 @@ class Storage(object):
"""
def __init__(self, path=None, keep_revisions=False):
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'
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not a 'suffix'; it's a hidden file. e.g. db_suffix isn't quite right; db_file would be more accurate.

try:
import ops
db_suffix = '.unit-state2.db'
del ops # Don't hold an unneeded reference.
except:
pass
Comment on lines +181 to +186
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes charm-helpers dependent on ops, which is entirely the wrong way around.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I disagree that it creates a dependency. It merely checks that a library can be imported; charm-helpers doesn't require ops to be installed for it to work.


self.keep_revisions = keep_revisions
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)
Expand Down