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
diff --git a/turnip/pack/git.py b/turnip/pack/git.py
index 4407085..9523337 100644
--- a/turnip/pack/git.py
+++ b/turnip/pack/git.py
@@ -11,6 +11,8 @@ from __future__ import (
11__metaclass__ = type11__metaclass__ = type
1212
1313
14import os
15import sys
14import uuid16import uuid
1517
16import six18import six
@@ -528,26 +530,44 @@ class PackBackendProtocol(PackServerProtocol):
528 xmlrpc_endpoint = config.get("virtinfo_endpoint")530 xmlrpc_endpoint = config.get("virtinfo_endpoint")
529 xmlrpc_timeout = int(config.get("virtinfo_timeout"))531 xmlrpc_timeout = int(config.get("virtinfo_timeout"))
530 proxy = xmlrpc.Proxy(xmlrpc_endpoint, allowNone=True)532 proxy = xmlrpc.Proxy(xmlrpc_endpoint, allowNone=True)
533 repo_path = compose_path(self.factory.root, pathname)
534 if clone_from:
535 clone_path = six.ensure_str(
536 compose_path(self.factory.root, clone_from))
537 else:
538 clone_path = None
531 try:539 try:
532 repo_path = compose_path(self.factory.root, pathname)540 self.log.info(
533 if clone_from:541 "Creating repository %s, clone of %s" %
534 clone_path = six.ensure_str(542 (repo_path, clone_path))
535 compose_path(self.factory.root, clone_from))
536 else:
537 clone_path = None
538 store.init_repo(six.ensure_str(repo_path), clone_path)543 store.init_repo(six.ensure_str(repo_path), clone_path)
544 self.log.info(
545 "Confirming with Launchpad repo %s creation." % repo_path)
539 yield proxy.callRemote(546 yield proxy.callRemote(
540 "confirmRepoCreation", six.ensure_text(pathname),547 "confirmRepoCreation", six.ensure_text(pathname),
541 auth_params).addTimeout(xmlrpc_timeout, default_reactor)548 auth_params).addTimeout(xmlrpc_timeout, default_reactor)
542 except AlreadyExistsError:549 except AlreadyExistsError:
543 # Do not abort nor try to delete existing repositories.550 # Do not abort nor try to delete existing repositories.
551 self.log.info("Repository %s already exists." % repo_path)
544 raise552 raise
545 except Exception:553 except Exception as e:
554 t, v, tb = sys.exc_info()
555 self.log.info(
556 "Aborting on Launchpad repo %s creation: %s" % (repo_path, e))
546 yield proxy.callRemote(557 yield proxy.callRemote(
547 "abortRepoCreation", six.ensure_text(pathname),558 "abortRepoCreation", six.ensure_text(pathname),
548 auth_params).addTimeout(xmlrpc_timeout, default_reactor)559 auth_params).addTimeout(xmlrpc_timeout, default_reactor)
549 store.delete_repo(repo_path)560 if os.path.exists(repo_path):
550 raise561 self.log.info(
562 "Deleting local repo creation attempt %s." % repo_path)
563 store.delete_repo(repo_path)
564 # Just using `raise` here could cause an error like "exceptions
565 # must be old-style classes or derived from BaseException,
566 # not NoneType", since proxy.callRemote and Twisted event loop
567 # could clean up the current exception. That's why we store
568 # current exception at the begining of the `except` block and
569 # reraise it here.
570 six.reraise(t, v, tb)
551571
552 def packetReceived(self, data):572 def packetReceived(self, data):
553 if self.expect_set_symbolic_ref:573 if self.expect_set_symbolic_ref:
diff --git a/turnip/pack/tests/test_git.py b/turnip/pack/tests/test_git.py
index d1a8162..c8e25c8 100644
--- a/turnip/pack/tests/test_git.py
+++ b/turnip/pack/tests/test_git.py
@@ -238,6 +238,8 @@ class TestPackBackendProtocol(TestCase):
238 self.virtinfo.xmlrpc_confirmRepoCreation = mock.Mock(238 self.virtinfo.xmlrpc_confirmRepoCreation = mock.Mock(
239 side_effect=Fault(1, "?"))239 side_effect=Fault(1, "?"))
240 store = mock.Mock()240 store = mock.Mock()
241 # Make `init_repo` create a fake repo directory.
242 store.init_repo.side_effect = lambda path, clone: os.mkdir(path)
241 self.useFixture(MonkeyPatch("turnip.pack.git.store", store))243 self.useFixture(MonkeyPatch("turnip.pack.git.store", store))
242244
243 params = {b'host': b'example.com'}245 params = {b'host': b'example.com'}

Subscribers

People subscribed via source and target branches