diff options
author | Rob Austein <sra@hactrn.net> | 2007-12-23 23:50:03 +0000 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2007-12-23 23:50:03 +0000 |
commit | d6f079b872af8c1e044131cd44adc287734df851 (patch) | |
tree | 76f56136771d57a72c693774783ba26fa33f76eb /scripts | |
parent | e6bb8b2f0fdba19eb44122f65953e467b11e4869 (diff) |
Support time deltas in sleep command too
svn path=/scripts/testdb.py; revision=1432
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/testdb.py | 48 | ||||
-rw-r--r-- | scripts/testdb1.yaml | 5 |
2 files changed, 30 insertions, 23 deletions
diff --git a/scripts/testdb.py b/scripts/testdb.py index 3251dcae..434ab87f 100644 --- a/scripts/testdb.py +++ b/scripts/testdb.py @@ -163,24 +163,6 @@ def main(): except Exception, data: rpki.log.warn("Couldn't clean up daemons (%s), continuing" % data) -def wakeup(signum, frame): - """Handler called when we receive a SIGALRM signal.""" - rpki.log.info("Wakeup call received, continuing") - -def cmd_sleep(seconds = None): - """Set an alarm, then wait for it to go off.""" - if seconds is None: - rpki.log.info("Pausing indefinitely, send a SIGALRM to wake me up") - else: - rpki.log.info("Sleeping %s seconds" % seconds) - signal.alarm(int(seconds)) - signal.pause() - -## @var cmds -# Dispatch table for commands embedded in delta sections - -cmds = { "sleep" : cmd_sleep } - class timedelta(datetime.timedelta): """Timedelta with text parsing. This accepts two input formats: @@ -205,14 +187,36 @@ class timedelta(datetime.timedelta): @classmethod def parse(cls, arg): """Parse text into a timedelta object.""" - if isinstance(arg, int): - return cls(seconds = arg) - assert isinstance(arg, str) - if (arg.isdigit()): + if not isinstance(arg, str): return cls(seconds = arg) + elif arg.isdigit(): + return cls(seconds = int(arg)) else: return cls(**dict((k, int(v)) for (k, v) in cls.regexp.match(arg).groupdict().items() if v is not None)) + def convert_to_seconds(self): + """Convert a timedelta interval to seconds.""" + return self.days * 24 * 60 * 60 + self.seconds + +def wakeup(signum, frame): + """Handler called when we receive a SIGALRM signal.""" + rpki.log.info("Wakeup call received, continuing") + +def cmd_sleep(interval = None): + """Set an alarm, then wait for it to go off.""" + if interval is None: + rpki.log.info("Pausing indefinitely, send a SIGALRM to wake me up") + else: + seconds = timedelta.parse(interval).convert_to_seconds() + rpki.log.info("Sleeping %s seconds" % seconds) + signal.alarm(seconds) + signal.pause() + +## @var cmds +# Dispatch table for commands embedded in delta sections + +cmds = { "sleep" : cmd_sleep } + class allocation_db(list): """Representation of all the entities and allocations in the test system. Almost everything is generated out of this database. diff --git a/scripts/testdb1.yaml b/scripts/testdb1.yaml index 32ea29ca..e7382ee0 100644 --- a/scripts/testdb1.yaml +++ b/scripts/testdb1.yaml @@ -11,7 +11,10 @@ kids: ipv4: 192.0.2.1-192.0.2.33 asn: 64533 --- -- sleep 5 +- name: Alice + valid_add: 10 +--- +- sleep 1M - name: Alice add_as: 33 valid_add: 2d |