From 02b53a72c8ad7b27093e58629b03f9ee00102130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Juli=C3=A1n=20Espina?= Date: Fri, 26 Jul 2024 15:08:49 -0600 Subject: [PATCH] fix: remove `decode` inside `_call` 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. --- lib/charms/hpc_libs/v0/slurm_ops.py | 6 +++--- tests/unit/test_slurm_ops.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/charms/hpc_libs/v0/slurm_ops.py b/lib/charms/hpc_libs/v0/slurm_ops.py index b48f0a3..f1eaa0d 100644 --- a/lib/charms/hpc_libs/v0/slurm_ops.py +++ b/lib/charms/hpc_libs/v0/slurm_ops.py @@ -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"] @@ -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: diff --git a/tests/unit/test_slurm_ops.py b/tests/unit/test_slurm_ops.py index 6d12d77..aae23de 100644 --- a/tests/unit/test_slurm_ops.py +++ b/tests/unit/test_slurm_ops.py @@ -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()