summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2022-11-10 19:46:40 -0700
committerGitHub <noreply@github.com>2022-11-10 19:46:40 -0700
commit4879ed28ad11571a1e5181bef44b4ab01745fc14 (patch)
treeb9e0752ae8073c4c9b3cb97b73dd3993d60440ea
parent2640f417fdb6fd1024a40a69b5e05b10c1aedc61 (diff)
downloadcloud-init-git-4879ed28ad11571a1e5181bef44b4ab01745fc14.tar.gz
tests: replace ansible install-method with underscore
Also support test runs in environments without pip
-rw-r--r--tests/unittests/config/test_cc_ansible.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/tests/unittests/config/test_cc_ansible.py b/tests/unittests/config/test_cc_ansible.py
index a955e511..a0d6bcab 100644
--- a/tests/unittests/config/test_cc_ansible.py
+++ b/tests/unittests/config/test_cc_ansible.py
@@ -17,6 +17,13 @@ from cloudinit.config.schema import (
from tests.unittests.helpers import skipUnlessJsonSchema
from tests.unittests.util import get_cloud
+try:
+ import pip as _pip # type: ignore # noqa: F401
+
+ HAS_PIP = True
+except ImportError:
+ HAS_PIP = False
+
M_PATH = "cloudinit.config.cc_ansible."
distro_version = dedent(
"""ansible 2.10.8
@@ -269,7 +276,7 @@ class TestAnsible:
(
{
"ansible": {
- "install-method": "pip",
+ "install_method": "pip",
"pull": {
"url": "https://github/holmanb/vmboot",
},
@@ -297,6 +304,7 @@ class TestAnsible:
cc_ansible.handle("", cfg, get_cloud(), None, None)
else:
cloud = get_cloud(mocked_distro=True)
+ cloud.distro.pip_package_name = "python3-pip"
install = cfg["ansible"]["install_method"]
cc_ansible.handle("", cfg, cloud, None, None)
if install == "distro":
@@ -305,7 +313,12 @@ class TestAnsible:
"ansible-core"
)
elif install == "pip":
- assert 0 == cloud.distro.install_packages.call_count
+ if HAS_PIP:
+ assert 0 == cloud.distro.install_packages.call_count
+ else:
+ cloud.distro.install_packages.assert_called_with(
+ "python3-pip"
+ )
@mock.patch(M_PATH + "which", return_value=False)
def test_deps_not_installed(self, m_which):