1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#!/usr/bin/env python
# Ubuntu Continuous Integration Engine
# Copyright 2014 Canonical Ltd.
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License version 3, as
# published by the Free Software Foundation.
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE. See the GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import json
import unittest
from ci_utils import amqp_utils
import deploy
import deployers
from ucitests import fixtures
RABBIT_SERVICE = 'ci-airline-rabbit'
def run_rabbit_cmd(args):
deployers.juju_run(RABBIT_SERVICE,
'sudo rabbitmqctl {}'.format(' '.join(args)))
def create_rabbit_user(user_name, password=None):
if password is None:
password = user_name
run_rabbit_cmd(['add_user', user_name, password])
run_rabbit_cmd(['set_permissions', '-p', '/', user_name, '".*" ".*" ".*"'])
def delete_rabbit_user(user_name):
run_rabbit_cmd(['delete_user', user_name])
class SmokeTestTestRunner(deployers.DeployerTest):
"""Integration tests for test runner service run on a juju deployment"""
def test_worker_running(self):
'''Ensure the rabbit worker is deployed and running.'''
# TODO ev 2014-06-16 We should really write status APIs that
# introspect with these sorts of tests.
self.assert_job_running('ci-airline-tr-rabbit-worker')
class TestTestRunner(deployers.DeployerTest):
def setUp(self):
super(TestTestRunner, self).setUp()
status = deploy.juju_status()
units = status['services']['ci-airline-rabbit']['units']
self.unit = 'ci-airline-rabbit/0'
self.public_ip = units[self.unit]['public-address']
# Expose rabbit service for this test.
deployers.juju_expose(RABBIT_SERVICE)
self.addCleanup(deployers.juju_expose, RABBIT_SERVICE, False)
class AmqpConfig(object):
def __init__(inner):
inner.AMQP_HOST = self.public_ip
inner.AMQP_VHOST = '/'
inner.AMQP_USER = 'tester'
inner.AMQP_PASSWORD = 's3cr3t'
fixtures.patch(self, amqp_utils, 'get_config', AmqpConfig)
create_rabbit_user('tester', 's3cr3t')
self.addCleanup(delete_rabbit_user, 'tester')
def test_process_ticket(self):
params = dict(ticket_id='t1', progress_trigger='test-progress',
# For canonistack:
# image_id=('ubuntu-released/ubuntu-precise-12.04'
# '-amd64-server-20140428-disk1.img'),
# For hpcloud:
series='precise',
image_id=('Ubuntu 12.04.4 LTS (amd64 20140613)'
' - CI Engineering'),
package_list=['libpng'])
# FIXME: We can't delete that queue with rabbitmqctl, we need the
# channel for that which is not exposed -- vila 2014-06-19
# self.addCleanup(delete_queue 'test-progress')
amqp_utils.send(amqp_utils.TEST_RUNNER_QUEUE, json.dumps(params),
raise_errors=True)
# FIXME: From there, the test runner worker receives the message,
# process it, send progress to the 'test-progress' queue (all checked
# manually by uncommenting the following pdb call and letting the
# ticket process happen or not while allowing the worker to be
# investigated).
# import pdb; pdb.set_trace()
# But we we need a way to subscribe to that 'test-progress' queue and
# process the received messages (and not hang like
# _run_forever()). That will provide a way to wait for the ticket to be
# processed without involving time.sleep(). Out-of-scope to fix
# http://pad.lv/1331989, so punting for now -- vila 2014-06-19
if __name__ == "__main__":
unittest.main()
|