Merge ~pappacena/turnip:fix-exception-reraising into turnip:master

Proposed by Thiago F. Pappacena
Status: Merged
Approved by: Thiago F. Pappacena
Approved revision: dfad08812fe1efa61e6df271066604ab5148b191
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~pappacena/turnip:fix-exception-reraising
Merge into: turnip:master
Diff against target: 80 lines (+31/-9)
2 files modified
turnip/pack/git.py (+29/-9)
turnip/pack/tests/test_git.py (+2/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+391631@code.launchpad.net

Commit message

Refactoring and improving logging on repo creation

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
Revision history for this message
Thiago F. Pappacena (pappacena) :
Revision history for this message
Thiago F. Pappacena (pappacena) :
dfad088... by Thiago F. Pappacena

Adding better explanation about reraising exception on repo creation

Revision history for this message
Thiago F. Pappacena (pappacena) wrote :

The problem seems to be affecting more users in production. I'll merge && QA this, and prepare a production deployment to get more information of what is happening there.

I couldn't reproduce the problem in QA env, nor locally (unless I explicitly raise an Exception on the repository creation), so I guess the best shot we have is adding more logs to production.

Revision history for this message
Colin Watson (cjwatson) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/turnip/pack/git.py b/turnip/pack/git.py
2index 4407085..9523337 100644
3--- a/turnip/pack/git.py
4+++ b/turnip/pack/git.py
5@@ -11,6 +11,8 @@ from __future__ import (
6 __metaclass__ = type
7
8
9+import os
10+import sys
11 import uuid
12
13 import six
14@@ -528,26 +530,44 @@ class PackBackendProtocol(PackServerProtocol):
15 xmlrpc_endpoint = config.get("virtinfo_endpoint")
16 xmlrpc_timeout = int(config.get("virtinfo_timeout"))
17 proxy = xmlrpc.Proxy(xmlrpc_endpoint, allowNone=True)
18+ repo_path = compose_path(self.factory.root, pathname)
19+ if clone_from:
20+ clone_path = six.ensure_str(
21+ compose_path(self.factory.root, clone_from))
22+ else:
23+ clone_path = None
24 try:
25- repo_path = compose_path(self.factory.root, pathname)
26- if clone_from:
27- clone_path = six.ensure_str(
28- compose_path(self.factory.root, clone_from))
29- else:
30- clone_path = None
31+ self.log.info(
32+ "Creating repository %s, clone of %s" %
33+ (repo_path, clone_path))
34 store.init_repo(six.ensure_str(repo_path), clone_path)
35+ self.log.info(
36+ "Confirming with Launchpad repo %s creation." % repo_path)
37 yield proxy.callRemote(
38 "confirmRepoCreation", six.ensure_text(pathname),
39 auth_params).addTimeout(xmlrpc_timeout, default_reactor)
40 except AlreadyExistsError:
41 # Do not abort nor try to delete existing repositories.
42+ self.log.info("Repository %s already exists." % repo_path)
43 raise
44- except Exception:
45+ except Exception as e:
46+ t, v, tb = sys.exc_info()
47+ self.log.info(
48+ "Aborting on Launchpad repo %s creation: %s" % (repo_path, e))
49 yield proxy.callRemote(
50 "abortRepoCreation", six.ensure_text(pathname),
51 auth_params).addTimeout(xmlrpc_timeout, default_reactor)
52- store.delete_repo(repo_path)
53- raise
54+ if os.path.exists(repo_path):
55+ self.log.info(
56+ "Deleting local repo creation attempt %s." % repo_path)
57+ store.delete_repo(repo_path)
58+ # Just using `raise` here could cause an error like "exceptions
59+ # must be old-style classes or derived from BaseException,
60+ # not NoneType", since proxy.callRemote and Twisted event loop
61+ # could clean up the current exception. That's why we store
62+ # current exception at the begining of the `except` block and
63+ # reraise it here.
64+ six.reraise(t, v, tb)
65
66 def packetReceived(self, data):
67 if self.expect_set_symbolic_ref:
68diff --git a/turnip/pack/tests/test_git.py b/turnip/pack/tests/test_git.py
69index d1a8162..c8e25c8 100644
70--- a/turnip/pack/tests/test_git.py
71+++ b/turnip/pack/tests/test_git.py
72@@ -238,6 +238,8 @@ class TestPackBackendProtocol(TestCase):
73 self.virtinfo.xmlrpc_confirmRepoCreation = mock.Mock(
74 side_effect=Fault(1, "?"))
75 store = mock.Mock()
76+ # Make `init_repo` create a fake repo directory.
77+ store.init_repo.side_effect = lambda path, clone: os.mkdir(path)
78 self.useFixture(MonkeyPatch("turnip.pack.git.store", store))
79
80 params = {b'host': b'example.com'}

Subscribers

People subscribed via source and target branches