summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2018-02-21 16:09:14 -0500
committerScott Moser <smoser@ubuntu.com>2018-02-21 19:13:28 -0500
commitb7497e807fa12a26d4a12aaf1ee9302a4fd24728 (patch)
treec7921169381921ac7a7becc0ec9e6595bea0e8b6 /tools
parent99171fb7b9bec446e25a338a0d36a820844fbc2d (diff)
downloadvyos-cloud-init-b7497e807fa12a26d4a12aaf1ee9302a4fd24728.tar.gz
vyos-cloud-init-b7497e807fa12a26d4a12aaf1ee9302a4fd24728.zip
ds-identify: Fix searching for iso9660 OVF cdroms.
This fixes a bug in parsing of 'blkid -o export' output. The result of the bug meant that DI_ISO9660_DEVS did not get set correctly and is_cdrom_ovf would not identify devices in most cases. The tests are improved to demonstrate both multiple iso devices and also a cdrom that doesn't sort "last" in blkid output. The code change is to use DEVNAME as the record separator when parsing blkid -o export rather than relying on being able to read the empty line. LP: #1749980
Diffstat (limited to 'tools')
-rwxr-xr-xtools/ds-identify39
1 files changed, 21 insertions, 18 deletions
diff --git a/tools/ds-identify b/tools/ds-identify
index 5f762438..5da51bcc 100755
--- a/tools/ds-identify
+++ b/tools/ds-identify
@@ -186,7 +186,8 @@ block_dev_with_label() {
read_fs_info() {
cached "${DI_BLKID_OUTPUT}" && return 0
# do not rely on links in /dev/disk which might not be present yet.
- # note that older blkid versions do not report DEVNAME in 'export' output.
+ # Note that blkid < 2.22 (centos6, trusty) do not output DEVNAME.
+ # that means that DI_ISO9660_DEVS will not be set.
if is_container; then
# blkid will in a container, or at least currently in lxd
# not provide useful information.
@@ -203,21 +204,26 @@ read_fs_info() {
DI_ISO9660_DEVS="$UNAVAILABLE:error"
return $ret
}
- IFS="$CR"
- set -- $out
- IFS="$oifs"
- for line in "$@" ""; do
+ # 'set --' will collapse multiple consecutive entries in IFS for
+ # whitespace characters (\n, tab, " ") so we cannot rely on getting
+ # empty lines in "$@" below.
+ IFS="$CR"; set -- $out; IFS="$oifs"
+
+ for line in "$@"; do
case "${line}" in
- DEVNAME=*) dev=${line#DEVNAME=};;
+ DEVNAME=*)
+ [ -n "$dev" -a "$ftype" = "iso9660" ] &&
+ isodevs="${isodevs} ${dev}=$label"
+ ftype=""; dev=""; label="";
+ dev=${line#DEVNAME=};;
LABEL=*) label="${line#LABEL=}";
labels="${labels}${line#LABEL=}${delim}";;
TYPE=*) ftype=${line#TYPE=};;
- "") if [ "$ftype" = "iso9660" ]; then
- isodevs="${isodevs} ${dev}=$label"
- fi
- ftype=""; devname=""; label="";
esac
done
+ [ -n "$dev" -a "$ftype" = "iso9660" ] &&
+ isodevs="${isodevs} ${dev}=$label"
+
DI_FS_LABELS="${labels%${delim}}"
DI_ISO9660_DEVS="${isodevs# }"
}
@@ -696,15 +702,12 @@ dscheck_OVF() {
# Azure provides ovf. Skip false positive by dis-allowing.
is_azure_chassis && return $DS_NOT_FOUND
- local isodevs="${DI_ISO9660_DEVS}"
- case "$isodevs" in
- ""|$UNAVAILABLE:*) return ${DS_NOT_FOUND};;
- esac
-
# DI_ISO9660_DEVS is <device>=label, like /dev/sr0=OVF-TRANSPORT
- for tok in $isodevs; do
- is_cdrom_ovf "${tok%%=*}" "${tok#*=}" && return $DS_FOUND
- done
+ if [ "${DI_ISO9660_DEVS#${UNAVAILABLE}:}" = "${DI_ISO9660_DEVS}" ]; then
+ for tok in ${DI_ISO9660_DEVS}; do
+ is_cdrom_ovf "${tok%%=*}" "${tok#*=}" && return $DS_FOUND
+ done
+ fi
if ovf_vmware_guest_customization; then
return ${DS_FOUND}