Merge lp:~vila/charms/precise/tarmac/cleanup-tests into lp:~canonical-ci-engineering/charms/precise/tarmac/trunk

Proposed by Vincent Ladeuil
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: 62
Merged at revision: 58
Proposed branch: lp:~vila/charms/precise/tarmac/cleanup-tests
Merge into: lp:~canonical-ci-engineering/charms/precise/tarmac/trunk
Diff against target: 131 lines (+25/-25)
3 files modified
hooks/hooks.py (+1/-1)
templates/cron.tmpl (+1/-0)
unit_tests/test_hooks.py (+23/-24)
To merge this branch: bzr merge lp:~vila/charms/precise/tarmac/cleanup-tests
Reviewer Review Type Date Requested Status
Evan (community) Approve
Review via email: mp+241805@code.launchpad.net

Commit message

Fix failing tests and cleanup some more.

Description of the change

Fix existing tests and cleanup some more as a pre-requisite to the next MP fixing the template expansion.

This will also be used to test adding a verify_command in tarmac for this project ;)

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

Looks good, thanks!

review: Approve
Revision history for this message
Ubuntu CI Bot (uci-bot) wrote :

The attempt to merge lp:~vila/charms/precise/tarmac/cleanup-tests into lp:~canonical-ci-engineering/charms/precise/tarmac/trunk failed. Below is the output from the failed tests.

PYTHONPATH=:hooks python -m unittest discover -s unit_tests

