Merge lp:~moon127/charms/precise/mongodb/add-execd-for-basenode into lp:charms/mongodb

Proposed by Gareth Woolridge
Status: Merged
Merged at revision: 51
Proposed branch: lp:~moon127/charms/precise/mongodb/add-execd-for-basenode
Merge into: lp:charms/mongodb
Diff against target: 109 lines (+58/-1)
5 files modified
.bzrignore (+1/-0)
charm-helpers-sync.yaml (+1/-0)
hooks/charmhelpers/payload/__init__.py (+1/-0)
hooks/charmhelpers/payload/execd.py (+50/-0)
hooks/hooks.py (+5/-1)
To merge this branch: bzr merge lp:~moon127/charms/precise/mongodb/add-execd-for-basenode
Reviewer Review Type Date Requested Status
Tom Haddon Approve
Review via email: mp+231757@code.launchpad.net

Description of the change

Add exec.d charm preinstall support from charmhelpers for basenode.

To post a comment you must log in.
Revision history for this message
Tom Haddon (mthaddon) wrote :

Looks good and works in my test environment. Will merge.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '.bzrignore'
--- .bzrignore 2014-07-10 18:38:27 +0000
+++ .bzrignore 2014-08-21 15:23:35 +0000
@@ -1,3 +1,4 @@
1.git1.git
2bin/*2bin/*
3scripts/charm-helpers-sync.py3scripts/charm-helpers-sync.py
4exec.d/*
45
=== modified file 'charm-helpers-sync.yaml'
--- charm-helpers-sync.yaml 2014-04-11 20:55:42 +0000
+++ charm-helpers-sync.yaml 2014-08-21 15:23:35 +0000
@@ -3,3 +3,4 @@
3include:3include:
4 - core4 - core
5 - fetch5 - fetch
6 - payload.execd
67
=== added directory 'exec.d'
=== added directory 'hooks/charmhelpers/payload'
=== added file 'hooks/charmhelpers/payload/__init__.py'
--- hooks/charmhelpers/payload/__init__.py 1970-01-01 00:00:00 +0000
+++ hooks/charmhelpers/payload/__init__.py 2014-08-21 15:23:35 +0000
@@ -0,0 +1,1 @@
1"Tools for working with files injected into a charm just before deployment."
02
=== added file 'hooks/charmhelpers/payload/execd.py'
--- hooks/charmhelpers/payload/execd.py 1970-01-01 00:00:00 +0000
+++ hooks/charmhelpers/payload/execd.py 2014-08-21 15:23:35 +0000
@@ -0,0 +1,50 @@
1#!/usr/bin/env python
2
3import os
4import sys
5import subprocess
6from charmhelpers.core import hookenv
7
8
9def default_execd_dir():
10 return os.path.join(os.environ['CHARM_DIR'], 'exec.d')
11
12
13def execd_module_paths(execd_dir=None):
14 """Generate a list of full paths to modules within execd_dir."""
15 if not execd_dir:
16 execd_dir = default_execd_dir()
17
18 if not os.path.exists(execd_dir):
19 return
20
21 for subpath in os.listdir(execd_dir):
22 module = os.path.join(execd_dir, subpath)
23 if os.path.isdir(module):
24 yield module
25
26
27def execd_submodule_paths(command, execd_dir=None):
28 """Generate a list of full paths to the specified command within exec_dir.
29 """
30 for module_path in execd_module_paths(execd_dir):
31 path = os.path.join(module_path, command)
32 if os.access(path, os.X_OK) and os.path.isfile(path):
33 yield path
34
35
36def execd_run(command, execd_dir=None, die_on_error=False, stderr=None):
37 """Run command for each module within execd_dir which defines it."""
38 for submodule_path in execd_submodule_paths(command, execd_dir):
39 try:
40 subprocess.check_call(submodule_path, shell=True, stderr=stderr)
41 except subprocess.CalledProcessError as e:
42 hookenv.log("Error ({}) running {}. Output: {}".format(
43 e.returncode, e.cmd, e.output))
44 if die_on_error:
45 sys.exit(e.returncode)
46
47
48def execd_preinstall(execd_dir=None):
49 """Run charm-pre-install for each module within execd_dir."""
50 execd_run('charm-pre-install', execd_dir=execd_dir)
051
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2014-07-30 15:39:55 +0000
+++ hooks/hooks.py 2014-08-21 15:23:35 +0000
@@ -43,6 +43,8 @@
4343
44from charmhelpers.core.hookenv import log as juju_log44from charmhelpers.core.hookenv import log as juju_log
4545
46from charmhelpers.payload.execd import execd_preinstall
47
46from charmhelpers.core.host import (48from charmhelpers.core.host import (
47 service,49 service,
48)50)
@@ -724,6 +726,8 @@
724###############################################################################726###############################################################################
725@hooks.hook('install')727@hooks.hook('install')
726def install_hook():728def install_hook():
729 juju_log('Begin install hook.')
730 execd_preinstall()
727 juju_log("Installing mongodb")731 juju_log("Installing mongodb")
728 add_source(config('source'), config('key'))732 add_source(config('source'), config('key'))
729 apt_update(fatal=True)733 apt_update(fatal=True)
@@ -1369,4 +1373,4 @@
1369###############################################################################1373###############################################################################
1370if __name__ == "__main__":1374if __name__ == "__main__":
1371 # execute a hook based on the name the program is called by1375 # execute a hook based on the name the program is called by
1372 hooks.execute(sys.argv)
1373\ No newline at end of file1376\ No newline at end of file
1377 hooks.execute(sys.argv)

Subscribers

People subscribed via source and target branches