Dmitriy Kruglov | 6146cb4 | 2023-04-10 00:13:59 +0200 | [diff] [blame] | 1 | import os |
| 2 | from typing import Any, Final, Union |
| 3 | |
| 4 | import openstack |
| 5 | |
| 6 | |
| 7 | # openstack.enable_logging(True, path='openstack.log') |
| 8 | |
| 9 | TEST_CLOUD: Final[str] = os.getenv('OS_TEST_CLOUD', 'target') |
| 10 | |
| 11 | cloud = openstack.connect(cloud=TEST_CLOUD) |
| 12 | config = openstack.config.loader.OpenStackConfig() |
| 13 | cloud_config = config.get_one(cloud=TEST_CLOUD) |
| 14 | |
| 15 | |
| 16 | def 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 | |
| 25 | CLOUD_NAME: Final[Any] = get_resource_value('cloud_name', '') |
| 26 | |
| 27 | UBUNTU_IMAGE_NAME: Final[Any] = get_resource_value( |
| 28 | 'ubuntu_image_name', 'Ubuntu-18.04') |
| 29 | FIO_SG_NAME: Final[Any] = get_resource_value('sg_name', 'fio-sg') |
Dmitriy Kruglov | 090cb19 | 2023-07-04 22:10:50 +0200 | [diff] [blame] | 30 | FIO_KEYPAIR_NAME: Final[str] = "-".join( |
Dmitriy Kruglov | 6146cb4 | 2023-04-10 00:13:59 +0200 | [diff] [blame] | 31 | [get_resource_value('keypair_name', 'fio-key'), CLOUD_NAME]) |
| 32 | PRIVATE_KEYPAIR_FILE: Final[str] = "{}/{}.pem".format( |
| 33 | get_resource_value('keypair_file_location', '.'), |
| 34 | FIO_KEYPAIR_NAME) |
| 35 | |
| 36 | FIO_NET_NAME: Final[Any] = get_resource_value('fixed_net_name', 'fio-net') |
| 37 | FIO_SUBNET_NAME: Final[Any] = get_resource_value( |
| 38 | 'fixed_subnet_name', 'fio-subnet') |
| 39 | FIO_SUBNET_RANGE: Final[Any] = get_resource_value( |
| 40 | 'fixed_subnet_range', '192.168.200.0/24') |
| 41 | NET_IPV4: Final[Any] = get_resource_value('net_ipv4', '4') |
| 42 | FIO_ROUTER_NAME: Final[Any] = get_resource_value( |
| 43 | 'fio_router_name', 'fio-router') |
| 44 | FLOATING_NET_NAME: Final[Any] = get_resource_value( |
| 45 | 'floating_net_name', 'public') |
| 46 | MTU_SIZE: Final[Any] = get_resource_value('mtu_size', 9000) |
| 47 | |
| 48 | FIO_FLAVOR_NAME: Final[Any] = get_resource_value('fio_flavor_name', 'fio') |
| 49 | FIO_FLAVOR_RAM: Final[Any] = get_resource_value('fio_flavor_ram', 2048) |
| 50 | FIO_FLAVOR_CPUS: Final[Any] = get_resource_value('fio_flavor_cpus', 10) |
| 51 | FIO_FLAVOR_DISK: Final[Any] = get_resource_value('fio_flavor_disk', 20) |
Dmitriy Kruglov | 090cb19 | 2023-07-04 22:10:50 +0200 | [diff] [blame] | 52 | FIO_CLIENTS_COUNT: Final[int] = int( |
Dmitriy Kruglov | 6146cb4 | 2023-04-10 00:13:59 +0200 | [diff] [blame] | 53 | get_resource_value('fio_clients_count', 10)) |
| 54 | FIO_VOL_NAME_MASK: Final[Any] = get_resource_value( |
| 55 | 'fio_vol_name_mask', 'fio-vol') |
| 56 | FIO_VOL_SIZE: Final[Any] = get_resource_value('fio_vol_size', 110) |
| 57 | FIO_VOL_TYPE: Final[Any] = get_resource_value( |
| 58 | 'fio_vol_type', 'volumes-nvme') |
| 59 | FIO_VOL_MOUNTPOINT: Final[Any] = get_resource_value( |
| 60 | 'fio_vol_mountpoint', '/dev/vdc') |
| 61 | FIO_CLIENT_NAME_MASK: Final[Any] = get_resource_value( |
| 62 | 'fio_client_name_mask', 'fio-vm') |
Dmitriy Kruglov | 090cb19 | 2023-07-04 22:10:50 +0200 | [diff] [blame] | 63 | FIO_AA_SERVER_GROUP_NAME: Final[Any] = get_resource_value( |
| 64 | 'fio_aa_group_name', 'fio-anti-affinity-group') |
Dmitriy Kruglov | 6146cb4 | 2023-04-10 00:13:59 +0200 | [diff] [blame] | 65 | |
| 66 | HV_SUFFIX: Final[Any] = get_resource_value('hv_suffix', '') |
Dmitriy Kruglov | 090cb19 | 2023-07-04 22:10:50 +0200 | [diff] [blame] | 67 | CONCURRENCY: Final[int] = int(get_resource_value('concurrency', 5)) |
Dmitriy Kruglov | 6146cb4 | 2023-04-10 00:13:59 +0200 | [diff] [blame] | 68 | |
| 69 | |
| 70 | def delete_server(srv: openstack.compute.v2.server.Server) -> None: |
| 71 | cloud.compute.delete_server(srv) |
| 72 | cloud.compute.wait_for_delete(srv) |
| 73 | |
| 74 | |
| 75 | def 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 | |
| 80 | def 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 | |
| 88 | if __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 Kruglov | 090cb19 | 2023-07-04 22:10:50 +0200 | [diff] [blame] | 108 | print(FIO_AA_SERVER_GROUP_NAME) |
Dmitriy Kruglov | 6146cb4 | 2023-04-10 00:13:59 +0200 | [diff] [blame] | 109 | 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 Kruglov | 090cb19 | 2023-07-04 22:10:50 +0200 | [diff] [blame] | 116 | print(CONCURRENCY) |