summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGonéri Le Bouder <goneri@lebouder.net>2021-12-13 12:31:39 -0500
committerGitHub <noreply@github.com>2021-12-13 11:31:39 -0600
commitf4692c5d96323dc635fca26b742199d4c41f88d3 (patch)
tree374e3ee1032738f11413a57af79644fbd3eb8d40
parente9634266ea52bf184727fb0782d5dc35f9ed1468 (diff)
downloadvyos-cloud-init-f4692c5d96323dc635fca26b742199d4c41f88d3.tar.gz
vyos-cloud-init-f4692c5d96323dc635fca26b742199d4c41f88d3.zip
find_devs_with_openbsd: ensure we return the last entry (#1149)
`sysctl -n hw.disknames` returns a trailing `\n`. We need to clean this up. In addition, the criteria matching system is a source of problem because: - we don't have a way to look up the label of the partition - we've got situation where an ISO image can be exposed through a virtio block device. So we just totally ignore the value of `criteria`. We end-up with a slightly longer loop of mount-retry. But this way we're sure we don't miss a configuration disk. Tested on Kubvirt with the help of Brady Pratt @jbpratt.
-rw-r--r--cloudinit/util.py8
-rw-r--r--tests/unittests/test_util.py2
2 files changed, 2 insertions, 8 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index b9c584d1..27821de5 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -1211,7 +1211,7 @@ def find_devs_with_openbsd(criteria=None, oformat='device',
tag=None, no_cache=False, path=None):
out, _err = subp.subp(['sysctl', '-n', 'hw.disknames'], rcs=[0])
devlist = []
- for entry in out.split(','):
+ for entry in out.rstrip().split(','):
if not entry.endswith(':'):
# ffs partition with a serial, not a config-drive
continue
@@ -1220,12 +1220,6 @@ def find_devs_with_openbsd(criteria=None, oformat='device',
devlist.append(entry[:-1] + 'a')
if not entry.startswith('cd'):
devlist.append(entry[:-1] + 'i')
- if criteria == "TYPE=iso9660":
- devlist = [i for i in devlist if i.startswith('cd')]
- elif criteria in ["LABEL=CONFIG-2", "TYPE=vfat"]:
- devlist = [i for i in devlist if not i.startswith('cd')]
- elif criteria:
- LOG.debug("Unexpected criteria: %s", criteria)
return ['/dev/' + i for i in devlist]
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
index c551835f..61b9e303 100644
--- a/tests/unittests/test_util.py
+++ b/tests/unittests/test_util.py
@@ -2336,7 +2336,7 @@ class TestFindDevs:
def test_find_devs_with_openbsd_with_criteria(self, m_subp):
m_subp.return_value = ('cd0:,sd0:630d98d32b5d3759,sd1:,fd0:', '')
devlist = util.find_devs_with_openbsd(criteria="TYPE=iso9660")
- assert devlist == ['/dev/cd0a']
+ assert devlist == ['/dev/cd0a', '/dev/sd1a', '/dev/sd1i']
# lp: #1841466
devlist = util.find_devs_with_openbsd(criteria="LABEL_FATBOOT=A_LABEL")