Skip to content

Commit

Permalink
installer.py update did not properly account for reporting errors to …
Browse files Browse the repository at this point in the history
…spack monitor :(

Signed-off-by: vsoch <vsoch@users.noreply.github.com>
  • Loading branch information
vsoch committed Nov 2, 2021
1 parent aeba721 commit b954c31
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lib/spack/docs/developer_guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,13 @@ If you need to write a hook that is relevant to a failure within a build
process, you would want to instead use ``on_phase_failure``.


"""""""""""""""""""""""""""
``on_install_cancel(spec)``
"""""""""""""""""""""""""""

The same, but triggered if a spec install is cancelled for any reason.


"""""""""""""""""""""""""""""""""""""""""""""""
``on_phase_success(pkg, phase_name, log_file)``
"""""""""""""""""""""""""""""""""""""""""""""""
Expand Down
2 changes: 0 additions & 2 deletions lib/spack/spack/cmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,9 @@ def parse_specs(args, **kwargs):
if not isinstance(args, six.string_types):
sargs = ' '.join(spack.util.string.quote(args))
specs = spack.spec.parse(sargs)

new = []
if all_versions:
for spec in specs:
tty.info("Adding all versions for spec %s" % spec)
for version, _ in spec.package.versions.items():
# Use same spec, but change version. This is hacky
spec_name = "%s@%s" % (spec.name, version)
Expand Down
3 changes: 3 additions & 0 deletions lib/spack/spack/cmd/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ def get_tests(specs):
kwargs['tests'] = tests

try:
if args.all:
tty.info("Adding all versions for specs %s" % " ".join(args.spec))
specs = spack.cmd.parse_specs(
args.spec, concretize=True, tests=tests,
all_versions=args.all)
Expand Down Expand Up @@ -476,4 +478,5 @@ def get_tests(specs):
# The full_hash is the main package id, the build_hash for others
if args.use_monitor and specs:
monitor.new_configuration(specs)

install_specs(args, kwargs, zip(abstract_specs, specs))
1 change: 1 addition & 0 deletions lib/spack/spack/hooks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def __call__(self, *args, **kwargs):
on_install_start = _HookRunner('on_install_start')
on_install_success = _HookRunner('on_install_success')
on_install_failure = _HookRunner('on_install_failure')
on_install_cancel = _HookRunner('on_install_cancel')

# Analyzer hooks
on_analyzer_save = _HookRunner('on_analyzer_save')
Expand Down
11 changes: 11 additions & 0 deletions lib/spack/spack/hooks/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ def on_install_failure(spec):
tty.verbose(result.get('message'))


def on_install_cancel(spec):
"""Triggered on cancel of an install
"""
if not spack.monitor.cli:
return

tty.debug("Running on_install_cancel for %s" % spec)
result = spack.monitor.cli.cancel_task(spec)
tty.verbose(result.get('message'))


def on_phase_success(pkg, phase_name, log_file):
"""Triggered on a phase success
"""
Expand Down
8 changes: 7 additions & 1 deletion lib/spack/spack/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,7 @@ def _install_task(self, task):
except spack.build_environment.StopPhase as e:
# A StopPhase exception means that do_install was asked to
# stop early from clients, and is not an error at this point
spack.hooks.on_install_failure(task.request.pkg.spec)
pid = '{0}: '.format(self.pid) if tty.show_pid() else ''
tty.debug('{0}{1}'.format(pid, str(e)))
tty.debug('Package stage directory: {0}' .format(pkg.stage.source_path))
Expand Down Expand Up @@ -1378,6 +1379,7 @@ def _update_failed(self, task, mark=False, exc=None):
# Ensure the dependent's uninstalled dependents are
# up-to-date and their build tasks removed.
dep_task = self.build_tasks[dep_id]
spack.hooks.on_install_cancel(dep_task.request.pkg.spec)
self._update_failed(dep_task, mark)
self._remove_task(dep_id)
else:
Expand Down Expand Up @@ -1655,7 +1657,7 @@ def install(self):
err = 'Failed to install {0} due to {1}: {2}'
tty.error(err.format(pkg.name, exc.__class__.__name__,
str(exc)))
spack.hooks.on_install_failure(task.request.pkg.spec)
spack.hooks.on_install_cancel(task.request.pkg.spec)
raise

except (Exception, SystemExit) as exc:
Expand Down Expand Up @@ -1710,6 +1712,7 @@ def install(self):
missing = [request.pkg_id for request in self.build_requests if
request.install_args.get('install_package') and
request.pkg_id not in self.installed]

if failed_explicits or missing:
for pkg_id, err in failed_explicits:
tty.error('{0}: {1}'.format(pkg_id, err))
Expand Down Expand Up @@ -1919,6 +1922,9 @@ def _real_install(self):
except BaseException:
combine_phase_logs(pkg.phase_log_files, pkg.log_path)
spack.hooks.on_phase_error(pkg, phase_name, log_file)

# phase error indicates install error
spack.hooks.on_install_failure(pkg.spec)
raise

# We assume loggers share echo True/False
Expand Down
5 changes: 5 additions & 0 deletions lib/spack/spack/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,11 @@ def fail_task(self, spec):
"""
return self.update_build(spec, status="FAILED")

def cancel_task(self, spec):
"""Given a spec, mark it as cancelled.
"""
return self.update_build(spec, status="CANCELLED")

def send_analyze_metadata(self, pkg, metadata):
"""
Send spack analyzer metadata to the spack monitor server.
Expand Down

0 comments on commit b954c31

Please sign in to comment.