Merge lp:~vila/uci-engine/1331989-homeless into lp:uci-engine

Proposed by Vincent Ladeuil
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: 606
Merged at revision: 604
Proposed branch: lp:~vila/uci-engine/1331989-homeless
Merge into: lp:uci-engine
Diff against target: 224 lines (+103/-19)
6 files modified
test_runner/tstrun/run_worker.py (+3/-0)
test_runner/tstrun/tests/test_testbed.py (+1/-1)
test_runner/tstrun/tests/test_worker.py (+1/-1)
tests/deployers.py (+22/-11)
tests/test_rabbit.py (+2/-3)
tests/test_test_runner.py (+74/-3)
To merge this branch: bzr merge lp:~vila/uci-engine/1331989-homeless
Reviewer Review Type Date Requested Status
Francis Ginther Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+223890@code.launchpad.net

Commit message

Fallback to current dir (/srv/<service>) if HOME is not set for the test runner worker.

Description of the change

This fixes http://pad.lv/1331989 caused by:
1) the worker running without HOME being set,
2) the lack of test covering such issues

The test lacks a way to process a rabbit queue.

But it's enough to debug such issues in the mean time.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:603
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/902/
Executed test runs:

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/uci-engine-ci/902/rebuild

review: Approve (continuous-integration)
Revision history for this message
Francis Ginther (fginther) wrote :

Approve.

This is going to hit some merge conflicts with some additional refactoring that went into juju_run. But nothing serious. If I get a few spare cycles, I'll look into this and will paste in an MP if I get it solved.

review: Approve
Revision history for this message
Francis Ginther (fginther) wrote :

I made a merge to trunk here:
https://code.launchpad.net/~fginther/uci-engine/1331989-homeless-merge-trunk

not sure if it helps much.

lp:~vila/uci-engine/1331989-homeless updated
604. By Vincent Ladeuil

Merge trunk, resolving conflicts

605. By Vincent Ladeuil

Better document juju_run constraints.

606. By Vincent Ladeuil

