diff --git a/cloudinit/config/cc_puppet.py b/cloudinit/config/cc_puppet.py index a0df1b77212..89f17c89869 100644 --- a/cloudinit/config/cc_puppet.py +++ b/cloudinit/config/cc_puppet.py @@ -22,7 +22,7 @@ from cloudinit.cloud import Cloud from cloudinit.config import Config from cloudinit.config.schema import MetaSchema, get_meta_doc -from cloudinit.distros import ALL_DISTROS, Distro, InstallerError +from cloudinit.distros import ALL_DISTROS, Distro, PackageInstallerError from cloudinit.settings import PER_INSTANCE AIO_INSTALL_URL = "https://raw.githubusercontent.com/puppetlabs/install-puppet/main/install.sh" # noqa: E501 @@ -242,7 +242,7 @@ def handle(name: str, cfg: Config, cloud: Cloud, args: list) -> None: to_install: List[Union[str, List[str]]] if package_name is None: # conf has no package_nam for puppet_name in PUPPET_PACKAGE_NAMES: - with suppress(InstallerError): + with suppress(PackageInstallerError): to_install = ( [[puppet_name, version]] if version diff --git a/cloudinit/distros/__init__.py b/cloudinit/distros/__init__.py index e7dfcff95ae..ffeeb6f1829 100644 --- a/cloudinit/distros/__init__.py +++ b/cloudinit/distros/__init__.py @@ -120,7 +120,7 @@ ] -class InstallerError(Exception): +class PackageInstallerError(Exception): pass @@ -187,7 +187,7 @@ def _validate_entry(self, entry): ) def _extract_package_by_manager( - self, pkglist: Iterable + self, pkglist: PackageList ) -> Tuple[Dict[Type[PackageManager], Set], Set]: """Transform the generic package list to package by package manager. @@ -257,7 +257,7 @@ def install_packages(self, pkglist: PackageList): ) if uninstalled: - raise InstallerError(error_message, uninstalled) + raise PackageInstallerError(error_message % uninstalled) def _write_network(self, settings): """Deprecated. Remove if/when arch and gentoo support renderers.""" diff --git a/tests/unittests/config/test_cc_package_update_upgrade_install.py b/tests/unittests/config/test_cc_package_update_upgrade_install.py index cf660472b23..9ba7f178787 100644 --- a/tests/unittests/config/test_cc_package_update_upgrade_install.py +++ b/tests/unittests/config/test_cc_package_update_upgrade_install.py @@ -11,7 +11,7 @@ get_schema, validate_cloudconfig_schema, ) -from cloudinit.distros import InstallerError +from cloudinit.distros import PackageInstallerError from cloudinit.subp import SubpResult from tests.unittests.helpers import skipUnlessJsonSchema from tests.unittests.util import get_cloud @@ -169,7 +169,7 @@ def _new_subp(*args, **kwargs): cloud = get_cloud("ubuntu") cfg = {"packages": ["pkg1"]} with mock.patch("cloudinit.subp.subp", side_effect=_new_subp): - with pytest.raises(InstallerError): + with pytest.raises(PackageInstallerError): handle("", cfg, cloud, []) assert caplog.records[-3].levelname == "WARNING" diff --git a/tests/unittests/config/test_cc_puppet.py b/tests/unittests/config/test_cc_puppet.py index e1c4e31a6df..b2095c32687 100644 --- a/tests/unittests/config/test_cc_puppet.py +++ b/tests/unittests/config/test_cc_puppet.py @@ -11,7 +11,7 @@ get_schema, validate_cloudconfig_schema, ) -from cloudinit.distros import InstallerError +from cloudinit.distros import PackageInstallerError from cloudinit.subp import ProcessExecutionError from tests.unittests.helpers import CiTestCase, mock, skipUnlessJsonSchema from tests.unittests.util import get_cloud @@ -408,7 +408,7 @@ def test_puppet_falls_back_to_older_name(self, m_subp, m_man_puppet): "tests.unittests.util.MockDistro.install_packages" ) as install_pkg: # puppet-agent not installed, but puppet is - install_pkg.side_effect = (InstallerError, 0) + install_pkg.side_effect = (PackageInstallerError, 0) cc_puppet.handle("notimportant", cfg, self.cloud, None) expected_calls = [ diff --git a/tests/unittests/distros/test_init.py b/tests/unittests/distros/test_init.py index c5715b3ac10..82cd184a3fa 100644 --- a/tests/unittests/distros/test_init.py +++ b/tests/unittests/distros/test_init.py @@ -11,7 +11,7 @@ from cloudinit.distros import ( LDH_ASCII_CHARS, - InstallerError, + PackageInstallerError, _get_package_mirror_info, ) from tests.unittests.distros import _get_distro @@ -316,7 +316,10 @@ def test_non_default_package_manager_fail( "cloudinit.distros.package_management.snap.Snap.install_packages", return_value=["pkg3"], ) - with pytest.raises(InstallerError): + with pytest.raises( + PackageInstallerError, + match="Failed to install the following packages: \['pkg3'\]", + ): _get_distro("debian").install_packages( [{"apt": ["pkg1"]}, "pkg2", {"snap": ["pkg3"]}] )