Skip to content

Commit

Permalink
fix: remove decode inside _call
Browse files Browse the repository at this point in the history
Fixes a bug where the script would throw when `check_output` throws an error, since the returned `stderr` would be a str instead of bytes.
  • Loading branch information
jedel1043 committed Jul 26, 2024
1 parent 4188e5c commit 02b53a7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/charms/hpc_libs/v0/slurm_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _on_install(self, _) -> None:

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 5
LIBPATCH = 6

# Charm library dependencies to fetch during `charmcraft pack`.
PYDEPS = ["pyyaml>=6.0.1"]
Expand Down Expand Up @@ -150,8 +150,8 @@ def _call(cmd: str, *args: str, stdin: Optional[str] = None) -> str:
return subprocess.check_output(cmd, input=stdin, stderr=subprocess.PIPE, text=True).strip()
except subprocess.CalledProcessError as e:
_logger.error(f"`{' '.join(cmd)}` failed")
_logger.error(f"stderr: {e.stderr.decode()}")
raise SlurmOpsError(f"command {cmd[0]} failed. Reason:\n{e.stderr.decode()}")
_logger.error(f"stderr: {e.stderr}")
raise SlurmOpsError(f"command {cmd[0]} failed. Reason:\n{e.stderr}")


def _snap(*args) -> str:
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_slurm_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_version_not_installed(self, subcmd) -> None:

def test_call_error(self, subcmd) -> None:
"""Test that `slurm_ops` propagates errors when a command fails."""
subcmd.side_effect = subprocess.CalledProcessError(-1, cmd=[""], stderr=b"error")
subcmd.side_effect = subprocess.CalledProcessError(-1, cmd=[""], stderr="error")
with self.assertRaises(slurm.SlurmOpsError):
slurm.install()

Expand Down

0 comments on commit 02b53a7

Please sign in to comment.