~launchpad-pqm/launchpad/devel

7167.3.2 by Francis J. Lacoste
Added lp-windmill.py wrapper that starts LP. Moved bare windmill to utilities.
1
#!/usr/bin/python2.4
2
# Copyright 2008 Canonical Ltd.  All rights reserved.
3
"""Windmill test integration wrapper for Launchpad.
7150.2.1 by Francis J. Lacoste
Add link to windmill sourcecode dependencies.
4
7167.3.2 by Francis J. Lacoste
Added lp-windmill.py wrapper that starts LP. Moved bare windmill to utilities.
5
This wrapper starts a test Launchpad instance that can be
6
used by Windmill.
7471.4.25 by Francis J. Lacoste
Add possibility only to start the launchpad server.
7
8
If the --server-only option is given, only the Launchpad server
9
is started.  This allows one to invoke the windmill script multiple
10
time directly.
7150.2.1 by Francis J. Lacoste
Add link to windmill sourcecode dependencies.
11
"""
7167.3.2 by Francis J. Lacoste
Added lp-windmill.py wrapper that starts LP. Moved bare windmill to utilities.
12
7150.2.1 by Francis J. Lacoste
Add link to windmill sourcecode dependencies.
13
import os
14
import sys
7471.4.25 by Francis J. Lacoste
Add possibility only to start the launchpad server.
15
import time
7150.2.1 by Francis J. Lacoste
Add link to windmill sourcecode dependencies.
16
7167.3.2 by Francis J. Lacoste
Added lp-windmill.py wrapper that starts LP. Moved bare windmill to utilities.
17
# Fix-up our path so that we can find all the modules.
7150.2.1 by Francis J. Lacoste
Add link to windmill sourcecode dependencies.
18
here = os.path.dirname(os.path.realpath(__file__))
19
sys.path.insert(0, os.path.join(here, 'lib'))
7167.3.2 by Francis J. Lacoste
Added lp-windmill.py wrapper that starts LP. Moved bare windmill to utilities.
20
sys.path.insert(0, os.path.join(here, 'lib', 'mailman'))
21
22
original_environ = dict(os.environ)
23
# Set the path for spawned process.
24
os.environ['PYTHONPATH'] = ":".join(sys.path)
25
26
# Hard-code the app-server configuration, since that's what can
27
# work with windmill.
28
os.environ['LPCONFIG'] = 'testrunner-appserver'
29
30
import atexit
31
import signal
32
import subprocess
33
from canonical.testing.layers import (
34
    BaseLayer,
35
    DatabaseLayer,
36
    LibrarianLayer,
37
    GoogleServiceLayer,
38
    LayerProcessController)
39
40
def setUpLaunchpad():
41
    """Set-up the Launchpad app-server against which windmill tests are run.
42
    """
43
    sys.stderr.write('Starting up Launchpad... ')
44
    BaseLayer.setUp()
45
    DatabaseLayer.setUp()
46
    # The below tests installs atexit handler that will clean-up their
47
    # resources on. So we install only one for the Database.
48
    atexit.register(DatabaseLayer.tearDown)
49
    LibrarianLayer.setUp()
50
    GoogleServiceLayer.setUp()
51
    LayerProcessController.startSMTPServer()
52
    LayerProcessController.startAppServer()
53
    sys.stderr.write('done.\n')
7150.2.1 by Francis J. Lacoste
Add link to windmill sourcecode dependencies.
54
7471.4.25 by Francis J. Lacoste
Add possibility only to start the launchpad server.
55
56
def runWindmill():
57
    """Start windmill using our command line arguments.
58
59
    This function exits once windmill has terminated.
60
    """
7167.3.2 by Francis J. Lacoste
Added lp-windmill.py wrapper that starts LP. Moved bare windmill to utilities.
61
    windmill_cmdline = [
62
        os.path.join(here, 'utilities', 'windmill.py'),
63
        ]
64
    windmill_cmdline.extend(sys.argv[1:])
65
    windmill = subprocess.Popen(
66
        windmill_cmdline, close_fds=True, env=original_environ)
67
    try:
68
        windmill.wait()
69
    except KeyboardInterrupt:
70
        os.kill(windmill.pid, signal.SIGTERM)
7471.4.25 by Francis J. Lacoste
Add possibility only to start the launchpad server.
71
72
73
def waitForInterrupt():
74
    """Sits in a sleep loop waiting for a Ctrl-C."""
75
    try:
76
        sys.stderr.write('Waiting for Ctrl-C...\n')
77
        while True:
78
            time.sleep(10)
79
    except KeyboardInterrupt:
80
        pass
81
82
83
if __name__ == '__main__':
84
    setUpLaunchpad()
85
    if sys.argv[1] == '--server-only':
86
        waitForInterrupt()
87
    else:
88
        runWindmill()
7167.3.2 by Francis J. Lacoste
Added lp-windmill.py wrapper that starts LP. Moved bare windmill to utilities.
89
    sys.stderr.write('Shutting down Launchpad...\n')