def process_reply(self, message): result = super(Iperf3Executor, self).process_reply(message) if not result['stdout']: raise base.ExecutorException(result, 'Empty result from iperf') data = json.loads(result['stdout']) # store verbose data in result result['verbose'] = yaml.safe_dump(dict(start=data['start'], end=data['end']), indent=2, default_flow_style=False) if 'error' in data: raise base.ExecutorException(result, data['error']) has_retransmits = False if (len(data['intervals']) > 0 and 'retransmits' in data['intervals'][0]['sum']): has_retransmits = True if self.test_definition.get('udp'): sampler = lambda p: [round(p['end'], 2), p['packets']] meta = [['time', 's'], ['packets', 'pps']] elif has_retransmits: sampler = lambda p: [ round(p['end'], 2), p['bits_per_second'], p['retransmits'] ] meta = [['time', 's'], ['bandwidth', 'bit/s'], ['retransmits', '']] else: sampler = lambda p: [round(p['end'], 2), p['bits_per_second']] meta = [['time', 's'], ['bandwidth', 'bit/s']] samples = [] for point in data['intervals']: samples.append(sampler(point['sum'])) result['samples'] = samples result['meta'] = meta stats = result['stats'] = {} if utils.copy_value_by_path(data, 'end.sum.jitter_ms', stats, 'jitter.avg'): utils.set_value_by_path(stats, 'jitter.unit', 'ms') if utils.copy_value_by_path(data, 'end.sum.lost_percent', stats, 'loss.avg'): utils.set_value_by_path(stats, 'loss.unit', '%') return result
def process_reply(self, message): result = super(Iperf3Executor, self).process_reply(message) if not result['stdout']: raise base.ExecutorException(result, 'Empty result from iperf') data = json.loads(result['stdout']) # store verbose data in result result['verbose'] = yaml.safe_dump( dict(start=data['start'], end=data['end']), indent=2, default_flow_style=False) if 'error' in data: raise base.ExecutorException(result, data['error']) has_retransmits = False if (len(data['intervals']) > 0 and 'retransmits' in data['intervals'][0]['sum']): has_retransmits = True if self.test_definition.get('udp'): sampler = lambda p: [round(p['end'], 2), p['packets']] meta = [['time', 's'], ['packets', 'pps']] elif has_retransmits: sampler = lambda p: [round(p['end'], 2), p['bits_per_second'], p['retransmits']] meta = [['time', 's'], ['bandwidth', 'bit/s'], ['retransmits', '']] else: sampler = lambda p: [round(p['end'], 2), p['bits_per_second']] meta = [['time', 's'], ['bandwidth', 'bit/s']] samples = [] for point in data['intervals']: samples.append(sampler(point['sum'])) result['samples'] = samples result['meta'] = meta stats = result['stats'] = {} if utils.copy_value_by_path(data, 'end.sum.jitter_ms', stats, 'jitter.avg'): utils.set_value_by_path(stats, 'jitter.unit', 'ms') if utils.copy_value_by_path(data, 'end.sum.lost_percent', stats, 'loss.avg'): utils.set_value_by_path(stats, 'loss.unit', '%') return result
def test_set_value_by_path_with_update(self): data = {'jitter': {'min': 5}} utils.set_value_by_path(data, 'jitter.avg', 10) self.assertEqual({'jitter': {'avg': 10, 'min': 5}}, data)
def test_set_value_by_path(self): data = {} utils.set_value_by_path(data, 'jitter.avg', 10) self.assertEqual({'jitter': {'avg': 10}}, data)