Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions reframe/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def __init__(self, command, stdout, stderr, exitcode):
self._exitcode = exitcode

def __str__(self):
lines = ["Command '{0}' failed with exit code {1}:".format(
lines = ["command '{0}' failed with exit code {1}:".format(
self._command, self._exitcode)]
lines.append('=== STDOUT ===')
if self._stdout:
Expand Down Expand Up @@ -162,7 +162,7 @@ def __init__(self, command, stdout, stderr, timeout):
self.args = command, stdout, stderr, timeout

def __str__(self):
lines = ["Command '{0}' timed out after {1}s:".format(self._command,
lines = ["command '{0}' timed out after {1}s:".format(self._command,
self._timeout)]
lines.append('=== STDOUT ===')
if self._stdout:
Expand Down
46 changes: 26 additions & 20 deletions reframe/core/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,25 +410,27 @@ def name(self):
def version(self):
return self._version

def _run_module_command(self, *args):
command = [self._command, *args]
return os_ext.run_command(' '.join(command))
def _run_module_command(self, *args, msg=None):
command = ' '.join([self._command, *args])
try:
completed = os_ext.run_command(command, check=True)
except SpawnedProcessError as e:
raise EnvironError(msg) from e

if self._module_command_failed(completed):
err = SpawnedProcessError(command,
completed.stdout,
completed.stderr,
completed.returncode)
raise EnvironError(msg) from err

return completed

def _module_command_failed(self, completed):
return re.search(r'ERROR', completed.stderr) is not None

def _exec_module_command(self, *args, msg=None):
completed = self._run_module_command(*args)
if self._module_command_failed(completed):
if msg is None:
msg = 'modules system command failed: '
if isinstance(completed.args, str):
msg += completed.args
else:
msg += ' '.join(completed.args)

raise EnvironError(msg)

completed = self._run_module_command(*args, msg=msg)
exec(completed.stdout)

def loaded_modules(self):
Expand All @@ -441,7 +443,8 @@ def loaded_modules(self):

def conflicted_modules(self, module):
conflict_list = []
completed = self._run_module_command('show', str(module))
completed = self._run_module_command(
'show', str(module), msg="could not show module '%s'" % module)
return [Module(m.group(1))
for m in re.finditer(r'^conflict\s+(\S+)',
completed.stderr, re.MULTILINE)]
Expand All @@ -450,12 +453,14 @@ def is_module_loaded(self, module):
return module in self.loaded_modules()

def load_module(self, module):
self._exec_module_command('load', str(module),
msg='could not load module %s' % module)
self._exec_module_command(
'load', str(module),
msg="could not load module '%s' correctly" % module)

def unload_module(self, module):
self._exec_module_command('unload', str(module),
msg='could not unload module %s' % module)
self._exec_module_command(
'unload', str(module),
msg="could not unload module '%s' correctly" % module)

def unload_all(self):
self._exec_module_command('purge')
Expand Down Expand Up @@ -558,7 +563,8 @@ def _module_command_failed(self, completed):

def conflicted_modules(self, module):
conflict_list = []
completed = self._run_module_command('show', str(module))
completed = self._run_module_command(
'show', str(module), msg="could not show module '%s'" % module)

# Lmod accepts both Lua and and Tcl syntax
# The following test allows incorrect syntax, e.g., `conflict
Expand Down
7 changes: 5 additions & 2 deletions reframe/frontend/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,11 @@ def filter_system(c):
for m in options.user_modules:
try:
rt.modules_system.load_module(m, force=True)
except EnvironError:
printer.info("could not load module `%s': Skipping..." % m)
raise EnvironError("test")
except EnvironError as e:
printer.warning("could not load module '%s' correctly: "
"Skipping..." % m)
printer.debug(str(e))

success = True
if options.list:
Expand Down
3 changes: 3 additions & 0 deletions reframe/frontend/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def timestamp(self, msg='', separator=None):
def info(self, msg=''):
self._logger.info(msg)

def debug(self, msg=''):
self._logger.debug(msg)

def warning(self, msg):
msg = AnsiColorizer.colorize('%s: %s' % (sys.argv[0], msg),
AnsiColorizer.yellow)
Expand Down
12 changes: 6 additions & 6 deletions unittests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_spawned_process_error(self):
exc_args = ('foo bar', 'partial output', 'error message', 1)
e = exc.SpawnedProcessError(*exc_args)
self.assertRaisesRegex(exc.ReframeError,
r"Command 'foo bar' failed with exit code 1:\n"
r"command 'foo bar' failed with exit code 1:\n"
r"=== STDOUT ===\n"
r'partial output\n'
r"=== STDERR ===\n"
Expand All @@ -62,7 +62,7 @@ def test_spawned_process_error_nostdout(self):
exc_args = ('foo bar', '', 'error message', 1)
e = exc.SpawnedProcessError(*exc_args)
self.assertRaisesRegex(exc.ReframeError,
r"Command 'foo bar' failed with exit code 1:\n"
r"command 'foo bar' failed with exit code 1:\n"
r"=== STDOUT ===\n"
r"=== STDERR ===\n"
r"error message",
Expand All @@ -72,7 +72,7 @@ def test_spawned_process_error_nostderr(self):
exc_args = ('foo bar', 'partial output', '', 1)
e = exc.SpawnedProcessError(*exc_args)
self.assertRaisesRegex(exc.ReframeError,
r"Command 'foo bar' failed with exit code 1:\n"
r"command 'foo bar' failed with exit code 1:\n"
r"=== STDOUT ===\n"
r'partial output\n'
r"=== STDERR ===",
Expand All @@ -82,7 +82,7 @@ def test_spawned_process_timeout(self):
exc_args = ('foo bar', 'partial output', 'partial error', 10)
e = exc.SpawnedProcessTimeout(*exc_args)
self.assertRaisesRegex(exc.ReframeError,
r"Command 'foo bar' timed out after 10s:\n"
r"command 'foo bar' timed out after 10s:\n"
r"=== STDOUT ===\n"
r'partial output\n'
r"=== STDERR ===\n"
Expand All @@ -94,7 +94,7 @@ def test_spawned_process_timeout_nostdout(self):
exc_args = ('foo bar', '', 'partial error', 10)
e = exc.SpawnedProcessTimeout(*exc_args)
self.assertRaisesRegex(exc.ReframeError,
r"Command 'foo bar' timed out after 10s:\n"
r"command 'foo bar' timed out after 10s:\n"
r"=== STDOUT ===\n"
r"=== STDERR ===\n"
r"partial error",
Expand All @@ -104,7 +104,7 @@ def test_spawned_process_timeout_nostderr(self):
exc_args = ('foo bar', 'partial output', '', 10)
e = exc.SpawnedProcessTimeout(*exc_args)
self.assertRaisesRegex(exc.ReframeError,
r"Command 'foo bar' timed out after 10s:\n"
r"command 'foo bar' timed out after 10s:\n"
r"=== STDOUT ===\n"
r'partial output\n'
r"=== STDERR ===",
Expand Down