Merge lp:~vila/charms/precise/tarmac/fix-template-expansion into lp:~canonical-ci-engineering/charms/precise/tarmac/trunk

Proposed by Vincent Ladeuil
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: 64
Merged at revision: 59
Proposed branch: lp:~vila/charms/precise/tarmac/fix-template-expansion
Merge into: lp:~canonical-ci-engineering/charms/precise/tarmac/trunk
Prerequisite: lp:~vila/charms/precise/tarmac/cleanup-tests
Diff against target: 71 lines (+27/-2)
2 files modified
hooks/hooks.py (+4/-2)
unit_tests/test_hooks.py (+23/-0)
To merge this branch: bzr merge lp:~vila/charms/precise/tarmac/fix-template-expansion
Reviewer Review Type Date Requested Status
Evan (community) Approve
Review via email: mp+241808@code.launchpad.net

Commit message

Fix template expansion that led to ~tarmac/.ssh/known_hosts corruption

Description of the change

This fixes the template expansion issue that led to ~tarmac/.ssh/known_hosts corruption with failing tests reproducing the issue.

An easier way would have been to add an additional newline in the templates (so one survive) but this is likely to regress.

To post a comment you must log in.
Revision history for this message
Evan (ev) wrote :

Spot on. Thanks!

review: Approve
64. By Vincent Ladeuil

Merge further fixes from the cleanup branch

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/hooks.py'
2--- hooks/hooks.py 2014-11-14 13:31:41 +0000
3+++ hooks/hooks.py 2014-11-14 16:46:19 +0000
4@@ -45,8 +45,10 @@
5
6
7 def get_config_template(name):
8- from jinja2 import Environment, FileSystemLoader
9- template_env = Environment(loader=FileSystemLoader(get_template_dir()))
10+ import jinja2
11+ fs_loader = jinja2.FileSystemLoader(get_template_dir())
12+ template_env = jinja2.Environment(loader=fs_loader,
13+ keep_trailing_newline=True)
14 return template_env.get_template(name)
15
16
17
18=== modified file 'unit_tests/test_hooks.py'
19--- unit_tests/test_hooks.py 2014-11-14 14:00:28 +0000
20+++ unit_tests/test_hooks.py 2014-11-14 16:46:19 +0000
21@@ -109,6 +109,7 @@
22 with open(os.path.join(self.conf_dir, 'tarmac.conf')) as fp:
23 expanded = fp.read()
24 self.assertIn('log_file = {}/foo.log'.format(self.log_dir), expanded)
25+ self.assertTrue(expanded.endswith('\n'))
26
27 def test_branch_population(self):
28 params = {'log_file': 'foo.log',
29@@ -122,6 +123,7 @@
30
31 self.assertIn('[lp:foo]', expanded)
32 self.assertIn('check_command = /bin/false', expanded)
33+ self.assertTrue(expanded.endswith('\n'))
34
35 def test_cron_population(self):
36 user = os.environ['USER']
37@@ -135,6 +137,7 @@
38 self.assertIn('TARMAC_CONFIG_HOME={}'.format(self.conf_dir), expanded)
39 self.assertIn('OS_USERNAME=ev', expanded)
40 self.assertIn('OS_PASSWORD=foo', expanded)
41+ self.assertTrue(expanded.endswith('\n'))
42
43 def test_credentials_population(self):
44 params = {'oauth_consumer_key': 'A',
45@@ -151,6 +154,26 @@
46 self.assertIn('consumer_secret = \n', expanded)
47 self.assertIn('access_token = B', expanded)
48 self.assertIn('access_secret = C', expanded)
49+ self.assertTrue(expanded.endswith('\n'))
50+
51+ def test_ssh_config_population(self):
52+ params = {'user': os.environ['USER'],
53+ 'group': grp.getgrgid(os.getgroups()[0]).gr_name,
54+ }
55+ hooks.update_ssh_template(params)
56+ with open(os.path.join(self.ssh_dir, 'config')) as fp:
57+ expanded = fp.read()
58+ self.assertTrue(expanded.endswith('\n'))
59+
60+ def test_ssh_known_hosts_population(self):
61+ params = {'user': os.environ['USER'],
62+ 'group': grp.getgrgid(os.getgroups()[0]).gr_name,
63+ }
64+ hooks.update_ssh_template(params)
65+ with open(os.path.join(self.ssh_dir, 'known_hosts')) as fp:
66+ expanded = fp.read()
67+ self.assertIn('bazaar.launchpad.net', expanded)
68+ self.assertTrue(expanded.endswith('\n'))
69
70
71 if __name__ == '__main__':

Subscribers

People subscribed via source and target branches