summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/spack/spack/installer.py14
-rw-r--r--lib/spack/spack/test/installer.py20
2 files changed, 31 insertions, 3 deletions
diff --git a/lib/spack/spack/installer.py b/lib/spack/spack/installer.py
index 0eeec020bc..786eec5383 100644
--- a/lib/spack/spack/installer.py
+++ b/lib/spack/spack/installer.py
@@ -1530,12 +1530,20 @@ class PackageInstaller(object):
self._update_installed(task)
raise
- except (Exception, KeyboardInterrupt, SystemExit) as exc:
- # Assuming best effort installs so suppress the exception and
- # mark as a failure UNLESS this is the explicit package.
+ except KeyboardInterrupt as exc:
+ # The build has been terminated with a Ctrl-C so terminate.
err = 'Failed to install {0} due to {1}: {2}'
tty.error(err.format(pkg.name, exc.__class__.__name__,
str(exc)))
+ raise
+
+ except (Exception, SystemExit) as exc:
+ # Best effort installs suppress the exception and mark the
+ # package as a failure UNLESS this is the explicit package.
+ err = 'Failed to install {0} due to {1}: {2}'
+ tty.error(err.format(pkg.name, exc.__class__.__name__,
+ str(exc)))
+
self._update_failed(task, True, exc)
if pkg_id == self.pkg_id:
diff --git a/lib/spack/spack/test/installer.py b/lib/spack/spack/test/installer.py
index 0be4bc78c0..96612c8f5f 100644
--- a/lib/spack/spack/test/installer.py
+++ b/lib/spack/spack/test/installer.py
@@ -718,6 +718,26 @@ def test_install_failed(install_mockery, monkeypatch, capsys):
assert 'Warning: b failed to install' in out
+def test_install_fail_on_interrupt(install_mockery, monkeypatch, capsys):
+ """Test ctrl-c interrupted install."""
+ err_msg = 'mock keyboard interrupt'
+
+ def _interrupt(installer, task, **kwargs):
+ raise KeyboardInterrupt(err_msg)
+
+ spec, installer = create_installer('a')
+
+ # Raise a KeyboardInterrupt error to trigger early termination
+ monkeypatch.setattr(inst.PackageInstaller, '_install_task', _interrupt)
+
+ with pytest.raises(KeyboardInterrupt, match=err_msg):
+ installer.install()
+
+ out = str(capsys.readouterr())
+ assert 'Failed to install' in out
+ assert err_msg in out
+
+
def test_install_lock_failures(install_mockery, monkeypatch, capfd):
"""Cover basic install lock failure handling in a single pass."""
def _requeued(installer, task):