diff --git a/lib/utils.py b/lib/utils.py index 7c7808f26cc2ed107448161eedc5aa0d3440313e..286ef2b23866e48f7ddd68df743acf9bbd91c2ff 100644 --- a/lib/utils.py +++ b/lib/utils.py @@ -2835,21 +2835,12 @@ def TailFile(fname, lines=20): return rows[-lines:] -def FormatTimestampWithTZ(secs): - """Formats a Unix timestamp with the local timezone. - - @type secs: number - @param secs: Seconds since the Epoch (1970-01-01 00:00:00 UTC) - - """ - return time.strftime("%F %T %Z", time.localtime(secs)) - - def _ParseAsn1Generalizedtime(value): """Parses an ASN1 GENERALIZEDTIME timestamp as used by pyOpenSSL. @type value: string @param value: ASN1 GENERALIZEDTIME timestamp + @return: Seconds since the Epoch (1970-01-01 00:00:00 UTC) """ m = _ASN1_TIME_REGEX.match(value) @@ -2931,19 +2922,18 @@ def _VerifyCertificateInner(expired, not_before, not_after, now, if not_before is not None and not_after is not None: msg += (" (valid from %s to %s)" % - (FormatTimestampWithTZ(not_before), - FormatTimestampWithTZ(not_after))) + (FormatTime(not_before), FormatTime(not_after))) elif not_before is not None: - msg += " (valid from %s)" % FormatTimestampWithTZ(not_before) + msg += " (valid from %s)" % FormatTime(not_before) elif not_after is not None: - msg += " (valid until %s)" % FormatTimestampWithTZ(not_after) + msg += " (valid until %s)" % FormatTime(not_after) return (CERT_ERROR, msg) elif not_before is not None and not_before > now: return (CERT_WARNING, "Certificate not yet valid (valid from %s)" % - FormatTimestampWithTZ(not_before)) + FormatTime(not_before)) elif not_after is not None: remaining_days = int((not_after - now) / (24 * 3600)) diff --git a/test/ganeti.utils_unittest.py b/test/ganeti.utils_unittest.py index c0b236079665fbd85032c501a9422119bd09a576..267b4ef4528a7df4d1942fee5247301c511ff2c9 100755 --- a/test/ganeti.utils_unittest.py +++ b/test/ganeti.utils_unittest.py @@ -1713,25 +1713,6 @@ class TestFormatTime(unittest.TestCase): FormatTime(int(time.time())) -class TestFormatTimestampWithTZ(unittest.TestCase): - @staticmethod - def _TestInProcess(tz, timestamp, expected): - os.environ["TZ"] = tz - time.tzset() - return utils.FormatTimestampWithTZ(timestamp) == expected - - def _Test(self, *args): - # Need to use separate process as we want to change TZ - self.assert_(utils.RunInSeparateProcess(self._TestInProcess, *args)) - - def test(self): - self._Test("UTC", 0, "1970-01-01 00:00:00 UTC") - self._Test("America/Sao_Paulo", 1292606926, "2010-12-17 15:28:46 BRST") - self._Test("Europe/London", 1292606926, "2010-12-17 17:28:46 GMT") - self._Test("Europe/Zurich", 1292606926, "2010-12-17 18:28:46 CET") - self._Test("Australia/Sydney", 1292606926, "2010-12-18 04:28:46 EST") - - class RunInSeparateProcess(unittest.TestCase): def test(self): for exp in [True, False]: