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_copy_value_by_path_src_not_found(self): src = {} dst = {} res = utils.copy_value_by_path(src, 'sum.jitter_ms', dst, 'jitter.avg') self.assertEqual({}, dst) self.assertFalse(res)
def test_copy_value_by_path(self): src = {'sum': {'jitter_ms': 7}} dst = {} res = utils.copy_value_by_path(src, 'sum.jitter_ms', dst, 'jitter.avg') self.assertEqual({'jitter': {'avg': 7}}, dst) self.assertTrue(res)