summaryrefslogtreecommitdiff
path: root/tests/unittests/distros/test__init__.py
diff options
context:
space:
mode:
authorBrett Holman <brett.holman@canonical.com>2023-03-02 10:19:37 -0700
committerGitHub <noreply@github.com>2023-03-02 10:19:37 -0700
commitd1ffbea556a06105d1ade88b4143ad43f53692c4 (patch)
treeb36b3502c24d890feec0a236244fcd542cb7c48c /tests/unittests/distros/test__init__.py
parent635b5a52590922668c13549d087723597a5cce7e (diff)
downloadcloud-init-git-d1ffbea556a06105d1ade88b4143ad43f53692c4.tar.gz
source: Force OpenStack when it is only option (#2045)
Running on OpenStack Ironic was broken in 1efa8a0a0, which prevented a system configured to run on only Openstack from actually running this ds. This change also prevents the kernel commandline definition from working. This change was required to prevent unnecessarily probing OpenStack on Ec2, and is therefore still required. This commit reverts an earlier attempt[1][2] to automatically detect OpenStack, due to regression it caused. Additionally, this change allows a system that defines a datasource list containing only [OpenStack] or [OpenStack, None] to attempt running on OpenStack, overriding ds_detect(). A datasource list that defines [OpenStack, None] still falls back to DataSourceNone if OpenStack fails to reach the IMDS. This change also lays groundwork for the following future work: 1. Add support for other datasources 2. Also override datasource checking when the kernel command line defines a datasource. This work needs to be done manually to support non-systemd systems. Besides forcing OpenStack to run when it is the only datasource in the datasource list, this commit also: [1] 0220295 (it breaks some use cases) [2] 29faf66 (no longer used) LP: #2008727
Diffstat (limited to 'tests/unittests/distros/test__init__.py')
-rw-r--r--tests/unittests/distros/test__init__.py96
1 files changed, 0 insertions, 96 deletions
diff --git a/tests/unittests/distros/test__init__.py b/tests/unittests/distros/test__init__.py
index ea017d58..7c5187fd 100644
--- a/tests/unittests/distros/test__init__.py
+++ b/tests/unittests/distros/test__init__.py
@@ -221,102 +221,6 @@ class TestGenericDistro(helpers.FilesystemMockingTestCase):
["pw", "usermod", "myuser", "-p", "01-Jan-1970"]
)
- @mock.patch("cloudinit.distros.uses_systemd")
- @mock.patch(
- "cloudinit.distros.subp.which",
- )
- @mock.patch(
- "cloudinit.distros.subp.subp",
- )
- def test_virtualization_detected(self, m_subp, m_which, m_uses_systemd):
- m_uses_systemd.return_value = True
- m_which.return_value = "/usr/bin/systemd-detect-virt"
- m_subp.return_value = ("kvm", None)
-
- cls = distros.fetch("ubuntu")
- d = cls("ubuntu", {}, None)
- self.assertTrue(d.is_virtual)
-
- @mock.patch("cloudinit.distros.uses_systemd")
- @mock.patch(
- "cloudinit.distros.subp.subp",
- )
- def test_virtualization_not_detected(self, m_subp, m_uses_systemd):
- m_uses_systemd.return_value = True
- m_subp.return_value = ("none", None)
-
- cls = distros.fetch("ubuntu")
- d = cls("ubuntu", {}, None)
- self.assertFalse(d.is_virtual)
-
- @mock.patch("cloudinit.distros.uses_systemd")
- def test_virtualization_unknown(self, m_uses_systemd):
- m_uses_systemd.return_value = True
-
- from cloudinit.subp import ProcessExecutionError
-
- cls = distros.fetch("ubuntu")
- d = cls("ubuntu", {}, None)
- with mock.patch(
- "cloudinit.distros.subp.which",
- return_value=None,
- ):
- self.assertIsNone(
- d.is_virtual,
- "Reflect unknown state when detection"
- " binary cannot be found",
- )
-
- with mock.patch(
- "cloudinit.distros.subp.subp",
- side_effect=ProcessExecutionError(),
- ):
- self.assertIsNone(
- d.is_virtual, "Reflect unknown state on ProcessExecutionError"
- )
-
- def test_virtualization_on_freebsd(self):
- # This test function is a bit unusual:
- # We need to first mock away the `ifconfig -a` subp call
- # Then, we can use side-effects to get the results of two subp calls
- # needed for is_container()/virtual() which is_virtual depends on.
- # We also have to clear cache between each of those assertions.
-
- cls = distros.fetch("freebsd")
- with mock.patch(
- "cloudinit.distros.subp.subp", return_value=("", None)
- ):
- d = cls("freebsd", {}, None)
- # This mock is called by `sysctl -n security.jail.jailed`
- with mock.patch(
- "cloudinit.distros.subp.subp",
- side_effect=[("0\n", None), ("literaly any truthy value", None)],
- ):
- self.assertFalse(d.is_container())
- d.is_container.cache_clear()
- self.assertTrue(d.is_container())
- d.is_container.cache_clear()
-
- # This mock is called by `sysctl -n kern.vm_guest`
- with mock.patch(
- "cloudinit.distros.subp.subp",
- # fmt: off
- side_effect=[
- ("0\n", None), ("hv\n", None), # virtual
- ("0\n", None), ("none\n", None), # physical
- ("0\n", None), ("hv\n", None) # virtual
- ],
- # fmt: on
- ):
- self.assertEqual(d.virtual(), "microsoft")
- d.is_container.cache_clear()
- d.virtual.cache_clear()
- self.assertEqual(d.virtual(), "none")
- d.is_container.cache_clear()
- d.virtual.cache_clear()
-
- self.assertTrue(d.is_virtual)
-
class TestGetPackageMirrors:
def return_first(self, mlist):