Ievgeniia Zadorozhna | 8402302 | 2021-12-30 13:00:41 +0200 | [diff] [blame] | 1 | import logging |
Ievgeniia Zadorozhna | 97dfde4 | 2022-06-17 20:05:09 +0300 | [diff] [blame] | 2 | import os |
| 3 | import sys |
| 4 | import yaml |
Ievgeniia Zadorozhna | 8402302 | 2021-12-30 13:00:41 +0200 | [diff] [blame] | 5 | |
| 6 | from utils import os_client |
| 7 | |
| 8 | logger = logging.getLogger(__name__) |
| 9 | |
| 10 | |
| 11 | def compile_pairs(nodes): |
| 12 | result = {} |
| 13 | if len(nodes) %2 != 0: |
| 14 | nodes.pop(1) |
| 15 | pairs = list(zip(*[iter(nodes)] * 2)) |
| 16 | for pair in pairs: |
| 17 | result[pair[0]+'<>'+pair[1]] = pair |
| 18 | return result |
| 19 | |
| 20 | |
| 21 | def get_pairs(): |
| 22 | config = get_configuration() |
| 23 | cmp_hosts = config.get('CMP_HOSTS') or [] |
| 24 | skipped_nodes = config.get('skipped_nodes') or [] |
| 25 | if skipped_nodes: |
Ievgeniia Zadorozhna | 97dfde4 | 2022-06-17 20:05:09 +0300 | [diff] [blame] | 26 | sys.stdout.write(("\nNotice: {} nodes will be skipped for vm2vm test" |
| 27 | "".format(",".join(skipped_nodes)))) |
Ievgeniia Zadorozhna | 8402302 | 2021-12-30 13:00:41 +0200 | [diff] [blame] | 28 | logger.info("Skipping nodes {}".format(",".join(skipped_nodes))) |
| 29 | if not cmp_hosts: |
| 30 | openstack_clients = os_client.OfficialClientManager( |
| 31 | username=os.environ['OS_USERNAME'], |
| 32 | password=os.environ['OS_PASSWORD'], |
| 33 | tenant_name=os.environ['OS_PROJECT_NAME'], |
| 34 | auth_url=os.environ['OS_AUTH_URL'], |
| 35 | cert=False, |
| 36 | domain=os.environ['OS_PROJECT_DOMAIN_NAME'] |
| 37 | ) |
| 38 | os_actions = os_client.OSCliActions(openstack_clients) |
| 39 | nova_computes = os_actions.list_nova_computes() |
| 40 | if len(nova_computes) < 2: |
| 41 | raise BaseException( |
| 42 | "At least 2 compute hosts are needed for VM2VM test, " |
| 43 | "now: {}.".format(len(nova_computes))) |
| 44 | cmp_hosts = [n.host_name for n in nova_computes |
| 45 | if n.host_name not in skipped_nodes] |
| 46 | if len(cmp_hosts) < 2: |
| 47 | raise BaseException( |
| 48 | "At least 2 compute hosts are needed for VM2VM test. " |
| 49 | "Cannot create a pair from {}. Please check skip list, at " |
| 50 | "least 2 computes should be tested.".format(cmp_hosts)) |
| 51 | logger.info("CMP_HOSTS option is not set, using host pair from " |
| 52 | "Nova compute list. Pair generated: {}".format(cmp_hosts)) |
| 53 | |
| 54 | return compile_pairs(cmp_hosts) |
| 55 | |
| 56 | |
| 57 | def get_configuration(): |
| 58 | """function returns configuration for environment |
| 59 | and for test if it's specified""" |
| 60 | |
| 61 | global_config_file = os.path.join( |
| 62 | os.path.dirname(os.path.abspath(__file__)), "../global_config.yaml") |
| 63 | with open(global_config_file, 'r') as file: |
| 64 | global_config = yaml.load(file, Loader=yaml.SafeLoader) |
| 65 | for param in list(global_config.keys()): |
| 66 | if param in list(os.environ.keys()): |
| 67 | if ',' in os.environ[param]: |
| 68 | global_config[param] = [] |
| 69 | for item in os.environ[param].split(','): |
| 70 | global_config[param].append(item) |
| 71 | else: |
| 72 | global_config[param] = os.environ[param] |
| 73 | |
| 74 | return global_config |
Ievgeniia Zadorozhna | 90aa802 | 2022-08-11 18:00:23 +0300 | [diff] [blame^] | 75 | |
| 76 | |
| 77 | def check_iperf_utility(actual_iperf_utility): |
| 78 | valid_values = ["iperf", "iperf3"] |
| 79 | if actual_iperf_utility not in valid_values: |
| 80 | raise BaseException("The iperf utility for multiple threads test case " |
| 81 | "is not correct. Valid value is one of {}. Actual " |
| 82 | "value is {}. Please set the correct value in " |
| 83 | "global_config.yaml:multiple_threads_iperf_utility" |
| 84 | "".format(valid_values, actual_iperf_utility)) |