Skip to content

Commit

Permalink
Chef - Preserve returncode in stateful_shell (project-chip#19144)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpagravel committed Jun 15, 2022
1 parent bedb58a commit 4149978
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions examples/chef/stateful_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def run_cmd(
redirect = ""

command_with_state = (
f"OLDPWD={self.env.get('OLDPWD', '')}; {cmd} {redirect};"
f" env -0 > {self.envfile_path}")
f"OLDPWD={self.env.get('OLDPWD', '')}; {cmd} {redirect}; RETCODE=$?;"
f" env -0 > {self.envfile_path}; exit $RETCODE")
with subprocess.Popen(
[command_with_state],
env=self.env, cwd=self.cwd,
Expand All @@ -114,7 +114,9 @@ def run_cmd(

if raise_on_returncode and returncode != 0:
raise RuntimeError(
f"Error. Return code is not 0. It is: {returncode}")
"Error. Nonzero return code."
f"\nReturncode: {returncode}"
f"\nCmd: {cmd}")

if return_cmd_output:
with open(self.cmd_output_path, encoding="latin1") as f:
Expand Down

0 comments on commit 4149978

Please sign in to comment.