Commit 213b3beb authored by Łukasz Nowak's avatar Łukasz Nowak

promise: Format times in check_surykatka_json

Since standard date format is used in the ssl_certificate checks, do the
same for readability and consistency in bot_status.
parent ec3ac84c
...@@ -55,20 +55,21 @@ class RunPromise(GenericPromise): ...@@ -55,20 +55,21 @@ class RunPromise(GenericPromise):
return return
timetuple = email.utils.parsedate(bot_status['date']) timetuple = email.utils.parsedate(bot_status['date'])
last_bot_datetime = datetime.datetime.fromtimestamp(time.mktime(timetuple)) last_bot_datetime = datetime.datetime.fromtimestamp(time.mktime(timetuple))
last_bot_datetime_string = email.utils.formatdate(time.mktime(timetuple))
delta = self.utcnow - last_bot_datetime delta = self.utcnow - last_bot_datetime
# sanity check # sanity check
if delta < datetime.timedelta(minutes=0): if delta < datetime.timedelta(minutes=0):
logError('Last bot datetime %s is in future, UTC now %s', logError('Last bot datetime %s is in future, UTC now %s',
last_bot_datetime, self.utcnow) last_bot_datetime_string, self.utcnow_string)
return return
if delta > datetime.timedelta(minutes=15): if delta > datetime.timedelta(minutes=15):
logError('Last bot datetime %s is more than 15 minutes old, UTC now %s', logError('Last bot datetime %s is more than 15 minutes old, UTC now %s',
last_bot_datetime, self.utcnow) last_bot_datetime_string, self.utcnow_string)
return return
self.appendInfo( self.appendInfo(
'%s: Last bot status from %s ok, UTC now is %s' % '%s: Last bot status from %s ok, UTC now is %s' %
(key, last_bot_datetime, self.utcnow)) (key, last_bot_datetime_string, self.utcnow_string))
def senseSslCertificate(self): def senseSslCertificate(self):
key = 'ssl_certificate' key = 'ssl_certificate'
...@@ -118,7 +119,8 @@ class RunPromise(GenericPromise): ...@@ -118,7 +119,8 @@ class RunPromise(GenericPromise):
appendError( appendError(
'Certificate for %s will expire on %s, which is less than %s days, ' 'Certificate for %s will expire on %s, which is less than %s days, '
'UTC now is %s', 'UTC now is %s',
url, entry['not_after'], certificate_expiration_days, self.utcnow_string) url, entry['not_after'], certificate_expiration_days,
self.utcnow_string)
return return
else: else:
self.appendInfo( self.appendInfo(
...@@ -182,7 +184,8 @@ class RunPromise(GenericPromise): ...@@ -182,7 +184,8 @@ class RunPromise(GenericPromise):
self.utcnow_string = test_utcnow self.utcnow_string = test_utcnow
else: else:
self.utcnow = datetime.datetime.utcnow() self.utcnow = datetime.datetime.utcnow()
self.utcnow_string = email.utils.formatdate(time.mktime(self.utcnow.timetuple())) self.utcnow_string = email.utils.formatdate(time.mktime(
self.utcnow.timetuple()))
self.json_file = self.getConfig('json-file', '') self.json_file = self.getConfig('json-file', '')
if not os.path.exists(self.json_file): if not os.path.exists(self.json_file):
......
...@@ -114,8 +114,8 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin): ...@@ -114,8 +114,8 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin):
self.launcher.run() self.launcher.run()
self.assertPassedMessage( self.assertPassedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"bot_status: Last bot status from 2222-12-13 09:10:11 ok, " "bot_status: Last bot status from Fri, 13 Dec 2222 08:10:11 -0000 "
"UTC now is 2222-12-13 09:11:12" "ok, UTC now is Wed, 13 Dec 2222 09:11:12 -0000"
) )
def test_bot_status_future(self): def test_bot_status_future(self):
...@@ -140,8 +140,8 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin): ...@@ -140,8 +140,8 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin):
self.launcher.run() self.launcher.run()
self.assertFailedMessage( self.assertFailedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"bot_status: Last bot datetime 2223-12-13 09:10:11 is in " "bot_status: Last bot datetime Sat, 13 Dec 2223 08:10:11 -0000 is "
"future, UTC now 2222-12-13 09:11:12" "in future, UTC now Wed, 13 Dec 2222 09:11:12 -0000"
) )
def test_bot_status_old(self): def test_bot_status_old(self):
...@@ -166,8 +166,8 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin): ...@@ -166,8 +166,8 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin):
self.launcher.run() self.launcher.run()
self.assertFailedMessage( self.assertFailedMessage(
self.getPromiseResult(self.promise_name), self.getPromiseResult(self.promise_name),
"bot_status: Last bot datetime 2223-12-13 09:10:11 is " "bot_status: Last bot datetime Sat, 13 Dec 2223 08:10:11 -0000 is "
"more than 15 minutes old, UTC now 2223-12-13 09:26:12" "more than 15 minutes old, UTC now Wed, 13 Dec 2223 09:26:12 -0000"
) )
def test_not_bot_status(self): def test_not_bot_status(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment