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
1diff --git a/tests/unittests/test_ds_identify.py b/tests/unittests/test_ds_identify.py
2index 03942de..2125834 100644
3--- a/tests/unittests/test_ds_identify.py
4+++ b/tests/unittests/test_ds_identify.py
5@@ -350,8 +350,10 @@ class TestDsIdentify(CiTestCase):
6 "OVFENV", "ovfenv"]
7 for valid_ovf_label in valid_ovf_labels:
8 ovf_cdrom_by_label['mocks'][0]['out'] = blkid_out([
9+ {'DEVNAME': 'sda1', 'TYPE': 'ext4', 'LABEL': 'rootfs'},
10 {'DEVNAME': 'sr0', 'TYPE': 'iso9660',
11- 'LABEL': valid_ovf_label}])
12+ 'LABEL': valid_ovf_label},
13+ {'DEVNAME': 'vda1', 'TYPE': 'ntfs', 'LABEL': 'data'}])
14 self._check_via_dict(
15 ovf_cdrom_by_label, rc=RC_FOUND, dslist=['OVF', DS_NONE])
16
17@@ -513,8 +515,9 @@ VALID_CFG = {
18 'mocks': [
19 {'name': 'blkid', 'ret': 0,
20 'out': blkid_out(
21- [{'DEVNAME': 'vda1', 'TYPE': 'vfat', 'PARTUUID': uuid4()},
22- {'DEVNAME': 'sr0', 'TYPE': 'iso9660', 'LABEL': ''}])
23+ [{'DEVNAME': 'sr0', 'TYPE': 'iso9660', 'LABEL': ''},
24+ {'DEVNAME': 'sr1', 'TYPE': 'iso9660', 'LABEL': 'ignoreme'},
25+ {'DEVNAME': 'vda1', 'TYPE': 'vfat', 'PARTUUID': uuid4()}]),
26 },
27 MOCK_VIRT_IS_VMWARE,
28 ],
29diff --git a/tools/ds-identify b/tools/ds-identify
30index 5f76243..5da51bc 100755
31--- a/tools/ds-identify
32+++ b/tools/ds-identify
33@@ -186,7 +186,8 @@ block_dev_with_label() {
34 read_fs_info() {
35 cached "${DI_BLKID_OUTPUT}" && return 0
36 # do not rely on links in /dev/disk which might not be present yet.
37- # note that older blkid versions do not report DEVNAME in 'export' output.
38+ # Note that blkid < 2.22 (centos6, trusty) do not output DEVNAME.
39+ # that means that DI_ISO9660_DEVS will not be set.
40 if is_container; then
41 # blkid will in a container, or at least currently in lxd
42 # not provide useful information.
43@@ -203,21 +204,26 @@ read_fs_info() {
44 DI_ISO9660_DEVS="$UNAVAILABLE:error"
45 return $ret
46 }
47- IFS="$CR"
48- set -- $out
49- IFS="$oifs"
50- for line in "$@" ""; do
51+ # 'set --' will collapse multiple consecutive entries in IFS for
52+ # whitespace characters (\n, tab, " ") so we cannot rely on getting
53+ # empty lines in "$@" below.
54+ IFS="$CR"; set -- $out; IFS="$oifs"
55+
56+ for line in "$@"; do
57 case "${line}" in
58- DEVNAME=*) dev=${line#DEVNAME=};;
59+ DEVNAME=*)
60+ [ -n "$dev" -a "$ftype" = "iso9660" ] &&
61+ isodevs="${isodevs} ${dev}=$label"
62+ ftype=""; dev=""; label="";
63+ dev=${line#DEVNAME=};;
64 LABEL=*) label="${line#LABEL=}";
65 labels="${labels}${line#LABEL=}${delim}";;
66 TYPE=*) ftype=${line#TYPE=};;
67- "") if [ "$ftype" = "iso9660" ]; then
68- isodevs="${isodevs} ${dev}=$label"
69- fi
70- ftype=""; devname=""; label="";
71 esac
72 done
73+ [ -n "$dev" -a "$ftype" = "iso9660" ] &&
74+ isodevs="${isodevs} ${dev}=$label"
75+
76 DI_FS_LABELS="${labels%${delim}}"
77 DI_ISO9660_DEVS="${isodevs# }"
78 }
79@@ -696,15 +702,12 @@ dscheck_OVF() {
80 # Azure provides ovf. Skip false positive by dis-allowing.
81 is_azure_chassis && return $DS_NOT_FOUND
82
83- local isodevs="${DI_ISO9660_DEVS}"
84- case "$isodevs" in
85- ""|$UNAVAILABLE:*) return ${DS_NOT_FOUND};;
86- esac
87-
88 # DI_ISO9660_DEVS is <device>=label, like /dev/sr0=OVF-TRANSPORT
89- for tok in $isodevs; do
90- is_cdrom_ovf "${tok%%=*}" "${tok#*=}" && return $DS_FOUND
91- done
92+ if [ "${DI_ISO9660_DEVS#${UNAVAILABLE}:}" = "${DI_ISO9660_DEVS}" ]; then
93+ for tok in ${DI_ISO9660_DEVS}; do
94+ is_cdrom_ovf "${tok%%=*}" "${tok#*=}" && return $DS_FOUND
95+ done
96+ fi
97
98 if ovf_vmware_guest_customization; then
99 return ${DS_FOUND}

Subscribers

People subscribed via source and target branches