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
=== modified file 'hooks/hooks.py'
--- hooks/hooks.py 2014-11-10 17:34:35 +0000
+++ hooks/hooks.py 2014-11-14 16:36:40 +0000
@@ -173,7 +173,7 @@
173 # Install packages.173 # Install packages.
174 charmhelpers.core.hookenv.log('Installing packages.')174 charmhelpers.core.hookenv.log('Installing packages.')
175 charmhelpers.fetch.configure_sources(update=True)175 charmhelpers.fetch.configure_sources(update=True)
176 pkgs = required_pkgs + config.get('packages', '').split(' ')176 pkgs = required_pkgs + config.get('packages', '').split()
177 charmhelpers.fetch.apt_install(pkgs, fatal=True)177 charmhelpers.fetch.apt_install(pkgs, fatal=True)
178178
179 # Set up ssh.179 # Set up ssh.
180180
=== modified file 'templates/cron.tmpl'
--- templates/cron.tmpl 2014-07-03 09:42:37 +0000
+++ templates/cron.tmpl 2014-11-14 16:36:40 +0000
@@ -2,6 +2,7 @@
22
3SHELL=/bin/sh3SHELL=/bin/sh
4PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin4PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
5USER={{user}}
5{{environment}}6{{environment}}
6TARMAC_CONFIG_HOME={{conf_dir}} 7TARMAC_CONFIG_HOME={{conf_dir}}
78
89
=== modified file 'unit_tests/test_hooks.py'
--- unit_tests/test_hooks.py 2014-06-27 22:38:30 +0000
+++ unit_tests/test_hooks.py 2014-11-14 16:36:40 +0000
@@ -21,6 +21,7 @@
2121
2222
23class InstallTestCase(unittest.TestCase):23class InstallTestCase(unittest.TestCase):
24
24 def setUp(self):25 def setUp(self):
25 super(InstallTestCase, self).setUp()26 super(InstallTestCase, self).setUp()
26 for spec in PATCHES:27 for spec in PATCHES:
@@ -29,12 +30,14 @@
29 setattr(self, attr_name, _m.start())30 setattr(self, attr_name, _m.start())
30 self.addCleanup(_m.stop)31 self.addCleanup(_m.stop)
3132
32 # Set a temporary {config, log} directory, to avoid writing under /srv.33 # Set temporary directories, to avoid writing under /srv or worse under
33 for attr_name in ('conf_dir', 'log_dir', 'var_dir'):34 # ~/.
35 for attr_name in ('conf_dir', 'log_dir', 'var_dir', 'ssh_dir'):
34 temp_dir = tempfile.mkdtemp()36 temp_dir = tempfile.mkdtemp()
35 setattr(self, attr_name, temp_dir)37 setattr(self, attr_name, temp_dir)
36 self.addCleanup(shutil.rmtree, temp_dir)38 self.addCleanup(shutil.rmtree, temp_dir)
37 _m = mock.patch('hooks.get_%s' % attr_name, return_value=temp_dir)39 _m = mock.patch('hooks.get_{}'.format(attr_name),
40 return_value=temp_dir)
38 _m.start()41 _m.start()
39 self.addCleanup(_m.stop)42 self.addCleanup(_m.stop)
4043
@@ -77,15 +80,10 @@
77 self.assertEqual(statbuf.st_gid, grp.getgrnam(group).gr_gid)80 self.assertEqual(statbuf.st_gid, grp.getgrnam(group).gr_gid)
7881
79 def test_setup_ssh(self):82 def test_setup_ssh(self):
80 temp_dir = tempfile.mkdtemp()
81 self.addCleanup(shutil.rmtree, temp_dir)
82 ssh_dir = os.path.join(temp_dir, '.ssh')
83 _p = mock.patch('hooks.get_ssh_dir', return_value=ssh_dir)
84 _p.start()
85 self.addCleanup(_p.stop)
86
87 hooks.setup_ssh(private_key='A', public_key='B')83 hooks.setup_ssh(private_key='A', public_key='B')
8884
85 ssh_dir = hooks.get_ssh_dir()
86
89 private_key = os.path.join(ssh_dir, 'id_rsa')87 private_key = os.path.join(ssh_dir, 'id_rsa')
90 with open(os.path.join(ssh_dir, 'id_rsa')) as fp:88 with open(os.path.join(ssh_dir, 'id_rsa')) as fp:
91 self.assertEqual(fp.read(), 'A')89 self.assertEqual(fp.read(), 'A')
@@ -109,7 +107,8 @@
109 params = {'log_file': 'foo.log'}107 params = {'log_file': 'foo.log'}
110 hooks.update_tarmac_template(params)108 hooks.update_tarmac_template(params)
111 with open(os.path.join(self.conf_dir, 'tarmac.conf')) as fp:109 with open(os.path.join(self.conf_dir, 'tarmac.conf')) as fp:
112 self.assertIn('log_file = %s/foo.log' % self.log_dir, fp.read())110 expanded = fp.read()
111 self.assertIn('log_file = {}/foo.log'.format(self.log_dir), expanded)
113112
114 def test_branch_population(self):113 def test_branch_population(self):
115 params = {'log_file': 'foo.log',114 params = {'log_file': 'foo.log',
@@ -119,10 +118,10 @@
119 }118 }
120 hooks.update_tarmac_template(params)119 hooks.update_tarmac_template(params)
121 with open(os.path.join(self.conf_dir, 'tarmac.conf')) as fp:120 with open(os.path.join(self.conf_dir, 'tarmac.conf')) as fp:
122 tmpl_data = fp.read()121 expanded = fp.read()
123122
124 self.assertIn('[lp:foo]', tmpl_data)123 self.assertIn('[lp:foo]', expanded)
125 self.assertIn('check_command = /bin/false', tmpl_data)124 self.assertIn('check_command = /bin/false', expanded)
126125
127 def test_cron_population(self):126 def test_cron_population(self):
128 user = os.environ['USER']127 user = os.environ['USER']
@@ -130,12 +129,12 @@
130 params = {'user': user, 'schedule': '*/5 * * * *', 'environment': env}129 params = {'user': user, 'schedule': '*/5 * * * *', 'environment': env}
131 hooks.update_cron_template(params)130 hooks.update_cron_template(params)
132 with open(os.path.join(self.cron_root, 'tarmac')) as fp:131 with open(os.path.join(self.cron_root, 'tarmac')) as fp:
133 tmpl_data = fp.read()132 expanded = fp.read()
134133
135 self.assertIn('*/5 * * * *', tmpl_data)134 self.assertIn('*/5 * * * *', expanded)
136 self.assertIn('TARMAC_CONFIG_HOME=%s' % self.conf_dir, tmpl_data)135 self.assertIn('TARMAC_CONFIG_HOME={}'.format(self.conf_dir), expanded)
137 self.assertIn('OS_USERNAME=ev', tmpl_data)136 self.assertIn('OS_USERNAME=ev', expanded)
138 self.assertIn('OS_PASSWORD=foo', tmpl_data)137 self.assertIn('OS_PASSWORD=foo', expanded)
139138
140 def test_credentials_population(self):139 def test_credentials_population(self):
141 params = {'oauth_consumer_key': 'A',140 params = {'oauth_consumer_key': 'A',
@@ -147,11 +146,11 @@
147 }146 }
148 hooks.update_credentials_template(params)147 hooks.update_credentials_template(params)
149 with open(os.path.join(self.conf_dir, 'credentials')) as fp:148 with open(os.path.join(self.conf_dir, 'credentials')) as fp:
150 tmpl_data = fp.read()149 expanded = fp.read()
151 self.assertIn('consumer_key = A', tmpl_data)150 self.assertIn('consumer_key = A', expanded)
152 self.assertIn('consumer_secret = \n', tmpl_data)151 self.assertIn('consumer_secret = \n', expanded)
153 self.assertIn('access_token = B', tmpl_data)152 self.assertIn('access_token = B', expanded)
154 self.assertIn('access_secret = C', tmpl_data)153 self.assertIn('access_secret = C', expanded)
155154
156155
157if __name__ == '__main__':156if __name__ == '__main__':

Subscribers

People subscribed via source and target branches