diff options
author | Joshua Harlow <harlowja@gmail.com> | 2013-09-07 00:07:26 -0700 |
---|---|---|
committer | Joshua Harlow <harlowja@gmail.com> | 2013-09-07 00:07:26 -0700 |
commit | 0575c837a6ca6c2a6d554177d9e0540fd70a7843 (patch) | |
tree | 22acdb865ed5cf4c02a2b7cd5f4f157298b18ac1 | |
parent | 1d27cd75eaaeef7b72f3be77de24da815c82a825 (diff) | |
download | vyos-cloud-init-0575c837a6ca6c2a6d554177d9e0540fd70a7843.tar.gz vyos-cloud-init-0575c837a6ca6c2a6d554177d9e0540fd70a7843.zip |
Ensure udelta is valid
It appears that udelta could
have been left undefined or left
defined as a string "N/A" and then
put threw a float formatter previously.
Fix that by ensure its set to a default
and put strong checking to make sure it
is a float before using float formatting.
-rw-r--r-- | cloudinit/util.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index 4a74ba57..5032cc47 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -1791,15 +1791,19 @@ def log_time(logfunc, msg, func, args=None, kwargs=None, get_uptime=False): ret = func(*args, **kwargs) finally: delta = time.time() - start + udelta = None if ustart is not None: try: udelta = float(uptime()) - ustart except ValueError: - udelta = "N/A" + pass tmsg = " took %0.3f seconds" % delta if get_uptime: - tmsg += "(%0.2f)" % udelta + if isinstance(udelta, (float)): + tmsg += " (%0.2f)" % udelta + else: + tmsg += " (N/A)" try: logfunc(msg + tmsg) except: |