Merge lp:~jpds/launchpad/fix_565345-mirror-prober-agent into lp:launchpad

Proposed by Jonathan Davies
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: no longer in the source branch.
Merged at revision: 10747
Proposed branch: lp:~jpds/launchpad/fix_565345-mirror-prober-agent
Merge into: lp:launchpad
Diff against target: 60 lines (+23/-2)
2 files modified
lib/lp/registry/scripts/distributionmirror_prober.py (+2/-0)
lib/lp/registry/tests/test_distributionmirror_prober.py (+21/-2)
To merge this branch: bzr merge lp:~jpds/launchpad/fix_565345-mirror-prober-agent
Reviewer Review Type Date Requested Status
Jeroen T. Vermeulen (community) code Approve
Review via email: mp+23708@code.launchpad.net

Commit message

Added "User-Agent" header to the mirror prober.

Description of the change

= Summary =

This branch adds a "User-Agent" header to the mirror prober so that probes can be identified easily in HTTPd logs.

To post a comment you must log in.
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

A good idea, especially since we've traditionally asked bots accessing our site to provide meaningful user agent identification. Shouldn't ours include a URL as well, by the way?

It's a shame you have to mess with sendHeader in this way, but the only alternative I see is to make FakeTransport log its header and that's probably more effort than it's worth.

A few points remain though:
 * Don't return self.assertEquals(...); just invoke it. It'll raise an exception if it fails.
 * Don't test "headers[1]"—a hard-coded index is far too fragile. Why not make "headers" a dict and test headers['User-Agent']?

Jeroen

review: Approve (code)
Revision history for this message
Jeroen T. Vermeulen (jtv) :
review: Needs Fixing (code)
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Thanks for the changes. You're good to go!

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/registry/scripts/distributionmirror_prober.py'
--- lib/lp/registry/scripts/distributionmirror_prober.py 2009-12-23 16:54:57 +0000
+++ lib/lp/registry/scripts/distributionmirror_prober.py 2010-04-20 15:05:40 +0000
@@ -122,6 +122,8 @@
122 """122 """
123 self.sendCommand('HEAD', self.factory.connect_path)123 self.sendCommand('HEAD', self.factory.connect_path)
124 self.sendHeader('HOST', self.factory.connect_host)124 self.sendHeader('HOST', self.factory.connect_host)
125 self.sendHeader('User-Agent',
126 'Launchpad Mirror Prober ( https://launchpad.net/ )')
125 self.endHeaders()127 self.endHeaders()
126128
127 def handleStatus(self, version, status, message):129 def handleStatus(self, version, status, message):
128130
=== modified file 'lib/lp/registry/tests/test_distributionmirror_prober.py'
--- lib/lp/registry/tests/test_distributionmirror_prober.py 2009-12-23 16:39:52 +0000
+++ lib/lp/registry/tests/test_distributionmirror_prober.py 2010-04-20 15:05:40 +0000
@@ -12,7 +12,6 @@
12import httplib12import httplib
13import logging13import logging
14import os14import os
15import re
16from StringIO import StringIO15from StringIO import StringIO
17import unittest16import unittest
1817
@@ -213,6 +212,25 @@
213 return self.assertFailure(d, ProberTimeout)212 return self.assertFailure(d, ProberTimeout)
214213
215214
215 def test_prober_user_agent(self):
216 protocol = RedirectAwareProberProtocol()
217
218 orig_sendHeader = protocol.sendHeader
219 headers = {}
220
221 def mySendHeader(header, value):
222 orig_sendHeader(header, value)
223 headers[header] = value
224
225 protocol.sendHeader = mySendHeader
226
227 protocol.factory = FakeFactory('http://foo.bar/')
228 protocol.makeConnection(FakeTransport())
229 self.assertEquals(
230 'Launchpad Mirror Prober ( https://launchpad.net/ )',
231 headers['User-Agent'])
232
233
216class FakeTimeOutCall:234class FakeTimeOutCall:
217 resetCalled = False235 resetCalled = False
218236
@@ -811,7 +829,8 @@
811 logger.logMessage("Ubuntu Warty Released")829 logger.logMessage("Ubuntu Warty Released")
812 logger.log_file.seek(0)830 logger.log_file.seek(0)
813 message = logger.log_file.read()831 message = logger.log_file.read()
814 self.failUnlessEqual('Wed Oct 20 12:00:00 2004: Ubuntu Warty Released',832 self.failUnlessEqual(
833 'Wed Oct 20 12:00:00 2004: Ubuntu Warty Released',
815 message)834 message)
816835
817 def test_logMessage_integration(self):836 def test_logMessage_integration(self):