Last active
August 29, 2015 14:01
-
-
Save nottrobin/6b801cad77a8e6afdad8 to your computer and use it in GitHub Desktop.
Testing charm locally by overriding charmhelpers log and config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Override "log" and "config" methods from charmhelpers | |
# so that they work outside of a juju context | |
# from charmhelpers.core.hookenv import config | |
# from charmhelpers.core.host import log | |
import yaml | |
def log(message): | |
print message | |
config_data = {} | |
with open(path.join(charm_dir, 'config.yaml')) as default_config_file: | |
default_yaml_data = yaml.load(default_config_file) | |
for option, settings in default_yaml_data['options'].iteritems(): | |
config_data[option] = settings.get('default', '') | |
with open('config.yaml') as config_file: | |
yaml_data = yaml.load(config_file) | |
for option, value in yaml_data['apache2-wsgi'].iteritems(): | |
config_data[option] = value | |
def config(key): | |
if key not in config_data: | |
raise Exception("Not a config option") | |
return config_data[key] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment