From aeb241828683bc4b69ff353e302ff558b30c9be9 Mon Sep 17 00:00:00 2001 From: "Jason C. Nucciarone" Date: Wed, 10 Jul 2024 14:41:51 -0400 Subject: [PATCH] refactor: `DetectVirtNotFoundError` -> `UnknownVirtStateError` Signed-off-by: Jason C. Nucciarone --- lib/charms/hpc_libs/v0/is_container.py | 6 +++--- tests/unit/test_is_container.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/charms/hpc_libs/v0/is_container.py b/lib/charms/hpc_libs/v0/is_container.py index 0d7b0b5..f5aa999 100644 --- a/lib/charms/hpc_libs/v0/is_container.py +++ b/lib/charms/hpc_libs/v0/is_container.py @@ -54,8 +54,8 @@ def _on_install(self, _: InstallEvent) -> None: LIBPATCH = 1 -class DetectVirtNotFoundError(Exception): - """Raise error if `systemd-detect-virt` executable is not found on machine.""" +class UnknownVirtStateError(Exception): + """Raise error if unknown virtualization state is returned.""" @property def message(self) -> str: @@ -70,7 +70,7 @@ def is_container() -> bool: DetectVirtNotFoundError: Raised if `systemd-detect-virt` is not found on machine. """ if shutil.which("systemd-detect-virt") is None: - raise DetectVirtNotFoundError( + raise UnknownVirtStateError( ( "executable `systemd-detect-virt` not found. " + "cannot determine if machine is a container instance" diff --git a/tests/unit/test_is_container.py b/tests/unit/test_is_container.py index 48496b4..1cdb533 100644 --- a/tests/unit/test_is_container.py +++ b/tests/unit/test_is_container.py @@ -7,7 +7,7 @@ from unittest import TestCase from unittest.mock import patch -from charms.hpc_libs.v0.is_container import DetectVirtNotFoundError, is_container +from charms.hpc_libs.v0.is_container import UnknownVirtStateError, is_container @patch("charms.hpc_libs.v0.is_container.shutil.which", return_value="/usr/bin/systemd-detect-virt") @@ -30,7 +30,7 @@ def test_detect_virt_not_found(self, _, which) -> None: try: is_container() - except DetectVirtNotFoundError as e: + except UnknownVirtStateError as e: self.assertEqual( e.message, (