From 9f69c6c2be985e81dd6b53b395b9d96d09e8e496 Mon Sep 17 00:00:00 2001 From: Kyr Shatskyy Date: Sun, 24 Aug 2025 14:00:58 +0200 Subject: [PATCH] provision/downburst: support multiple config per machine_type Signed-off-by: Kyr Shatskyy --- teuthology/lock/ops.py | 18 ++++++----- teuthology/lock/util.py | 2 +- teuthology/provision/downburst.py | 51 ++++++++++++++++++++----------- 3 files changed, 45 insertions(+), 26 deletions(-) diff --git a/teuthology/lock/ops.py b/teuthology/lock/ops.py index 52dce68575..4fb6ba86a5 100644 --- a/teuthology/lock/ops.py +++ b/teuthology/lock/ops.py @@ -76,18 +76,20 @@ def lock_many(ctx, num, machine_type, user=None, description=None, # all in one shot. If we are passed 'plana,mira,burnupi,vps', do one query # for 'plana,mira,burnupi' and one for 'vps' machine_types_list = misc.get_multi_machine_types(machine_type) - if machine_types_list == ['vps']: + downburst_types = teuthology.provision.downburst.get_types() + if all(t in downburst_types for t in machine_types_list): machine_types = machine_types_list elif machine_types_list == ['openstack']: return lock_many_openstack(ctx, num, machine_type, user=user, description=description, arch=arch) - elif 'vps' in machine_types_list: - machine_types_non_vps = list(machine_types_list) - machine_types_non_vps.remove('vps') - machine_types_non_vps = '|'.join(machine_types_non_vps) - machine_types = [machine_types_non_vps, 'vps'] + elif any(t in downburst_types for t in machine_types_list): + the_vps = list(t for t in machine_types_list + if t in downburst_types) + non_vps = list(t for t in machine_types_list + if not t in downburst_types) + machine_types = ['|'.join(non_vps), '|'.join(the_vps)] else: machine_types_str = '|'.join(machine_types_list) machine_types = [machine_types_str, ] @@ -102,9 +104,9 @@ def lock_many(ctx, num, machine_type, user=None, description=None, ) # Only query for os_type/os_version if non-vps and non-libcloud, since # in that case we just create them. - vm_types = ['vps'] + teuthology.provision.cloud.get_types() + vm_types = downburst_types + teuthology.provision.cloud.get_types() reimage_types = teuthology.provision.get_reimage_types() - if machine_type not in vm_types + reimage_types: + if machine_type not in (vm_types + reimage_types): if os_type: data['os_type'] = os_type if os_version: diff --git a/teuthology/lock/util.py b/teuthology/lock/util.py index 91f957eab7..955b97e43d 100644 --- a/teuthology/lock/util.py +++ b/teuthology/lock/util.py @@ -18,7 +18,7 @@ def vps_version_or_type_valid(machine_type, os_type, os_version): is skipped (so that this code should behave as it did before this check was added). """ - if not machine_type == 'vps': + if not (machine_type in teuthology.provision.downburst.get_types()): return True if os_type is None or os_version is None: # we'll use the defaults provided by provision.create_if_vm diff --git a/teuthology/provision/downburst.py b/teuthology/provision/downburst.py index 3dc3c2e826..a776bc2834 100644 --- a/teuthology/provision/downburst.py +++ b/teuthology/provision/downburst.py @@ -14,6 +14,15 @@ from teuthology.lock import query log = logging.getLogger(__name__) +def get_types(): + types = ['vps'] + if 'downburst' in config and 'machine' in config.downburst: + machine = config.downburst.get('machine') + if isinstance(machine, list): + types = list(m.get('type') for m in machine) + return types + + def downburst_executable(): """ First check for downburst in the user's path. @@ -186,24 +195,32 @@ class Downburst(object): os_version = self.os_version.lower() mac_address = self.status['mac_address'] - defaults = dict( - downburst=dict( - machine=dict( - disk=os.environ.get('DOWNBURST_DISK_SIZE', '100G'), - ram=os.environ.get('DOWNBURST_RAM_SIZE', '3.8G'), - cpus=int(os.environ.get('DOWNBURST_CPUS', 1)), - volumes=dict( - count=int(os.environ.get('DOWNBURST_EXTRA_DISK_NUMBER', 4)), - size=os.environ.get('DOWNBURST_EXTRA_DISK_SIZE', '100G'), - ), - ), - ) + machine = dict( + disk=os.environ.get('DOWNBURST_DISK_SIZE', '100G'), + ram=os.environ.get('DOWNBURST_RAM_SIZE', '3.8G'), + cpus=int(os.environ.get('DOWNBURST_CPUS', 1)), + volumes=dict( + count=int(os.environ.get('DOWNBURST_EXTRA_DISK_NUMBER', 4)), + size=os.environ.get('DOWNBURST_EXTRA_DISK_SIZE', '100G'), + ), ) - downburst_config = defaults['downburst'] - if config.downburst and isinstance(config.downburst, dict): - deep_merge(downburst_config, config.downburst) - log.debug('downburst_config: %s', downburst_config) - machine = downburst_config['machine'] + def belongs_machine_type(machine_config: dict, machine_type: str) -> bool: + if isinstance(machine_config, dict): + t = machine_config.get('type', None) + if isinstance(t, str): + return machine_type == t + elif isinstance(t, list): + return machine_type in t + return False + if isinstance(config.downburst, dict) and isinstance(config.downburst.get('machine'), list): + machine_type = self.status['machine_type'] + machine_config = next((m for m in config.downburst.get('machine') + if belongs_machine_type(m, machine_type)), None) + if machine_config is None: + raise RuntimeError(f"Cannot find config for machine type {machine_type}.") + elif isinstance(config.downburst, dict) and isinstance(config.downburst.get('machine'), dict): + machine_config = config.downburst.get('machine') + deep_merge(machine, machine_config) log.debug('Using machine config: %s', machine) file_info = { 'disk-size': machine['disk'], -- 2.39.5