blob: 8e858b3ecf730ed47b6169b49c2f4c1a5e403da2 [file] [log] [blame]
Ievgeniia Zadorozhna84023022021-12-30 13:00:41 +02001import os
2import yaml
3import logging
4
5from utils import os_client
6
7logger = logging.getLogger(__name__)
8
9
10def compile_pairs(nodes):
11 result = {}
12 if len(nodes) %2 != 0:
13 nodes.pop(1)
14 pairs = list(zip(*[iter(nodes)] * 2))
15 for pair in pairs:
16 result[pair[0]+'<>'+pair[1]] = pair
17 return result
18
19
20def get_pairs():
21 config = get_configuration()
22 cmp_hosts = config.get('CMP_HOSTS') or []
23 skipped_nodes = config.get('skipped_nodes') or []
24 if skipped_nodes:
25 print(("\nNotice: {} nodes will be skipped for vm2vm test".format(
26 ",".join(skipped_nodes))))
27 logger.info("Skipping nodes {}".format(",".join(skipped_nodes)))
28 if not cmp_hosts:
29 openstack_clients = os_client.OfficialClientManager(
30 username=os.environ['OS_USERNAME'],
31 password=os.environ['OS_PASSWORD'],
32 tenant_name=os.environ['OS_PROJECT_NAME'],
33 auth_url=os.environ['OS_AUTH_URL'],
34 cert=False,
35 domain=os.environ['OS_PROJECT_DOMAIN_NAME']
36 )
37 os_actions = os_client.OSCliActions(openstack_clients)
38 nova_computes = os_actions.list_nova_computes()
39 if len(nova_computes) < 2:
40 raise BaseException(
41 "At least 2 compute hosts are needed for VM2VM test, "
42 "now: {}.".format(len(nova_computes)))
43 cmp_hosts = [n.host_name for n in nova_computes
44 if n.host_name not in skipped_nodes]
45 if len(cmp_hosts) < 2:
46 raise BaseException(
47 "At least 2 compute hosts are needed for VM2VM test. "
48 "Cannot create a pair from {}. Please check skip list, at "
49 "least 2 computes should be tested.".format(cmp_hosts))
50 logger.info("CMP_HOSTS option is not set, using host pair from "
51 "Nova compute list. Pair generated: {}".format(cmp_hosts))
52
53 return compile_pairs(cmp_hosts)
54
55
56def get_configuration():
57 """function returns configuration for environment
58 and for test if it's specified"""
59
60 global_config_file = os.path.join(
61 os.path.dirname(os.path.abspath(__file__)), "../global_config.yaml")
62 with open(global_config_file, 'r') as file:
63 global_config = yaml.load(file, Loader=yaml.SafeLoader)
64 for param in list(global_config.keys()):
65 if param in list(os.environ.keys()):
66 if ',' in os.environ[param]:
67 global_config[param] = []
68 for item in os.environ[param].split(','):
69 global_config[param].append(item)
70 else:
71 global_config[param] = os.environ[param]
72
73 return global_config