blob: 6d82179c19765746b8d9ad867ac3c0e5490b70cc [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(
81 srv: openstack.compute.v2.server.Server,
82 vol: openstack.block_storage.v3.volume.Volume
83) -> None:
84 cloud.compute.delete_volume_attachment(srv, vol)
85 cloud.volume.wait_for_status(vol, status='available')
86
87
88if __name__ == "__main__":
89 print(UBUNTU_IMAGE_NAME)
90 print(FIO_SG_NAME)
91 print(FIO_KEYPAIR_NAME)
92 print(PRIVATE_KEYPAIR_FILE)
93
94 print(FIO_NET_NAME)
95 print(FIO_SUBNET_NAME)
96 print(FIO_SUBNET_RANGE)
97 print(NET_IPV4)
98 print(FIO_ROUTER_NAME)
99 print(FLOATING_NET_NAME)
100 print(MTU_SIZE)
101
102 print(FIO_FLAVOR_NAME)
103 print(FIO_FLAVOR_RAM)
104 print(FIO_FLAVOR_CPUS)
105 print(FIO_FLAVOR_DISK)
106 print(FIO_CLIENTS_COUNT)
107 print(FIO_CLIENT_NAME_MASK)
Dmitriy Kruglov090cb192023-07-04 22:10:50 +0200108 print(FIO_AA_SERVER_GROUP_NAME)
Dmitriy Kruglov6146cb42023-04-10 00:13:59 +0200109 print(FIO_VOL_NAME_MASK)
110 print(FIO_VOL_SIZE)
111 print(FIO_VOL_TYPE)
112 print(FIO_VOL_MOUNTPOINT)
113
114 print(HV_SUFFIX)
115 print(CLOUD_NAME)
Dmitriy Kruglov090cb192023-07-04 22:10:50 +0200116 print(CONCURRENCY)