17
17
import argparse
18
18
import atexit
19
19
import datetime
20
+ import glob
20
21
import json
21
22
import os
22
23
import re
35
36
DEBUG_FILE = "runner.log"
36
37
DRIVER_DIR = "/usr/libexec/kubernetes/kubelet-plugins/volume/exec/oracle~oci"
37
38
TERRAFORM_DIR = "terraform"
39
+ RC_CONTROLLER_YAML = "replication-controller-with-volume-claim.yaml"
38
40
TIMEOUT = 180
39
41
LOCKFILE = "/tmp/system-test-lock-file"
40
42
MAX_NUM_LOCKFILE_RETRIES = 100
49
51
REPORT_DIR_PATH = "/tmp/results"
50
52
REPORT_FILE = "done"
51
53
54
+ # Clean test resources.
55
+ def _clean ():
56
+ # Clean replication controller support files.
57
+ for f in glob .glob (RC_CONTROLLER_YAML + ".[0123456789abcdef]*" ):
58
+ os .remove (f )
59
+
52
60
# On exit return 0 for success or any other integer for a failure.
53
61
# If write_report is true then write a completion file to the Sonabuoy plugin result file.
54
62
# The default location is: /tmp/results/done
55
63
def _finish_with_exit_code (exit_code , write_report = True , report_dir_path = REPORT_DIR_PATH , report_file = REPORT_FILE ):
56
- print "finishing with exit code: " + str (exit_code )
57
64
if write_report :
58
65
if not os .path .exists (report_dir_path ):
59
66
os .makedirs (report_dir_path )
@@ -66,7 +73,13 @@ def _finish_with_exit_code(exit_code, write_report=True, report_dir_path=REPORT_
66
73
with open (report_dir_path + "/" + report_file , "w+" ) as file :
67
74
file .write (str (report_dir_path + "/" + DEBUG_FILE ))
68
75
finish_canary_metrics ()
69
- sys .exit (exit_code )
76
+ if "CANARY_MODE" in os .environ and os .environ ["CANARY_MODE" ] == "run_once" :
77
+ # In 'run_once' mode we exit on completion.
78
+ print ("finished with exit code: %d" % exit_code )
79
+ sys .exit (exit_code )
80
+ # Clean resources.
81
+ _clean ()
82
+
70
83
71
84
def _check_env (args ):
72
85
should_exit = False
@@ -472,8 +485,7 @@ def finish_canary_metrics():
472
485
# Main ************************************************************************
473
486
#
474
487
475
- def _main ():
476
- _reset_debug_file ()
488
+ def parse_args ():
477
489
parser = argparse .ArgumentParser (description = 'System test runner for the OCI Block Volume flexvolume driver' )
478
490
parser .add_argument ('--cluster-check' ,
479
491
help = 'Enable the check that tests if the cluster has the correct shape to run this test' ,
@@ -507,7 +519,12 @@ def _main():
507
519
help = 'If we are creating the test volume, then dont destroy it' ,
508
520
action = 'store_true' ,
509
521
default = False )
510
- args = vars (parser .parse_args ())
522
+ return vars (parser .parse_args ())
523
+
524
+
525
+ def _run_once ():
526
+ _reset_debug_file ()
527
+ args = parse_args ()
511
528
512
529
_check_env (args )
513
530
_create_key_files ()
@@ -610,6 +627,26 @@ def _destroy_test_volume_atexit():
610
627
611
628
_finish_with_exit_code (0 )
612
629
630
+ def _run_monitor ():
631
+ print "Running canary!"
632
+ wait_in_seconds = 30
633
+ if "MONITOR_PERIOD" in os .environ :
634
+ wait_in_seconds = int (os .environ ["MONITOR_PERIOD" ])
635
+ _log ("Monitor wait period is " + str (wait_in_seconds ) + " seconds." )
636
+ while True :
637
+ _run_once ()
638
+ _log ("Waiting %d seconds before next test." % wait_in_seconds )
639
+ time .sleep (wait_in_seconds )
640
+
641
+
642
+ def _main ():
643
+ if "CANARY_MODE" in os .environ and os .environ ["CANARY_MODE" ] == "run_once" :
644
+ # The CI should be configured with CANARY_MODE set to 'run_once' so that
645
+ # it completes and does not run forever.
646
+ _run_once ()
647
+ else :
648
+ # By default we run in monitor mode.
649
+ _run_monitor ()
613
650
614
651
if __name__ == "__main__" :
615
652
_main ()
0 commit comments