|
9 | 9 | import threading
|
10 | 10 | import json
|
11 | 11 | from concurrent.futures.thread import ThreadPoolExecutor
|
12 |
| -from concurrent.futures import as_completed |
13 | 12 | from datetime import datetime
|
14 | 13 | from math import floor
|
15 | 14 | from shutil import copyfile, rmtree
|
@@ -7314,42 +7313,31 @@ def factory(namespace=None):
|
7314 | 7313 | # Load VM configs from cnv_vm_workload yaml
|
7315 | 7314 | vm_configs = templating.load_yaml(constants.CNV_VM_WORKLOADS)
|
7316 | 7315 |
|
7317 |
| - # Function to create a VM using cnv_workload |
7318 |
| - def create_vm(index, vm_config, sc_obj_def_compr, sc_obj_aggressive, namespace): |
7319 |
| - # Determine the storage class based on the compression type |
7320 |
| - if vm_config["sc_compression"] == "default": |
7321 |
| - storageclass = sc_obj_def_compr.name |
7322 |
| - elif vm_config["sc_compression"] == "aggressive": |
7323 |
| - storageclass = sc_obj_aggressive.name |
7324 |
| - |
7325 |
| - return cnv_workload( |
7326 |
| - volume_interface=vm_config["volume_interface"], |
7327 |
| - access_mode=vm_config["access_mode"], |
7328 |
| - storageclass=storageclass, |
7329 |
| - pvc_size="30Gi", # Assuming pvc_size is fixed for all |
7330 |
| - source_url=constants.CNV_FEDORA_SOURCE, # Assuming source_url is the same for all VMs |
7331 |
| - namespace=namespace, |
7332 |
| - )[index] |
7333 |
| - |
7334 |
| - # Use ThreadPoolExecutor for parallel execution |
| 7316 | + # Use ThreadPoolExecutor to create VMs parallel |
7335 | 7317 | with ThreadPoolExecutor() as executor:
|
7336 |
| - future_to_vm = { |
7337 |
| - executor.submit( |
7338 |
| - create_vm, |
7339 |
| - index, |
7340 |
| - vm_config, |
7341 |
| - sc_obj_def_compr, |
7342 |
| - sc_obj_aggressive, |
7343 |
| - namespace, |
7344 |
| - ): vm_config |
7345 |
| - for index, vm_config in enumerate(vm_configs["cnv_vm_configs"]) |
7346 |
| - } |
| 7318 | + futures = [] |
| 7319 | + for vm_config in vm_configs["cnv_vm_configs"]: |
| 7320 | + # Determine the storage class based on the compression type |
| 7321 | + if vm_config["sc_compression"] == "default": |
| 7322 | + storageclass = sc_obj_def_compr.name |
| 7323 | + elif vm_config["sc_compression"] == "aggressive": |
| 7324 | + storageclass = sc_obj_aggressive.name |
| 7325 | + future = executor.submit( |
| 7326 | + cnv_workload, |
| 7327 | + volume_interface=vm_config["volume_interface"], |
| 7328 | + access_mode=vm_config["access_mode"], |
| 7329 | + storageclass=storageclass, |
| 7330 | + pvc_size="30Gi", # Assuming pvc_size is fixed for all |
| 7331 | + source_url=constants.CNV_FEDORA_SOURCE, # Assuming source_url is the same for all VMs |
| 7332 | + namespace=namespace, |
| 7333 | + ) |
| 7334 | + |
| 7335 | + futures.append((future, vm_config["sc_compression"])) |
7347 | 7336 |
|
7348 |
| - for future in as_completed(future_to_vm): |
7349 |
| - vm_config = future_to_vm[future] |
| 7337 | + for future, sc_compression in futures: |
7350 | 7338 | try:
|
7351 |
| - vm_obj = future.result() |
7352 |
| - if vm_config["sc_compression"] == "aggressive": |
| 7339 | + vm_obj = future.result()[0] |
| 7340 | + if sc_compression == "aggressive": |
7353 | 7341 | vm_list_agg_compr.append(vm_obj)
|
7354 | 7342 | else:
|
7355 | 7343 | vm_list_default_compr.append(vm_obj)
|
|
0 commit comments