Skip to content

Commit

Permalink
Make sure we detect dependency installation failure
Browse files Browse the repository at this point in the history
Right now, we just ignore the failure because we do not check the
return code of the children process. This commit just makes sure we
are notified when the dependency command fails.
  • Loading branch information
Tadej Borovšak committed May 9, 2021
1 parent 56abe29 commit 539845b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
14 changes: 8 additions & 6 deletions src/molecule/dependency/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import os
import time

from subprocess import CalledProcessError

from molecule import constants, util

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -53,11 +55,11 @@ def execute_with_retries(self):

try:
# print(555, self._sh_command)
util.run_command(self._sh_command, debug=self._config.debug)
util.run_command(self._sh_command, debug=self._config.debug, check=True)
msg = "Dependency completed successfully."
LOG.info(msg)
return
except Exception:
except CalledProcessError:
pass

for counter in range(1, (self.RETRY + 1)):
Expand All @@ -70,15 +72,15 @@ def execute_with_retries(self):
self.SLEEP += self.BACKOFF

try:
util.run_command(self._sh_command, debug=self._config.debug)
util.run_command(self._sh_command, debug=self._config.debug, check=True)
msg = "Dependency completed successfully."
LOG.info(msg)
return
except Exception as _exception:
except CalledProcessError as _exception:
exception = _exception

LOG.error(str(exception), self._sh_command)
util.sysexit(getattr(exception, "exit_code", constants.RC_UNKNOWN_ERROR))
LOG.error(str(exception))
util.sysexit(exception.returncode)

@abc.abstractmethod
def execute(self): # pragma: no cover
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ def test_execute(
)
assert os.path.isdir(role_directory)

patched_run_command.assert_called_once_with("patched-command", debug=False)
patched_run_command.assert_called_once_with(
"patched-command", debug=False, check=True
)

msg = "Dependency completed successfully."
patched_logger_info.assert_called_once_with(msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ def test_execute(
)
assert os.path.isdir(role_directory)

patched_run_command.assert_called_once_with("patched-command", debug=False)
patched_run_command.assert_called_once_with(
"patched-command", debug=False, check=True
)

msg = "Dependency completed successfully."
patched_logger_info.assert_called_once_with(msg)
Expand Down
4 changes: 3 additions & 1 deletion src/molecule/test/unit/dependency/test_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ def test_execute(patched_run_command, patched_logger_info, _instance):
_instance._sh_command = "patched-command"
_instance.execute()

patched_run_command.assert_called_once_with("patched-command", debug=False)
patched_run_command.assert_called_once_with(
"patched-command", debug=False, check=True
)

msg = "Dependency completed successfully."
patched_logger_info.assert_called_once_with(msg)
Expand Down

0 comments on commit 539845b

Please sign in to comment.