blob: 40018c47e0fd3ed2189dc5915bee5a49e764986c [file] [log] [blame]
Dmitriy Kruglov6146cb42023-04-10 00:13:59 +02001import os
2from typing import Any, Final, Union
3
4import openstack
5
6
7# openstack.enable_logging(True, path='openstack.log')
8
9TEST_CLOUD: Final[str] = os.getenv('OS_TEST_CLOUD', 'target')
10
11cloud = openstack.connect(cloud=TEST_CLOUD)
12config = openstack.config.loader.OpenStackConfig()
13cloud_config = config.get_one(cloud=TEST_CLOUD)
14
15
16def get_resource_value(
17 resource_key: str, default: Union[int, str]
18) -> Union[int, str]:
19 try:
20 return cloud_config.config['custom_vars'][resource_key]
21 except KeyError:
22 return default
23
24
25CLOUD_NAME: Final[Any] = get_resource_value('cloud_name', '')
26
27UBUNTU_IMAGE_NAME: Final[Any] = get_resource_value(
28 'ubuntu_image_name', 'Ubuntu-18.04')
29FIO_SG_NAME: Final[Any] = get_resource_value('sg_name', 'fio-sg')
Dmitriy Kruglov090cb192023-07-04 22:10:50 +020030FIO_KEYPAIR_NAME: Final[str] = "-".join(
Dmitriy Kruglov6146cb42023-04-10 00:13:59 +020031 [get_resource_value('keypair_name', 'fio-key'), CLOUD_NAME])
32PRIVATE_KEYPAIR_FILE: Final[str] = "{}/{}.pem".format(
33 get_resource_value('keypair_file_location', '.'),
34 FIO_KEYPAIR_NAME)
35
36FIO_NET_NAME: Final[Any] = get_resource_value('fixed_net_name', 'fio-net')
37FIO_SUBNET_NAME: Final[Any] = get_resource_value(
38 'fixed_subnet_name', 'fio-subnet')
39FIO_SUBNET_RANGE: Final[Any] = get_resource_value(
40 'fixed_subnet_range', '192.168.200.0/24')
41NET_IPV4: Final[Any] = get_resource_value('net_ipv4', '4')
42FIO_ROUTER_NAME: Final[Any] = get_resource_value(
43 'fio_router_name', 'fio-router')
44FLOATING_NET_NAME: Final[Any] = get_resource_value(
45 'floating_net_name', 'public')
46MTU_SIZE: Final[Any] = get_resource_value('mtu_size', 9000)
47
48FIO_FLAVOR_NAME: Final[Any] = get_resource_value('fio_flavor_name', 'fio')
49FIO_FLAVOR_RAM: Final[Any] = get_resource_value('fio_flavor_ram', 2048)
50FIO_FLAVOR_CPUS: Final[Any] = get_resource_value('fio_flavor_cpus', 10)
51FIO_FLAVOR_DISK: Final[Any] = get_resource_value('fio_flavor_disk', 20)
Dmitriy Kruglov090cb192023-07-04 22:10:50 +020052FIO_CLIENTS_COUNT: Final[int] = int(
Dmitriy Kruglov6146cb42023-04-10 00:13:59 +020053 get_resource_value('fio_clients_count', 10))
54FIO_VOL_NAME_MASK: Final[Any] = get_resource_value(
55 'fio_vol_name_mask', 'fio-vol')
56FIO_VOL_SIZE: Final[Any] = get_resource_value('fio_vol_size', 110)
57FIO_VOL_TYPE: Final[Any] = get_resource_value(
58 'fio_vol_type', 'volumes-nvme')
59FIO_VOL_MOUNTPOINT: Final[Any] = get_resource_value(
60 'fio_vol_mountpoint', '/dev/vdc')
61FIO_CLIENT_NAME_MASK: Final[Any] = get_resource_value(
62 'fio_client_name_mask', 'fio-vm')
Dmitriy Kruglov090cb192023-07-04 22:10:50 +020063FIO_AA_SERVER_GROUP_NAME: Final[Any] = get_resource_value(
64 'fio_aa_group_name', 'fio-anti-affinity-group')
Dmitriy Kruglov6146cb42023-04-10 00:13:59 +020065
66HV_SUFFIX: Final[Any] = get_resource_value('hv_suffix', '')
Dmitriy Kruglov090cb192023-07-04 22:10:50 +020067CONCURRENCY: Final[int] = int(get_resource_value('concurrency', 5))
Dmitriy Kruglov6146cb42023-04-10 00:13:59 +020068
69
70def delete_server(srv: openstack.compute.v2.server.Server) -> None:
71 cloud.compute.delete_server(srv)
72 cloud.compute.wait_for_delete(srv)
73
74
75def delete_volume(vol: openstack.block_storage.v3.volume.Volume) -> None:
76 cloud.volume.delete_volume(vol)
77 cloud.volume.wait_for_delete(vol)
78
79
80def detach_volume(
Ievgeniia Zadorozhnac230e2e2023-09-18 15:18:19 +030081 att: openstack.compute.v2.volume_attachment.VolumeAttachment,
Dmitriy Kruglov6146cb42023-04-10 00:13:59 +020082 srv: openstack.compute.v2.server.Server,
83 vol: openstack.block_storage.v3.volume.Volume
84) -> None:
Ievgeniia Zadorozhnac230e2e2023-09-18 15:18:19 +030085 cloud.compute.delete_volume_attachment(att, srv)
Dmitriy Kruglov6146cb42023-04-10 00:13:59 +020086 cloud.volume.wait_for_status(vol, status='available')
87
88
Ievgeniia Zadorozhnac230e2e2023-09-18 15:18:19 +030089def find_server_group(
90 name: str
91) -> Union[openstack.compute.v2.server_group.ServerGroup, None]:
92 server_groups = cloud.compute.server_groups(all_projects=True)
93 matching_server_groups = [s for s in server_groups
94 if s.name == name]
95 server_group = matching_server_groups[0] \
96 if matching_server_groups else None
97 return server_group
98
99
Dmitriy Kruglov6146cb42023-04-10 00:13:59 +0200100if __name__ == "__main__":
101 print(UBUNTU_IMAGE_NAME)
102 print(FIO_SG_NAME)
103 print(FIO_KEYPAIR_NAME)
104 print(PRIVATE_KEYPAIR_FILE)
105
106 print(FIO_NET_NAME)
107 print(FIO_SUBNET_NAME)
108 print(FIO_SUBNET_RANGE)
109 print(NET_IPV4)
110 print(FIO_ROUTER_NAME)
111 print(FLOATING_NET_NAME)
112 print(MTU_SIZE)
113
114 print(FIO_FLAVOR_NAME)
115 print(FIO_FLAVOR_RAM)
116 print(FIO_FLAVOR_CPUS)
117 print(FIO_FLAVOR_DISK)
118 print(FIO_CLIENTS_COUNT)
119 print(FIO_CLIENT_NAME_MASK)
Dmitriy Kruglov090cb192023-07-04 22:10:50 +0200120 print(FIO_AA_SERVER_GROUP_NAME)
Dmitriy Kruglov6146cb42023-04-10 00:13:59 +0200121 print(FIO_VOL_NAME_MASK)
122 print(FIO_VOL_SIZE)
123 print(FIO_VOL_TYPE)
124 print(FIO_VOL_MOUNTPOINT)
125
126 print(HV_SUFFIX)
127 print(CLOUD_NAME)
Dmitriy Kruglov090cb192023-07-04 22:10:50 +0200128 print(CONCURRENCY)