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
=== modified file 'lander/bin/lander_service_wrapper.py'
--- lander/bin/lander_service_wrapper.py 2014-03-04 19:52:45 +0000
+++ lander/bin/lander_service_wrapper.py 2014-03-06 17:35:28 +0000
@@ -19,6 +19,7 @@
19import logging19import logging
20import os20import os
21import sys21import sys
22import time
22import urllib223import urllib2
23import yaml24import yaml
2425
@@ -117,10 +118,24 @@
117 return TicketApi(master['ts_url'], master['request_id'])118 return TicketApi(master['ts_url'], master['request_id'])
118119
119120
121def _get_ppa(ppa_assigner_url, ticket_id):
122 timeout = 120
123 url = '%s/api/v1/ppa/' % ppa_assigner_url
124 while True:
125 try:
126 loc = _post(url, {'ticket_id': ticket_id})
127 return loc
128 except urllib2.HTTPError as e:
129 if e.getcode() != 404:
130 raise e
131 logging.warn('No free PPAs can be found. Retrying in %ds', timeout)
132 time.sleep(timeout)
133
134
120def _handle_ppa_assigner(args):135def _handle_ppa_assigner(args):
121 config = _get_config(args)136 config = _get_config(args)
122 url = '%s/api/v1/ppa/' % config['master']['ppa_assigner_url']137 loc = _get_ppa(
123 loc = _post(url, {'ticket_id': config['master']['request_id']})138 config['master']['ppa_assigner_url'], config['master']['request_id'])
124 data = _get(loc)139 data = _get(loc)
125 result = {140 result = {
126 'result': 'PASSED',141 'result': 'PASSED',
127142
=== modified file 'lander/lander/tests/test_service_wrapper.py'
--- lander/lander/tests/test_service_wrapper.py 2014-03-03 23:22:58 +0000
+++ lander/lander/tests/test_service_wrapper.py 2014-03-06 17:35:28 +0000
@@ -153,22 +153,25 @@
153 self.assertItemsEqual(expected, actual)153 self.assertItemsEqual(expected, actual)
154154
155 @mock.patch('lander_service_wrapper._post')155 @mock.patch('lander_service_wrapper._post')
156 def testPPAAssigner404(self, post):156 @mock.patch('lander_service_wrapper._get')
157 '''Ensure a "no ppas" type error generates a response'''157 @mock.patch('time.sleep')
158 err_msg = 'foo bar'158 def testPPAAssigner404(self, sleep, get, post):
159 post.side_effect = urllib2.HTTPError(159 '''Ensure we do proper retrying when no ppa's are available'''
160 'url', 404, '404', None, StringIO.StringIO(err_msg))160 ppa = 'ppa:foo'
161 get.return_value = {'name': ppa}
162 err = urllib2.HTTPError(
163 'url', 404, '404', None, StringIO.StringIO('foo bar'))
164 post.side_effect = [err, err, err, 'http://foo/api/v1/ppa/1']
161165
162 args = self.base_args + ['--service', 'ppa_assigner']166 args = self.base_args + ['--service', 'ppa_assigner']
163 args = lander_service_wrapper._get_parser().parse_args(args)167 args = lander_service_wrapper._get_parser().parse_args(args)
164 rc = lander_service_wrapper.main(args)168 rc = lander_service_wrapper.main(args)
165 self.assertEqual(1, rc)169 self.assertEqual(0, rc)
166170
167 with open(self.results) as f:171 with open(self.results) as f:
168 data = json.loads(f.read())172 data = json.loads(f.read())
169 self.assertEqual('ERROR', data['result'])173 self.assertEqual('PASSED', data['result'])
170 self.assertEqual(err_msg, data['resp_body'])174 self.assertEqual(ppa, data['ppa'])
171 self.assertEqual('404', data['resp_code'])
172175
173 @mock.patch('lander_service_wrapper._post')176 @mock.patch('lander_service_wrapper._post')
174 def testPPAAssignerUnexpected(self, post):177 def testPPAAssignerUnexpected(self, post):

Subscribers

People subscribed via source and target branches