Merge ~smoser/cloud-init:bug/ds-identify-fix-parse-blkid-export into cloud-init:master

Proposed by Scott Moser
Status: Merged
Merged at revision: b7497e807fa12a26d4a12aaf1ee9302a4fd24728
Proposed branch: ~smoser/cloud-init:bug/ds-identify-fix-parse-blkid-export
Merge into: cloud-init:master
Diff against target: 99 lines (+27/-21)
2 files modified
tests/unittests/test_ds_identify.py (+6/-3)
tools/ds-identify (+21/-18)
Reviewer Review Type Date Requested Status
Chad Smith Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+338470@code.launchpad.net

Commit message

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.

Description of the change

see commit message

To post a comment you must log in.
Revision history for this message
Sankar Tanguturi (sankaraditya) wrote :

Thanks Scott for fixing this. One minor comment.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:29e5a1f94cf88cc07d8fb13776992864930ba471
https://jenkins.ubuntu.com/server/job/cloud-init-ci/777/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/777/rebuild

review: Approve (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:78df90204b1ad177952707be78039d0fb5336438
https://jenkins.ubuntu.com/server/job/cloud-init-ci/778/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/778/rebuild

review: Approve (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) wrote :

Validated ovf behavior continues to work on juju-deployed OVF datasource.

review: Approve
Revision history for this message
Sankar Tanguturi (sankaraditya) wrote :

Tested this patch in my test environment. Didn't find the failures which I encountered earlier. DataSourceOVF was properly detected.

Thanks Scott for this patch. If possible, can you attach this fix to the bug https://bugs.launchpad.net/cloud-init/+bug/1749980 ?

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/tests/unittests/test_ds_identify.py b/tests/unittests/test_ds_identify.py
index 03942de..2125834 100644
--- a/tests/unittests/test_ds_identify.py
+++ b/tests/unittests/test_ds_identify.py
@@ -350,8 +350,10 @@ class TestDsIdentify(CiTestCase):
350 "OVFENV", "ovfenv"]350 "OVFENV", "ovfenv"]
351 for valid_ovf_label in valid_ovf_labels:351 for valid_ovf_label in valid_ovf_labels:
352 ovf_cdrom_by_label['mocks'][0]['out'] = blkid_out([352 ovf_cdrom_by_label['mocks'][0]['out'] = blkid_out([
353 {'DEVNAME': 'sda1', 'TYPE': 'ext4', 'LABEL': 'rootfs'},
353 {'DEVNAME': 'sr0', 'TYPE': 'iso9660',354 {'DEVNAME': 'sr0', 'TYPE': 'iso9660',
354 'LABEL': valid_ovf_label}])355 'LABEL': valid_ovf_label},
356 {'DEVNAME': 'vda1', 'TYPE': 'ntfs', 'LABEL': 'data'}])
355 self._check_via_dict(357 self._check_via_dict(
356 ovf_cdrom_by_label, rc=RC_FOUND, dslist=['OVF', DS_NONE])358 ovf_cdrom_by_label, rc=RC_FOUND, dslist=['OVF', DS_NONE])
357359
@@ -513,8 +515,9 @@ VALID_CFG = {
513 'mocks': [515 'mocks': [
514 {'name': 'blkid', 'ret': 0,516 {'name': 'blkid', 'ret': 0,
515 'out': blkid_out(517 'out': blkid_out(
516 [{'DEVNAME': 'vda1', 'TYPE': 'vfat', 'PARTUUID': uuid4()},518 [{'DEVNAME': 'sr0', 'TYPE': 'iso9660', 'LABEL': ''},
517 {'DEVNAME': 'sr0', 'TYPE': 'iso9660', 'LABEL': ''}])519 {'DEVNAME': 'sr1', 'TYPE': 'iso9660', 'LABEL': 'ignoreme'},
520 {'DEVNAME': 'vda1', 'TYPE': 'vfat', 'PARTUUID': uuid4()}]),
518 },521 },
519 MOCK_VIRT_IS_VMWARE,522 MOCK_VIRT_IS_VMWARE,
520 ],523 ],
diff --git a/tools/ds-identify b/tools/ds-identify
index 5f76243..5da51bc 100755
--- a/tools/ds-identify
+++ b/tools/ds-identify
@@ -186,7 +186,8 @@ block_dev_with_label() {
186read_fs_info() {186read_fs_info() {
187 cached "${DI_BLKID_OUTPUT}" && return 0187 cached "${DI_BLKID_OUTPUT}" && return 0
188 # do not rely on links in /dev/disk which might not be present yet.188 # do not rely on links in /dev/disk which might not be present yet.
189 # note that older blkid versions do not report DEVNAME in 'export' output.189 # Note that blkid < 2.22 (centos6, trusty) do not output DEVNAME.
190 # that means that DI_ISO9660_DEVS will not be set.
190 if is_container; then191 if is_container; then
191 # blkid will in a container, or at least currently in lxd192 # blkid will in a container, or at least currently in lxd
192 # not provide useful information.193 # not provide useful information.
@@ -203,21 +204,26 @@ read_fs_info() {
203 DI_ISO9660_DEVS="$UNAVAILABLE:error"204 DI_ISO9660_DEVS="$UNAVAILABLE:error"
204 return $ret205 return $ret
205 }206 }
206 IFS="$CR"207 # 'set --' will collapse multiple consecutive entries in IFS for
207 set -- $out208 # whitespace characters (\n, tab, " ") so we cannot rely on getting
208 IFS="$oifs"209 # empty lines in "$@" below.
209 for line in "$@" ""; do210 IFS="$CR"; set -- $out; IFS="$oifs"
211
212 for line in "$@"; do
210 case "${line}" in213 case "${line}" in
211 DEVNAME=*) dev=${line#DEVNAME=};;214 DEVNAME=*)
215 [ -n "$dev" -a "$ftype" = "iso9660" ] &&
216 isodevs="${isodevs} ${dev}=$label"
217 ftype=""; dev=""; label="";
218 dev=${line#DEVNAME=};;
212 LABEL=*) label="${line#LABEL=}";219 LABEL=*) label="${line#LABEL=}";
213 labels="${labels}${line#LABEL=}${delim}";;220 labels="${labels}${line#LABEL=}${delim}";;
214 TYPE=*) ftype=${line#TYPE=};;221 TYPE=*) ftype=${line#TYPE=};;
215 "") if [ "$ftype" = "iso9660" ]; then
216 isodevs="${isodevs} ${dev}=$label"
217 fi
218 ftype=""; devname=""; label="";
219 esac222 esac
220 done223 done
224 [ -n "$dev" -a "$ftype" = "iso9660" ] &&
225 isodevs="${isodevs} ${dev}=$label"
226
221 DI_FS_LABELS="${labels%${delim}}"227 DI_FS_LABELS="${labels%${delim}}"
222 DI_ISO9660_DEVS="${isodevs# }"228 DI_ISO9660_DEVS="${isodevs# }"
223}229}
@@ -696,15 +702,12 @@ dscheck_OVF() {
696 # Azure provides ovf. Skip false positive by dis-allowing.702 # Azure provides ovf. Skip false positive by dis-allowing.
697 is_azure_chassis && return $DS_NOT_FOUND703 is_azure_chassis && return $DS_NOT_FOUND
698704
699 local isodevs="${DI_ISO9660_DEVS}"
700 case "$isodevs" in
701 ""|$UNAVAILABLE:*) return ${DS_NOT_FOUND};;
702 esac
703
704 # DI_ISO9660_DEVS is <device>=label, like /dev/sr0=OVF-TRANSPORT705 # DI_ISO9660_DEVS is <device>=label, like /dev/sr0=OVF-TRANSPORT
705 for tok in $isodevs; do706 if [ "${DI_ISO9660_DEVS#${UNAVAILABLE}:}" = "${DI_ISO9660_DEVS}" ]; then
706 is_cdrom_ovf "${tok%%=*}" "${tok#*=}" && return $DS_FOUND707 for tok in ${DI_ISO9660_DEVS}; do
707 done708 is_cdrom_ovf "${tok%%=*}" "${tok#*=}" && return $DS_FOUND
709 done
710 fi
708711
709 if ovf_vmware_guest_customization; then712 if ovf_vmware_guest_customization; then
710 return ${DS_FOUND}713 return ${DS_FOUND}

Subscribers

People subscribed via source and target branches