Merge lp:~doanac/ubuntu-ci-services-itself/lander-ppa-retry into lp:ubuntu-ci-services-itself

Proposed by Andy Doan
Status: Merged
Approved by: Andy Doan
Approved revision: 323
Merged at revision: 331
Proposed branch: lp:~doanac/ubuntu-ci-services-itself/lander-ppa-retry
Merge into: lp:ubuntu-ci-services-itself
Diff against target: 77 lines (+29/-11)
2 files modified
lander/bin/lander_service_wrapper.py (+17/-2)
lander/lander/tests/test_service_wrapper.py (+12/-9)
To merge this branch: bzr merge lp:~doanac/ubuntu-ci-services-itself/lander-ppa-retry
Reviewer Review Type Date Requested Status
Francis Ginther Approve
Paul Larson Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+209738@code.launchpad.net

Commit message

lander: retry getting ppa

We should retry getting a PPA in the lander when all PPAs are
currently reserved.

Description of the change

There were 2 parts to dealing with the "no free ppas" issue

Part 1 was simply reporting this type of error status in the webui. This piece is now complete

The MP is for part 2: have the lander retry getting a PPA when there are none available.

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

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

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

review: Approve (continuous-integration)
Revision history for this message
Paul Larson (pwlars) wrote :

+ while True:
This part bothers me, but maybe it's just because there's no good way to cancel operations at the moment. In this case, since it's just trying to get the ppa though, I think that should be safe. Something to think about for later perhaps though.

review: Approve
Revision history for this message
Andy Doan (doanac) wrote :

On 03/06/2014 03:47 PM, Paul Larson wrote:
> + while True:
> This part bothers me, but maybe it's just because there's no good way to cancel operations at the moment. In this case, since it's just trying to get the ppa though, I think that should be safe. Something to think about for later perhaps though.

I was thinking we could always configure a jenkins job timeout for this.
The code should be safe to interrupt in that way.

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

Regarding Paul's comment. We really need a central way to terminate processing of a ticket. Something that allows the lander and components to check in with the ticket system and abort the current task gracefully. Given the limitations and the problem being addressed here, approved.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lander/bin/lander_service_wrapper.py'
2--- lander/bin/lander_service_wrapper.py 2014-03-04 19:52:45 +0000
3+++ lander/bin/lander_service_wrapper.py 2014-03-06 17:35:28 +0000
4@@ -19,6 +19,7 @@
5 import logging
6 import os
7 import sys
8+import time
9 import urllib2
10 import yaml
11
12@@ -117,10 +118,24 @@
13 return TicketApi(master['ts_url'], master['request_id'])
14
15
16+def _get_ppa(ppa_assigner_url, ticket_id):
17+ timeout = 120
18+ url = '%s/api/v1/ppa/' % ppa_assigner_url
19+ while True:
20+ try:
21+ loc = _post(url, {'ticket_id': ticket_id})
22+ return loc
23+ except urllib2.HTTPError as e:
24+ if e.getcode() != 404:
25+ raise e
26+ logging.warn('No free PPAs can be found. Retrying in %ds', timeout)
27+ time.sleep(timeout)
28+
29+
30 def _handle_ppa_assigner(args):
31 config = _get_config(args)
32- url = '%s/api/v1/ppa/' % config['master']['ppa_assigner_url']
33- loc = _post(url, {'ticket_id': config['master']['request_id']})
34+ loc = _get_ppa(
35+ config['master']['ppa_assigner_url'], config['master']['request_id'])
36 data = _get(loc)
37 result = {
38 'result': 'PASSED',
39
40=== modified file 'lander/lander/tests/test_service_wrapper.py'
41--- lander/lander/tests/test_service_wrapper.py 2014-03-03 23:22:58 +0000
42+++ lander/lander/tests/test_service_wrapper.py 2014-03-06 17:35:28 +0000
43@@ -153,22 +153,25 @@
44 self.assertItemsEqual(expected, actual)
45
46 @mock.patch('lander_service_wrapper._post')
47- def testPPAAssigner404(self, post):
48- '''Ensure a "no ppas" type error generates a response'''
49- err_msg = 'foo bar'
50- post.side_effect = urllib2.HTTPError(
51- 'url', 404, '404', None, StringIO.StringIO(err_msg))
52+ @mock.patch('lander_service_wrapper._get')
53+ @mock.patch('time.sleep')
54+ def testPPAAssigner404(self, sleep, get, post):
55+ '''Ensure we do proper retrying when no ppa's are available'''
56+ ppa = 'ppa:foo'
57+ get.return_value = {'name': ppa}
58+ err = urllib2.HTTPError(
59+ 'url', 404, '404', None, StringIO.StringIO('foo bar'))
60+ post.side_effect = [err, err, err, 'http://foo/api/v1/ppa/1']
61
62 args = self.base_args + ['--service', 'ppa_assigner']
63 args = lander_service_wrapper._get_parser().parse_args(args)
64 rc = lander_service_wrapper.main(args)
65- self.assertEqual(1, rc)
66+ self.assertEqual(0, rc)
67
68 with open(self.results) as f:
69 data = json.loads(f.read())
70- self.assertEqual('ERROR', data['result'])
71- self.assertEqual(err_msg, data['resp_body'])
72- self.assertEqual('404', data['resp_code'])
73+ self.assertEqual('PASSED', data['result'])
74+ self.assertEqual(ppa, data['ppa'])
75
76 @mock.patch('lander_service_wrapper._post')
77 def testPPAAssignerUnexpected(self, post):

Subscribers

People subscribed via source and target branches