tests/dumbhttp.py
author Gregory Szorc <gregory.szorc@gmail.com>
Sun, 20 Dec 2015 11:56:24 -0800
changeset 27633 37d7cf569cf3
parent 27282 0bb8c405a7c7
child 28194 7623ba92af72
permissions -rwxr-xr-x
wireproto: support disabling bundle1 only if repo is generaldelta I recently implemented the server.bundle1* options to control whether bundle1 exchange is allowed. After thinking about Mozilla's strategy for handling generaldelta rollout a bit more, I think server operators need an additional lever: disable bundle1 if and only if the repo is generaldelta. bundle1 exchange for non-generaldelta repos will not have the potential for CPU explosion that generaldelta repos do. Therefore, it makes sense for server operators to continue to allow bundle1 exchange for non-generaldelta repos without having to set a per-repo hgrc option to change the policy depending on whether the repo is generaldelta. This patch introduces a new set of options to control bundle1 behavior for generaldelta repos. These options enable server operators to limit bundle1 restrictions to the class of repos that can be performance issues. It also allows server operators to tie bundle1 access to store format. In many server environments (including Mozilla's), legacy repos will not be generaldelta and new repos will or might be. New repos often aren't bound by legacy access requirements, so setting a global policy that disallows access to new/generaldelta repos via bundle1 could be a reasonable policy in many server environments. This patch makes this policy very easy to implement (modify global hgrc, add options to existing generaldelta repos to grandfather them in).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22959
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
     1
#!/usr/bin/env python
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
     2
27282
0bb8c405a7c7 tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23136
diff changeset
     3
from __future__ import absolute_import
0bb8c405a7c7 tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23136
diff changeset
     4
22959
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
     5
"""
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
     6
Small and dumb HTTP server for use in tests.
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
     7
"""
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
     8
27282
0bb8c405a7c7 tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23136
diff changeset
     9
import optparse
0bb8c405a7c7 tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23136
diff changeset
    10
import BaseHTTPServer
0bb8c405a7c7 tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23136
diff changeset
    11
import signal
0bb8c405a7c7 tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23136
diff changeset
    12
import SimpleHTTPServer
0bb8c405a7c7 tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23136
diff changeset
    13
import sys
22959
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    14
27282
0bb8c405a7c7 tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23136
diff changeset
    15
from mercurial import (
0bb8c405a7c7 tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23136
diff changeset
    16
    cmdutil,
0bb8c405a7c7 tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23136
diff changeset
    17
)
0bb8c405a7c7 tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23136
diff changeset
    18
0bb8c405a7c7 tests/dumbhttp: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 23136
diff changeset
    19
OptionParser = optparse.OptionParser
22959
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    20
23136
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
    21
class simplehttpservice(object):
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
    22
    def __init__(self, host, port):
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
    23
        self.address = (host, port)
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
    24
    def init(self):
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
    25
        self.httpd = BaseHTTPServer.HTTPServer(
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
    26
            self.address, SimpleHTTPServer.SimpleHTTPRequestHandler)
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
    27
    def run(self):
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
    28
        self.httpd.serve_forever()
22959
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    29
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    30
if __name__ == '__main__':
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    31
    parser = OptionParser()
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    32
    parser.add_option('-p', '--port', dest='port', type='int', default=8000,
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    33
        help='TCP port to listen on', metavar='PORT')
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    34
    parser.add_option('-H', '--host', dest='host', default='localhost',
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    35
        help='hostname or IP to listen on', metavar='HOST')
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    36
    parser.add_option('--pid', dest='pid',
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    37
        help='file name where the PID of the server is stored')
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    38
    parser.add_option('-f', '--foreground', dest='foreground',
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    39
        action='store_true',
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    40
        help='do not start the HTTP server in the background')
23136
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
    41
    parser.add_option('--daemon-pipefds')
22959
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    42
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    43
    (options, args) = parser.parse_args()
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    44
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    45
    signal.signal(signal.SIGTERM, lambda x, y: sys.exit(0))
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    46
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    47
    if options.foreground and options.pid:
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    48
        parser.error("options --pid and --foreground are mutually exclusive")
10116463b0b1 tests: pull common http server setup out of individual tests
Mike Hommey <mh@glandium.org>
parents:
diff changeset
    49
23136
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
    50
    opts = {'pid_file': options.pid,
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
    51
            'daemon': not options.foreground,
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
    52
            'daemon_pipefds': options.daemon_pipefds}
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
    53
    service = simplehttpservice(options.host, options.port)
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
    54
    cmdutil.service(opts, initfn=service.init, runfn=service.run,
6eab50a34fed tests: have dumbhttp.py use cmdutil.service() to wait for child to listen()
Yuya Nishihara <yuya@tcha.org>
parents: 22959
diff changeset
    55
                    runargs=[sys.executable, __file__] + sys.argv[1:])