Merge lp:~psivaa/uci-engine/swift-failure-exposure into lp:uci-engine

Proposed by Para Siva
Status: Merged
Approved by: Para Siva
Approved revision: 915
Merged at revision: 914
Proposed branch: lp:~psivaa/uci-engine/swift-failure-exposure
Merge into: lp:uci-engine
Diff against target: 98 lines (+64/-0)
2 files modified
test_runner/tstrun/run_worker.py (+4/-0)
test_runner/tstrun/tests/test_worker.py (+60/-0)
To merge this branch: bzr merge lp:~psivaa/uci-engine/swift-failure-exposure
Reviewer Review Type Date Requested Status
Vincent Ladeuil (community) Approve
Joe Talbott (community) Approve
Review via email: mp+245745@code.launchpad.net

Commit message

To ensure that we do not swallow the swiftclient related exceptions in the test runner worker

Description of the change

To ensure that we do not swallow the swiftclient related exceptions in the test runner worker. Any client error response in swiftclient during file uploads (save_artefact) is raised in data_store as an exception and this MP disables catching that exception in test runner.

The failure analysis, in http://bazaar.launchpad.net/~vila/uci-engine/analysis/view/head:/tasks.rst lists 3 types of possible failures swift related.
1. PUT can fail with 401 (tested with this MP)
2. ail to upload because we can't reset content (this should also raise client exception and therefore will be tested with the same test)
3. Failure due to connecting to keystone (this is being handled by some other tasks)

To post a comment you must log in.
Revision history for this message
Joe Talbott (joetalbott) wrote :

This looks good to me.

review: Approve
Revision history for this message
Vincent Ladeuil (vila) wrote :

See inline comment for one fix, otherwise, well done, good to land.

Revision history for this message
Vincent Ladeuil (vila) wrote :

And I vote...

review: Needs Fixing
914. By Para Siva

Log before raising the exception

Revision history for this message
Para Siva (psivaa) wrote :

Thanks for that. Fixed that in r914.

Revision history for this message
Vincent Ladeuil (vila) wrote :

Thanks !

review: Approve
Revision history for this message
Vincent Ladeuil (vila) wrote :

pep8 ?

915. By Para Siva

pyflakes fix

Revision history for this message
Para Siva (psivaa) wrote :

pyflakes :) thanks

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'test_runner/tstrun/run_worker.py'
--- test_runner/tstrun/run_worker.py 2014-12-15 09:25:00 +0000
+++ test_runner/tstrun/run_worker.py 2015-01-07 16:31:30 +0000
@@ -105,8 +105,12 @@
105 artifact_name = '{}.{}'.format(self.artifact_prefix, name)105 artifact_name = '{}.{}'.format(self.artifact_prefix, name)
106 self.artifacts.append(106 self.artifacts.append(
107 dict(name=artifact_name, reference=url, type=kind))107 dict(name=artifact_name, reference=url, type=kind))
108 # Any swiftclient exception in data_store has to be treated here as
109 # a failure in infra, hence specific client return codes
110 # are not tested here
108 except:111 except:
109 self.logger.exception('Unable to upload {}'.format(description))112 self.logger.exception('Unable to upload {}'.format(description))
113 raise
110114
111 def save_testbed_console(self, package):115 def save_testbed_console(self, package):
112 self.save_artifact('{}-testbed-cloud-init.log'.format(package),116 self.save_artifact('{}-testbed-cloud-init.log'.format(package),
113117
=== modified file 'test_runner/tstrun/tests/test_worker.py'
--- test_runner/tstrun/tests/test_worker.py 2014-11-04 12:07:12 +0000
+++ test_runner/tstrun/tests/test_worker.py 2015-01-07 16:31:30 +0000
@@ -16,6 +16,8 @@
16import os16import os
17import unittest17import unittest
1818
19from swiftclient import client
20
19from ucitests import (21from ucitests import (
20 assertions,22 assertions,
21 fixtures as uci_fixtures,23 fixtures as uci_fixtures,
@@ -26,6 +28,7 @@
26 amqp_utils,28 amqp_utils,
27 image_store,29 image_store,
28 unit_config,30 unit_config,
31 data_store,
29)32)
30from ci_utils.testing import (33from ci_utils.testing import (
31 features,34 features,
@@ -227,3 +230,60 @@
227 run_worker.format_britney_result(230 run_worker.format_britney_result(
228 'trusty', 'armhf', 'adduser', 2,231 'trusty', 'armhf', 'adduser', 2,
229 '1.0', [('foo', '1.0')]))232 '1.0', [('foo', '1.0')]))
233
234
235class SaveArtefactClient(object):
236 """Fake swift client to emulate swift failures.
237
238 This is injected into a DataStore object to execute failure scenarios
239 """
240
241 def __init__(self, calls):
242 self.calls = calls
243
244 def put_object(self, container, *args, **kwargs):
245 return self.calls(container, *args, **kwargs)
246
247
248class SaveArtefactDataStore(data_store.DataStore):
249 """An instrumented DataStore to emulate errors in container upload."""
250
251 def __init__(self, component, calls):
252 # We don't use the config so we inject a fake but valid one
253 auth_config = {'auth_url': 'http://example.com',
254 'auth_user': 'user',
255 'auth_password': 'pass',
256 'auth_tenant_name': 'tenant',
257 'auth_region': 'region'}
258 super(SaveArtefactDataStore, self).__init__(
259 component, auth_config)
260 self.client = SaveArtefactClient(calls)
261
262
263class TestTestRequestHandler(unittest.TestCase):
264 """Test the container deletion.
265
266 We don't have a swift server to inject errors into so we're faking that
267 part to exercise the error handling in TestRequestHandler.save_artifact()
268 """
269 def raise_401(self, container, *args, **kwargs):
270 # The return code does not matter so much,
271 # any swiftclient exception in the swift client will have
272 # to be treated as an infrastructure failure
273 raise client.ClientException('401', http_status=401)
274
275 @tests.log_on_failure()
276 def test_save_artefact_401(self, logger):
277 rel_path = 'foo'
278 content = 'foo content'
279 calls = self.raise_401
280 ds = SaveArtefactDataStore('ignored', calls)
281 req_handler = run_worker.TestRequestHandler(logger,
282 'progress_queue_name',
283 ds,
284 'ticket_id',
285 'some desc')
286 with self.assertRaises(data_store.DataStoreException) as cm:
287 req_handler.save_artifact(rel_path, content)
288
289 self.assertIn("Failed to upload file", '{}'.format(cm.exception))

Subscribers

People subscribed via source and target branches