From b2c2cbadcda1394025605c317e2eb9c2b5b200ba Mon Sep 17 00:00:00 2001 From: Peter Scheibel Date: Tue, 29 Jan 2019 17:41:15 -0600 Subject: debug output includes modulecmd output (#9476) Debug output now includes the output of modulecmd executions. Only output module content when a failure occurs; always report when a module is loaded/unloaded. --- lib/spack/spack/util/module_cmd.py | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/lib/spack/spack/util/module_cmd.py b/lib/spack/spack/util/module_cmd.py index a7ceee6d3d..6a1ca8113d 100644 --- a/lib/spack/spack/util/module_cmd.py +++ b/lib/spack/spack/util/module_cmd.py @@ -99,9 +99,17 @@ def get_module_cmd_from_bash(bashopts=''): def unload_module(mod): """Takes a module name and unloads the module from the environment. It does not check whether conflicts arise from the unloaded module""" + tty.debug("Unloading module: {0}".format(mod)) + modulecmd = get_module_cmd() - exec(compile(modulecmd('unload', mod, output=str, error=str), '', - 'exec')) + unload_output = modulecmd('unload', mod, output=str, error=str) + + try: + exec(compile(unload_output, '', 'exec')) + except Exception: + tty.debug("Module unload output of {0}:\n{1}\n".format( + mod, unload_output)) + raise def load_module(mod): @@ -109,6 +117,8 @@ def load_module(mod): load that module. It then loads the provided module. Depends on the modulecmd implementation of modules used in cray and lmod. """ + tty.debug("Loading module: {0}".format(mod)) + # Create an executable of the module command that will output python code modulecmd = get_module_cmd() @@ -116,17 +126,28 @@ def load_module(mod): # We do this without checking that they are already installed # for ease of programming because unloading a module that is not # loaded does nothing. - text = modulecmd('show', mod, output=str, error=str).split() - for i, word in enumerate(text): - if word == 'conflict': - unload_module(text[i + 1]) + module_content = modulecmd('show', mod, output=str, error=str) + text = module_content.split() + try: + for i, word in enumerate(text): + if word == 'conflict': + unload_module(text[i + 1]) + except Exception: + tty.debug("Module show output of {0}:\n{1}\n".format( + mod, module_content)) + raise # Load the module now that there are no conflicts # Some module systems use stdout and some use stderr load = modulecmd('load', mod, output=str, error='/dev/null') if not load: load = modulecmd('load', mod, error=str) - exec(compile(load, '', 'exec')) + + try: + exec(compile(load, '', 'exec')) + except Exception: + tty.debug("Module load output of {0}:\n{1}\n".format(mod, load)) + raise def get_path_arg_from_module_line(line): -- cgit v1.2.3-70-g09d2