Merge lp:~smoser/cloud-init/trunk.dmidecode-null into lp:~cloud-init-dev/cloud-init/trunk

Proposed by Scott Moser on 2016-03-14
Status: Merged
Merged at revision: 1181
Proposed branch: lp:~smoser/cloud-init/trunk.dmidecode-null
Merge into: lp:~cloud-init-dev/cloud-init/trunk
Diff against target: 35 lines (+5/-2)
2 files modified
cloudinit/util.py (+4/-1)
tests/unittests/test_util.py (+1/-1)
To merge this branch: bzr merge lp:~smoser/cloud-init/trunk.dmidecode-null
Reviewer Review Type Date Requested Status
Dan Watkins 2016-03-14 Approve on 2016-03-14
Review via email: mp+288925@code.launchpad.net

Commit Message

change return value for dmi data of all \xff to be ""

Previously we returned a string of "." the same length as the dmi field.
That seems confusing to the user as "." would seem like a valid response
when in fact this value should not be considered valid.

So now, in this case, return empty string.

To post a comment you must log in.
1183. By Scott Moser on 2016-03-14

change where we handle the translation

review: Approve
1184. By Scott Moser on 2016-03-14

strip return of dmidecode and do so before checking for all "."

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cloudinit/util.py'
2--- cloudinit/util.py 2016-03-10 21:56:44 +0000
3+++ cloudinit/util.py 2016-03-14 13:35:24 +0000
4@@ -2148,7 +2148,7 @@
5 # uninitialized dmi values show as all \xff and /sys appends a '\n'.
6 # in that event, return a string of '.' in the same length.
7 if key_data == b'\xff' * (len(key_data) - 1) + b'\n':
8- key_data = b'.' * (len(key_data) - 1) + b'\n'
9+ key_data = b""
10
11 str_data = key_data.decode('utf8').strip()
12 LOG.debug("dmi data %s returned %s", dmi_key_path, str_data)
13@@ -2168,6 +2168,9 @@
14 cmd = [dmidecode_path, "--string", key]
15 (result, _err) = subp(cmd)
16 LOG.debug("dmidecode returned '%s' for '%s'", result, key)
17+ result = result.strip()
18+ if result.replace(".", "") == "":
19+ return ""
20 return result
21 except (IOError, OSError) as _err:
22 LOG.debug('failed dmidecode cmd: %s\n%s', cmd, _err.message)
23
24=== modified file 'tests/unittests/test_util.py'
25--- tests/unittests/test_util.py 2016-03-10 21:56:44 +0000
26+++ tests/unittests/test_util.py 2016-03-14 13:35:24 +0000
27@@ -389,7 +389,7 @@
28 # uninitialized dmi values show as \xff, return those as .
29 my_len = 32
30 dmi_value = b'\xff' * my_len + b'\n'
31- expected = '.' * my_len
32+ expected = ""
33 dmi_key = 'system-product-name'
34 sysfs_key = 'product_name'
35 self._create_sysfs_file(sysfs_key, dmi_value)