From 20c74020ac4f11823fbd3aeb52934bb271b55cad Mon Sep 17 00:00:00 2001 From: Jonathan Paynter Date: Thu, 10 Sep 2020 17:59:17 +0100 Subject: [PATCH] configuration/core: Add programmatic labels A label may include ``{}`` where is any valid workload, boot or runtime parameter that the workload may take. The generated job will then substitute in the value of that parameter that was taken. More than one parameter may be identified (within separate sets of ``{}``) within a single label, and these may be alongside normal text similar to python replacement fields. --- wa/framework/configuration/core.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/wa/framework/configuration/core.py b/wa/framework/configuration/core.py index 4d6d6446..20bbf842 100644 --- a/wa/framework/configuration/core.py +++ b/wa/framework/configuration/core.py @@ -997,6 +997,33 @@ class JobSpec(Configuration): if self.label is None: self.label = self.workload_name + self.convert_auto_label() + + def convert_auto_label(self): + to_fetch = set() # Total parameter names required + for _, name, _, _ in Formatter().parse(str(self.label)): + if name: + to_fetch.add(name) + + if not to_fetch: + return + + fetched = {} # maps parameter name -> value + for k, v in self.workload_parameters.items(): + if k in to_fetch: + fetched[k] = v + for k, v in self.runtime_parameters.items(): + if k in to_fetch: + fetched[k] = v + for k, v in self.boot_parameters.items(): + if k in to_fetch: + fetched[k] = v + + try: + self.label = self.label.format(**fetched) + except KeyError as e: + msg = '{} is not a recognised parameter' + raise ConfigError(msg.format(e.args[0])) # This is used to construct the list of Jobs WA will run class JobGenerator(object):