E
======================================================================
ERROR: test_hooks (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: test_hooks
Traceback (most recent call last):
  File "/usr/lib/python2.7/unittest/loader.py", line 254, in _find_tests
    module = self._get_module_from_name(name)
  File "/usr/lib/python2.7/unittest/loader.py", line 232, in _get_module_from_name
    __import__(name)
  File "/tmp/tarmac/branch.ZGJ4RA/unit_tests/test_hooks.py", line 7, in <module>
    import mock
ImportError: No module named mock

----------------------------------------------------------------------
Ran 1 test in 0.001s

FAILED (errors=1)
make: *** [check] Error 1

Revision history for this message
Vincent Ladeuil (vila) wrote :

/me sighs

No easy way to have that as a test dependency (cm.py could help, but no lp branch for python-mock, only packages...), I'm going to add it to tarmac itself :-/

Revision history for this message
Ubuntu CI Bot (uci-bot) wrote :
Download full text (3.9 KiB)

The attempt to merge lp:~vila/charms/precise/tarmac/cleanup-tests into lp:~canonical-ci-engineering/charms/precise/tarmac/trunk failed. Below is the output from the failed tests.

PYTHONPATH=:hooks python -m unittest discover -s unit_tests

EEEEEEEE
======================================================================
ERROR: test_install (test_hooks.InstallTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/tarmac/branch.rWCjFT/unit_tests/test_hooks.py", line 59, in setUp
    'user': os.environ['USER'],
  File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
    raise KeyError(key)
KeyError: 'USER'

======================================================================
ERROR: test_setup_ssh (test_hooks.InstallTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/tarmac/branch.rWCjFT/unit_tests/test_hooks.py", line 59, in setUp
    'user': os.environ['USER'],
  File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
    raise KeyError(key)
KeyError: 'USER'

======================================================================
ERROR: test_basic_population (test_hooks.TestTemplatePopulation)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/tarmac/branch.rWCjFT/unit_tests/test_hooks.py", line 59, in setUp
    'user': os.environ['USER'],
  File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
    raise KeyError(key)
KeyError: 'USER'

======================================================================
ERROR: test_branch_population (test_hooks.TestTemplatePopulation)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/tarmac/branch.rWCjFT/unit_tests/test_hooks.py", line 59, in setUp
    'user': os.environ['USER'],
  File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
    raise KeyError(key)
KeyError: 'USER'

======================================================================
ERROR: test_credentials_population (test_hooks.TestTemplatePopulation)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/tarmac/branch.rWCjFT/unit_tests/test_hooks.py", line 59, in setUp
    'user': os.environ['USER'],
  File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
    raise KeyError(key)
KeyError: 'USER'

======================================================================
ERROR: test_cron_population (test_hooks.TestTemplatePopulation)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/tmp/tarmac/branch.rWCjFT/unit_tests/test_hooks.py", line 59, in setUp
    'user': os.environ['USER'],
  File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
    raise KeyError(key)
KeyError: 'USER'

======================================================================
ERROR: test_install (test_hooks.TestTemplatePopulation)
----------------------------------------------------------------------
Traceback (most ...

Read more...

62. By Vincent Ladeuil

Hairy bootstrapping issue: when tarmac run the tests it needs USER to be set which is done in the cron template. So we need that fix to be available on tarmac to be able to land this fix.

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-10 17:34:35 +0000
3+++ hooks/hooks.py 2014-11-14 16:36:40 +0000
4@@ -173,7 +173,7 @@
5 # Install packages.
6 charmhelpers.core.hookenv.log('Installing packages.')
7 charmhelpers.fetch.configure_sources(update=True)
8- pkgs = required_pkgs + config.get('packages', '').split(' ')
9+ pkgs = required_pkgs + config.get('packages', '').split()
10 charmhelpers.fetch.apt_install(pkgs, fatal=True)
11
12 # Set up ssh.
13
14=== modified file 'templates/cron.tmpl'
15--- templates/cron.tmpl 2014-07-03 09:42:37 +0000
16+++ templates/cron.tmpl 2014-11-14 16:36:40 +0000
17@@ -2,6 +2,7 @@
18
19 SHELL=/bin/sh
20 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
21+USER={{user}}
22 {{environment}}
23 TARMAC_CONFIG_HOME={{conf_dir}}
24
25
26=== modified file 'unit_tests/test_hooks.py'
27--- unit_tests/test_hooks.py 2014-06-27 22:38:30 +0000
28+++ unit_tests/test_hooks.py 2014-11-14 16:36:40 +0000
29@@ -21,6 +21,7 @@
30
31
32 class InstallTestCase(unittest.TestCase):
33+
34 def setUp(self):
35 super(InstallTestCase, self).setUp()
36 for spec in PATCHES:
37@@ -29,12 +30,14 @@
38 setattr(self, attr_name, _m.start())
39 self.addCleanup(_m.stop)
40
41- # Set a temporary {config, log} directory, to avoid writing under /srv.
42- for attr_name in ('conf_dir', 'log_dir', 'var_dir'):
43+ # Set temporary directories, to avoid writing under /srv or worse under
44+ # ~/.
45+ for attr_name in ('conf_dir', 'log_dir', 'var_dir', 'ssh_dir'):
46 temp_dir = tempfile.mkdtemp()
47 setattr(self, attr_name, temp_dir)
48 self.addCleanup(shutil.rmtree, temp_dir)
49- _m = mock.patch('hooks.get_%s' % attr_name, return_value=temp_dir)
50+ _m = mock.patch('hooks.get_{}'.format(attr_name),
51+ return_value=temp_dir)
52 _m.start()
53 self.addCleanup(_m.stop)
54
55@@ -77,15 +80,10 @@
56 self.assertEqual(statbuf.st_gid, grp.getgrnam(group).gr_gid)
57
58 def test_setup_ssh(self):
59- temp_dir = tempfile.mkdtemp()
60- self.addCleanup(shutil.rmtree, temp_dir)
61- ssh_dir = os.path.join(temp_dir, '.ssh')
62- _p = mock.patch('hooks.get_ssh_dir', return_value=ssh_dir)
63- _p.start()
64- self.addCleanup(_p.stop)
65-
66 hooks.setup_ssh(private_key='A', public_key='B')
67
68+ ssh_dir = hooks.get_ssh_dir()
69+
70 private_key = os.path.join(ssh_dir, 'id_rsa')
71 with open(os.path.join(ssh_dir, 'id_rsa')) as fp:
72 self.assertEqual(fp.read(), 'A')
73@@ -109,7 +107,8 @@
74 params = {'log_file': 'foo.log'}
75 hooks.update_tarmac_template(params)
76 with open(os.path.join(self.conf_dir, 'tarmac.conf')) as fp:
77- self.assertIn('log_file = %s/foo.log' % self.log_dir, fp.read())
78+ expanded = fp.read()
79+ self.assertIn('log_file = {}/foo.log'.format(self.log_dir), expanded)
80
81 def test_branch_population(self):
82 params = {'log_file': 'foo.log',
83@@ -119,10 +118,10 @@
84 }
85 hooks.update_tarmac_template(params)
86 with open(os.path.join(self.conf_dir, 'tarmac.conf')) as fp:
87- tmpl_data = fp.read()
88+ expanded = fp.read()
89
90- self.assertIn('[lp:foo]', tmpl_data)
91- self.assertIn('check_command = /bin/false', tmpl_data)
92+ self.assertIn('[lp:foo]', expanded)
93+ self.assertIn('check_command = /bin/false', expanded)
94
95 def test_cron_population(self):
96 user = os.environ['USER']
97@@ -130,12 +129,12 @@
98 params = {'user': user, 'schedule': '*/5 * * * *', 'environment': env}
99 hooks.update_cron_template(params)
100 with open(os.path.join(self.cron_root, 'tarmac')) as fp:
101- tmpl_data = fp.read()
102+ expanded = fp.read()
103
104- self.assertIn('*/5 * * * *', tmpl_data)
105- self.assertIn('TARMAC_CONFIG_HOME=%s' % self.conf_dir, tmpl_data)
106- self.assertIn('OS_USERNAME=ev', tmpl_data)
107- self.assertIn('OS_PASSWORD=foo', tmpl_data)
108+ self.assertIn('*/5 * * * *', expanded)
109+ self.assertIn('TARMAC_CONFIG_HOME={}'.format(self.conf_dir), expanded)
110+ self.assertIn('OS_USERNAME=ev', expanded)
111+ self.assertIn('OS_PASSWORD=foo', expanded)
112
113 def test_credentials_population(self):
114 params = {'oauth_consumer_key': 'A',
115@@ -147,11 +146,11 @@
116 }
117 hooks.update_credentials_template(params)
118 with open(os.path.join(self.conf_dir, 'credentials')) as fp:
119- tmpl_data = fp.read()
120- self.assertIn('consumer_key = A', tmpl_data)
121- self.assertIn('consumer_secret = \n', tmpl_data)
122- self.assertIn('access_token = B', tmpl_data)
123- self.assertIn('access_secret = C', tmpl_data)
124+ expanded = fp.read()
125+ self.assertIn('consumer_key = A', expanded)
126+ self.assertIn('consumer_secret = \n', expanded)
127+ self.assertIn('access_token = B', expanded)
128+ self.assertIn('access_secret = C', expanded)
129
130
131 if __name__ == '__main__':

Subscribers

People subscribed via source and target branches