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

Commit da565a8

Browse files
templecloudowainlewis
authored andcommitted
Add canary test json output. (#145)
* Add canary test.json output.
1 parent a7b38c0 commit da565a8

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

test/system/runner.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def _finish_with_exit_code(exit_code, write_report=True, report_dir_path=REPORT_
6565
copyfile(DEBUG_FILE, report_dir_path + "/" + DEBUG_FILE)
6666
with open(report_dir_path + "/" + report_file, "w+") as file:
6767
file.write(str(report_dir_path + "/" + DEBUG_FILE))
68+
finish_canary_metrics()
6869
sys.exit(exit_code)
6970

7071
def _check_env(args):
@@ -438,6 +439,39 @@ def _cluster_check():
438439
_finish_with_exit_code(1)
439440

440441

442+
# Canary Metrics **************************************************************
443+
#
444+
445+
CM_SIMPLE = "flex_volume_driver_simple"
446+
447+
def canary_metric_date():
448+
return datetime.datetime.today().strftime('%Y-%m-%d-%H%m%S')
449+
450+
def init_canary_metrics():
451+
if "METRICS_FILE" in os.environ:
452+
_log("generating metrics file...")
453+
canary_metrics = {}
454+
canary_metrics["start_time"] = canary_metric_date()
455+
canary_metrics[CM_SIMPLE] = 0
456+
with open(os.environ.get("METRICS_FILE"), 'w') as metrics_file:
457+
json.dump(canary_metrics, metrics_file, sort_keys=True, indent=4)
458+
459+
def update_canary_metric(name, result):
460+
if "METRICS_FILE" in os.environ:
461+
_log("updating metrics fle...")
462+
with open(os.environ.get("METRICS_FILE"), 'r') as metrics_file:
463+
canary_metrics = json.load(metrics_file)
464+
canary_metrics[name] = result
465+
with open(os.environ.get("METRICS_FILE"), 'w') as metrics_file:
466+
json.dump(canary_metrics, metrics_file, sort_keys=True, indent=4)
467+
468+
def finish_canary_metrics():
469+
update_canary_metric("end_time", canary_metric_date())
470+
471+
472+
# Main ************************************************************************
473+
#
474+
441475
def _main():
442476
_reset_debug_file()
443477
parser = argparse.ArgumentParser(description='System test runner for the OCI Block Volume flexvolume driver')
@@ -524,6 +558,8 @@ def _destroy_test_volume_atexit():
524558
if not args['no_test']:
525559
_log("Running system test: ", as_banner=True)
526560

561+
init_canary_metrics()
562+
527563
_log("Starting the replication controller (creates a single nginx pod).")
528564
_kubectl("delete -f " + replication_controller, exit_on_error=False, display_errors=False)
529565
_kubectl("create -f " + replication_controller)
@@ -569,6 +605,8 @@ def _destroy_test_volume_atexit():
569605
if args['destructive']:
570606
_log("Adding the original node back into the cluster.")
571607
_kubectl("uncordon " + node1)
608+
609+
update_canary_metric(CM_SIMPLE, 1)
572610

573611
_finish_with_exit_code(0)
574612

0 commit comments

Comments
 (0)