Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure we detect dependency installation failure #3105

Merged
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
15 changes: 8 additions & 7 deletions src/molecule/dependency/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
import logging
import os
import time
from subprocess import CalledProcessError

from molecule import constants, util
from molecule import util

LOG = logging.getLogger(__name__)

Expand Down Expand Up @@ -53,11 +54,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 +71,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