blob: 8cfe8975359e15b3c77e3061fad09f8036735e02 [file] [log] [blame]
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +02001import logging
Ievgeniia Zadorozhna97dfde42022-06-17 20:05:09 +03002import os
3import sys
4import yaml
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +02005
6from utils import os_client
7
8logger = logging.getLogger(__name__)
9
10
11def 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
21def 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 Zadorozhna97dfde42022-06-17 20:05:09 +030026 sys.stdout.write(("\nNotice: {} nodes will be skipped for vm2vm test"
27 "".format(",".join(skipped_nodes))))
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +020028 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
57def 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 Zadorozhna90aa8022022-08-11 18:00:23 +030075
76
77def 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))