def __time_passes(self, ctx):
""" Modify system time. """
- ctx.time += int(self.args[1])
+ time_file = open(os.environ["FAKETIME_TIMESTAMP_FILE"], 'r')
+ line = time_file.readline().strip()
+ time_file.close()
+ t = time.mktime(datetime.strptime(line, '%Y-%m-%d %H:%M:%S').timetuple())
+ t += int(self.args[1])
time_file = open(os.environ["FAKETIME_TIMESTAMP_FILE"], 'w')
- time_file.write(datetime.fromtimestamp(ctx.time).strftime('%Y-%m-%d %H:%M:%S') + "\n")
+ time_file.write(datetime.fromtimestamp(t).strftime('%Y-%m-%d %H:%M:%S') + "\n")
+ time_file.close()
class Scenario:
def __init__(self, info):
""" Initialize scenario with description. """
self.info = info
- self.time = 0
self.ranges = []
self.steps = []
self.current_step = None
except Exception as e:
raise Exception('step #%d %s' % (step.id, str(e)))
finally:
- self.child_sock.close()
- self.child_sock = None
+ self.child_sock.close()
+ self.child_sock = None
result.append(path)
return result
+def write_timestamp_file(path, tst):
+ time_file = open(path, 'w')
+ time_file.write(datetime.fromtimestamp(tst).strftime('%Y-%m-%d %H:%M:%S'))
+ time_file.close()
+
def setup_env(child_env, config, config_name, j2template):
""" Set up test environment and config """
# Clear test directory
# Set up libfaketime
os.environ["FAKETIME_NO_CACHE"] = "1"
os.environ["FAKETIME_TIMESTAMP_FILE"] = '%s/.time' % TMPDIR
- time_file = open(os.environ["FAKETIME_TIMESTAMP_FILE"], 'w')
- time_file.write(datetime.fromtimestamp(0).strftime('%Y-%m-%d %H:%M:%S'))
- time_file.close()
+ child_env["FAKETIME_NO_CACHE"] = "1"
+ child_env["FAKETIME_TIMESTAMP_FILE"] = '%s/.time' % TMPDIR
+ write_timestamp_file(child_env["FAKETIME_TIMESTAMP_FILE"], 0)
# Set up child process env()
child_env["SOCKET_WRAPPER_DEFAULT_IFACE"] = "%i" % CHILD_IFACE
child_env["SOCKET_WRAPPER_DIR"] = TMPDIR
no_minimize = "false"
elif k == 'trust-anchor':
if ((v[0] == '"') and (v[-1] == '"')) or ((v[0] == '\'') and (v[-1] == '\'')):
- trust_anchor = v[1:-1]
+ trust_anchor_str = v[1:-1]
+ else:
+ trust_anchor_str = v
+ elif k == 'val-override-date':
+ override_date_str = ""
+ if ((v[0] == '"') and (v[-1] == '"')) or ((v[0] == '\'') and (v[-1] == '\'')):
+ override_date_str = v[1:-1]
else:
- trust_anchor = v
+ override_date_str = v
+ write_timestamp_file(child_env["FAKETIME_TIMESTAMP_FILE"], int(override_date_str))
selfaddr = testserver.get_local_addr_str(socket.AF_INET, DEFAULT_IFACE)
childaddr = testserver.get_local_addr_str(socket.AF_INET, CHILD_IFACE)
# Prebind to sockets to create necessary files
"ROOT_ADDR" : selfaddr,
"SELF_ADDR" : childaddr,
"NO_MINIMIZE" : no_minimize,
- "TRUST_ANCHOR" : trust_anchor,
+ "TRUST_ANCHOR" : trust_anchor_str,
"WORKING_DIR" : TMPDIR,
}
cfg_rendered = j2template.render(j2template_ctx)