This is reached when running the integration tests against just a juju bootstrapped node.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'test_runner/tstrun/run_worker.py'
2--- test_runner/tstrun/run_worker.py 2014-06-16 13:18:53 +0000
3+++ test_runner/tstrun/run_worker.py 2014-06-24 10:47:47 +0000
4@@ -38,6 +38,9 @@
5 super(TestRunnerWorker, self).__init__('image_test')
6 self.data_store_factory = _data_store_factory
7 self.data_store = None
8+ if os.environ.get('HOME', None) is None:
9+ # Fall back to the current dir where the worker is run from
10+ os.environ['HOME'] = os.getcwd()
11
12 def _create_data_store(self, ticket_id):
13 if self.data_store_factory is None:
14
15=== modified file 'test_runner/tstrun/tests/test_testbed.py'
16--- test_runner/tstrun/tests/test_testbed.py 2014-06-06 16:50:01 +0000
17+++ test_runner/tstrun/tests/test_testbed.py 2014-06-24 10:47:47 +0000
18@@ -61,7 +61,7 @@
19 # whether canonistack or hpcloud is used.
20 if unit_config.is_hpcloud(self.conf.get('os.auth_url')):
21 test_images = dict(
22- precise=('Ubuntu Server 12.04.4 LTS (amd64 20140306)'
23+ precise=('Ubuntu 12.04.4 LTS (amd64 20140613)'
24 ' - CI Engineering'),
25 saucy=('Ubuntu Server 13.10 (amd64 20131030) - Partner Image'),
26 )
27
28=== modified file 'test_runner/tstrun/tests/test_worker.py'
29--- test_runner/tstrun/tests/test_worker.py 2014-06-11 13:05:04 +0000
30+++ test_runner/tstrun/tests/test_worker.py 2014-06-24 10:47:47 +0000
31@@ -68,7 +68,7 @@
32 # '-amd64-server-20140428-disk1.img'),
33 # For hpcloud:
34 series='precise',
35- image_id=('Ubuntu Server 12.04.4 LTS (amd64 20140306)'
36+ image_id=('Ubuntu 12.04.4 LTS (amd64 20140613)'
37 ' - CI Engineering'),
38 package_list=['libpng'])
39 self.queue.publish(params)
40
41=== modified file 'tests/deployers.py'
42--- tests/deployers.py 2014-06-23 19:41:51 +0000
43+++ tests/deployers.py 2014-06-24 10:47:47 +0000
44@@ -12,6 +12,8 @@
45
46 # You should have received a copy of the GNU Affero General Public License
47 # along with this program. If not, see <http://www.gnu.org/licenses/>.
48+
49+
50 import collections
51 import errno
52 import os
53@@ -43,20 +45,30 @@
54 p = subprocess.Popen(
55 args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
56 except OSError as e:
57+ # MISSINGTEST: not covered by any test -- vila 2014-06-20
58 if e.errno != errno.ENOENT:
59 raise
60 raise OSError("juju not found, do you have Juju installed?")
61 out, err = p.communicate()
62 if p.returncode:
63- raise IOError(
64- 'juju command failed {!r}:\n{}'.format(juju_args, err))
65+ raise IOError('juju command failed {!r}:\n{}'.format(juju_args, err))
66 return out
67
68
69-def juju_run(service, unit=0, args=''):
70- unit = '{}/{}'.format(service, unit)
71- juju_args = ['run', '--unit', unit, args]
72- return _juju_call(juju_args)
73+def juju_run(service, cmd, unit=0):
74+ """Call a command on a single given unit.
75+
76+ :param service: A service name.
77+
78+ :param cmd: The command to execute on a unit. This should be provided as a
79+ string to avoid evaluation on the originating host (the evaluation will
80+ happen on the unit itself if needed).
81+
82+ :param unit: The unit number where the command should be run. It defaults
83+ to 0 if not provided.
84+
85+ """
86+ return _juju_call(['run', '--unit', '{}/{}'.format(service, unit), cmd])
87
88
89 def juju_expose(service, expose=True):
90@@ -64,8 +76,7 @@
91 action = 'expose'
92 else:
93 action = 'unexpose'
94- juju_args = [action, service]
95- return _juju_call(juju_args)
96+ return _juju_call([action, service])
97
98
99 # TODO ev 2014-06-16 @features.requires(features.settled_units)
100@@ -82,9 +93,9 @@
101 return ip, int(port)
102
103 def assert_job_running(self, service, unit=0, upstart_job=None):
104- '''ensure the given upstart job is running on a unit'''
105+ # Ensure the given upstart job is running on a unit
106 if upstart_job is None:
107 upstart_job = service
108- cmd = '/sbin/status {}'.format(upstart_job)
109- output = juju_run(service, unit, cmd)
110+ output = juju_run(service, '/sbin/status {}'.format(upstart_job),
111+ unit=unit)
112 self.assertIn('start/running', output)
113
114=== modified file 'tests/test_rabbit.py'
115--- tests/test_rabbit.py 2014-06-19 18:10:38 +0000
116+++ tests/test_rabbit.py 2014-06-24 10:47:47 +0000
117@@ -46,9 +46,8 @@
118 fixtures.patch(self, amqp_utils, 'get_config', AmqpConfig)
119
120 def run_ctl_cmd(self, args):
121- cmd = ' '.join(args)
122- cmd = 'sudo rabbitmqctl {}'.format(cmd)
123- deployers.juju_run(RABBIT_SERVICE, args=cmd)
124+ deployers.juju_run(RABBIT_SERVICE,
125+ 'sudo rabbitmqctl {}'.format(' '.join(args)))
126
127 def create_user(self, user_name, password=None):
128 if password is None:
129
130=== modified file 'tests/test_test_runner.py'
131--- tests/test_test_runner.py 2014-06-23 19:41:51 +0000
132+++ tests/test_test_runner.py 2014-06-24 10:47:47 +0000
133@@ -14,11 +14,36 @@
134 # You should have received a copy of the GNU Affero General Public License
135 # along with this program. If not, see <http://www.gnu.org/licenses/>.
136
137+import json
138 import unittest
139+
140+
141+from ci_utils import amqp_utils
142+import deploy
143 import deployers
144-
145-
146-class TestTestRunner(deployers.DeployerTest):
147+from ucitests import fixtures
148+
149+
150+RABBIT_SERVICE = 'ci-airline-rabbit'
151+
152+
153+def run_rabbit_cmd(args):
154+ deployers.juju_run(RABBIT_SERVICE,
155+ 'sudo rabbitmqctl {}'.format(' '.join(args)))
156+
157+
158+def create_rabbit_user(user_name, password=None):
159+ if password is None:
160+ password = user_name
161+ run_rabbit_cmd(['add_user', user_name, password])
162+ run_rabbit_cmd(['set_permissions', '-p', '/', user_name, '".*" ".*" ".*"'])
163+
164+
165+def delete_rabbit_user(user_name):
166+ run_rabbit_cmd(['delete_user', user_name])
167+
168+
169+class SmokeTestTestRunner(deployers.DeployerTest):
170 """Integration tests for test runner service run on a juju deployment"""
171
172 def test_worker_running(self):
173@@ -28,5 +53,51 @@
174 self.assert_job_running('ci-airline-tr-rabbit-worker')
175
176
177+class TestTestRunner(deployers.DeployerTest):
178+
179+ def setUp(self):
180+ super(TestTestRunner, self).setUp()
181+ status = deploy.juju_status()
182+ units = status['services']['ci-airline-rabbit']['units']
183+ self.unit = 'ci-airline-rabbit/0'
184+ self.public_ip = units[self.unit]['public-address']
185+
186+ class AmqpConfig(object):
187+
188+ def __init__(inner):
189+ inner.AMQP_HOST = self.public_ip
190+ inner.AMQP_VHOST = '/'
191+ inner.AMQP_USER = 'tester'
192+ inner.AMQP_PASSWORD = 's3cr3t'
193+ fixtures.patch(self, amqp_utils, 'get_config', AmqpConfig)
194+ create_rabbit_user('tester', 's3cr3t')
195+ self.addCleanup(delete_rabbit_user, 'tester')
196+
197+ def test_process_ticket(self):
198+ params = dict(ticket_id='t1', progress_trigger='test-progress',
199+ # For canonistack:
200+ # image_id=('ubuntu-released/ubuntu-precise-12.04'
201+ # '-amd64-server-20140428-disk1.img'),
202+ # For hpcloud:
203+ series='precise',
204+ image_id=('Ubuntu 12.04.4 LTS (amd64 20140613)'
205+ ' - CI Engineering'),
206+ package_list=['libpng'])
207+ # FIXME: We can't delete that queue with rabbitmqctl, we need the
208+ # channel for that which is not exposed -- vila 2014-06-19
209+ # self.addCleanup(delete_queue 'test-progress')
210+ amqp_utils.send(amqp_utils.TEST_RUNNER_QUEUE, json.dumps(params),
211+ raise_errors=True)
212+ # FIXME: From there, the test runner worker receives the message,
213+ # process it, send progress to the 'test-progress' queue (all checked
214+ # manually by adding 'import pdb; pdb.set_trace() HERE and checking
215+ # that uci-vms.conf was properly created on the worker). But we we need
216+ # a way to subscribe to that 'test-progress' queue and process the
217+ # received messages (and not hang like _run_forever()). That will
218+ # provide a way to wait for the ticket to be processed without
219+ # involving time.sleep(). Out-of-scope to fix http://pad.lv/1331989, so
220+ # punting for now -- vila 2014-06-19
221+
222+
223 if __name__ == "__main__":
224 unittest.main()

Subscribers

People subscribed via source and target branches