summaryrefslogtreecommitdiff
path: root/tests/unittests/distros/test__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unittests/distros/test__init__.py')
-rw-r--r--tests/unittests/distros/test__init__.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/unittests/distros/test__init__.py b/tests/unittests/distros/test__init__.py
index 4201c687..ea017d58 100644
--- a/tests/unittests/distros/test__init__.py
+++ b/tests/unittests/distros/test__init__.py
@@ -275,6 +275,48 @@ class TestGenericDistro(helpers.FilesystemMockingTestCase):
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):