forked from h2oai/h2o-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
executable file
·2626 lines (2284 loc) · 93.7 KB
/
run.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
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
Test harness.
:copyright: (c) 2016 H2O.ai
:license: Apache License Version 2.0 (see LICENSE for details)
"""
import sys
import os
import shutil
import signal
import time
import random
import getpass
import re
import subprocess
import requests
import socket
import multiprocessing
import platform
if sys.version_info[0] < 3:
# noinspection PyPep8Naming
import ConfigParser as configparser
else:
import configparser
def is_rdemo(file_name):
"""
Return True if file_name matches a regexp for an R demo. False otherwise.
:param file_name: file to test
"""
packaged_demos = ["h2o.anomaly.R", "h2o.deeplearning.R", "h2o.gbm.R", "h2o.glm.R", "h2o.glrm.R", "h2o.kmeans.R",
"h2o.naiveBayes.R", "h2o.prcomp.R", "h2o.randomForest.R"]
if file_name in packaged_demos: return True
if re.match("^rdemo.*\.(r|R|ipynb)$", file_name): return True
return False
def is_runit(file_name):
"""
Return True if file_name matches a regexp for an R unit test. False otherwise.
:param file_name: file to test
"""
if file_name == "h2o-runit.R": return False
if re.match("^runit.*\.[rR]$", file_name): return True
return False
def is_rbooklet(file_name):
"""
Return True if file_name matches a regexp for an R booklet. False otherwise.
:param file_name: file to test
"""
if re.match("^rbooklet.*\.[rR]$", file_name): return True
return False
def is_pydemo(file_name):
"""
Return True if file_name matches a regexp for a python demo. False otherwise.
:param file_name: file to test
"""
if re.match("^pydemo.*\.py$", file_name): return True
return False
def is_ipython_notebook(file_name):
"""
Return True if file_name matches a regexp for an ipython notebook. False otherwise.
:param file_name: file to test
"""
if (not re.match("^.*checkpoint\.ipynb$", file_name)) and re.match("^.*\.ipynb$", file_name): return True
return False
def is_pyunit(file_name):
"""
Return True if file_name matches a regexp for a python unit test. False otherwise.
:param file_name: file to test
"""
if re.match("^pyunit.*\.py$", file_name): return True
return False
def is_pybooklet(file_name):
"""
Return True if file_name matches a regexp for a python unit test. False otherwise.
:param file_name: file to test
"""
if re.match("^pybooklet.*\.py$", file_name): return True
return False
def is_gradle_build_python_test(file_name):
"""
Return True if file_name matches a regexp for on of the python test run during gradle build. False otherwise.
:param file_name: file to test
"""
return file_name in ["gen_all.py", "test_gbm_prostate.py", "test_rest_api.py"]
def is_javascript_test_file(file_name):
"""
Return True if file_name matches a regexp for a javascript test. False otherwise.
:param file_name: file to test
"""
if re.match("^.*test.*\.js$", file_name): return True
return False
'''
function grab_java_message() will look through the java text output and try to extract the
java messages from Java side.
'''
def grab_java_message(node_list, curr_testname):
"""scan through the java output text and extract the java messages related to running
test specified in curr_testname.
Parameters
----------
:param node_list: list of H2O nodes
List of H2o nodes associated with a H2OCloud that are performing the test specified in curr_testname.
:param curr_testname: str
Store the unit test name (can be R unit or Py unit) that has been completed and failed.
:return: a string object that is either empty or the java messages that associated with the test in curr_testname.
The java messages can usually be found in one of the java_*_0.out.txt
"""
global g_java_start_text # contains text that describe the start of a unit test.
java_messages = ""
start_test = False # denote when the current test was found in the java_*_0.out.txt file
# grab each java file and try to grab the java messages associated with curr_testname
for each_node in node_list:
java_filename = each_node.output_file_name # find the java_*_0.out.txt file
if os.path.isfile(java_filename):
java_file = open(java_filename, 'r')
for each_line in java_file:
if g_java_start_text in each_line:
start_str, found, end_str = each_line.partition(g_java_start_text)
if len(found) > 0: # a new test is being started.
current_testname = end_str.strip() # grab the test name and check if it is curr_testname
if current_testname == curr_testname:
# found the line starting with current test. Grab everything now
start_test = True # found text in java_*_0.out.txt that describe curr_testname
# add header to make JAVA messages visible.
java_messages += "\n\n**********************************************************\n"
java_messages += "**********************************************************\n"
java_messages += "JAVA Messages\n"
java_messages += "**********************************************************\n"
java_messages += "**********************************************************\n\n"
else:
# found a differnt test than our curr_testname. We are done!
if start_test:
# in the middle of curr_testname but found a new test starting, can quit now.
break
# store java message associated with curr_testname into java_messages
if start_test:
java_messages += each_line
java_file.close() # finished finding java messages
if start_test:
# found java message associate with our test already. No need to continue the loop.
break
return java_messages
class H2OUseCloudNode(object):
"""
A class representing one node in an H2O cloud which was specified by the user.
Don't try to build or tear down this kind of node.
use_ip: The given ip of the cloud.
use_port: The given port of the cloud.
"""
def __init__(self, use_ip, use_port):
self.use_ip = use_ip
self.use_port = use_port
def start(self):
"""Not implemented."""
def stop(self):
"""Not implemented."""
def terminate(self):
"""Not implemented."""
def get_ip(self):
"""Cloud's IP-address."""
return self.use_ip
def get_port(self):
"""Cloud's port number."""
return self.use_port
class H2OUseCloud(object):
"""
A class representing an H2O clouds which was specified by the user.
Don't try to build or tear down this kind of cloud.
"""
def __init__(self, cloud_num, use_ip, use_port):
self.cloud_num = cloud_num
self.use_ip = use_ip
self.use_port = use_port
self.nodes = []
node = H2OUseCloudNode(self.use_ip, self.use_port)
self.nodes.append(node)
def start(self):
"""Not implemented."""
def wait_for_cloud_to_be_up(self):
"""Not implemented."""
def stop(self):
"""Not implemented."""
def terminate(self):
"""Not implemented."""
def get_ip(self):
"""Cloud's IP-address."""
node = self.nodes[0]
return node.get_ip()
def get_port(self):
"""Cloud's port number."""
node = self.nodes[0]
return node.get_port()
class H2OCloudNode(object):
"""
A class representing one node in an H2O cloud.
Note that the base_port is only a request for H2O.
H2O may choose to ignore our request and pick any port it likes.
So we have to scrape the real port number from stdout as part of cloud startup.
port: The actual port chosen at run time.
pid: The process id of the node.
output_file_name: Where stdout and stderr go. They are merged.
child: subprocess.Popen object.
terminated: Only from a signal. Not normal shutdown.
"""
def __init__(self, is_client, cloud_num, nodes_per_cloud, node_num, cloud_name, h2o_jar, ip, base_port,
xmx, cp, output_dir, test_ssl):
"""
Create a node in a cloud.
:param is_client: Whether this node is an H2O client node (vs a worker node) or not.
:param cloud_num: Dense 0-based cloud index number.
:param nodes_per_cloud: How many H2O java instances are in a cloud. Clouds are symmetric.
:param node_num: This node's dense 0-based node index number.
:param cloud_name: The H2O -name command-line argument.
:param h2o_jar: Path to H2O jar file.
:param base_port: The starting port number we are trying to get our nodes to listen on.
:param xmx: Java memory parameter.
:param cp: Java classpath parameter.
:param output_dir: The directory where we can create an output file for this process.
:return The node object.
"""
self.is_client = is_client
self.cloud_num = cloud_num
self.nodes_per_cloud = nodes_per_cloud
self.node_num = node_num
self.cloud_name = cloud_name
self.h2o_jar = h2o_jar
self.ip = ip
self.base_port = base_port
self.xmx = xmx
self.cp = cp
self.output_dir = output_dir
self.port = -1
self.pid = -1
self.output_file_name = ""
self.child = None
self.terminated = False
self.test_ssl = test_ssl
# Choose my base port number here. All math is done here. Every node has the same
# base_port and calculates it's own my_base_port.
ports_per_node = 2
self.my_base_port = \
self.base_port + \
(self.cloud_num * self.nodes_per_cloud * ports_per_node) + \
(self.node_num * ports_per_node)
def start(self):
"""
Start one node of H2O.
(Stash away the self.child and self.pid internally here.)
:return none
"""
# there is no hdfs currently in ec2, except s3n/hdfs
# the core-site.xml provides s3n info
# it's possible that we can just always hardware the hdfs version
# to match the cdh3 cluster we're hard-wiring tests to
# i.e. it won't make s3n/s3 break on ec2
if self.is_client:
main_class = "water.H2OClientApp"
else:
main_class = "water.H2OApp"
if "JAVA_HOME" in os.environ:
java = os.environ["JAVA_HOME"] + "/bin/java"
else:
java = "java"
classpath_sep = ";" if sys.platform == "win32" else ":"
classpath = self.h2o_jar if self.cp == "" else self.h2o_jar + classpath_sep + self.cp
cmd = [java,
# "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005",
"-Xmx" + self.xmx,
"-ea",
"-cp", classpath,
main_class,
"-name", self.cloud_name,
"-baseport", str(self.my_base_port),
"-ga_opt_out"]
# If the jacoco flag was included, then modify cmd to generate coverage
# data using the jacoco agent
if g_jacoco_include:
root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
agent_dir = os.path.join(root_dir, "jacoco", "jacocoagent.jar")
jresults_dir = os.path.join(self.output_dir, "jacoco")
if not os.path.exists(jresults_dir):
os.mkdir(jresults_dir)
jresults_dir = os.path.join(jresults_dir, "{cloud}_{node}".format(cloud=self.cloud_num, node=self.node_num))
jacoco = "-javaagent:" + agent_dir + "=destfile=" + \
os.path.join(jresults_dir, "{cloud}_{node}.exec".format(cloud=self.cloud_num, node=self.node_num))
opt0, opt1 = g_jacoco_options
if opt0 is not None:
jacoco += ",includes={inc}".format(inc=opt0.replace(',', ':'))
if opt1 is not None:
jacoco += ",excludes={ex}".format(ex=opt1.replace(',', ':'))
cmd = cmd[:1] + [jacoco] + cmd[1:]
if self.test_ssl:
cmd.append("-internal_security_conf")
if g_convenient:
cmd.append("../h2o-algos/src/test/resources/ssl.properties")
else:
cmd.append("../../../h2o-algos/src/test/resources/ssl3.properties")
# Add S3N credentials to cmd if they exist.
# ec2_hdfs_config_file_name = os.path.expanduser("~/.ec2/core-site.xml")
# if (os.path.exists(ec2_hdfs_config_file_name)):
# cmd.append("-hdfs_config")
# cmd.append(ec2_hdfs_config_file_name)
self.output_file_name = \
os.path.join(self.output_dir, "java_" + str(self.cloud_num) + "_" + str(self.node_num) + ".out.txt")
f = open(self.output_file_name, "w")
if g_convenient:
cwd = os.getcwd()
here = os.path.abspath(os.path.dirname(__file__))
there = os.path.abspath(os.path.join(here, ".."))
os.chdir(there)
self.child = subprocess.Popen(args=cmd,
stdout=f,
stderr=subprocess.STDOUT,
cwd=there)
os.chdir(cwd)
else:
try:
self.child = subprocess.Popen(args=cmd,
stdout=f,
stderr=subprocess.STDOUT,
cwd=self.output_dir)
self.pid = self.child.pid
print("+ CMD: " + ' '.join(cmd))
except OSError:
raise "Failed to spawn %s in %s" % (cmd, self.output_dir)
def scrape_port_from_stdout(self):
"""
Look at the stdout log and figure out which port the JVM chose.
If successful, port number is stored in self.port; otherwise the
program is terminated. This call is blocking, and will wait for
up to 30s for the server to start up.
"""
regex = re.compile(r"Open H2O Flow in your web browser: https?://([^:]+):(\d+)")
retries_left = 30
while retries_left and not self.terminated:
with open(self.output_file_name, "r") as f:
for line in f:
mm = re.search(regex, line)
if mm is not None:
self.port = mm.group(2)
print("H2O cloud %d node %d listening on port %s\n with output file %s" %
(self.cloud_num, self.node_num, self.port, self.output_file_name))
return
if self.terminated: break
retries_left -= 1
time.sleep(1)
if self.terminated: return
print("\nERROR: Too many retries starting cloud %d.\nCheck the output log %s.\n" %
(self.cloud_num, self.output_file_name))
sys.exit(1)
def scrape_cloudsize_from_stdout(self, nodes_per_cloud):
"""
Look at the stdout log and wait until the cloud of proper size is formed.
This call is blocking.
Exit if this fails.
:param nodes_per_cloud:
:return none
"""
retries = 60
while retries > 0:
if self.terminated: return
f = open(self.output_file_name, "r")
s = f.readline()
while len(s) > 0:
if self.terminated: return
match_groups = re.search(r"Cloud of size (\d+) formed", s)
if match_groups is not None:
size = match_groups.group(1)
if size is not None:
size = int(size)
if size == nodes_per_cloud:
f.close()
return
s = f.readline()
f.close()
retries -= 1
if self.terminated: return
time.sleep(1)
print("")
print("ERROR: Too many retries starting cloud.")
print("")
sys.exit(1)
def stop(self):
"""
Normal node shutdown.
Ignore failures for now.
:return none
"""
if self.pid > 0:
print("Killing JVM with PID {}".format(self.pid))
try:
self.child.terminate()
self.child.wait()
except OSError:
pass
self.pid = -1
def terminate(self):
"""
Terminate a running node. (Due to a signal.)
:return none
"""
self.terminated = True
self.stop()
def get_ip(self):
""" Return the ip address this node is really listening on. """
return self.ip
def get_port(self):
""" Return the port this node is really listening on. """
return self.port
def __str__(self):
s = ""
s += " node {}\n".format(self.node_num)
s += " xmx: {}\n".format(self.xmx)
s += " my_base_port: {}\n".format(self.my_base_port)
s += " port: {}\n".format(self.port)
s += " pid: {}\n".format(self.pid)
return s
class H2OCloud(object):
"""
A class representing one of the H2O clouds.
"""
def __init__(self, cloud_num, use_client, nodes_per_cloud, h2o_jar, base_port, xmx, cp, output_dir, test_ssl):
"""
Create a cloud.
See node definition above for argument descriptions.
:return The cloud object.
"""
self.use_client = use_client
self.cloud_num = cloud_num
self.nodes_per_cloud = nodes_per_cloud
self.h2o_jar = h2o_jar
self.base_port = base_port
self.xmx = xmx
self.cp = cp
self.output_dir = output_dir
self.test_ssl = test_ssl
# Randomly choose a seven digit cloud number.
n = random.randint(1000000, 9999999)
user = getpass.getuser()
user = ''.join(user.split())
self.cloud_name = "H2O_runit_{}_{}".format(user, n)
self.nodes = []
self.client_nodes = []
self.jobs_run = 0
if use_client:
actual_nodes_per_cloud = self.nodes_per_cloud + 1
else:
actual_nodes_per_cloud = self.nodes_per_cloud
for node_num in range(actual_nodes_per_cloud):
is_client = False
if use_client:
if node_num == (actual_nodes_per_cloud - 1):
is_client = True
node = H2OCloudNode(is_client,
self.cloud_num, actual_nodes_per_cloud, node_num,
self.cloud_name,
self.h2o_jar,
"127.0.0.1", self.base_port,
self.xmx, self.cp, self.output_dir,
self.test_ssl)
if is_client:
self.client_nodes.append(node)
else:
self.nodes.append(node)
def start(self):
"""
Start H2O cloud.
The cloud is not up until wait_for_cloud_to_be_up() is called and returns.
:return none
"""
for node in self.nodes:
node.start()
for node in self.client_nodes:
node.start()
def wait_for_cloud_to_be_up(self):
"""
Blocking call ensuring the cloud is available.
:return none
"""
self._scrape_port_from_stdout()
self._scrape_cloudsize_from_stdout()
def stop(self):
"""
Normal cloud shutdown.
:return none
"""
for node in self.nodes:
node.stop()
for node in self.client_nodes:
node.stop()
def terminate(self):
"""
Terminate a running cloud. (Due to a signal.)
:return none
"""
for node in self.client_nodes:
node.terminate()
for node in self.nodes:
node.terminate()
def get_ip(self):
""" Return an ip to use to talk to this cloud. """
if len(self.client_nodes) > 0:
node = self.client_nodes[0]
else:
node = self.nodes[0]
return node.get_ip()
def get_port(self):
""" Return a port to use to talk to this cloud. """
if len(self.client_nodes) > 0:
node = self.client_nodes[0]
else:
node = self.nodes[0]
return node.get_port()
def _scrape_port_from_stdout(self):
for node in self.nodes:
node.scrape_port_from_stdout()
for node in self.client_nodes:
node.scrape_port_from_stdout()
def _scrape_cloudsize_from_stdout(self):
for node in self.nodes:
node.scrape_cloudsize_from_stdout(self.nodes_per_cloud)
for node in self.client_nodes:
node.scrape_cloudsize_from_stdout(self.nodes_per_cloud)
def __str__(self):
s = ""
s += "cloud {}\n".format(self.cloud_num)
s += " name: {}\n".format(self.cloud_name)
s += " jobs_run: {}\n".format(self.jobs_run)
for node in self.nodes:
s += str(node)
for node in self.client_nodes:
s += str(node)
return s
class Test(object):
"""
A class representing one Test.
cancelled: Don't start this test.
terminated: Test killed due to signal.
returncode: Exit code of child.
pid: Process id of the test.
ip: IP of cloud to run test.
port: Port of cloud to run test.
child: subprocess.Popen object.
"""
@staticmethod
def test_did_not_complete():
"""
returncode marker to know if the test ran or not.
"""
return -9999999
def __init__(self, test_dir, test_short_dir, test_name, output_dir, hadoop_namenode, on_hadoop):
"""
Create a Test.
:param test_dir: Full absolute path to the test directory.
:param test_short_dir: Path from h2o/R/tests to the test directory.
:param test_name: Test filename with the directory removed.
:param output_dir: The directory where we can create an output file for this process.
:param hadoop_namenode:
:param on_hadoop:
:return The test object.
"""
self.test_dir = test_dir
self.test_short_dir = test_short_dir
self.test_name = test_name
self.output_dir = output_dir
self.output_file_name = ""
self.hadoop_namenode = hadoop_namenode
self.on_hadoop = on_hadoop
self.exclude_flows = None
self.cancelled = False
self.terminated = False
self.returncode = Test.test_did_not_complete()
self.start_seconds = -1
self.pid = -1
self.ip = None
self.port = -1
self.child = None
def start(self, ip, port):
"""
Start the test in a non-blocking fashion.
:param ip: IP address of cloud to run on.
:param port: Port of cloud to run on.
:return none
"""
if self.cancelled or self.terminated:
return
self.start_seconds = time.time()
self.ip = ip
self.port = port
if is_rdemo(self.test_name) or is_runit(self.test_name) or is_rbooklet(self.test_name):
cmd = self._rtest_cmd(self.test_name, self.ip, self.port, self.on_hadoop, self.hadoop_namenode)
elif (is_ipython_notebook(self.test_name) or is_pydemo(self.test_name) or is_pyunit(self.test_name) or
is_pybooklet(self.test_name)):
cmd = self._pytest_cmd(self.test_name, self.ip, self.port, self.on_hadoop, self.hadoop_namenode)
elif is_gradle_build_python_test(self.test_name):
cmd = ["python", self.test_name, "--usecloud", self.ip + ":" + str(self.port)]
elif is_javascript_test_file(self.test_name):
cmd = self._javascript_cmd(self.test_name, self.ip, self.port)
else:
print("")
print("ERROR: Test runner failure with test: " + self.test_name)
print("")
sys.exit(1)
test_short_dir_with_no_slashes = re.sub(r'[\\/]', "_", self.test_short_dir)
if len(test_short_dir_with_no_slashes) > 0:
test_short_dir_with_no_slashes += "_"
self.output_file_name = \
os.path.join(self.output_dir, test_short_dir_with_no_slashes + self.test_name + ".out.txt")
f = open(self.output_file_name, "w")
self.child = subprocess.Popen(args=cmd, stdout=f, stderr=subprocess.STDOUT, cwd=self.test_dir)
self.pid = self.child.pid
def is_completed(self):
"""
Check if test has completed.
This has side effects and MUST be called for the normal test queueing to work.
Specifically, child.poll().
:return True if the test completed, False otherwise.
"""
child = self.child
if child is None:
return False
child.poll()
if child.returncode is None:
return False
self.pid = -1
self.returncode = child.returncode
return True
def cancel(self):
"""
Mark this test as cancelled so it never tries to start.
:return none
"""
if self.pid <= 0:
self.cancelled = True
def terminate_if_started(self):
"""
Terminate a running test. (Due to a signal.)
:return none
"""
if self.pid > 0:
self.terminate()
def terminate(self):
"""
Terminate a running test. (Due to a signal.)
:return none
"""
self.terminated = True
if self.pid > 0:
print("Killing Test {} with PID {}".format(os.path.join(self.test_short_dir, self.test_name), self.pid))
try:
self.child.terminate()
except OSError:
pass
self.pid = -1
def get_test_dir_file_name(self):
"""
:return The full absolute path of this test.
"""
return os.path.join(self.test_dir, self.test_name)
def get_test_name(self):
"""
:return The file name (no directory) of this test.
"""
return self.test_name
def get_seed_used(self):
"""
:return The seed used by this test.
"""
return self._scrape_output_for_seed()
def get_ip(self):
"""
:return IP of the cloud where this test ran.
"""
return self.ip
def get_port(self):
"""
:return Integer port number of the cloud where this test ran.
"""
return int(self.port)
def get_passed(self):
"""
:return True if the test passed, False otherwise.
"""
return self.returncode == 0
def get_skipped(self):
"""
:return True if the test skipped, False otherwise.
"""
return self.returncode == 42
def get_nopass(self, nopass):
"""
Some tests are known not to fail and even if they don't pass we don't want
to fail the overall regression PASS/FAIL status.
:param nopass:
:return True if the test has been marked as NOPASS, False otherwise.
"""
a = re.compile("NOPASS")
return a.search(self.test_name) and not nopass
def get_nofeature(self, nopass):
"""
Some tests are known not to fail and even if they don't pass we don't want
to fail the overall regression PASS/FAIL status.
:param nopass:
:return True if the test has been marked as NOFEATURE, False otherwise.
"""
a = re.compile("NOFEATURE")
return a.search(self.test_name) and not nopass
def get_h2o_internal(self):
"""
Some tests are only run on h2o internal network.
:return True if the test has been marked as INTERNAL, False otherwise.
"""
a = re.compile("INTERNAL")
return a.search(self.test_name)
def get_completed(self):
"""
:return True if the test completed (pass or fail), False otherwise.
"""
return self.returncode > Test.test_did_not_complete()
def get_terminated(self):
"""
For a test to be terminated it must have started and had a PID.
:return True if the test was terminated, False otherwise.
"""
return self.terminated
def get_output_dir_file_name(self):
"""
:return Full path to the output file which you can paste to a terminal window.
"""
return os.path.join(self.output_dir, self.output_file_name)
@staticmethod
def _rtest_cmd(test_name, ip, port, on_hadoop, hadoop_namenode):
if is_runit(test_name):
r_test_driver = test_name
else:
r_test_driver = g_r_test_setup
cmd = ["R", "-f", r_test_driver, "--args", "--usecloud", ip + ":" + str(port), "--resultsDir", g_output_dir,
"--testName", test_name]
if is_runit(test_name):
if on_hadoop: cmd += ["--onHadoop"]
if hadoop_namenode: cmd += ["--hadoopNamenode", hadoop_namenode]
cmd += ["--rUnit"]
elif is_rdemo(test_name) and is_ipython_notebook(test_name):
cmd += ["--rIPythonNotebook"]
elif is_rdemo(test_name):
cmd += ["--rDemo"]
elif is_rbooklet(test_name):
cmd += ["--rBooklet"]
else:
raise ValueError("Unsupported R test type: %s" % test_name)
return cmd
@staticmethod
def _pytest_cmd(test_name, ip, port, on_hadoop, hadoop_namenode):
if g_pycoverage:
pyver = "coverage-3.5" if g_py3 else "coverage"
cmd = [pyver, "run", "-a", g_py_test_setup, "--usecloud", ip + ":" + str(port), "--resultsDir",
g_output_dir,
"--testName", test_name]
print("Running Python test with coverage:")
print(cmd)
else:
pyver = "python3.5" if g_py3 else "python"
cmd = [pyver, g_py_test_setup, "--usecloud", ip + ":" + str(port), "--resultsDir", g_output_dir,
"--testName", test_name]
if is_pyunit(test_name):
if on_hadoop: cmd += ["--onHadoop"]
if hadoop_namenode: cmd += ["--hadoopNamenode", hadoop_namenode]
cmd += ["--pyUnit"]
elif is_ipython_notebook(test_name):
cmd += ["--ipynb"]
elif is_pydemo(test_name):
cmd += ["--pyDemo"]
else:
cmd += ["--pyBooklet"]
if g_jacoco_include:
# When using JaCoCo we don't want the test to return an error if a cloud reports as unhealthy
cmd += ["--forceConnect"]
return cmd
def _javascript_cmd(self, test_name, ip, port):
# return ["phantomjs", test_name]
if g_perf:
return ["phantomjs", test_name, "--host", ip + ":" + str(port), "--timeout", str(g_phantomjs_to),
"--packs", g_phantomjs_packs, "--perf", g_date, str(g_build_id), g_git_hash, g_git_branch,
str(g_ncpu), g_os, g_job_name, g_output_dir, "--excludeFlows", self.exclude_flows]
else:
return ["phantomjs", test_name, "--host", ip + ":" + str(port), "--timeout", str(g_phantomjs_to),
"--packs", g_phantomjs_packs, "--excludeFlows", self.exclude_flows]
def _scrape_output_for_seed(self):
"""
:return The seed scraped from the output file.
"""
res = ""
with open(self.get_output_dir_file_name(), "r") as f:
for line in f:
if "SEED used" in line:
line = line.strip().split(' ')
res = line[-1]
break
return res
def __str__(self):
s = ""
s += "Test: {}/{}\n".format(self.test_dir, self.test_name)
return s
class TestRunner(object):
"""
A class for running tests.
The tests list contains an object for every test.
The tests_not_started list acts as a job queue.
The tests_running list is polled for jobs that have finished.
"""
def __init__(self,
test_root_dir,
use_cloud, use_cloud2, use_client, cloud_config, use_ip, use_port,
num_clouds, nodes_per_cloud, h2o_jar, base_port, xmx, cp, output_dir,
failed_output_dir, path_to_tar, path_to_whl, produce_unit_reports,
testreport_dir, r_pkg_ver_chk, hadoop_namenode, on_hadoop, perf, test_ssl):
"""
Create a runner.
:param test_root_dir: h2o/R/tests directory.
:param use_cloud: Use this one user-specified cloud. Overrides num_clouds.
:param use_cloud2: Use the cloud_config to define the list of H2O clouds.
:param cloud_config: (if use_cloud2) the config file listing the H2O clouds.
:param use_ip: (if use_cloud) IP of one cloud to use.
:param use_port: (if use_cloud) Port of one cloud to use.
:param num_clouds: Number of H2O clouds to start.
:param nodes_per_cloud: Number of H2O nodes to start per cloud.
:param h2o_jar: Path to H2O jar file to run.
:param base_port: Base H2O port (e.g. 54321) to start choosing from.
:param xmx: Java -Xmx parameter.
:param cp: Java -cp parameter (appended to h2o.jar cp).
:param output_dir: Directory for output files.
:param failed_output_dir: Directory to copy failed test output.