2017-09-18 10:50:00 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import json
|
2018-02-12 01:44:40 +00:00
|
|
|
import os
|
2017-09-18 10:50:00 +00:00
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
2018-02-28 02:57:35 +00:00
|
|
|
from systemd import journal
|
2017-09-18 10:50:00 +00:00
|
|
|
|
2018-02-12 00:37:00 +00:00
|
|
|
json_file = sys.argv[1]
|
2018-02-28 02:57:35 +00:00
|
|
|
event_identifier = sys.argv[2]
|
2019-11-20 22:47:52 +00:00
|
|
|
log_location = sys.argv[3]
|
2017-09-18 10:50:00 +00:00
|
|
|
|
2018-02-28 02:57:35 +00:00
|
|
|
scale_factor = float(os.environ.get('SUBIQUITY_REPLAY_TIMESCALE', "4"))
|
2017-09-18 10:50:00 +00:00
|
|
|
|
2018-02-28 02:57:35 +00:00
|
|
|
def time_for_entry(e):
|
|
|
|
return int(e['__MONOTONIC_TIMESTAMP'])/1e6
|
2017-09-18 10:50:00 +00:00
|
|
|
|
2019-11-20 22:25:43 +00:00
|
|
|
rc = 0
|
|
|
|
|
2019-11-20 22:47:52 +00:00
|
|
|
def report(e, log_file):
|
2019-11-20 22:25:43 +00:00
|
|
|
global rc
|
2018-02-28 02:57:35 +00:00
|
|
|
if e['SYSLOG_IDENTIFIER'].startswith("curtin_event"):
|
|
|
|
e['SYSLOG_IDENTIFIER'] = event_identifier
|
|
|
|
e['CODE_LINE'] = int(e['CODE_LINE'])
|
|
|
|
journal.send(**e)
|
2019-11-20 22:25:43 +00:00
|
|
|
r = e.get("CURTIN_RESULT")
|
|
|
|
if r == "SUCCESS":
|
|
|
|
rc = 0
|
|
|
|
elif r == "FAIL":
|
|
|
|
rc = 1
|
2019-02-21 08:45:40 +00:00
|
|
|
elif e['SYSLOG_IDENTIFIER'].startswith("curtin_log") and scale_factor < 10:
|
2018-02-28 02:57:35 +00:00
|
|
|
print(e['MESSAGE'], flush=True)
|
2019-11-20 22:47:52 +00:00
|
|
|
log_file.write(e['MESSAGE'] + '\n')
|
|
|
|
|
|
|
|
with open(log_location, 'w') as fp:
|
|
|
|
prev_ev = None
|
|
|
|
for line in open(json_file):
|
|
|
|
ev = json.loads(line.strip())
|
|
|
|
if prev_ev is not None:
|
|
|
|
report(prev_ev, fp)
|
|
|
|
delay = time_for_entry(ev) - time_for_entry(prev_ev)
|
|
|
|
time.sleep(min(delay, 8)/scale_factor)
|
|
|
|
prev_ev = ev
|
|
|
|
report(ev, fp)
|
2018-02-12 01:44:40 +00:00
|
|
|
|
2019-10-31 00:47:30 +00:00
|
|
|
sys.exit(rc)
|