Commit 2cecd072 authored by Łukasz Nowak's avatar Łukasz Nowak

Feature/promise surykatka improvements

Improvements:

 * total_seconds from surykatka is parsed
 * failure-amount is configurable
 * various smaller bugfixes

/reviewed-on !77
parents ded03013 0d91448e
......@@ -24,13 +24,18 @@ class RunPromise(GenericPromise):
super(RunPromise, self).__init__(config)
# Set frequency compatible to default surykatka interval - 2 minutes
self.setPeriodicity(float(self.getConfig('frequency', 2)))
self.failure_amount = int(
self.getConfig('failure-amount', self.getConfig('failure_amount', 1)))
self.result_count = self.failure_amount
self.error_list = []
self.info_list = []
# Make promise test-less, as it's result is not important for instantiation
self.setTestLess()
def appendError(self, message):
def appendErrorMessage(self, message):
self.error_list.append(message)
def appendInfo(self, message):
def appendInfoMessage(self, message):
self.info_list.append(message)
def emitLog(self):
......@@ -39,24 +44,30 @@ class RunPromise(GenericPromise):
else:
emit = self.logger.info
emit(' '.join(self.error_list + self.info_list))
message_list = self.error_list + self.info_list
url = self.getConfig('url')
if url:
message_list.insert(0, '%s :' % (url,))
emit(' '.join(message_list))
def senseBotStatus(self):
key = 'bot_status'
def logError(msg, *args):
self.appendError(key + ': ' + msg % args)
def appendError(msg, *args):
self.appendErrorMessage(key + ': ERROR ' + msg % args)
if key not in self.surykatka_json:
logError("%r not in %r", key, self.json_file)
appendError("%r not in %r", key, self.json_file)
return
bot_status_list = self.surykatka_json[key]
if len(bot_status_list) == 0:
logError("%r empty in %r", key, self.json_file)
appendError("%r empty in %r", key, self.json_file)
return
bot_status = bot_status_list[0]
if bot_status.get('text') != 'loop':
logError("No type loop detected in %r", self.json_file)
appendError(
"bot_status is %r instead of 'loop' in %r",
str(bot_status.get('text')), self.json_file)
return
timetuple = email.utils.parsedate(bot_status['date'])
last_bot_datetime = datetime.datetime.fromtimestamp(time.mktime(timetuple))
......@@ -64,23 +75,24 @@ class RunPromise(GenericPromise):
delta = self.utcnow - last_bot_datetime
# sanity check
if delta < datetime.timedelta(minutes=0):
logError('Last bot datetime %s is in future, UTC now %s',
appendError('Last bot datetime %s is in future, UTC now %s',
last_bot_datetime_string, self.utcnow_string)
return
if delta > datetime.timedelta(minutes=15):
logError('Last bot datetime %s is more than 15 minutes old, UTC now %s',
appendError(
'Last bot datetime %s is more than 15 minutes old, UTC now %s',
last_bot_datetime_string, self.utcnow_string)
return
self.appendInfo(
'%s: Last bot status from %s ok, UTC now is %s' %
self.appendInfoMessage(
'%s: OK Last bot status from %s, UTC now is %s' %
(key, last_bot_datetime_string, self.utcnow_string))
def senseSslCertificate(self):
key = 'ssl_certificate'
def appendError(msg, *args):
self.appendError(key + ': ' + msg % args)
self.appendErrorMessage(key + ': ERROR ' + msg % args)
url = self.getConfig('url')
parsed_url = urlparse(url)
......@@ -104,46 +116,49 @@ class RunPromise(GenericPromise):
self.getConfig('certificate-expiration-days'))
return
if not hostname:
appendError('url %r is incorrect', url)
appendError('url is incorrect')
return
if key not in self.surykatka_json:
appendError(
'No data for %s . If the error persist, please update surykatka.', url)
'No key %r. If the error persist, please update surykatka.' % (key,))
return
entry_list = [
q for q in self.surykatka_json[key] if q['hostname'] == hostname]
if len(entry_list) == 0:
appendError('No data for %s', url)
appendError('No data')
return
for entry in entry_list:
timetuple = email.utils.parsedate(entry['not_after'])
if timetuple is None:
appendError('No certificate information for %s' % (entry['ip']))
else:
certificate_expiration_time = datetime.datetime.fromtimestamp(
time.mktime(timetuple))
if certificate_expiration_time - datetime.timedelta(
days=certificate_expiration_days) < self.utcnow:
appendError(
'Certificate for %s will expire on %s, which is less than %s days, '
'Certificate on %s will expire on %s, which is less than %s days, '
'UTC now is %s',
url, entry['not_after'], certificate_expiration_days,
entry['ip'], entry['not_after'], certificate_expiration_days,
self.utcnow_string)
return
else:
self.appendInfo(
'%s: Certificate for %s will expire on %s, which is more than %s '
'days, UTC now is %s' %
(key, url, entry['not_after'], certificate_expiration_days,
self.appendInfoMessage(
'%s: OK Certificate on %s will expire on %s, which is more than '
'%s days, UTC now is %s' %
(key, entry['ip'], entry['not_after'], certificate_expiration_days,
self.utcnow_string))
return
def senseHttpQuery(self):
key = 'http_query'
error_list = []
error = False
def logError(msg, *args):
self.appendError(key + ': ' + msg % args)
def appendError(msg, *args):
self.appendErrorMessage(key + ': ERROR ' + msg % args)
if key not in self.surykatka_json:
logError("%r not in %r", key, self.json_file)
appendError("%r not in %r", key, self.json_file)
return
url = self.getConfig('url')
......@@ -152,9 +167,8 @@ class RunPromise(GenericPromise):
entry_list = [q for q in self.surykatka_json[key] if q['url'] == url]
if len(entry_list) == 0:
logError('No data for %s', url)
appendError('No data')
return
error_list = []
for entry in entry_list:
entry_status_code = str(entry['status_code'])
if entry_status_code != status_code:
......@@ -165,26 +179,63 @@ class RunPromise(GenericPromise):
entry_status_code, status_code_explanation)
else:
status_code_explanation = entry_status_code
error_list.append(
appendError(
'IP %s got status code %s instead of %s' % (
entry['ip'], status_code_explanation, status_code))
error = True
db_ip_list = [q['ip'] for q in entry_list]
if len(ip_list):
if set(ip_list) != set(db_ip_list):
error_list.append(
appendError(
'expected IPs %s differes from got %s' % (
' '.join(ip_list), ' '.join(db_ip_list)))
if len(error_list):
logError('Problem with %s : ' % (url,) + ', '.join(error_list))
error = True
if error:
return
if len(ip_list) > 0:
self.appendInfo(
'%s: %s replied correctly with status code %s on ip list %s' %
(key, url, status_code, ' '.join(ip_list)))
self.appendInfoMessage('%s: OK status code %s on IPs %s' % (
key, status_code, ' '.join(ip_list)))
else:
self.appendInfoMessage('%s: OK with status code %s' % (
key, status_code))
def senseElapsedTime(self):
key = 'elapsed_time'
surykatka_key = 'http_query'
def appendError(msg, *args):
self.appendErrorMessage(key + ': ERROR ' + msg % args)
if surykatka_key not in self.surykatka_json:
appendError(
'No key %r. If the error persist, please update surykatka.' % (
surykatka_key,))
return
url = self.getConfig('url')
maximum_elapsed_time = self.getConfig('maximum-elapsed-time')
entry_list = [
q for q in self.surykatka_json[surykatka_key] if q['url'] == url]
if len(entry_list) == 0:
appendError('No data')
return
for entry in entry_list:
if maximum_elapsed_time:
if 'total_seconds' in entry:
maximum_elapsed_time = float(maximum_elapsed_time)
if entry['total_seconds'] == 0.:
appendError('IP %s failed to reply' % (entry['ip']))
elif entry['total_seconds'] > maximum_elapsed_time:
appendError(
'IP %s replied in %.2fs which is longer than '
'maximum %.2fs' %
(entry['ip'], entry['total_seconds'], maximum_elapsed_time))
else:
self.appendInfo(
'%s: %s replied correctly with status code %s' %
(key, url, status_code))
self.appendInfoMessage(
'%s: OK IP %s replied in %.2fs which is shorter than '
'maximum %.2fs' % (key, entry['ip'],
entry['total_seconds'], maximum_elapsed_time))
def sense(self):
"""
......@@ -202,13 +253,14 @@ class RunPromise(GenericPromise):
self.json_file = self.getConfig('json-file', '')
if not os.path.exists(self.json_file):
self.appendError('File %r does not exists' % self.json_file)
self.appendErrorMessage('ERROR File %r does not exists' % self.json_file)
else:
with open(self.json_file) as fh:
try:
self.surykatka_json = json.load(fh)
except Exception:
self.appendError("Problem loading JSON from %r" % self.json_file)
self.appendErrorMessage(
"ERROR loading JSON from %r" % self.json_file)
else:
report = self.getConfig('report')
if report == 'bot_status':
......@@ -216,9 +268,12 @@ class RunPromise(GenericPromise):
elif report == 'http_query':
self.senseHttpQuery()
self.senseSslCertificate()
self.senseElapsedTime()
else:
self.appendError("Report %r is not supported" % report)
self.appendErrorMessage(
"ERROR Report %r is not supported" % report)
self.emitLog()
def anomaly(self):
return self._test(result_count=3, failure_amount=3)
return self._test(
result_count=self.result_count, failure_amount=self.failure_amount)
......@@ -46,31 +46,31 @@ class CheckSurykatkaJSONMixin(TestPromisePluginMixin):
class TestCheckSurykatkaJSON(CheckSurykatkaJSONMixin):
def test_no_config(self):
self.writeSurykatkaPromise()
self.configureLauncher()
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"File '' does not exists")
"ERROR File '' does not exists")
def test_not_existing_file(self):
self.writeSurykatkaPromise({'json-file': self.json_file})
self.configureLauncher()
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"File '%s' does not exists" % (self.json_file,))
"ERROR File '%s' does not exists" % (self.json_file,))
def test_empty_file(self):
self.writeSurykatkaPromise({'json-file': self.json_file})
self.writeSurykatkaJson('')
self.configureLauncher()
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"Problem loading JSON from '%s'" % (self.json_file,))
"ERROR loading JSON from '%s'" % (self.json_file,))
class TestCheckSurykatkaJSONUnknownReport(CheckSurykatkaJSONMixin):
......@@ -84,12 +84,12 @@ class TestCheckSurykatkaJSONUnknownReport(CheckSurykatkaJSONMixin):
self.writeSurykatkaJson("""{
}
""")
self.configureLauncher()
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"Report 'NOT_EXISTING_ENTRY' is not supported")
"ERROR Report 'NOT_EXISTING_ENTRY' is not supported")
class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin):
......@@ -110,12 +110,38 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin):
]
}
""")
self.configureLauncher()
self.configureLauncher(enable_anomaly=True)
self.launcher.run()
self.assertPassedMessage(
self.getPromiseResult(self.promise_name),
"bot_status: Last bot status from Fri, 13 Dec 2222 08:10:11 -0000 "
"ok, UTC now is Wed, 13 Dec 2222 09:11:12 -0000"
"bot_status: OK Last bot status from Fri, 13 Dec 2222 08:10:11 -0000, "
"UTC now is Wed, 13 Dec 2222 09:11:12 -0000"
)
def test_no_loop(self):
self.writeSurykatkaPromise(
{
'report': 'bot_status',
'json-file': self.json_file,
'test-utcnow': 'Wed, 13 Dec 2222 09:11:12 -0000'
}
)
self.writeSurykatkaJson("""{
"bot_status": [
{
"date": "Wed, 13 Dec 2222 09:10:11 -0000",
"text": "error"
}
]
}
""")
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"bot_status: ERROR bot_status is 'error' instead of 'loop' in '%s'" % (
self.json_file,)
)
def test_bot_status_future(self):
......@@ -135,12 +161,12 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin):
]
}
""")
self.configureLauncher()
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"bot_status: Last bot datetime Sat, 13 Dec 2223 08:10:11 -0000 is "
"bot_status: ERROR Last bot datetime Sat, 13 Dec 2223 08:10:11 -0000 is "
"in future, UTC now Wed, 13 Dec 2222 09:11:12 -0000"
)
......@@ -161,12 +187,12 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin):
]
}
""")
self.configureLauncher()
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"bot_status: Last bot datetime Sat, 13 Dec 2223 08:10:11 -0000 is "
"bot_status: ERROR Last bot datetime Sat, 13 Dec 2223 08:10:11 -0000 is "
"more than 15 minutes old, UTC now Wed, 13 Dec 2223 09:26:12 -0000"
)
......@@ -180,12 +206,12 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin):
self.writeSurykatkaJson("""{
}
""")
self.configureLauncher()
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"bot_status: 'bot_status' not in '%s'" % (self.json_file,))
"bot_status: ERROR 'bot_status' not in '%s'" % (self.json_file,))
def test_empty_bot_status(self):
self.writeSurykatkaPromise(
......@@ -198,12 +224,12 @@ class TestCheckSurykatkaJSONBotStatus(CheckSurykatkaJSONMixin):
"bot_status": []
}
""")
self.configureLauncher()
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"bot_status: 'bot_status' empty in '%s'" % (self.json_file,))
"bot_status: ERROR 'bot_status' empty in '%s'" % (self.json_file,))
class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
......@@ -255,15 +281,203 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
]
}
""")
self.configureLauncher()
self.configureLauncher(enable_anomaly=True)
self.launcher.run()
self.assertPassedMessage(
self.getPromiseResult(self.promise_name),
"http_query: https://www.erp5.com/ replied correctly with "
"status code 302 on ip list 127.0.0.1 127.0.0.2 ssl_certificate: "
"Certificate for https://www.erp5.com/ will expire on Mon, 13 Jul "
"2020 12:00:00 -0000, which is more than 15 days, UTC now is "
"Fri, 27 Dec 2019 15:11:12 -0000"
"https://www.erp5.com/ : http_query: OK status code 302 on IPs "
"127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will "
"expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, "
"UTC now is Fri, 27 Dec 2019 15:11:12 -0000"
)
def test_maximum_elapsed_time(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2',
'maximum-elapsed-time': '5',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
}
)
self.writeSurykatkaJson("""{
"http_query": [
{
"date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/",
"total_seconds": 4
},
{
"date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.2",
"status_code": 302,
"url": "https://www.erp5.com/",
"total_seconds": 4
},
{
"date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "176.31.129.213",
"status_code": 200,
"url": "https://www.erp5.org/",
"total_seconds": 4
}
],
"ssl_certificate": [
{
"date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000"
},
{
"date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com",
"ip": "127.0.0.2",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000"
}
]
}
""")
self.configureLauncher(enable_anomaly=True)
self.launcher.run()
self.assertPassedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : http_query: OK status code 302 on IPs "
"127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will "
"expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, "
"UTC now is Fri, 27 Dec 2019 15:11:12 -0000 elapsed_time: OK IP "
"127.0.0.1 replied in 4.00s which is shorter than maximum 5.00s "
"elapsed_time: OK IP 127.0.0.2 replied in 4.00s which is shorter than "
"maximum 5.00s"
)
def test_maximum_elapsed_time_too_long(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2',
'maximum-elapsed-time': '5',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
}
)
self.writeSurykatkaJson("""{
"http_query": [
{
"date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/",
"total_seconds": 6
},
{
"date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.2",
"status_code": 302,
"url": "https://www.erp5.com/",
"total_seconds": 0
},
{
"date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "176.31.129.213",
"status_code": 200,
"url": "https://www.erp5.org/",
"total_seconds": 4
}
],
"ssl_certificate": [
{
"date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000"
},
{
"date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com",
"ip": "127.0.0.2",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000"
}
]
}
""")
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : elapsed_time: ERROR IP 127.0.0.1 replied in "
"6.00s which is longer than maximum 5.00s elapsed_time: ERROR IP "
"127.0.0.2 failed to reply http_query: OK status code 302 on IPs "
"127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will "
"expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, "
"UTC now is Fri, 27 Dec 2019 15:11:12 -0000"
)
def test_maximum_elapsed_time_no_total_seconds(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'status-code': '302',
'ip-list': '127.0.0.1 127.0.0.2',
'maximum-elapsed-time': '5',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
}
)
self.writeSurykatkaJson("""{
"http_query": [
{
"date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/"
},
{
"date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.2",
"status_code": 302,
"url": "https://www.erp5.com/"
},
{
"date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "176.31.129.213",
"status_code": 200,
"url": "https://www.erp5.org/"
}
],
"ssl_certificate": [
{
"date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000"
},
{
"date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com",
"ip": "127.0.0.2",
"not_after": "Mon, 13 Jul 2020 12:00:00 -0000"
}
]
}
""")
self.configureLauncher(enable_anomaly=True)
self.launcher.run()
self.assertPassedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : http_query: OK status code 302 on IPs "
"127.0.0.1 127.0.0.2 ssl_certificate: OK Certificate on 127.0.0.1 will "
"expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, "
"UTC now is Fri, 27 Dec 2019 15:11:12 -0000"
)
def test_http(self):
......@@ -302,12 +516,12 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
]
}
""")
self.configureLauncher()
self.configureLauncher(enable_anomaly=True)
self.launcher.run()
self.assertPassedMessage(
self.getPromiseResult(self.promise_name),
"http_query: http://www.erp5.com/ replied correctly with "
"status code 302 on ip list 127.0.0.1 127.0.0.2"
"http://www.erp5.com/ : http_query: OK status code 302 on IPs 127.0.0.1 "
"127.0.0.2"
)
def test_no_ip_list(self):
......@@ -357,14 +571,14 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
]
}
""")
self.configureLauncher()
self.configureLauncher(enable_anomaly=True)
self.launcher.run()
self.assertPassedMessage(
self.getPromiseResult(self.promise_name),
"http_query: https://www.erp5.com/ replied correctly with status "
"code 302 ssl_certificate: Certificate for https://www.erp5.com/ will "
"expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 "
"days, UTC now is Fri, 27 Dec 2019 15:11:12 -0000"
"https://www.erp5.com/ : http_query: OK with status code 302 "
"ssl_certificate: OK Certificate on 127.0.0.1 will expire on Mon, 13 "
"Jul 2020 12:00:00 -0000, which is more than 15 days, UTC now is Fri, "
"27 Dec 2019 15:11:12 -0000"
)
def test_no_http_query_data(self):
......@@ -397,15 +611,15 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
]
}
""")
self.configureLauncher()
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"http_query: No data for https://www.erp5.com/ ssl_certificate: "
"Certificate for https://www.erp5.com/ will expire on Mon, 13 Jul "
"2020 12:00:00 -0000, which is more than 15 days, UTC now is "
"Fri, 27 Dec 2019 15:11:12 -0000"
"https://www.erp5.com/ : http_query: ERROR No data elapsed_time: ERROR "
"No data ssl_certificate: OK Certificate on 127.0.0.1 will expire on "
"Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, UTC now "
"is Fri, 27 Dec 2019 15:11:12 -0000"
)
def test_no_ssl_certificate_data(self):
......@@ -444,14 +658,13 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
]
}
""")
self.configureLauncher()
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"ssl_certificate: No data for https://www.erp5.com/ http_query: "
"https://www.erp5.com/ replied correctly with "
"status code 302 on ip list 127.0.0.1 127.0.0.2"
"https://www.erp5.com/ : ssl_certificate: ERROR No data http_query: "
"OK status code 302 on IPs 127.0.0.1 127.0.0.2"
)
def test_no_ssl_certificate(self):
......@@ -488,14 +701,14 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
]
}
""")
self.configureLauncher()
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"ssl_certificate: No data for https://www.erp5.com/ . If the error "
"persist, please update surykatka. http_query: https://www.erp5.com/ "
"replied correctly with status code 302 on ip list 127.0.0.1 127.0.0.2"
"https://www.erp5.com/ : ssl_certificate: ERROR No key "
"'ssl_certificate'. If the error persist, please update surykatka. "
"http_query: OK status code 302 on IPs 127.0.0.1 127.0.0.2"
)
def test_bad_code(self):
......@@ -545,16 +758,15 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
]
}
""")
self.configureLauncher()
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"http_query: Problem with https://www.erp5.com/ : IP 127.0.0.1 got "
"status code 302 instead of 301 ssl_certificate: Certificate for "
"https://www.erp5.com/ will expire on Mon, 13 Jul 2020 12:00:00 "
"-0000, which is more than 15 days, UTC now is Fri, 27 Dec 2019 "
"15:11:12 -0000"
"https://www.erp5.com/ : http_query: ERROR IP 127.0.0.1 got status code "
"302 instead of 301 ssl_certificate: OK Certificate on 127.0.0.1 will "
"expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, "
"UTC now is Fri, 27 Dec 2019 15:11:12 -0000"
)
def _test_bad_code_explanation(self, status_code, explanation):
......@@ -592,16 +804,15 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
]
}
""" % status_code)
self.configureLauncher()
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"http_query: Problem with https://www.erp5.com/ : IP 127.0.0.1 got "
"status code %s instead of 301 ssl_certificate: Certificate for "
"https://www.erp5.com/ will expire on Mon, 13 Jul 2020 12:00:00 "
"-0000, which is more than 15 days, UTC now is Fri, 27 Dec 2019 "
"15:11:12 -0000" % explanation
"https://www.erp5.com/ : http_query: ERROR IP 127.0.0.1 got status code "
"%s instead of 301 ssl_certificate: OK Certificate on 127.0.0.1 will "
"expire on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, "
"UTC now is Fri, 27 Dec 2019 15:11:12 -0000" % (explanation,)
)
def test_bad_code_explanation_520(self):
......@@ -664,16 +875,16 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
]
}
""")
self.configureLauncher()
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"http_query: Problem with https://www.erp5.com/ : expected IPs "
"127.0.0.1 127.0.0.2 differes from got 127.0.0.1 127.0.0.4 "
"ssl_certificate: Certificate for https://www.erp5.com/ will expire "
"on Mon, 13 Jul 2020 12:00:00 -0000, which is more than 15 days, "
"UTC now is Fri, 27 Dec 2019 15:11:12 -0000"
"https://www.erp5.com/ : http_query: ERROR expected IPs 127.0.0.1 "
"127.0.0.2 differes from got 127.0.0.1 127.0.0.4 ssl_certificate: "
"OK Certificate on 127.0.0.1 will expire on Mon, 13 Jul 2020 12:00:00 "
"-0000, which is more than 15 days, UTC now is Fri, 27 Dec 2019 "
"15:11:12 -0000"
)
def test_bad_ip_status_code(self):
......@@ -724,15 +935,68 @@ class TestCheckSurykatkaJSONHttpQuery(CheckSurykatkaJSONMixin):
]
}
""")
self.configureLauncher()
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"http_query: Problem with https://www.erp5.com/ : IP 127.0.0.1 got "
"status code 302 instead of 301, expected IPs 127.0.0.1 127.0.0.2 "
"differes from got 127.0.0.1 127.0.0.4 ssl_certificate: Certificate "
"for https://www.erp5.com/ will expire on Mon, 13 Jul 2020 12:00:00 "
"-0000, which is more than 15 days, UTC now is Fri, 27 Dec 2019 "
"15:11:12 -0000"
"https://www.erp5.com/ : http_query: ERROR IP 127.0.0.1 got status code "
"302 instead of 301 http_query: ERROR expected IPs 127.0.0.1 127.0.0.2 "
"differes from got 127.0.0.1 127.0.0.4 ssl_certificate: OK Certificate "
"on 127.0.0.1 will expire on Mon, 13 Jul 2020 12:00:00 -0000, which is "
"more than 15 days, UTC now is Fri, 27 Dec 2019 15:11:12 -0000"
)
def test_https_no_cert(self):
self.writeSurykatkaPromise(
{
'report': 'http_query',
'json-file': self.json_file,
'url': 'https://www.erp5.com/',
'status-code': '301',
'ip-list': '127.0.0.1 127.0.0.2',
'test-utcnow': 'Fri, 27 Dec 2019 15:11:12 -0000'
}
)
self.writeSurykatkaJson("""{
"http_query": [
{
"date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.1",
"status_code": 302,
"url": "https://www.erp5.com/"
},
{
"date": "Wed, 11 Dec 2019 09:35:28 -0000",
"ip": "127.0.0.4",
"status_code": 301,
"url": "https://www.erp5.com/"
}
],
"ssl_certificate": [
{
"date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com",
"ip": "127.0.0.1",
"not_after": null
},
{
"date": "Fri, 27 Dec 2019 14:43:26 -0000",
"hostname": "www.erp5.com",
"ip": "127.0.0.2",
"not_after": null
}
]
}
""")
self.configureLauncher(enable_anomaly=True)
with self.assertRaises(PromiseError):
self.launcher.run()
self.assertFailedMessage(
self.getPromiseResult(self.promise_name),
"https://www.erp5.com/ : http_query: ERROR IP 127.0.0.1 got status code "
"302 instead of 301 http_query: ERROR expected IPs 127.0.0.1 127.0.0.2 "
"differes from got 127.0.0.1 127.0.0.4 ssl_certificate: ERROR No "
"certificate information for 127.0.0.1 ssl_certificate: ERROR No "
"certificate information for 127.0.0.2"
)
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