Skip to content
This repository was archived by the owner on Jun 23, 2020. It is now read-only.

Commit f6ad85b

Browse files
templecloudowainlewis
authored andcommitted
Update tests to have an infinite canary mode. (#152)
1 parent 5e34244 commit f6ad85b

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Ignore env
22
wercker.env
3+
env.sh
34

45
# Ignore keys
56
*.pem

test/system/run-test-image.yaml.template

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,7 @@ spec:
3535
containers:
3636
- name: flexvolume-driver-system-test
3737
image: iad.ocir.io/{{DOCKER_REGISTRY_USERNAME}}/oci-flexvolume-driver-test:{{VERSION}}
38+
env:
39+
- name: CANARY_MODE
40+
value: "run_once"
3841
restartPolicy: Never

test/system/runner.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import argparse
1818
import atexit
1919
import datetime
20+
import glob
2021
import json
2122
import os
2223
import re
@@ -35,6 +36,7 @@
3536
DEBUG_FILE = "runner.log"
3637
DRIVER_DIR = "/usr/libexec/kubernetes/kubelet-plugins/volume/exec/oracle~oci"
3738
TERRAFORM_DIR = "terraform"
39+
RC_CONTROLLER_YAML="replication-controller-with-volume-claim.yaml"
3840
TIMEOUT = 180
3941
LOCKFILE = "/tmp/system-test-lock-file"
4042
MAX_NUM_LOCKFILE_RETRIES = 100
@@ -49,11 +51,16 @@
4951
REPORT_DIR_PATH="/tmp/results"
5052
REPORT_FILE="done"
5153

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+
5260
# On exit return 0 for success or any other integer for a failure.
5361
# If write_report is true then write a completion file to the Sonabuoy plugin result file.
5462
# The default location is: /tmp/results/done
5563
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)
5764
if write_report:
5865
if not os.path.exists(report_dir_path):
5966
os.makedirs(report_dir_path)
@@ -66,7 +73,13 @@ def _finish_with_exit_code(exit_code, write_report=True, report_dir_path=REPORT_
6673
with open(report_dir_path + "/" + report_file, "w+") as file:
6774
file.write(str(report_dir_path + "/" + DEBUG_FILE))
6875
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+
7083

7184
def _check_env(args):
7285
should_exit = False
@@ -472,8 +485,7 @@ def finish_canary_metrics():
472485
# Main ************************************************************************
473486
#
474487

475-
def _main():
476-
_reset_debug_file()
488+
def parse_args():
477489
parser = argparse.ArgumentParser(description='System test runner for the OCI Block Volume flexvolume driver')
478490
parser.add_argument('--cluster-check',
479491
help='Enable the check that tests if the cluster has the correct shape to run this test',
@@ -507,7 +519,12 @@ def _main():
507519
help='If we are creating the test volume, then dont destroy it',
508520
action='store_true',
509521
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()
511528

512529
_check_env(args)
513530
_create_key_files()
@@ -610,6 +627,26 @@ def _destroy_test_volume_atexit():
610627

611628
_finish_with_exit_code(0)
612629

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()
613650

614651
if __name__ == "__main__":
615652
_main()

wercker.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ system-test:
5353
code: |
5454
export VERSION=$(cat VERSION.txt)
5555
echo "Pushing test version ${VERSION}"
56+
export CANARY_MODE="run_once"
5657
5758
- script:
5859
name: prepare
@@ -85,6 +86,7 @@ validate-test-image:
8586
code: |
8687
export VERSION=$(cat VERSION.txt)
8788
echo "Test image version ${VERSION}"
89+
export CANARY_MODE="run_once"
8890
8991
- script:
9092
name: validate test image

0 commit comments

Comments
 (0)