620
by Canonical.com Patch Queue Manager
Now checks pagetests on merge. Much work on page tests. Refactor of forgotten password pages. |
1 |
#!/usr/bin/env python2.3
|
44
by Canonical.com Patch Queue Manager
added test_on_merge.py |
2 |
# Copyright 2004 Canonical Ltd. All rights reserved.
|
3 |
||
4 |
"""Tests that get run automatically on a merge."""
|
|
5 |
||
1257
by Canonical.com Patch Queue Manager
Improve database locale checks, add locale sanity check to test_on_merge.py and improve test_on_merge output |
6 |
import sys, re |
657
by Canonical.com Patch Queue Manager
Tabnanny putting on her jackboots for the whitespace impared |
7 |
import os, os.path |
759
by Canonical.com Patch Queue Manager
Make test_on_merge.py check test results more accurately (Bug #2155) |
8 |
import popen2 |
657
by Canonical.com Patch Queue Manager
Tabnanny putting on her jackboots for the whitespace impared |
9 |
import tabnanny |
699
by Canonical.com Patch Queue Manager
Now checks for new or changes tags on merge. |
10 |
import checkarchtag |
657
by Canonical.com Patch Queue Manager
Tabnanny putting on her jackboots for the whitespace impared |
11 |
from StringIO import StringIO |
816
by Canonical.com Patch Queue Manager
Enabled cookie-auth, and various other incidental things. |
12 |
from threading import Thread |
940
by Canonical.com Patch Queue Manager
Full text indexing, database schema patches |
13 |
import psycopg |
816
by Canonical.com Patch Queue Manager
Enabled cookie-auth, and various other incidental things. |
14 |
|
15 |
class NonBlockingReader(Thread): |
|
16 |
||
17 |
result = None |
|
18 |
||
19 |
def __init__(self,file): |
|
20 |
Thread.__init__(self) |
|
21 |
self.file = file |
|
22 |
||
23 |
def run(self): |
|
24 |
self.result = self.file.read() |
|
25 |
||
26 |
def read(self): |
|
27 |
if self.result is None: |
|
28 |
raise RuntimeError("read() called before run()") |
|
29 |
return self.result |
|
30 |
||
31 |
def readlines(self): |
|
32 |
if self.result is None: |
|
33 |
raise RuntimeError("readlines() called before run()") |
|
34 |
return self.result.splitlines() |
|
35 |
||
44
by Canonical.com Patch Queue Manager
added test_on_merge.py |
36 |
|
37 |
def main(): |
|
38 |
"""Call test.py with whatever arguments this script was run with.
|
|
39 |
||
40 |
If the tests ran ok (last line of stderr is 'OK<return>') then suppress
|
|
41 |
output and exit(0).
|
|
42 |
||
43 |
Otherwise, print output and exit(1).
|
|
44 |
"""
|
|
45
by Canonical.com Patch Queue Manager
improve test_on_merge.py |
45 |
here = os.path.dirname(os.path.realpath(__file__)) |
657
by Canonical.com Patch Queue Manager
Tabnanny putting on her jackboots for the whitespace impared |
46 |
|
699
by Canonical.com Patch Queue Manager
Now checks for new or changes tags on merge. |
47 |
if not checkarchtag.is_tree_good(): |
48 |
return 1 |
|
49 |
||
856
by Canonical.com Patch Queue Manager
++resource++ URLs should be absolute and favicon |
50 |
# Tabnanny
|
657
by Canonical.com Patch Queue Manager
Tabnanny putting on her jackboots for the whitespace impared |
51 |
org_stdout = sys.stdout |
52 |
sys.stdout = StringIO() |
|
53 |
tabnanny.check(os.path.join(here, 'lib', 'canonical')) |
|
54 |
tabnanny_results = sys.stdout.getvalue() |
|
55 |
sys.stdout = org_stdout |
|
56 |
if len(tabnanny_results) > 0: |
|
57 |
print '---- tabnanny bitching ----' |
|
58 |
print tabnanny_results |
|
59 |
print '---- end tabnanny bitching ----' |
|
60 |
return 1 |
|
706
by Canonical.com Patch Queue Manager
Make merge check use full test suite |
61 |
|
856
by Canonical.com Patch Queue Manager
++resource++ URLs should be absolute and favicon |
62 |
# Ensure ++resource++ URL's are all absolute - this ensures they
|
63 |
# are cache friendly
|
|
64 |
results = os.popen( |
|
65 |
"find lib/canonical -type f | xargs grep '[^/]++resource++'"
|
|
66 |
).readlines() |
|
67 |
if results: |
|
68 |
print '---- non-absolute ++resource++ URLs found ----' |
|
69 |
print ''.join(results) |
|
70 |
print '---- end non-absolute ++resource++ URLs found ----' |
|
71 |
return 1 |
|
72 |
||
1064.1.3
by James Henstridge
merge from marius |
73 |
# Sanity check PostgreSQL version. No point in trying to create a test
|
74 |
# database when PostgreSQL is too old.
|
|
75 |
con = psycopg.connect('dbname=template1') |
|
76 |
cur = con.cursor() |
|
77 |
cur.execute('show server_version') |
|
78 |
server_version = cur.fetchone()[0] |
|
79 |
try: |
|
80 |
numeric_server_version = tuple(map(int, server_version.split('.'))) |
|
81 |
except ValueError: |
|
82 |
# Skip this check if the version number is more complicated than
|
|
83 |
# we expected.
|
|
84 |
pass
|
|
85 |
else: |
|
86 |
if numeric_server_version < (7, 4): |
|
87 |
print 'Your PostgreSQL version is too old. You need 7.4.x' |
|
88 |
print 'You have %s' % server_version |
|
89 |
return 1 |
|
90 |
||
940
by Canonical.com Patch Queue Manager
Full text indexing, database schema patches |
91 |
# Drop the template database if it exists - the Makefile does this
|
92 |
# too, but we can explicity check for errors here
|
|
93 |
con = psycopg.connect('dbname=template1') |
|
94 |
cur = con.cursor() |
|
1064.1.3
by James Henstridge
merge from marius |
95 |
try: |
96 |
cur.execute('end transaction; drop database launchpad_ftest_template') |
|
1520
by Canonical.com Patch Queue Manager
Review and fix database security update code |
97 |
except psycopg.ProgrammingError, x: |
98 |
if 'does not exist' not in str(x): |
|
99 |
raise
|
|
940
by Canonical.com Patch Queue Manager
Full text indexing, database schema patches |
100 |
cur.close() |
101 |
con.close() |
|
102 |
||
103 |
||
104 |
# Build the template database. Tests duplicate this.
|
|
105 |
here = os.path.dirname(os.path.realpath(__file__)) |
|
106 |
schema_dir = os.path.join(here, 'database', 'schema') |
|
1297
by Canonical.com Patch Queue Manager
Merge in database security branch |
107 |
if os.system('cd %s; make test PYTHON=%s > /dev/null' % ( |
1155
by Canonical.com Patch Queue Manager
More robust authentication |
108 |
schema_dir, sys.executable)) != 0: |
1764
by Canonical.com Patch Queue Manager
Now make check fails if anything goes wrong when loading the sampledata. r=stub |
109 |
print 'Failed to create database or load sampledata.' |
940
by Canonical.com Patch Queue Manager
Full text indexing, database schema patches |
110 |
return 1 |
111 |
||
112 |
# Sanity check the database. No point running tests if the
|
|
113 |
# bedrock is crumbling.
|
|
114 |
con = psycopg.connect('dbname=launchpad_ftest_template') |
|
115 |
cur = con.cursor() |
|
116 |
cur.execute('show search_path') |
|
117 |
search_path = cur.fetchone()[0] |
|
118 |
if search_path != '$user,public,ts2': |
|
119 |
print 'Search path incorrect.' |
|
120 |
print 'Add the following line to /etc/postgresql/postgresql.conf:' |
|
121 |
print " search_path = '$user,public,ts2'" |
|
1064.1.3
by James Henstridge
merge from marius |
122 |
print "and tell postgresql to reload its configuration file." |
940
by Canonical.com Patch Queue Manager
Full text indexing, database schema patches |
123 |
return 1 |
124 |
cur.execute(""" |
|
125 |
select pg_encoding_to_char(encoding) as encoding from pg_database
|
|
126 |
where datname='launchpad_ftest_template'
|
|
127 |
""") |
|
128 |
enc = cur.fetchone()[0] |
|
129 |
if enc != 'UNICODE': |
|
130 |
print 'Database encoding incorrectly set' |
|
131 |
return 1 |
|
1257
by Canonical.com Patch Queue Manager
Improve database locale checks, add locale sanity check to test_on_merge.py and improve test_on_merge output |
132 |
cur.execute(r""" |
133 |
SELECT setting FROM pg_settings
|
|
134 |
WHERE context='internal' AND name='lc_ctype'
|
|
135 |
""") |
|
136 |
loc = cur.fetchone()[0] |
|
137 |
if not (loc.startswith('en_') or loc in ('C', 'en')): |
|
138 |
print 'Database locale incorrectly set. Need to rerun initdb.' |
|
139 |
return 1 |
|
140 |
||
940
by Canonical.com Patch Queue Manager
Full text indexing, database schema patches |
141 |
# Explicity close our connections - things will fail if we leave open
|
142 |
# connections.
|
|
143 |
cur.close() |
|
144 |
del cur |
|
145 |
con.close() |
|
146 |
del con |
|
147 |
||
148 |
||
706
by Canonical.com Patch Queue Manager
Make merge check use full test suite |
149 |
print 'Running tests.' |
1257
by Canonical.com Patch Queue Manager
Improve database locale checks, add locale sanity check to test_on_merge.py and improve test_on_merge output |
150 |
cmd = 'cd %s; %s test.py %s < /dev/null' % ( |
151 |
here, sys.executable, ' '.join(sys.argv[1:]) |
|
152 |
)
|
|
153 |
print cmd |
|
154 |
proc = popen2.Popen3(cmd, True) |
|
759
by Canonical.com Patch Queue Manager
Make test_on_merge.py check test results more accurately (Bug #2155) |
155 |
stdin, out, err = proc.tochild, proc.fromchild, proc.childerr |
816
by Canonical.com Patch Queue Manager
Enabled cookie-auth, and various other incidental things. |
156 |
|
157 |
# Use non-blocking reader threads to cope with differing expectations
|
|
158 |
# from the proess of when to consume data from out and error.
|
|
159 |
errthread = NonBlockingReader(err) |
|
160 |
outthread = NonBlockingReader(out) |
|
161 |
errthread.start() |
|
162 |
outthread.start() |
|
163 |
errthread.join() |
|
164 |
outthread.join() |
|
759
by Canonical.com Patch Queue Manager
Make test_on_merge.py check test results more accurately (Bug #2155) |
165 |
exitcode = proc.wait() |
761
by Canonical.com Patch Queue Manager
Make test_on_merge.py rely only on exit code, to avoid spurious failures. |
166 |
test_ok = (os.WIFEXITED(exitcode) and os.WEXITSTATUS(exitcode) == 0) |
44
by Canonical.com Patch Queue Manager
added test_on_merge.py |
167 |
|
816
by Canonical.com Patch Queue Manager
Enabled cookie-auth, and various other incidental things. |
168 |
errlines = errthread.readlines() |
169 |
dataout = outthread.read() |
|
170 |
||
44
by Canonical.com Patch Queue Manager
added test_on_merge.py |
171 |
if test_ok: |
1257
by Canonical.com Patch Queue Manager
Improve database locale checks, add locale sanity check to test_on_merge.py and improve test_on_merge output |
172 |
for line in errlines: |
173 |
if re.match('^Ran\s\d+\stest(s)?\sin\s[\d\.]+s$', line): |
|
174 |
print line |
|
44
by Canonical.com Patch Queue Manager
added test_on_merge.py |
175 |
return 0 |
176 |
else: |
|
177 |
print '---- test stdout ----' |
|
178 |
print dataout |
|
179 |
print '---- end test stdout ----' |
|
180 |
||
181 |
print '---- test stderr ----' |
|
830
by Canonical.com Patch Queue Manager
Work around bug in tales and traversal. |
182 |
print '\n'.join(errlines) |
44
by Canonical.com Patch Queue Manager
added test_on_merge.py |
183 |
print '---- end test stderr ----' |
184 |
return 1 |
|
185 |
||
186 |
if __name__ == '__main__': |
|
187 |
sys.exit(main()) |