replace get_nested_option_as_list with get_cfg_by_path, improve ruparts
this makes runparts take exe_prefix and do string to list conversion inside. that means we don't have to do it in cc_scripts_vendor. Also, get_nested_option_as_list was essentially get_cfg_by_path anyway.
This commit is contained in:
parent
ce150bd290
commit
2f38bddc4c
@ -27,13 +27,16 @@ frequency = PER_INSTANCE
|
||||
SCRIPT_SUBDIR = 'vendor'
|
||||
|
||||
|
||||
def handle(name, _cfg, cloud, log, _args):
|
||||
def handle(name, cfg, cloud, log, _args):
|
||||
# This is written to by the vendor data handlers
|
||||
# any vendor data shell scripts get placed in runparts_path
|
||||
runparts_path = os.path.join(cloud.get_ipath_cur(), 'scripts',
|
||||
SCRIPT_SUBDIR)
|
||||
|
||||
prefix = util.get_cfg_by_path(cfg, ('vendor_data', 'prefix'), [])
|
||||
|
||||
try:
|
||||
util.runparts(runparts_path)
|
||||
util.runparts(runparts_path, exe_prefix=prefix)
|
||||
except:
|
||||
log.warn("Failed to run module %s (%s in %s)",
|
||||
name, SCRIPT_SUBDIR, runparts_path)
|
||||
|
@ -614,15 +614,22 @@ def runparts(dirp, skip_no_exist=True, exe_prefix=None):
|
||||
|
||||
failed = []
|
||||
attempted = []
|
||||
|
||||
if exe_prefix is None:
|
||||
prefix = []
|
||||
elif isinstance(exe_prefix, str):
|
||||
prefix = [str(exe_prefix)]
|
||||
elif isinstance(exe_prefix, list):
|
||||
prefix = exe_prefix
|
||||
else:
|
||||
raise TypeError("exe_prefix must be None, str, or list")
|
||||
|
||||
for exe_name in sorted(os.listdir(dirp)):
|
||||
exe_path = os.path.join(dirp, exe_name)
|
||||
if os.path.isfile(exe_path) and os.access(exe_path, os.X_OK):
|
||||
attempted.append(exe_path)
|
||||
try:
|
||||
exe_cmd = exe_prefix
|
||||
if isinstance(exe_prefix, list):
|
||||
exe_cmd.extend(exe_path)
|
||||
subp([exe_cmd], capture=False)
|
||||
subp(prefix + [exe_path], capture=False)
|
||||
except ProcessExecutionError as e:
|
||||
logexc(LOG, "Failed running %s [%s]", exe_path, e.exit_code)
|
||||
failed.append(e)
|
||||
@ -1852,26 +1859,3 @@ def expand_dotted_devname(dotted):
|
||||
return toks
|
||||
else:
|
||||
return (dotted, None)
|
||||
|
||||
|
||||
def get_nested_option_as_list(dct, first, second):
|
||||
"""
|
||||
Return a nested option from a dict as a list
|
||||
"""
|
||||
if not isinstance(dct, dict):
|
||||
raise TypeError("get_nested_option_as_list only works with dicts")
|
||||
root = dct.get(first)
|
||||
if not isinstance(root, dict):
|
||||
return None
|
||||
|
||||
token = root.get(second)
|
||||
if isinstance(token, list):
|
||||
return token
|
||||
elif isinstance(token, dict):
|
||||
ret_list = []
|
||||
for k, v in dct.iteritems():
|
||||
ret_list.append((k, v))
|
||||
return ret_list
|
||||
elif isinstance(token, str):
|
||||
return token.split()
|
||||
return None
|
||||
|
Loading…
Reference in New Issue
Block a user