-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
2008 lines (1677 loc) · 98.8 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import re
import os
import stat
import sys
import shutil
import subprocess
import argparse
import yaml
import logging
import time
import atexit
from subprocess import Popen, PIPE
import shlex
import datetime
import glob
import sys
if sys.version_info[0] < 3:
reload(sys)
sys.setdefaultencoding('utf8')
class RegressionTestErrorPG(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)
# this class must be initialized per repository/branch/revision
class Build:
def __init__(self, config, repository, build_dir):
self.config = config
self.repository = repository
self.build_dir = build_dir
self.install_dir = False
# holds scripts to execute on cleanup
self.cleanup_exec = []
# holds files and directories to remove in case of error
self.cleanup_error = []
# holds files and directories to remove when instance is destroyed
self.cleanup_clean = []
# holds all the support archives
self.support_archives = []
# logfile directory, valid during Greenplum tests
self.regression_logfile_directory = False
# directory which holds the buildfarm logfiles
self.buildfarm_logs = os.path.join(build_dir, '.buildfarm-logs')
# create directory for buildfarm logfiles
os.mkdir(self.buildfarm_logs, 0o0700)
atexit.register(self.exit_handler)
def exit_handler(self):
for script in self.cleanup_exec:
logging.debug("execute cleanup script: " + script)
run = self.run_shell(script)
# throw away the result
for entry in self.cleanup_error:
if (os.path.isdir(entry)):
logging.debug("remove directory after error: " + entry)
shutil.rmtree(entry, ignore_errors=True)
if (os.path.isfile(entry)):
logging.debug("remove file after error: " + entry)
try:
os.remove(entry)
except OSError as e:
logging.error("failed to remove file: " + entry)
logging.error("error: " + e.strerror)
for entry in self.cleanup_clean:
if (os.path.isdir(entry)):
logging.debug("remove clean directory: " + entry)
shutil.rmtree(entry, ignore_errors=True)
if (os.path.isfile(entry)):
logging.debug("remove clean file: " + entry)
try:
os.remove(entry)
except OSError as e:
logging.error("failed to remove file: " + entry)
logging.error("error: " + e.strerror)
# add_support_archive()
#
# store a support archive path
#
# parameter:
# - self
# - path to archive
# return:
# none
def add_support_archive(self, script):
self.support_archives.append(script)
# list_all_support_archives()
#
# list all stored support archives
#
# parameter:
# - self
# return:
# - list of created support archives
def list_all_support_archives(self):
return self.support_archives
# add_script_to_delete_exec()
#
# execute a script before the repository is deleted
#
# parameter:
# - self
# - path to script
# return:
# none
def add_script_to_delete_exec(self, script):
self.cleanup_exec.append(script)
# add_entry_to_delete_error()
#
# remember file or directory to be deleted in case of error
#
# parameter:
# - self
# - path name
# return:
# none
def add_entry_to_delete_error(self, entry):
if (self.config.get('clean-everything') is False):
logging.debug("not cleaning up: " + entry)
else:
if (self.config.get('clean-on-failure') == True):
self.cleanup_error.append(entry)
# add_entry_to_delete_clean()
#
# remember file or directory to be deleted when instance is destroyed
#
# parameter:
# - self
# - path name
# return:
# none
def add_entry_to_delete_clean(self, entry):
if (self.config.get('clean-everything') is False):
logging.debug("not cleaning up: " + entry)
else:
self.cleanup_clean.append(entry)
# portcheck()
#
# check socketfiles for TCP ports
#
# parameter:
# - self
# - repository type
# - log data object
# return:
# - True/False
def portcheck(self, repository_type, log_data):
if (repository_type == 'PostgreSQL'):
log_data['result_portcheck'] = 0
# PostgreSQL usually uses '57832', or $PGPORT
ports = ['57832']
if (os.environ.get('PGPORT') is not None and len(os.environ.get('PGPORT')) > 0):
ports.append(os.environ.get('PGPORT'))
sockets_exist = []
for port in ports:
if (os.path.exists('/tmp/.s.PGSQL.' + port)):
sockets_exist.append('/tmp/.s.PGSQL.' + port)
if (len(sockets_exist) > 0):
# at least one port is blocked
log_data['errorstr'] = 'Socket file(s) exists: ' + ", ".join(sockets_exist)
logging.error(log_data['errorstr'])
log_data['result_portcheck'] = 1
return False
else:
log_data['result_portcheck'] = 0
return True
elif (repository_type == 'Greenplum'):
# ports are hardcoded for now, although the Greenplum suite allows it to change the ports
ports = ['15432']
for i in range(25432, 25432 + 20):
ports.append(str(i))
if (os.environ.get('PGPORT') is not None and len(os.environ.get('PGPORT')) > 0):
ports.append(os.environ.get('PGPORT'))
sockets_exist = []
for port in ports:
if (os.path.exists('/tmp/.s.PGSQL.' + port)):
sockets_exist.append('/tmp/.s.PGSQL.' + port)
if (len(sockets_exist) > 0):
# at least one port is blocked
log_data['errorstr'] = 'Socket file(s) exists: ' + ", ".join(sockets_exist)
logging.error(log_data['errorstr'])
log_data['result_portcheck'] = 1
return False
else:
log_data['result_portcheck'] = 0
return True
else:
logging.error("Unsupported repository type: " + repository_type)
sys.exit(1)
# run_configure()
#
# run "./configure" command in build directory
#
# parameter:
# - self
# - optional extra options for "configure"
# - name of the build directory (without path)
# - pointer to log data
# return:
# - True/False (False if error)
def run_configure(self, extra_options, build_dir_name, log_data):
self.extra_configure_options = extra_options
install_dir = self.config.get('install-dir')
# write 'githead.log'
f = open(os.path.join(self.buildfarm_logs, 'githead.log'), 'w')
f.write(log_data['revision'])
f.close()
full_install_dir = os.path.join(install_dir, build_dir_name)
self.install_dir = full_install_dir
logging.info("install dir: " + full_install_dir)
repository_type = self.repository.identify_repository_type(self.build_dir)
execute = "./configure --prefix='" + full_install_dir + "'"
# FIXME: Orca
if (len(extra_options) > 0):
execute += ' ' + extra_options
if (repository_type == 'PostgreSQL'):
execute += ' --with-pgport=5678'
# FIXME: remove existing --with-pgport from configure line
run = self.run_shell(execute)
self.dump_logs(self.build_dir, run, execute, self.config.logfile_name("configure"))
log_data['run_configure'] = True
log_data['extra_configure'] = extra_options
log_data['result_configure'] = run[0]
log_data['time_configure'] = run[2]
# before handling an error during configure, create 'configure.log' and 'config.log' in the log directory
# keep metadata (like mtime) intact, the PostgreSQL buildfarm depends on it
self.copy_logfile(self.config.logfile_name("configure", file_type = 'stdout_stderr', full_path = self.build_dir), os.path.join(self.buildfarm_logs, 'configure.log'))
self.copy_logfile(os.path.join(self.build_dir, 'config.log'), os.path.join(self.buildfarm_logs, 'config.log'))
if (run[0] > 0):
self.print_run_error(run, execute)
return False
# read version information from src/include/pg_config.h
f = open(os.path.join(self.build_dir, 'src', 'include', 'pg_config.h'), 'rU')
for line in iter(f):
line = line.rstrip('\n')
v = re.match('^#define PG_MAJORVERSION "(.+?)"', line)
if (v):
log_data['pg_majorversion'] = v.group(1)
#print("pg_majorversion: " + v.group(1))
continue
v = re.match('^#define PG_VERSION "(.+?)"', line)
if (v):
log_data['pg_version'] = v.group(1)
#print("pg_version: " + v.group(1))
continue
v = re.match('^#define PG_VERSION_NUM (\d+)', line)
if (v):
log_data['pg_version_num'] = v.group(1)
#print("pg_version_num: " + v.group(1))
continue
v = re.match('^#define PG_VERSION_STR "(.+?)"', line)
if (v):
log_data['pg_version_str'] = v.group(1)
#print("pg_version_str: " + v.group(1))
continue
v = re.match('^#define GP_MAJORVERSION "(.+?)"', line)
if (v):
log_data['gp_majorversion'] = v.group(1)
#print("gp_majorversion: " + v.group(1))
continue
v = re.match('^#define GP_VERSION "(.+?)"', line)
if (v):
log_data['gp_version'] = v.group(1)
#print("gp_version: " + v.group(1))
continue
v = re.match('^#define GP_VERSION_NUM (\d+)', line)
if (v):
log_data['gp_version_num'] = v.group(1)
#print("gp_version_num: " + v.group(1))
continue
f.close()
return True
# run_make()
#
# run "make" in build directory
#
# parameter:
# - self
# - optional extra options for "make"
# - pointer to log data
# return:
# - True/False (False if error)
def run_make(self, extra_options, log_data):
self.extra_make_options = extra_options
# FIXME: ccache
#ccache_bin = self.config.get('ccache-bin')
make_parallel = self.config.get('make-parallel')
execute = "make"
if (make_parallel > 1):
execute += ' -j ' + str(make_parallel)
if (len(extra_options) > 0):
execute += ' ' + extra_options
run = self.run_shell(execute)
self.dump_logs(self.build_dir, run, execute, self.config.logfile_name("make"))
log_data['run_make'] = True
log_data['extra_make'] = extra_options
log_data['result_make'] = run[0]
log_data['time_make'] = run[2]
# before handling an error during configure, create 'make.log' in the log directory
# keep metadata (like mtime) intact, the PostgreSQL buildfarm depends on it
self.copy_logfile(self.config.logfile_name("make", file_type = 'stdout_stderr', full_path = self.build_dir), os.path.join(self.buildfarm_logs, 'make.log'))
if (run[0] > 0):
self.print_run_error(run, execute)
return False
return True
# run_make_install()
#
# run "make install" in build directory
#
# parameter:
# - self
# - optional extra options for "make install"
# - pointer to log data
# - extra options for make
# return:
# - False (if error)
# - path to install dir
def run_make_install(self, extra_options, log_data, make_extra_options):
self.extra_install_options = extra_options
execute = "make install"
if (len(extra_options) > 0):
execute += ' ' + extra_options
run = self.run_shell(execute)
self.dump_logs(self.build_dir, run, execute, self.config.logfile_name("install"))
log_data['run_install'] = True
log_data['extra_install'] = extra_options
log_data['result_install'] = run[0]
log_data['time_install'] = run[2]
if (run[0] > 0):
self.print_run_error(run, execute)
return False
repository_type = self.repository.identify_repository_type(self.build_dir)
if (repository_type == 'PostgreSQL'):
make_parallel = self.config.get('make-parallel')
make_execute = "make"
make_execute_parallel = "make"
if (make_parallel > 1):
make_execute_parallel += ' -j ' + str(make_parallel)
if (len(make_extra_options) > 0):
make_execute += ' ' + make_extra_options
make_execute_parallel += ' ' + make_extra_options
# create script to run 'make check'
filename = os.path.join(self.build_dir, 'buildclient_run_regression_tests.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write(make_execute + " check" + os.linesep)
# FIXME: run additional targets
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
datadirs = os.path.join(self.install_dir, "tmp_demo_db")
# initialize and start the database
filename = os.path.join(self.install_dir, 'buildclient_initdb.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("" + os.linesep)
f.write("cd '" + self.install_dir + "'" + os.linesep)
f.write("mkdir -p '" + datadirs + "'" + os.linesep)
f.write("./bin/initdb -D '" + datadirs + "'" + os.linesep)
f.write("echo 'port = 15432' >> '" + os.path.join(datadirs, 'postgresql.conf') + "'" + os.linesep)
f.write("./bin/pg_ctl -D '" + datadirs + "' -l '" + os.path.join(datadirs, 'logfile') + "' start" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# script which will start psql + arguments
filename = os.path.join(self.install_dir, 'buildclient_psql.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("" + os.linesep)
f.write("cd '" + self.install_dir + "'" + os.linesep)
f.write('./bin/psql -p 15432 "$@"' + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# script which will start arbitrary tools
filename = os.path.join(self.install_dir, 'buildclient_debug.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("" + os.linesep)
f.write("cd '" + self.install_dir + "'" + os.linesep)
f.write("set -x" + os.linesep);
f.write("" + os.linesep);
f.write("# build dir: " + self.build_dir + os.linesep);
f.write("# install dir: " + self.install_dir + os.linesep);
f.write("" + os.linesep);
f.write('# add your script here' + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# script which will generate a support package
if (self.config.get("support-bin")):
filename = os.path.join(self.install_dir, 'buildclient_support.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write("" + os.linesep);
f.write(self.config.get("support-bin") + " --archive-type " + self.config.get('support-archive-type') + "" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# script which will start the database
filename = os.path.join(self.install_dir, 'buildclient_start_db.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("cd '" + self.install_dir + "'" + os.linesep)
f.write("./bin/pg_ctl -D '" + datadirs + "' -l '" + os.path.join(datadirs, 'logfile') + "' start" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# script which will stop the database
filename = os.path.join(self.install_dir, 'buildclient_stop_db.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("cd '" + self.install_dir + "'" + os.linesep)
f.write("./bin/pg_ctl -D '" + datadirs + "' -m fast stop" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# stop the cluster when the module is destroyed
self.add_script_to_delete_exec(filename)
if (log_data['is_buildfarm'] is True):
# create script to run the buildfarm regression tests (make check)
filename = os.path.join(self.build_dir, 'buildclient_run_buildfarm_regression_tests.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
# FIXME: add locales, add user
# FIXME: start server separately
#f.write("make check" + os.linesep)
f.write("cd " + os.path.join('src', 'test', 'regress') + os.linesep)
f.write(make_execute + " NO_LOCALE=1 check" + os.linesep)
# FIXME: run additional targets: run_extra_targets
# FIXME: test_locales
# FIXME: stop server
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# create script to run the buildfarm regression tests (make contrib)
filename = os.path.join(self.build_dir, 'buildclient_run_buildfarm_make_contrib.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write("cd contrib" + os.linesep)
if (int(log_data['pg_version_num']) >= 90100):
f.write(make_execute_parallel + "" + os.linesep)
else:
f.write(make_execute + "" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# create script to run the buildfarm regression tests (make testmodules)
filename = os.path.join(self.build_dir, 'buildclient_run_buildfarm_make_testmodules.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write("cd " + os.path.join('src', 'test', 'modules') + os.linesep)
f.write(make_execute_parallel + "" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# create script to run the buildfarm regression tests (make install in contrib)
filename = os.path.join(self.build_dir, 'buildclient_run_buildfarm_make_contrib-install.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write("cd contrib" + os.linesep)
f.write(make_execute + " install" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# create script to run the buildfarm regression tests (make install in modules)
filename = os.path.join(self.build_dir, 'buildclient_run_buildfarm_make_testmodules-install.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write("cd " + os.path.join('src', 'test', 'modules') + os.linesep)
f.write(make_execute + " install" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
if (int(log_data['pg_version_num']) >= 90200):
# create script to run the buildfarm regression tests (test upgrade)
filename = os.path.join(self.build_dir, 'buildclient_run_buildfarm_make_pg_upgrade.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write("export PGHOST=/tmp" + os.linesep)
if (int(log_data['pg_version_num']) >= 90500):
f.write("cd " + os.path.join('src', 'bin', 'pg_upgrade') + os.linesep)
else:
f.write("cd " + os.path.join('contrib', 'pg_upgrade') + os.linesep)
f.write(make_execute + " check" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# create script to run the buildfarm regression tests (test-decoding-check)
filename = os.path.join(self.build_dir, 'buildclient_run_buildfarm_make_test-decoding-check.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write("cd " + os.path.join('contrib', 'test_decoding') + os.linesep)
f.write(make_execute + " check" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# create script to run the buildfarm regression tests (initdb with locale)
filename = os.path.join(self.build_dir, 'buildclient_run_buildfarm_initdb.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("cd '" + self.install_dir + "'" + os.linesep)
f.write("./bin/initdb -U ads --locale=$1 data-$1" + os.linesep)
f.write("cat buildfarm_append_postgresql.conf >> data-$1/postgresql.conf" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# create part of a config file which will be appended to the main config
filename = os.path.join(self.install_dir, 'buildfarm_append_postgresql.conf')
f = open(filename, 'w')
f.write(os.linesep + os.linesep)
f.write("# settings for buildfarm:" + os.linesep)
f.write("log_line_prefix = '%m [%c:%l] '" + os.linesep)
f.write("log_connections = 'true'" + os.linesep)
f.write("log_disconnections = 'true'" + os.linesep)
f.write("log_statement = 'all'" + os.linesep)
f.write("fsync = off" + os.linesep)
f.close()
# create script to run the buildfarm regression tests (start database)
filename = os.path.join(self.build_dir, 'buildclient_run_buildfarm_startdb.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("cd '" + self.install_dir + "'" + os.linesep)
# the original buildfarm uses the same logfile, and deletes it every time
# use a different logfile each time instead
f.write("./bin/pg_ctl -D data-$1 -l logfile-$1-$2 -w start" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# create script to run the buildfarm regression tests (stop database)
filename = os.path.join(self.build_dir, 'buildclient_run_buildfarm_stopdb.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("cd '" + self.install_dir + "'" + os.linesep)
f.write("export PGCTLTIMEOUT=120" + os.linesep)
#f.write("export PGUSER=ads" + os.linesep)
f.write("./bin/pg_ctl -D data-$1 stop" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# create script to run the buildfarm regression tests (shutdown database after failure)
filename = os.path.join(self.build_dir, 'buildclient_run_buildfarm_stopdbs_after_failure.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
#f.write('set -e' + os.linesep)
f.write("cd '" + self.install_dir + "'" + os.linesep)
f.write("export PGCTLTIMEOUT=120" + os.linesep)
#f.write("export PGUSER=ads" + os.linesep)
f.write("mkdir data-failure" + os.linesep)
f.write("for d in data*; do" + os.linesep)
f.write("./bin/pg_ctl -m immediate -l logfile_stop_after_failure -D $d stop" + os.linesep)
f.write("done" + os.linesep)
f.write("exit 0" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# create script to run the buildfarm regression tests (installcheck)
filename = os.path.join(self.build_dir, 'buildclient_run_buildfarm_installcheck.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write("cd " + os.path.join('src', 'test', 'regress') + os.linesep)
#f.write("export PGUSER=ads" + os.linesep)
f.write(make_execute + " installcheck" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# create script to run the buildfarm regression tests (isolation-check)
filename = os.path.join(self.build_dir, 'buildclient_run_buildfarm_isolation-check.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write("cd " + os.path.join('src', 'test', 'isolation') + os.linesep)
#f.write("export PGUSER=ads" + os.linesep)
f.write(make_execute + " NO_LOCALE=1 installcheck" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# create script to run the buildfarm regression tests (pl-installcheck)
filename = os.path.join(self.build_dir, 'buildclient_run_buildfarm_pl-installcheck.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write("cd " + os.path.join('src', 'pl') + os.linesep)
#f.write("export PGUSER=ads" + os.linesep)
f.write(make_execute + " installcheck" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# create script to run the buildfarm regression tests (contrib-installcheck)
filename = os.path.join(self.build_dir, 'buildclient_run_buildfarm_contrib-installcheck.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write("cd " + os.path.join('contrib') + os.linesep)
#f.write("export PGUSER=ads" + os.linesep)
f.write(make_execute + " USE_MODULE_DB=1 installcheck" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# create script to run the buildfarm regression tests (testmodules-installcheck)
filename = os.path.join(self.build_dir, 'buildclient_run_buildfarm_testmodules-installcheck.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write("cd " + os.path.join('src', 'test', 'modules') + os.linesep)
#f.write("export PGUSER=ads" + os.linesep)
f.write(make_execute + " USE_MODULE_DB=1 installcheck" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# create script to run the buildfarm regression tests (ecpg-check)
filename = os.path.join(self.build_dir, 'buildclient_run_buildfarm_ecpg-check.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write('set -e' + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write("cd " + os.path.join('src', 'interfaces', 'ecpg') + os.linesep)
#f.write("export PGUSER=ads" + os.linesep)
f.write(make_execute + " NO_LOCALE=1 check" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
elif (repository_type == 'Greenplum'):
# create script to start and stop the demo cluster
# and to run the test suite
datadirs = os.path.join(self.install_dir, "tmp_regression_tests")
# make cluster script (starts the cluster)
filename = os.path.join(self.install_dir, 'buildclient_make_cluster.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write("# try passwordless ssh login to localhost" + os.linesep)
f.write("ssh -oBatchMode=yes localhost 'exit 0'" + os.linesep)
f.write("result=$?" + os.linesep)
f.write('if [ "$result" -ne "0" ];' + os.linesep)
f.write("then" + os.linesep)
f.write("\techo 'ssh login without password is not working!'" + os.linesep)
f.write("\techo 'please verify your ssh configuration.'" + os.linesep)
f.write("\texit 1" + os.linesep)
f.write("fi" + os.linesep)
f.write("" + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write(". '" + os.path.join(self.install_dir, "greenplum_path.sh") + "'" + os.linesep)
f.write("cd gpAux/gpdemo" + os.linesep)
# debug:
f.write("export DATADIRS='" + datadirs + "'" + os.linesep)
# FIXME: make ports dynamic
# FIXME: make directory dynamic
f.write("export MASTER_PORT=15432" + os.linesep)
f.write("export PORT_BASE=25432" + os.linesep)
f.write("" + os.linesep)
f.write("make cluster" + os.linesep)
f.write("#. gpdemo-env.sh" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# extract MASTER_DATA_DIRECTORY
#/home/ads/postgresql/buildfarm/build/2016-03-01_185803_master/gpAux/gpdemo/datadirs/qddir/demoDataDir-1
# script which will start psql + arguments
filename = os.path.join(self.install_dir, 'buildclient_psql.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write(". '" + os.path.join(self.install_dir, 'greenplum_path.sh') + "'" + os.linesep)
f.write(". '" + os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'gpdemo-env.sh') + "'" + os.linesep)
#f.write("export MASTER_DATA_DIRECTORY='" . os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'datadirs', 'qddir', 'demoDataDir-1') + "'" + os.linesep)
f.write('psql "$@"' + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# script which will start arbitrary tools
filename = os.path.join(self.install_dir, 'buildclient_debug.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write(". '" + os.path.join(self.install_dir, 'greenplum_path.sh') + "'" + os.linesep)
f.write(". '" + os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'gpdemo-env.sh') + "'" + os.linesep)
#f.write("export MASTER_DATA_DIRECTORY='" . os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'datadirs', 'qddir', 'demoDataDir-1') + "'" + os.linesep)
f.write("" + os.linesep);
f.write("set -x" + os.linesep);
f.write("" + os.linesep);
f.write("# build dir: " + self.build_dir + os.linesep);
f.write("# install dir: " + self.install_dir + os.linesep);
f.write("" + os.linesep);
f.write('# add your script here' + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# script which will generate a support package
if (self.config.get("support-bin")):
filename = os.path.join(self.install_dir, 'buildclient_support.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write("" + os.linesep);
f.write(self.config.get("support-bin") + " --archive-type " + self.config.get('support-archive-type') + " --logfiles '" + os.path.join(datadirs, "gpAdminLogs") + "'" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# script which will start the cluster
filename = os.path.join(self.install_dir, 'buildclient_start_cluster.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write(". '" + os.path.join(self.install_dir, 'greenplum_path.sh') + "'" + os.linesep)
f.write("if [ -f '" + os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'gpdemo-env.sh') + "' ];" + os.linesep)
f.write("then" + os.linesep)
f.write(" . '" + os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'gpdemo-env.sh') + "'" + os.linesep)
#f.write("export MASTER_DATA_DIRECTORY='" . os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'datadirs', 'qddir', 'demoDataDir-1') + "'" + os.linesep)
f.write(" gpstart -a" + ' -l "$MASTER_DATA_DIRECTORY/../gpAdminLogs"' + os.linesep)
#f.write(" gpstart -a" + os.linesep)
f.write("fi" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# script which will stop the cluster
filename = os.path.join(self.install_dir, 'buildclient_stop_cluster.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write(". '" + os.path.join(self.install_dir, 'greenplum_path.sh') + "'" + os.linesep)
f.write("if [ -f '" + os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'gpdemo-env.sh') + "' ];" + os.linesep)
f.write("then" + os.linesep)
f.write(" . '" + os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'gpdemo-env.sh') + "'" + os.linesep)
#f.write("export MASTER_DATA_DIRECTORY='" . os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'datadirs', 'qddir', 'demoDataDir-1') + "'" + os.linesep)
f.write(" gpstop -a" + ' -l "$MASTER_DATA_DIRECTORY/../gpAdminLogs"' + os.linesep)
#f.write(" gpstop -a" + os.linesep)
f.write("fi" + os.linesep)
f.write("" + os.linesep)
f.write("# there is a problem hidden in the gpMgmt scripts, which leaves an empty" + os.linesep)
f.write("# logfile around in ~/gpAdminLogs/, even if a log directory is specified" + os.linesep)
f.write("# remove empty files in the default log directory" + os.linesep)
f.write("find ~/gpAdminLogs/ -type f -empty -atime -1 -mtime -1 -exec rm {} \;" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# stop the cluster when the module is destroyed
self.add_script_to_delete_exec(filename)
# combine everything into one script which runs the regression tests
filename = os.path.join(self.build_dir, 'buildclient_run_regression_tests.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
#f.write('set -e' + os.linesep + os.linesep)
f.write("cd '" + self.install_dir + "'" + os.linesep)
# for debugging purpose:
#f.write("exit 1" + os.linesep)
f.write("./buildclient_make_cluster.sh" + os.linesep)
f.write("" + os.linesep)
f.write(". '" + os.path.join(self.install_dir, 'greenplum_path.sh') + "'" + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write("if [ -f '" + os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'gpdemo-env.sh') + "' ];" + os.linesep)
f.write("then" + os.linesep)
f.write(" . '" + os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'gpdemo-env.sh') + "'" + os.linesep)
f.write("fi" + os.linesep)
# for debugging purpose:
#f.write("exit 1" + os.linesep)
f.write("make installcheck-world" + os.linesep)
f.write("result=$?" + os.linesep)
f.write("" + os.linesep)
f.write("cd '" + self.install_dir + "'" + os.linesep)
f.write("./buildclient_stop_cluster.sh" + os.linesep)
f.write("" + os.linesep)
f.write("exit $result" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# script which will run bugbuster tests
filename = os.path.join(self.install_dir, 'buildclient_bugbuster.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write(". '" + os.path.join(self.install_dir, 'greenplum_path.sh') + "'" + os.linesep)
f.write("if [ -f '" + os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'gpdemo-env.sh') + "' ];" + os.linesep)
f.write("then" + os.linesep)
f.write(" . '" + os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'gpdemo-env.sh') + "'" + os.linesep)
#f.write("export MASTER_DATA_DIRECTORY='" . os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'datadirs', 'qddir', 'demoDataDir-1') + "'" + os.linesep)
f.write(" export PATH='" + os.path.join(self.install_dir, 'bin') + "':$PATH" + os.linesep)
# change this when dynamic ports are used
f.write(" export PGPORT=15432" + os.linesep)
f.write(" cd '" + os.path.join(self.build_dir, 'src', 'test', 'regress') + "'" + os.linesep)
f.write(" ./pg_regress --psqldir='" + os.path.join(self.install_dir, 'tmp_regression_tests', 'qddir', 'demoDataDir-1') + "' --schedule=./bugbuster/known_good_schedule --psqldir='" + os.path.join(self.install_dir, 'bin') + "' --inputdir=bugbuster" + os.linesep)
f.write("fi" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# script which will run one regression test
filename = os.path.join(self.install_dir, 'buildclient_run_one_regression_test.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write(". '" + os.path.join(self.install_dir, 'greenplum_path.sh') + "'" + os.linesep)
f.write("if [ -f '" + os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'gpdemo-env.sh') + "' ];" + os.linesep)
f.write("then" + os.linesep)
f.write(" . '" + os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'gpdemo-env.sh') + "'" + os.linesep)
#f.write("export MASTER_DATA_DIRECTORY='" . os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'datadirs', 'qddir', 'demoDataDir-1') + "'" + os.linesep)
f.write(" export PATH='" + os.path.join(self.install_dir, 'bin') + "':$PATH" + os.linesep)
# change this when dynamic ports are used
f.write(" export PGPORT=15432" + os.linesep)
f.write(" cd '" + os.path.join(self.build_dir, 'src', 'test', 'regress') + "'" + os.linesep)
f.write(" ./pg_regress --psqldir='" + os.path.join(self.install_dir, 'tmp_regression_tests', 'qddir', 'demoDataDir-1') + "' --psqldir='" + os.path.join(self.install_dir, 'bin') + "' --inputdir=expected " + '"$@"'+ os.linesep)
f.write("fi" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
# script which will run only installcheck-good
filename = os.path.join(self.install_dir, 'buildclient_run_installcheck-good_test.sh')
f = open(filename, 'w')
f.write('#!/bin/sh' + os.linesep + os.linesep)
f.write("cd '" + self.build_dir + "'" + os.linesep)
f.write(". '" + os.path.join(self.install_dir, 'greenplum_path.sh') + "'" + os.linesep)
f.write("if [ -f '" + os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'gpdemo-env.sh') + "' ];" + os.linesep)
f.write("then" + os.linesep)
f.write(" . '" + os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'gpdemo-env.sh') + "'" + os.linesep)
#f.write("export MASTER_DATA_DIRECTORY='" . os.path.join(self.build_dir, 'gpAux', 'gpdemo', 'datadirs', 'qddir', 'demoDataDir-1') + "'" + os.linesep)
f.write(" export PATH='" + os.path.join(self.install_dir, 'bin') + "':$PATH" + os.linesep)
# change this when dynamic ports are used
f.write(" export PGPORT=15432" + os.linesep)
f.write(" cd '" + self.build_dir + "'" + os.linesep)
f.write(" make -C src/test installcheck-good" + os.linesep)
f.write("fi" + os.linesep)
f.close()
os.chmod(filename, stat.S_IRWXU | stat.S_IRWXG)
return self.install_dir
# run_tests()
#
# run tests in build directory
#
# parameter:
# - self
# - optional extra options for tests
# - pointer to log data
# return:
# - True/False (False if error)
def run_tests(self, extra_options, log_data):
self.extra_tests_options = extra_options
# FIXME: extra_options
# FIXME: run_extra_targets
repository_type = self.repository.identify_repository_type(self.build_dir)
if (repository_type == 'PostgreSQL'):
# FIXME: buildfarm timings
if (log_data['is_buildfarm'] is True):
execute = "./buildclient_run_buildfarm_regression_tests.sh"
else:
execute = "./buildclient_run_regression_tests.sh"
run = self.run_shell(execute)
test_log_number = 0
self.dump_logs(self.build_dir, run, execute, self.config.logfile_name("tests", second_number = test_log_number))
log_data['run_tests'] = True
log_data['extra_tests'] = extra_options
log_data['result_tests'] = run[0]
log_data['time_tests'] = run[2]
self.copy_logfile(self.config.logfile_name("tests", second_number = test_log_number, file_type = 'stdout_stderr', full_path = self.build_dir), os.path.join(self.buildfarm_logs, 'check.log'))
# add more logfiles, 'check.log' is a mingle-mangle of logs
files_log = glob.glob(os.path.join(self.build_dir, 'src', 'test', 'regress', 'log') + os.sep + '*.log')
files_log.extend(glob.glob(os.path.join(self.build_dir, 'tmp_install', 'log') + os.sep + '*'))
if (os.path.isfile(os.path.join(self.build_dir, 'src', 'test', 'regress', 'regression.diffs'))):
files_log[:0] = [os.path.join(self.build_dir, 'src', 'test', 'regress', 'regression.diffs')]
for file_log in files_log:
self.attach_logfile_pg_buildfarm(file_log,
os.path.join(self.buildfarm_logs, 'check.log'),