Ievgeniia Zadorozhna | a080ec0 | 2023-12-05 02:08:52 +0100 | [diff] [blame^] | 1 | import logging |
| 2 | import sys |
| 3 | |
| 4 | import pytest |
| 5 | from texttable import Texttable |
| 6 | |
| 7 | import utils |
| 8 | from utils import helpers |
| 9 | from utils import ssh |
| 10 | from utils.k8s_client import K8SCliActions |
| 11 | |
| 12 | |
| 13 | logger = logging.getLogger(__name__) |
| 14 | |
| 15 | |
| 16 | def test_hw2hw(hw_pair, k8s_v1_client, request, html_report): |
| 17 | """ |
| 18 | Simplified Performance Test: HW to HW test via some specific interface |
| 19 | 1. Get the nodes list from the config, or get computes from K8S nodes list |
| 20 | 2. Connect to the nodes, install iperf, iperf3 there |
| 21 | 3. Start iperf, iperf3 at some specific interface |
| 22 | 4. Measure HW to HW nodes via some interface IP, 1 thread |
| 23 | 5. Measure HW to HW nodes via some interface IP, 1 thread, multiple threads |
| 24 | (10 by default) |
| 25 | 6. Draw the table with all pairs and results |
| 26 | """ |
| 27 | k8s_actions = K8SCliActions(k8s_v1_client) |
| 28 | config = utils.get_configuration() |
| 29 | node_ssh_key_path = config.get("node_ssh_key_path", "") |
| 30 | node_ssh_username = config.get("node_ssh_username", "mcc-user") |
| 31 | iperf_time = int(config.get('iperf_time', 60)) |
| 32 | threads = int(config.get('multiple_threads_number', 10)) |
| 33 | iperf_utility = config.get('multiple_threads_iperf_utility', 'iperf3') |
| 34 | result_table = Texttable(max_width=120) |
| 35 | network_cidr = config.get('network_cidr', '') |
| 36 | cleanup_list = [] |
| 37 | |
| 38 | if not node_ssh_key_path: |
| 39 | pytest.skip("No private key for the MOSK K8S nodes is provided. " |
| 40 | "Please set the ssh key path in the config option " |
| 41 | "'node_ssh_key_path'.") |
| 42 | |
| 43 | if not network_cidr: |
| 44 | # TODO: implement setting several comma-separated net ranges |
| 45 | # TODO: take some default (storage or tenant) interface if not set |
| 46 | pytest.skip("No network interface is provided. Please set the " |
| 47 | "network range in the config option 'network_cidr'.") |
| 48 | |
| 49 | # get K8S nodes' names and Internal IPs for the hw_pair list |
| 50 | nodes_info = k8s_actions.get_nodes_info_by_names(hw_pair) |
| 51 | # connect to the nodes and prepare iperf |
| 52 | node_connect = ssh.SSHTransport(address=nodes_info[0]["address"], |
| 53 | username=node_ssh_username, |
| 54 | private_key=node_ssh_key_path) |
| 55 | for node in nodes_info: |
| 56 | iperf_ip = node_connect.get_node_ip_addresses_from_cidr( |
| 57 | node['address'], network_cidr, user=node_ssh_username, |
| 58 | private_key=node_ssh_key_path) |
| 59 | node["iperf_ip"] = iperf_ip |
| 60 | logger.info( |
| 61 | f"Connecting to the node {node['name']}, IP {node['address']}") |
| 62 | iperf = ssh.IperfAtNode( |
| 63 | ip=node["address"], iperf_test_ip=iperf_ip, |
| 64 | user=node_ssh_username, |
| 65 | private_key=node_ssh_key_path) |
| 66 | if iperf.install_iperf: |
| 67 | cleanup_list.append(node["address"]) |
| 68 | |
| 69 | # Prepare the result table and run iperf3 |
| 70 | table_rows = [[ |
| 71 | 'Test Case', 'Node 1', 'Node 2', 'Network', 'Result' |
| 72 | ]] |
| 73 | # Do iperf3 measurement #1 |
| 74 | measurement1 = f"HW to HW via {network_cidr} interface, 1 thread; iperf3" |
| 75 | logger.info("Doing '{}' measurement...".format(measurement1)) |
| 76 | command1 = "iperf3 -c {} -t {} -B {} | grep sender | tail -n 1".format( |
| 77 | nodes_info[1]["iperf_ip"], iperf_time, nodes_info[0]["iperf_ip"]) |
| 78 | logger.info(f"Running the command: {command1}") |
| 79 | result1 = node_connect.exec_command(command1) |
| 80 | res1 = (b" ".join(result1.split()[-4:-2:])).decode('utf-8') |
| 81 | logger.info("Result #1 is {}".format(res1)) |
| 82 | table_rows.append([measurement1, |
| 83 | "{}".format(nodes_info[0]["name"]), |
| 84 | "{}".format(nodes_info[1]["name"]), |
| 85 | "{}".format(network_cidr), |
| 86 | "{}".format(res1)]) |
| 87 | |
| 88 | # Do iperf/iperf3 measurement #2 |
| 89 | measurement2 = (f"HW to HW via {network_cidr} interface, {threads} " |
| 90 | f"threads; {iperf_utility}") |
| 91 | logger.info(f"Doing '{measurement2}' measurement...") |
| 92 | if iperf_utility == "iperf3": |
| 93 | command2 = '{} -c {} -P {} -t {} -B {} | grep sender | tail -n 1'\ |
| 94 | .format(iperf_utility, nodes_info[1]["iperf_ip"], |
| 95 | threads, iperf_time, nodes_info[0]["iperf_ip"]) |
| 96 | logger.info(f"Running the command: {command2}") |
| 97 | result2 = node_connect.exec_command(command2) |
| 98 | res2 = (b" ".join(result2.split()[-4:-2:])).decode('utf-8') |
| 99 | else: |
| 100 | iperf_utility = "iperf" |
| 101 | command2 = '{} -c {} -P {} -t {} -B {} | tail -n 1'.format( |
| 102 | iperf_utility, nodes_info[1]["iperf_ip"], threads, iperf_time, |
| 103 | nodes_info[0]["iperf_ip"]) |
| 104 | logger.info(f"Running the command: {command2}") |
| 105 | result2 = node_connect.exec_command(command2) |
| 106 | res2 = (b" ".join(result2.split()[-2::])).decode('utf-8') |
| 107 | logger.info("Result #2 is {}".format(res2)) |
| 108 | table_rows.append([measurement2, |
| 109 | "{}".format(nodes_info[0]["name"]), |
| 110 | "{}".format(nodes_info[1]["name"]), |
| 111 | "{}".format(network_cidr), |
| 112 | "{}".format(res2)]) |
| 113 | |
| 114 | # Draw the results table |
| 115 | logger.info("Drawing the table with iperf results...") |
| 116 | result_table.add_rows(table_rows) |
| 117 | sys.stdout.write('\n{}\n'.format(result_table.draw())) |
| 118 | |
| 119 | # Send the results to CSV file at reports/ directory |
| 120 | helpers.create_test_result_table_csv_file( |
| 121 | table_rows, request.node.name) |
| 122 | |
| 123 | # Delete the iperf, iperf3 packages if they were installed |
| 124 | for ip in cleanup_list: |
| 125 | ssh.IperfAtNode.remove_iperf_packages( |
| 126 | ip, node_ssh_username, node_ssh_key_path) |