Skip to content

Commit

Permalink
tests: mock LXD datasource detection in ds-identify on LXD containers (
Browse files Browse the repository at this point in the history
…#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.
  • Loading branch information
blackboxsw authored Jan 10, 2022
1 parent 26de41a commit 57ccd89
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/unittests/test_ds_identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"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.
Expand All @@ -100,6 +101,8 @@
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

Expand Down Expand Up @@ -230,6 +233,13 @@ def _call_via_dict(self, data, rootd=None, **kwargs):
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)

Expand Down

0 comments on commit 57ccd89

Please sign in to comment.