Skip to content

Instantly share code, notes, and snippets.

@nottrobin
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nottrobin/6b801cad77a8e6afdad8 to your computer and use it in GitHub Desktop.
Save nottrobin/6b801cad77a8e6afdad8 to your computer and use it in GitHub Desktop.
Testing charm locally by overriding charmhelpers log and config
# 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