mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-04-28 19:55:20 +08:00
Abstract influx logging logic and add writes in a couple of other places to catch errors better
This commit is contained in:
@@ -1114,6 +1114,29 @@ def parse_args( argv ):
|
||||
args, _ = parser.parse_known_args()
|
||||
return args
|
||||
|
||||
def influx_write( influx_client, test_start, test_name, status ):
|
||||
test_time = datetime.utcnow() - test_start
|
||||
git_commit = os.environ["GIT_COMMIT"]
|
||||
git_branch = os.environ["GIT_BRANCH"]
|
||||
num_tests = os.environ["NUM_TESTS"]
|
||||
point = [
|
||||
{
|
||||
"measurement": "integration_tests",
|
||||
"tags": {
|
||||
"git_branch": git_branch,
|
||||
"git_commit": git_commit,
|
||||
"status": status,
|
||||
"test_scenario": test_name
|
||||
},
|
||||
"time": datetime.utcnow().isoformat(),
|
||||
"fields": {
|
||||
"runtime": test_time.seconds,
|
||||
"num_tests": num_tests
|
||||
}
|
||||
}
|
||||
]
|
||||
influx_client.write_points(point)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -1195,7 +1218,12 @@ if __name__ == "__main__":
|
||||
# load up the scenario (so it can set its own extra envars)
|
||||
scenario = load_scenario( scenario_module )
|
||||
if scenario is None:
|
||||
|
||||
print "Failed to load '%s'" % scenario_module
|
||||
|
||||
if args.influx
|
||||
influx_write(influx_client, test_start, testscenario_module.split(".")[2]_name, "failure-load")
|
||||
|
||||
sys.exit(1)
|
||||
|
||||
# *now* we can import blockstack
|
||||
@@ -1252,6 +1280,10 @@ if __name__ == "__main__":
|
||||
{"ZONEFILES": os.path.join(working_dir, "zonefiles")} )
|
||||
if rc != 0:
|
||||
log.error("failed to write config file: exit %s" % rc)
|
||||
|
||||
if args.influx
|
||||
influx_write(influx_client, test_start, testscenario_module.split(".")[2]_name, "failure-config")
|
||||
|
||||
sys.exit(1)
|
||||
|
||||
# generate config file for the client
|
||||
@@ -1269,6 +1301,9 @@ if __name__ == "__main__":
|
||||
|
||||
|
||||
if rc != 0:
|
||||
if args.influx
|
||||
influx_write(influx_client, test_start, testscenario_module.split(".")[2]_name, "failure-config")
|
||||
|
||||
log.error("failed to write config file: exit %s" % rc)
|
||||
sys.exit(1)
|
||||
|
||||
@@ -1284,52 +1319,12 @@ if __name__ == "__main__":
|
||||
print "SUCCESS %s" % scenario.__name__
|
||||
# shutil.rmtree( working_dir )
|
||||
if args.influx:
|
||||
test_time = datetime.utcnow() - test_start
|
||||
git_commit = os.environ["GIT_COMMIT"]
|
||||
git_branch = os.environ["GIT_BRANCH"]
|
||||
num_tests = os.environ["NUM_TESTS"]
|
||||
point = [
|
||||
{
|
||||
"measurement": "integration_tests",
|
||||
"tags": {
|
||||
"git_branch": git_branch,
|
||||
"git_commit": git_commit,
|
||||
"success": "true",
|
||||
"test_scenario": scenario_module.split(".")[2]
|
||||
},
|
||||
"time": datetime.utcnow().isoformat(),
|
||||
"fields": {
|
||||
"runtime": test_time.microseconds,
|
||||
"num_tests": num_tests
|
||||
}
|
||||
}
|
||||
]
|
||||
influx_client.write_points(point)
|
||||
influx_write(influx_client, test_start, testscenario_module.split(".")[2]_name, "success")
|
||||
|
||||
sys.exit(0)
|
||||
else:
|
||||
if args.influx:
|
||||
test_time = datetime.utcnow() - test_start
|
||||
git_commit = os.environ["GIT_COMMIT"]
|
||||
git_branch = os.environ["GIT_BRANCH"]
|
||||
num_tests = os.environ["NUM_TESTS"]
|
||||
point = [
|
||||
{
|
||||
"measurement": "integration_tests",
|
||||
"tags": {
|
||||
"git_branch": git_branch,
|
||||
"git_commit": git_commit,
|
||||
"success": "false",
|
||||
"test_scenario": scenario_module.split(".")[2]
|
||||
},
|
||||
"time": datetime.datetime.utcnow().isoformat(),
|
||||
"fields": {
|
||||
"runtime": test_time.microseconds,
|
||||
"num_tests": num_tests
|
||||
}
|
||||
}
|
||||
]
|
||||
influx_client.write_points(point)
|
||||
influx_write(influx_client, test_start, testscenario_module.split(".")[2]_name, "failure")
|
||||
|
||||
print >> sys.stderr, "FAILURE %s" % scenario.__name__
|
||||
print >> sys.stderr, "Test output in %s" % working_dir
|
||||
|
||||
Reference in New Issue
Block a user