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/>.
17
from ci_utils import amqp_utils, amqp_worker
18
from ci_utils.data_store import DataStoreException
19
from coverageretriever import (snip_coverage_xml,
20
CoverageRetrieverException,
23
SUCCESS_MESSAGE_TEMPLATE = 'Deposited coverage.xml into swift for ticket {}.'
24
PARSE_FAILURE_TEMPLATE = 'Failed to parse build log for ticket {}.'
25
SWIFT_FAILURE_TEMPLATE = ('Failed to retrieve build log from swift '
29
class CoverageRetrieverWorker(amqp_worker.AMQPWorker):
32
super(CoverageRetrieverWorker, self).__init__('coverageretriever')
34
@retry(DataStoreException, tries=5, delay=1, backoff=2)
35
def get_build_log(self, data_store, build_log_filename):
36
"""Get build log; retry swift if our log's not there yet."""
37
return data_store.get_file(build_log_filename)
39
def handle_request(self, params, logger):
40
"""Snip coverage.xml from incoming build log and put in swift."""
41
build_log_filename = params['build_log_filename']
42
data_store = self._create_data_store(params['ticket_id'])
44
log_text = self.get_build_log(data_store, build_log_filename)
45
coverage_xml_text = snip_coverage_xml(log_text)
46
result_link = data_store.put_file('coverage.xml',
49
except CoverageRetrieverException:
50
message = PARSE_FAILURE_TEMPLATE.format(
53
# FGINTHER: what more to put here?
54
result_data = {'message': message}
55
return amqp_utils.progress_failed, result_data
56
except DataStoreException:
57
message = SWIFT_FAILURE_TEMPLATE.format(
60
# FGINTHER: what more to put here?
61
result_data = {'message': message}
62
return amqp_utils.progress_failed, result_data
63
message = SUCCESS_MESSAGE_TEMPLATE.format(
68
'result_link': result_link # FGINTHER: necessary?
69
# FGINTHER: what else do we need to report here?
70
# FGINTHER: should this result be stashed in swift also?
72
return amqp_utils.progress_completed, result_data
75
# FGINTHER: correct? also when/how is this called?
76
if __name__ == '__main__':
77
CoverageRetrieverWorker().main(amqp_utils.COVERAGE_RETRIEVER_QUEUE)