Merge lp:~cjwatson/launchpad/code-import-push-bzr-ssh into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18752
Proposed branch: lp:~cjwatson/launchpad/code-import-push-bzr-ssh
Merge into: lp:launchpad
Diff against target: 61 lines (+29/-3)
2 files modified
lib/lp/codehosting/codeimport/tests/test_worker.py (+17/-0)
lib/lp/codehosting/codeimport/worker.py (+12/-3)
To merge this branch: bzr merge lp:~cjwatson/launchpad/code-import-push-bzr-ssh
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+353243@code.launchpad.net

Commit message

Push code imports over bzr+ssh rather than sftp.

Description of the change

Some imports seem to hang when pushing to sftp; I can reproduce this when experimenting locally, but bzr+ssh fixes things (as long as SSH connection sharing is disabled).

I've done this here rather than in the production configs in order that we can carry on pulling over sftp, which is apparently less CPU-intensive.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/codehosting/codeimport/tests/test_worker.py'
--- lib/lp/codehosting/codeimport/tests/test_worker.py 2018-05-06 08:52:34 +0000
+++ lib/lp/codehosting/codeimport/tests/test_worker.py 2018-08-16 12:53:42 +0000
@@ -169,6 +169,23 @@
169 store.transport.base.rstrip('/'),169 store.transport.base.rstrip('/'),
170 config.codeimport.bazaar_branch_store.rstrip('/'))170 config.codeimport.bazaar_branch_store.rstrip('/'))
171171
172 def test__getMirrorURL(self):
173 # _getMirrorURL returns a URL for the branch with the given id.
174 store = BazaarBranchStore(get_transport_from_url(
175 'sftp://storage.example/branches'))
176 self.assertEqual(
177 'sftp://storage.example/branches/000186a0',
178 store._getMirrorURL(100000))
179
180 def test__getMirrorURL_push(self):
181 # _getMirrorURL prefers bzr+ssh over sftp when constructing push
182 # URLs.
183 store = BazaarBranchStore(get_transport_from_url(
184 'sftp://storage.example/branches'))
185 self.assertEqual(
186 'bzr+ssh://storage.example/branches/000186a0',
187 store._getMirrorURL(100000, push=True))
188
172 def test_getNewBranch(self):189 def test_getNewBranch(self):
173 # If there's no Bazaar branch of this id, then pull creates a new190 # If there's no Bazaar branch of this id, then pull creates a new
174 # Bazaar branch.191 # Bazaar branch.
175192
=== modified file 'lib/lp/codehosting/codeimport/worker.py'
--- lib/lp/codehosting/codeimport/worker.py 2018-03-15 20:44:04 +0000
+++ lib/lp/codehosting/codeimport/worker.py 2018-08-16 12:53:42 +0000
@@ -166,9 +166,18 @@
166 """Construct a Bazaar branch store based at `transport`."""166 """Construct a Bazaar branch store based at `transport`."""
167 self.transport = transport167 self.transport = transport
168168
169 def _getMirrorURL(self, db_branch_id):169 def _getMirrorURL(self, db_branch_id, push=False):
170 """Return the URL that `db_branch` is stored at."""170 """Return the URL that `db_branch` is stored at."""
171 return urljoin(self.transport.base, '%08x' % db_branch_id)171 base_url = self.transport.base
172 if push:
173 # Pulling large branches over sftp is less CPU-intensive, but
174 # pushing over bzr+ssh seems to be more reliable.
175 split = urlsplit(base_url)
176 if split.scheme == 'sftp':
177 base_url = urlunsplit([
178 'bzr+ssh', split.netloc, split.path, split.query,
179 split.fragment])
180 return urljoin(base_url, '%08x' % db_branch_id)
172181
173 def pull(self, db_branch_id, target_path, required_format,182 def pull(self, db_branch_id, target_path, required_format,
174 needs_tree=False, stacked_on_url=None):183 needs_tree=False, stacked_on_url=None):
@@ -218,7 +227,7 @@
218 (i.e. actually transferred revisions).227 (i.e. actually transferred revisions).
219 """228 """
220 self.transport.create_prefix()229 self.transport.create_prefix()
221 target_url = self._getMirrorURL(db_branch_id)230 target_url = self._getMirrorURL(db_branch_id, push=True)
222 try:231 try:
223 remote_branch = Branch.open(target_url)232 remote_branch = Branch.open(target_url)
224 except NotBranchError:233 except NotBranchError: