~charmers/charms/wily/ubuntu/trunk

« back to all changes in this revision

Viewing changes to hooks/hooks.py

  • Committer: Tim Van Steenburgh
  • Date: 2015-05-01 10:12:08 UTC
  • mfrom: (10.1.4 ubuntu)
  • Revision ID: tim.van.steenburgh@canonical.com-20150501101208-7jvqc9dtmlfz7kvk
[1chb1n] Remove hooks and lxc stuff; update tests

Revert charm to have no hooks and no config options; add functional tests for all currently-supported Ubuntu releases; add bundletester usage examples.

Charm is now compatible with both 'juju test' and bundletester.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
 
3
 
#
4
 
# Copyright 2015 Canonical Ltd.
5
 
#
6
 
# Authors:
7
 
#  Liang Chen <liang.chen@ubuntu.com>
8
 
#
9
 
 
10
 
import subprocess
11
 
import sys
12
 
 
13
 
from charmhelpers.core.hookenv import (
14
 
    config,
15
 
    Hooks, UnregisteredHookError,
16
 
    log,
17
 
)
18
 
 
19
 
from utils import render_template
20
 
 
21
 
hooks = Hooks()
22
 
 
23
 
 
24
 
def emit_lxc_br_conf():
25
 
    lxc_context = {}
26
 
    if config('new-lxc-network'):
27
 
        lxc_context['new_network'] = True
28
 
 
29
 
    lxc_bridge_conf = "/etc/network/interfaces.d/lxcbr0.cfg"
30
 
    with open(lxc_bridge_conf, 'w') as lxc_br_conf:
31
 
        lxc_br_conf.write(render_template('lxc-bridge.conf', lxc_context))
32
 
 
33
 
 
34
 
@hooks.hook('config-changed')
35
 
def config_changed():
36
 
    emit_lxc_br_conf()
37
 
    cmd = ['ifup', 'lxcbr0']
38
 
    subprocess.check_call(cmd)
39
 
 
40
 
 
41
 
if __name__ == '__main__':
42
 
    try:
43
 
        hooks.execute(sys.argv)
44
 
    except UnregisteredHookError as e:
45
 
        log('Unknown hook {} - skipping.'.format(e))