-
Notifications
You must be signed in to change notification settings - Fork 128
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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' | ||
try: | ||
import ops | ||
db_suffix = '.unit-state2.db' | ||
del ops # Don't hold an unneeded reference. | ||
except: | ||
pass | ||
Comment on lines
+181
to
+186
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
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) | ||
|
There was a problem hiding this comment.
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.