Merge lp:~tribaal/charms/trusty/ntp/use-charm-helpers-templating into lp:charms/trusty/ntp

Proposed by Chris Glass
Status: Merged
Merged at revision: 16
Proposed branch: lp:~tribaal/charms/trusty/ntp/use-charm-helpers-templating
Merge into: lp:charms/trusty/ntp
Diff against target: 78 lines (+9/-26)
4 files modified
charm-helpers-sync.yaml (+1/-0)
hooks/charmhelpers/core/host.py (+4/-0)
hooks/ntp_hooks.py (+4/-5)
hooks/utils.py (+0/-21)
To merge this branch: bzr merge lp:~tribaal/charms/trusty/ntp/use-charm-helpers-templating
Reviewer Review Type Date Requested Status
Charles Butler (community) Approve
Cory Johns (community) Approve
Review via email: mp+229557@code.launchpad.net

Description of the change

This branch removes the copy/pasted jinja templating code and makes the charm use the charmhelpers version instead.

To post a comment you must log in.
Revision history for this message
Cory Johns (johnsca) wrote :

Chris,

This change looks good. I have one question about the in-memory apt_pkg change. Since hooks won't ever run concurrently, is there really a need for that change? That said, it won't hurt, but if there really is a concern about collisions, should be it merged upstream?

Regardless, this MP gets my +1.

review: Approve
Revision history for this message
Charles Butler (lazypower) wrote :

Merged,

Thanks for the fix tribaal

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charm-helpers-sync.yaml'
2--- charm-helpers-sync.yaml 2013-08-29 18:41:41 +0000
3+++ charm-helpers-sync.yaml 2014-08-05 05:46:38 +0000
4@@ -3,3 +3,4 @@
5 include:
6 - core
7 - fetch
8+ - contrib.templating.jinja
9
10=== modified file 'hooks/charmhelpers/core/host.py'
11--- hooks/charmhelpers/core/host.py 2014-07-16 05:40:55 +0000
12+++ hooks/charmhelpers/core/host.py 2014-08-05 05:46:38 +0000
13@@ -322,6 +322,10 @@
14 import apt_pkg
15 if not pkgcache:
16 apt_pkg.init()
17+ # Force Apt to build its cache in memory. That way we avoid race
18+ # conditions with other applications building the cache in the same
19+ # place.
20+ apt_pkg.config.set("Dir::Cache::pkgcache", "")
21 pkgcache = apt_pkg.Cache()
22 pkg = pkgcache[package]
23 return apt_pkg.version_compare(pkg.current_ver.ver_str, revno)
24
25=== modified file 'hooks/ntp_hooks.py'
26--- hooks/ntp_hooks.py 2013-08-29 21:07:57 +0000
27+++ hooks/ntp_hooks.py 2014-08-05 05:46:38 +0000
28@@ -5,11 +5,10 @@
29 import charmhelpers.core.host as host
30 import charmhelpers.fetch as fetch
31 from charmhelpers.core.hookenv import UnregisteredHookError
32+from charmhelpers.contrib.templating.jinja import render
33 import shutil
34 import os
35-from utils import (
36- render_template,
37-)
38+
39
40 NTP_CONF = '/etc/ntp.conf'
41 NTP_CONF_ORIG = '{}.orig'.format(NTP_CONF)
42@@ -46,8 +45,8 @@
43 shutil.copy(NTP_CONF_ORIG, NTP_CONF)
44 else:
45 with open(NTP_CONF, "w") as ntpconf:
46- ntpconf.write(render_template(os.path.basename(NTP_CONF),
47- {'servers': remote_sources}))
48+ ntpconf.write(render(os.path.basename(NTP_CONF),
49+ {'servers': remote_sources}))
50
51
52 if __name__ == '__main__':
53
54=== removed file 'hooks/utils.py'
55--- hooks/utils.py 2013-08-29 18:41:41 +0000
56+++ hooks/utils.py 1970-01-01 00:00:00 +0000
57@@ -1,21 +0,0 @@
58-from charmhelpers.fetch import (
59- apt_install,
60- filter_installed_packages
61-)
62-
63-
64-TEMPLATES_DIR = 'templates'
65-
66-try:
67- import jinja2
68-except ImportError:
69- apt_install(filter_installed_packages(['python-jinja2']),
70- fatal=True)
71- import jinja2
72-
73-
74-def render_template(template_name, context, template_dir=TEMPLATES_DIR):
75- templates = jinja2.Environment(
76- loader=jinja2.FileSystemLoader(template_dir))
77- template = templates.get_template(template_name)
78- return template.render(context)

Subscribers

People subscribed via source and target branches

to all changes: