示例#1
0
def configure_environment():
    # Make tests run in a timezone no launchpad developers live in.
    # Our tests need to run in any timezone.
    # (This is no longer actually required, as PQM does this.)
    os.environ['TZ'] = 'Asia/Calcutta'
    time.tzset()

    # Httplib2 0.7 started validating SSL certificates, and the test suite
    # uses a self-signed certificate, so disable it with an env variable.
    os.environ['LP_DISABLE_SSL_CERTIFICATE_VALIDATION'] = '1'

    # Storm's C extensions should already be enabled from
    # lp_sitecustomize.py, which our custom sitecustomize.py ran.
    assert os.environ['STORM_CEXTENSIONS'] == '1'

    # Install the import fascist import hook and atexit handler.
    importfascist.install_import_fascist()

    # Install the warning handler hook and atexit handler.
    warninghandler.install_warning_handler()

    # Ensure that atexit handlers are executed on TERM.
    def exit_with_atexit_handlers(*ignored):
        sys.exit(-1 * signal.SIGTERM)

    signal.signal(signal.SIGTERM, exit_with_atexit_handlers)

    # Tell lp.services.config to use the testrunner config instance.
    config.setInstance('testrunner')
    config.generate_overrides()

    # Remove this module's directory from path, so that zope.testbrowser
    # can import pystone from test:
    sys.path[:] = [p for p in sys.path if os.path.abspath(p) != config.root]

    # Turn on psycopg debugging wrapper
    #import lp.services.database.debug
    #lp.services.database.debug.install()

    # Unset the http_proxy environment variable, because we're going to make
    # requests to localhost and we don't want this to be proxied.
    os.environ.pop('http_proxy', None)

    # Suppress accessibility warning because the test runner does not have UI.
    os.environ['GTK_MODULES'] = ''
def main():
    args = sys.argv[1:]
    if '-h' in args or '--help' in args:
        print(__doc__)
        return 0
    # Tell lp.services.config to use the testrunner config instance, so that
    # we don't kill the real services.
    config.setInstance('testrunner')
    config.generate_overrides()
    print("Killing Memcached....", end="")
    kill_by_pidfile(MemcachedLayer.getPidFile())
    print("done.")
    print("Killing Librarian....", end="")
    librarian_fixture = LibrarianServerFixture(None)
    kill_by_pidfile(librarian_fixture.pidfile)
    librarian_fixture.tearDownRoot()
    print("done.")
    return 0
def start_launchpad(argv=list(sys.argv), setup=None):
    # We really want to replace this with a generic startup harness.
    # However, this should last us until this is developed
    services, argv = split_out_runlaunchpad_arguments(argv[1:])
    argv = process_config_arguments(argv)
    services = get_services_to_run(services)
    # Create the ZCML override file based on the instance.
    config.generate_overrides()
    # Many things rely on a directory called 'logs' existing in the current
    # working directory.
    ensure_directory_exists('logs')
    if setup is not None:
        # This is the setup from start_testapp, above.
        setup()
    try:
        with nested(*services):
            # Store our process id somewhere
            make_pidfile('launchpad')
            if config.launchpad.launch:
                main(argv)
            else:
                # We just need the foreground process to sit around forever
                # waiting for the signal to shut everything down.  Normally,
                # Zope itself would be this master process, but we're not
                # starting that up, so we need to do something else.
                try:
                    signal.pause()
                except KeyboardInterrupt:
                    pass
    except Exception as e:
        print >> sys.stderr, "stopping services on exception %r" % e
        for service in services:
            print >> sys.stderr, service, "fixture details:"
            # There may be no details on some services if they haven't been
            # initialized yet.
            if getattr(service, '_details', None) is None:
                print >> sys.stderr, "(not ready yet?)"
                continue
            details_str = _details_to_str(service.getDetails())
            if details_str:
                print >> sys.stderr, details_str
            else:
                print >> sys.stderr, "(no details present)"
        raise
def start_librarian():
    """Start the Librarian in the background."""
    # Create the ZCML override file based on the instance.
    config.generate_overrides()
    # Create the Librarian storage directory if it doesn't already exist.
    prepare_for_librarian()
    pidfile = pidfile_path('librarian')
    cmd = [
        tachandler.twistd_script,
        "--python",
        'daemons/librarian.tac',
        "--pidfile",
        pidfile,
        "--prefix",
        'Librarian',
        "--logfile",
        config.librarian_server.logfile,
    ]
    return subprocess.call(cmd)