@@ -202,29 +202,39 @@ def comma_separated_kv_to_dict(input_string: str) -> dict:
202202 for kv_pair in kv_pairs :
203203 try :
204204 key , value = kv_pair .split ("=" )
205- except ValueError :
206- raise ValueError ("Not a <key>=<value> pair: %s" % kv_pair )
205+ except ValueError as err :
206+ raise ValueError (
207+ "Not a <key>=<value> pair: %s. " % kv_pair ) from err
207208 out [key ] = value
208209 return out
209210
210211
211- def compose_user_scripts (global_scripts , instance_scripts ):
212+ def compose_user_scripts (
213+ global_scripts : list [dict ],
214+ instance_scripts : list [dict ],
215+ ) -> dict :
216+ """Process user script arguments.
217+
218+ :param global_scripts: a list of dicts describing user scripts, the target
219+ OS and the phase in which the scripts should be invoked.
220+ The dicts are expected to contain the following keys:
221+ * <os>: one of the operating systems supported by Coriolis,
222+ e.g. "windows" or "linux". The value will be a local script path.
223+ * "phase": optional phase, defaults to "osmorphing_post_os_mount".
224+ :param instance_scripts: a list of dicts describing user scripts, each
225+ having a corresponding instance.
226+ The dicts are expected to contain the following keys:
227+ * <instance>: The name of the instance where the script must run.
228+ * "phase": optional phase, defaults to "osmorphing_post_os_mount".
229+ :returns: the processed list of scripts as expected by the Coriolis API.
230+ """
212231 ret = {
213232 "global" : {},
214233 "instances" : {}
215234 }
216235 global_scripts = global_scripts or []
217236 instance_scripts = instance_scripts or []
218- for global_script_str_params in global_scripts :
219- try :
220- params = comma_separated_kv_to_dict (global_script_str_params )
221- except ValueError :
222- raise ValueError (
223- "Invalid global user script parameter: %s. Expecting "
224- "<os_type>=<script_path>. Can optionally include a comma "
225- "separated phase parameter, "
226- "e.g. <os_type>=<script_path>,phase=<phase>" %
227- global_script_str_params )
237+ for params in global_scripts :
228238 phase = params .pop ("phase" , constants .PHASE_OSMORPHING_POST_OS_MOUNT )
229239 if phase not in constants .USER_SCRIPT_PHASES :
230240 raise ValueError (
@@ -264,17 +274,7 @@ def compose_user_scripts(global_scripts, instance_scripts):
264274 }
265275 ret ["global" ][os_type ].append (script_entry )
266276
267- for instance_scripts_str_params in instance_scripts :
268- try :
269- params = comma_separated_kv_to_dict (instance_scripts_str_params )
270- except ValueError :
271- raise ValueError (
272- "Invalid instance user script parameter: %s. Expecting "
273- "<instance>=<script_path>. Can optionally include a comma "
274- "separated phase parameter, "
275- "e.g. <instance>=<script_path>,phase=<phase>" %
276- instance_scripts_str_params )
277-
277+ for params in instance_scripts :
278278 phase = params .pop ("phase" , constants .PHASE_OSMORPHING_POST_OS_MOUNT )
279279 if phase not in constants .USER_SCRIPT_PHASES :
280280 raise ValueError (
0 commit comments