Skip to content

Commit

Permalink
Make report hashing more robust
Browse files Browse the repository at this point in the history
Don't rely on list ordering, always sort item
  • Loading branch information
Radek Novacek committed May 5, 2016
1 parent 6940d21 commit 1034d71
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions virt/virt.py
Expand Up @@ -21,6 +21,7 @@
import sys
import time
import logging
from operator import itemgetter
from datetime import datetime
from multiprocessing import Process, Event
import json
Expand Down Expand Up @@ -118,7 +119,7 @@ def toDict(self):
d = OrderedDict((
('hypervisorId', {'hypervisorId': self.hypervisorId}),
('name', self.name),
('guestIds', [g.toDict() for g in self.guestIds])
('guestIds', sorted([g.toDict() for g in self.guestIds], key=itemgetter('guestId')))
))
if self.name is None:
del d['name']
Expand Down Expand Up @@ -200,7 +201,7 @@ def hypervisor_id(self):
def hash(self):
return hashlib.md5(
json.dumps(
[g.toDict() for g in self.guests],
sorted([g.toDict() for g in self.guests], key=itemgetter('guestId')),
sort_keys=True) +
str(self.hypervisor_id)
).hexdigest()
Expand Down Expand Up @@ -235,7 +236,9 @@ def association(self):

@property
def serializedAssociation(self):
return {'hypervisors': [h.toDict() for h in self.association['hypervisors']]}
return {
'hypervisors': sorted([h.toDict() for h in self.association['hypervisors']], key=itemgetter('hypervisorId'))
}

@property
def hash(self):
Expand Down

0 comments on commit 1034d71

Please sign in to comment.