1# 2# Migration test output result reporting 3# 4# Copyright (c) 2016 Red Hat, Inc. 5# 6# This library is free software; you can redistribute it and/or 7# modify it under the terms of the GNU Lesser General Public 8# License as published by the Free Software Foundation; either 9# version 2.1 of the License, or (at your option) any later version. 10# 11# This library is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14# Lesser General Public License for more details. 15# 16# You should have received a copy of the GNU Lesser General Public 17# License along with this library; if not, see <http://www.gnu.org/licenses/>. 18# 19 20import json 21 22from guestperf.hardware import Hardware 23from guestperf.scenario import Scenario 24from guestperf.progress import Progress 25from guestperf.timings import Timings 26 27class ReportResult(object): 28 29 def __init__(self, success=False): 30 self._success = success 31 32 def serialize(self): 33 return { 34 "success": self._success, 35 } 36 37 @classmethod 38 def deserialize(cls, data): 39 return cls( 40 data["success"]) 41 42 43class Report(object): 44 45 def __init__(self, 46 hardware, 47 scenario, 48 progress_history, 49 guest_timings, 50 qemu_timings, 51 vcpu_timings, 52 result, 53 binary, 54 dst_host, 55 kernel, 56 initrd, 57 transport, 58 sleep): 59 60 self._hardware = hardware 61 self._scenario = scenario 62 self._progress_history = progress_history 63 self._guest_timings = guest_timings 64 self._qemu_timings = qemu_timings 65 self._vcpu_timings = vcpu_timings 66 self._result = result 67 self._binary = binary 68 self._dst_host = dst_host 69 self._kernel = kernel 70 self._initrd = initrd 71 self._transport = transport 72 self._sleep = sleep 73 74 def serialize(self): 75 return { 76 "hardware": self._hardware.serialize(), 77 "scenario": self._scenario.serialize(), 78 "progress_history": [progress.serialize() for progress in self._progress_history], 79 "guest_timings": self._guest_timings.serialize(), 80 "qemu_timings": self._qemu_timings.serialize(), 81 "vcpu_timings": self._vcpu_timings.serialize(), 82 "result": self._result.serialize(), 83 "binary": self._binary, 84 "dst_host": self._dst_host, 85 "kernel": self._kernel, 86 "initrd": self._initrd, 87 "transport": self._transport, 88 "sleep": self._sleep, 89 } 90 91 @classmethod 92 def deserialize(cls, data): 93 return cls( 94 Hardware.deserialize(data["hardware"]), 95 Scenario.deserialize(data["scenario"]), 96 [Progress.deserialize(record) for record in data["progress_history"]], 97 Timings.deserialize(data["guest_timings"]), 98 Timings.deserialize(data["qemu_timings"]), 99 Timings.deserialize(data["vcpu_timings"]), 100 ReportResult.deserialize(data["result"]), 101 data["binary"], 102 data["dst_host"], 103 data["kernel"], 104 data["initrd"], 105 data["transport"], 106 data["sleep"]) 107 108 def to_json(self): 109 return json.dumps(self.serialize(), indent=4) 110 111 @classmethod 112 def from_json(cls, data): 113 return cls.deserialize(json.loads(data)) 114 115 @classmethod 116 def from_json_file(cls, filename): 117 with open(filename, "r") as fh: 118 return cls.deserialize(json.load(fh)) 119