summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChad Smith <chad.smith@canonical.com>2022-01-10 15:05:52 -0700
committerGitHub <noreply@github.com>2022-01-10 16:05:52 -0600
commit57ccd89b6af7d3551915df56f548b7617dfcebf9 (patch)
tree0293f8acb930e09f7868812eac17cd411e273771
parent26de41a36ac6191f8a93e7ba40fea6ac3628b1e6 (diff)
downloadvyos-cloud-init-57ccd89b6af7d3551915df56f548b7617dfcebf9.tar.gz
vyos-cloud-init-57ccd89b6af7d3551915df56f548b7617dfcebf9.zip
tests: mock LXD datasource detection in ds-identify on LXD containers (#1178)
On LXD containers /dev/lxd/sock will always exist. Mock dscheck_LXD to return 1 (NOT_FOUND) to avoid leaking into test environment and returning LXD as detected. We have integration tests covering proper LXD datasource detection so we don't need a Unit test validating the [ -S /dev/lxd/sock] that is in ds-identify.
-rw-r--r--tests/unittests/test_ds_identify.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/unittests/test_ds_identify.py b/tests/unittests/test_ds_identify.py
index f2d2b494..0b0de395 100644
--- a/tests/unittests/test_ds_identify.py
+++ b/tests/unittests/test_ds_identify.py
@@ -92,6 +92,7 @@ MOCK_VIRT_IS_CONTAINER_OTHER = {
"RET": "container-other",
"ret": 0,
}
+MOCK_NOT_LXD_DATASOURCE = {"name": "dscheck_LXD", "ret": 1}
MOCK_VIRT_IS_KVM = {"name": "detect_virt", "RET": "kvm", "ret": 0}
MOCK_VIRT_IS_VMWARE = {"name": "detect_virt", "RET": "vmware", "ret": 0}
# currenty' SmartOS hypervisor "bhyve" is unknown by systemd-detect-virt.
@@ -100,6 +101,8 @@ MOCK_VIRT_IS_XEN = {"name": "detect_virt", "RET": "xen", "ret": 0}
MOCK_UNAME_IS_PPC64 = {"name": "uname", "out": UNAME_PPC64EL, "ret": 0}
MOCK_UNAME_IS_FREEBSD = {"name": "uname", "out": UNAME_FREEBSD, "ret": 0}
+DEFAULT_MOCKS = [MOCK_NOT_LXD_DATASOURCE]
+
shell_true = 0
shell_false = 1
@@ -230,6 +233,13 @@ class DsIdentifyBase(CiTestCase):
xwargs[k] = data[k]
if k in kwargs:
xwargs[k] = kwargs[k]
+ if "mocks" not in xwargs:
+ xwargs["mocks"] = DEFAULT_MOCKS
+ else:
+ mocked_funcs = [m["name"] for m in xwargs["mocks"]]
+ for default_mock in DEFAULT_MOCKS:
+ if default_mock["name"] not in mocked_funcs:
+ xwargs["mocks"].append(default_mock)
return self.call(**xwargs)