summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMina Galić <me+git@igalic.co>2020-11-04 15:49:34 +0100
committerGitHub <noreply@github.com>2020-11-04 09:49:34 -0500
commitcf6c36a18de233190996f7c2dde1e04908bad50a (patch)
tree332a0f625ba1699b9fb9ee4d9dd8148f7190f015 /tests
parentd1c01c1df94e07afd3843e31b1e1ce670cf07387 (diff)
downloadvyos-cloud-init-cf6c36a18de233190996f7c2dde1e04908bad50a.tar.gz
vyos-cloud-init-cf6c36a18de233190996f7c2dde1e04908bad50a.zip
split read_fs_info into linux & freebsd parts (#625)
FreeBSD doesn't have blkid, so we want to use geom to list devices and their fstypes and labels. This PR also adds `jail` to the list of is_container() And we now also properly cache geom and blkid output! A test is added to verify the new behaviour by correctly identifying NoCloud on FreeBSD. Co-authored-by: Scott Moser <smoser@brickies.net>
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/test_ds_identify.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/unittests/test_ds_identify.py b/tests/unittests/test_ds_identify.py
index 9314b244..5f8a4a29 100644
--- a/tests/unittests/test_ds_identify.py
+++ b/tests/unittests/test_ds_identify.py
@@ -20,6 +20,8 @@ UNAME_MYSYS = ("Linux bart 4.4.0-62-generic #83-Ubuntu "
UNAME_PPC64EL = ("Linux diamond 4.4.0-83-generic #106-Ubuntu SMP "
"Mon Jun 26 17:53:54 UTC 2017 "
"ppc64le ppc64le ppc64le GNU/Linux")
+UNAME_FREEBSD = ("FreeBSD fbsd12-1 12.1-RELEASE-p10 "
+ "FreeBSD 12.1-RELEASE-p10 GENERIC amd64")
BLKID_EFI_ROOT = """
DEVNAME=/dev/sda1
@@ -80,6 +82,7 @@ MOCK_VIRT_IS_VMWARE = {'name': 'detect_virt', 'RET': 'vmware', 'ret': 0}
MOCK_VIRT_IS_VM_OTHER = {'name': 'detect_virt', 'RET': 'vm-other', 'ret': 0}
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}
shell_true = 0
shell_false = 1
@@ -257,6 +260,10 @@ class TestDsIdentify(DsIdentifyBase):
"""EC2: bobrightbox.com in product_serial is not brightbox'"""
self._test_ds_not_found('Ec2-brightbox-negative')
+ def test_freebsd_nocloud(self):
+ """NoCloud identified on FreeBSD via label by geom."""
+ self._test_ds_found('NoCloud-fbsd')
+
def test_gce_by_product_name(self):
"""GCE identifies itself with product_name."""
self._test_ds_found('GCE')
@@ -725,6 +732,26 @@ def blkid_out(disks=None):
return '\n'.join(lines)
+def geom_out(disks=None):
+ """Convert a list of disk dictionaries into geom content.
+
+ geom called with -a (provider) and -s (script-friendly), will produce the
+ following output:
+
+ gpt/gptboot0 N/A vtbd1p1
+ gpt/swap0 N/A vtbd1p2
+ iso9660/cidata N/A vtbd2
+ """
+ if disks is None:
+ disks = []
+ lines = []
+ for disk in disks:
+ lines.append("%s/%s N/A %s" % (
+ disk["TYPE"], disk["LABEL"], disk["DEVNAME"]))
+ lines.append("")
+ return '\n'.join(lines)
+
+
def _print_run_output(rc, out, err, cfg, files):
"""A helper to print return of TestDsIdentify.
@@ -807,6 +834,19 @@ VALID_CFG = {
'dev/vdb': 'pretend iso content for cidata\n',
}
},
+ 'NoCloud-fbsd': {
+ 'ds': 'NoCloud',
+ 'mocks': [
+ MOCK_VIRT_IS_KVM,
+ MOCK_UNAME_IS_FREEBSD,
+ {'name': 'geom', 'ret': 0,
+ 'out': geom_out(
+ [{'DEVNAME': 'vtbd', 'TYPE': 'iso9660', 'LABEL': 'cidata'}])},
+ ],
+ 'files': {
+ '/dev/vtdb': 'pretend iso content for cidata\n',
+ }
+ },
'NoCloudUpper': {
'ds': 'NoCloud',
'mocks': [