Commit 40fd7799 authored by Łukasz Nowak's avatar Łukasz Nowak

check_surykatka_json: Assure stable information generation

Sort entry_list by known key, the one most important for the usage.
parent 52ea1591
...@@ -8,6 +8,7 @@ import json ...@@ -8,6 +8,7 @@ import json
import os import os
import time import time
from six.moves.urllib.parse import urlparse from six.moves.urllib.parse import urlparse
import operator
@implementer(interface.IPromise) @implementer(interface.IPromise)
...@@ -126,7 +127,7 @@ class RunPromise(GenericPromise): ...@@ -126,7 +127,7 @@ class RunPromise(GenericPromise):
def addError(msg, *args): def addError(msg, *args):
self.error = True self.error = True
self.appendMessage('ERROR ' + msg % args) self.appendMessage('ERROR ' + msg % args)
for entry in entry_list: for entry in sorted(entry_list, key=operator.itemgetter('ip')):
timetuple = email.utils.parsedate(entry['not_after']) timetuple = email.utils.parsedate(entry['not_after'])
if timetuple is None: if timetuple is None:
addError('IP %s no information' % (entry['ip'],)) addError('IP %s no information' % (entry['ip'],))
...@@ -167,7 +168,7 @@ class RunPromise(GenericPromise): ...@@ -167,7 +168,7 @@ class RunPromise(GenericPromise):
self.error = True self.error = True
self.appendMessage('ERROR ' + msg % args) self.appendMessage('ERROR ' + msg % args)
self.appendMessage('%s:' % (key,)) self.appendMessage('%s:' % (key,))
for entry in entry_list: for entry in sorted(entry_list, key=operator.itemgetter('ip')):
entry_status_code = str(entry['status_code']) entry_status_code = str(entry['status_code'])
if entry_status_code != status_code: if entry_status_code != status_code:
status_code_explanation = self.EXTENDED_STATUS_CODE_MAPPING.get( status_code_explanation = self.EXTENDED_STATUS_CODE_MAPPING.get(
...@@ -219,7 +220,7 @@ class RunPromise(GenericPromise): ...@@ -219,7 +220,7 @@ class RunPromise(GenericPromise):
self.appendMessage('%s:' % (key,)) self.appendMessage('%s:' % (key,))
if len(ip_set): if len(ip_set):
for entry in entry_list: for entry in sorted(entry_list, key=operator.itemgetter('resolver_ip')):
response_ip_set = set([ response_ip_set = set([
q.strip() for q in entry['response'].split(",") if q.strip()]) q.strip() for q in entry['response'].split(",") if q.strip()])
if ip_set != response_ip_set: if ip_set != response_ip_set:
...@@ -269,7 +270,7 @@ class RunPromise(GenericPromise): ...@@ -269,7 +270,7 @@ class RunPromise(GenericPromise):
if len(ip_set) > 0: if len(ip_set) > 0:
for ip in sorted(ip_set): for ip in sorted(ip_set):
ok = False ok = False
for entry in entry_list: for entry in sorted(entry_list, key=operator.itemgetter('ip')):
if entry['ip'] == ip: if entry['ip'] == ip:
if entry['state'] == 'closed': if entry['state'] == 'closed':
ok = False ok = False
...@@ -312,7 +313,7 @@ class RunPromise(GenericPromise): ...@@ -312,7 +313,7 @@ class RunPromise(GenericPromise):
self.appendMessage('%s:' % (key,)) self.appendMessage('%s:' % (key,))
if maximum_elapsed_time: if maximum_elapsed_time:
found = False found = False
for entry in entry_list: for entry in sorted(entry_list, key=operator.itemgetter('ip')):
if 'total_seconds' in entry: if 'total_seconds' in entry:
found = True found = True
maximum_elapsed_time = float(maximum_elapsed_time) maximum_elapsed_time = float(maximum_elapsed_time)
......
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