2
# Ubuntu Continuous Integration Engine
3
# Copyright 2014 Canonical Ltd.
5
# This program is free software: you can redistribute it and/or modify it
6
# under the terms of the GNU Affero General Public License version 3, as
7
# published by the Free Software Foundation.
9
# This program is distributed in the hope that it will be useful, but
10
# WITHOUT ANY WARRANTY; without even the implied warranties of
11
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12
# PURPOSE. See the GNU Affero General Public License for more details.
14
# You should have received a copy of the GNU Affero General Public License
15
# along with this program. If not, see <http://www.gnu.org/licenses/>.
23
from ci_utils import amqp_utils
24
from ucitests import (
29
RABBIT_SERVICE = 'ci-airline-rabbit'
32
def run_rabbit_cmd(args):
33
deployers.juju_run(RABBIT_SERVICE,
34
'sudo rabbitmqctl {}'.format(' '.join(args)))
37
def create_rabbit_user(user_name, password=None):
40
run_rabbit_cmd(['add_user', user_name, password])
41
run_rabbit_cmd(['set_permissions', '-p', '/', user_name, '".*" ".*" ".*"'])
44
def delete_rabbit_user(user_name):
45
run_rabbit_cmd(['delete_user', user_name])
48
class TestPPACreator(deployers.DeployerTest):
49
"""Integration tests for ppacreator service run on a juju deployment"""
52
super(TestPPACreator, self).setUp()
53
status = deploy.juju_status()
54
units = status['services']['ci-airline-rabbit']['units']
55
self.unit = 'ci-airline-rabbit/0'
56
self.public_ip = units[self.unit]['public-address']
57
# Expose rabbit service for this test.
58
deployers.juju_expose(RABBIT_SERVICE)
59
self.addCleanup(deployers.juju_expose, RABBIT_SERVICE, False)
61
class AmqpConfig(object):
64
inner.AMQP_HOST = self.public_ip
65
inner.AMQP_VHOST = '/'
66
inner.AMQP_USER = 'tester'
67
inner.AMQP_PASSWORD = 's3cr3t'
68
fixtures.patch(self, amqp_utils, 'get_config', AmqpConfig)
69
create_rabbit_user('tester', 's3cr3t')
70
self.addCleanup(delete_rabbit_user, 'tester')
72
def drain_queue(self, queue_name):
76
body = json.loads(msg.body)
77
self.messages.append(body)
78
msg.channel.basic_ack(msg.delivery_tag)
80
# this will kick us out of the run-forever worker loop, relying
81
# on the worker last message setting 'exit'
82
msg.channel.basic_cancel(msg.consumer_tag)
84
conf = amqp_utils.get_config()
85
# Process all messages and delete the queue when done
86
amqp_utils.process_queue(conf, queue_name, on_message, delete=True)
89
def assertStatusMsg(self, expected, msg):
90
self.assertEqual('STATUS', msg['state'])
91
without_state = msg.copy()
92
del without_state['state']
93
self.assertDictEqual(expected, without_state)
95
def test_worker_running(self):
96
"""Ensure the ppacreator worker is deployed and running."""
97
self.assert_job_running('ci-airline-ppa-creator-worker')
99
def test_create_ppa(self):
100
"""Ensure that ppa's can be created or their name can
101
be retrieved if they are already existing"""
102
unique_id = uuid.uuid1()
103
progress_queue_name = 'progress-trigger'
105
name='ppacreator-inttest-{}'.format(unique_id),
106
displayname='ppacreator-inttest-{}'.format(unique_id),
107
description='int-test-ppa-description',
108
progress_trigger=progress_queue_name,
109
ticket_id='int-test-ppa-ticket-id',
110
architectures=('all'),
113
amqp_utils.send(amqp_utils.PPA_CREATOR_QUEUE, json.dumps(params),
115
msgs = self.drain_queue(progress_queue_name)
116
assertions.assertLength(self, 3, msgs)
117
self.assertStatusMsg({u'message': u'Creating PPA {} for ticket, '
118
'int-test-ppa-ticket-id'.format(params['name'])},
122
self.assertEqual('COMPLETED', final['state'])
123
self.assertEqual('PASSED', final['result'])
125
if __name__ == "__main__":