Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | import itertools |
| 3 | import re |
| 4 | import os |
| 5 | import yaml |
| 6 | import requests |
Hanna Arhipova | 16e93fb | 2019-01-23 19:03:01 +0200 | [diff] [blame] | 7 | import utils |
| 8 | from utils import helpers |
Hanna Arhipova | 55cc129 | 2019-01-08 14:22:18 +0200 | [diff] [blame] | 9 | from netaddr import IPNetwork, IPAddress |
| 10 | |
| 11 | |
| 12 | def test_hw2hw (local_salt_client,hw_pair,record_property): |
| 13 | helpp = helpers.helpers(local_salt_client) |
| 14 | config = utils.get_configuration() |
| 15 | nodes = local_salt_client.cmd(expr_form='compound', tgt=str(hw_pair[0]+' or '+hw_pair[1]), |
| 16 | fun='network.interfaces') |
| 17 | short_name = [] |
| 18 | short_name.append(hw_pair[0].split('.')[0]) |
| 19 | short_name.append(hw_pair[1].split('.')[0]) |
| 20 | nets = config.get('networks').split(',') |
| 21 | local_salt_client.cmd(expr_form='compound', tgt=str(hw_pair[0]+' or '+hw_pair[1]), |
| 22 | fun='cmd.run', param=['nohup iperf -s > file 2>&1 &']) |
| 23 | global_results = [] |
| 24 | for net in nets: |
| 25 | for interf in nodes[hw_pair[0]]: |
| 26 | if 'inet' not in nodes[hw_pair[0]][interf].keys(): |
| 27 | continue |
| 28 | ip = nodes[hw_pair[0]][interf]['inet'][0]['address'] |
| 29 | if (IPAddress(ip) in IPNetwork(net)) and (nodes[hw_pair[0]][interf]['inet'][0]['broadcast']): |
| 30 | for interf2 in nodes[hw_pair[1]]: |
| 31 | if 'inet' not in nodes[hw_pair[1]][interf2].keys(): |
| 32 | continue |
| 33 | ip2 = nodes[hw_pair[1]][interf2]['inet'][0]['address'] |
| 34 | if (IPAddress(ip2) in IPNetwork(net)) and (nodes[hw_pair[1]][interf2]['inet'][0]['broadcast']): |
| 35 | print "Will IPERF between {0} and {1}".format(ip,ip2) |
| 36 | try: |
| 37 | res = helpp.start_iperf_between_hosts(global_results, hw_pair[0], hw_pair[1], |
| 38 | ip, ip2, net) |
| 39 | record_property("1-worst {0}-{1}".format(short_name[0],short_name[1]), res[0] if res[0] < res[2] else res[2]) |
| 40 | record_property("1-best {0}-{1}".format(short_name[0],short_name[1]), res[0] if res[0] > res[2] else res[2]) |
| 41 | record_property("10-best {0}-{1}".format(short_name[0],short_name[1]), res[1] if res[1] > res[3] else res[3]) |
| 42 | record_property("10-best {0}-{1}".format(short_name[0],short_name[1]), res[1] if res[1] > res[3] else res[3]) |
| 43 | print "Measurement between {} and {} " \ |
| 44 | "has been finished".format(hw_pair[0], |
| 45 | hw_pair[1]) |
| 46 | except Exception as e: |
| 47 | print "Failed for {0} {1}".format( |
| 48 | hw_pair[0], hw_pair[1]) |
| 49 | print e |
| 50 | local_salt_client.cmd(expr_form='compound', tgt=str(hw_pair[0]+' or '+hw_pair[1]), |
| 51 | fun='cmd.run', param=['killall -9 iperf']) |
| 52 | helpp.draw_table_with_results(global_results) |