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
1=== modified file 'lib/lp/registry/scripts/distributionmirror_prober.py'
2--- lib/lp/registry/scripts/distributionmirror_prober.py 2009-12-23 16:54:57 +0000
3+++ lib/lp/registry/scripts/distributionmirror_prober.py 2010-04-20 15:05:40 +0000
4@@ -122,6 +122,8 @@
5 """
6 self.sendCommand('HEAD', self.factory.connect_path)
7 self.sendHeader('HOST', self.factory.connect_host)
8+ self.sendHeader('User-Agent',
9+ 'Launchpad Mirror Prober ( https://launchpad.net/ )')
10 self.endHeaders()
11
12 def handleStatus(self, version, status, message):
13
14=== modified file 'lib/lp/registry/tests/test_distributionmirror_prober.py'
15--- lib/lp/registry/tests/test_distributionmirror_prober.py 2009-12-23 16:39:52 +0000
16+++ lib/lp/registry/tests/test_distributionmirror_prober.py 2010-04-20 15:05:40 +0000
17@@ -12,7 +12,6 @@
18 import httplib
19 import logging
20 import os
21-import re
22 from StringIO import StringIO
23 import unittest
24
25@@ -213,6 +212,25 @@
26 return self.assertFailure(d, ProberTimeout)
27
28
29+ def test_prober_user_agent(self):
30+ protocol = RedirectAwareProberProtocol()
31+
32+ orig_sendHeader = protocol.sendHeader
33+ headers = {}
34+
35+ def mySendHeader(header, value):
36+ orig_sendHeader(header, value)
37+ headers[header] = value
38+
39+ protocol.sendHeader = mySendHeader
40+
41+ protocol.factory = FakeFactory('http://foo.bar/')
42+ protocol.makeConnection(FakeTransport())
43+ self.assertEquals(
44+ 'Launchpad Mirror Prober ( https://launchpad.net/ )',
45+ headers['User-Agent'])
46+
47+
48 class FakeTimeOutCall:
49 resetCalled = False
50
51@@ -811,7 +829,8 @@
52 logger.logMessage("Ubuntu Warty Released")
53 logger.log_file.seek(0)
54 message = logger.log_file.read()
55- self.failUnlessEqual('Wed Oct 20 12:00:00 2004: Ubuntu Warty Released',
56+ self.failUnlessEqual(
57+ 'Wed Oct 20 12:00:00 2004: Ubuntu Warty Released',
58 message)
59
60 def test_logMessage_integration(self):