summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-03-14 09:45:11 -0400
committerScott Moser <smoser@ubuntu.com>2016-03-14 09:45:11 -0400
commit97f81cbecf39c340b6c000d62536fcb7f1ef87b0 (patch)
tree7890a7ca3535cd66b22a462acd207fbae2305956
parent41470d29f5888baf7ec78e170cc0d6d981dcf63e (diff)
parent001057f01e698c3ca0c078d9535f05fdebec2d80 (diff)
downloadvyos-cloud-init-97f81cbecf39c340b6c000d62536fcb7f1ef87b0.tar.gz
vyos-cloud-init-97f81cbecf39c340b6c000d62536fcb7f1ef87b0.zip
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.
-rw-r--r--cloudinit/util.py5
-rw-r--r--tests/unittests/test_util.py2
2 files changed, 5 insertions, 2 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 01dc7751..20916e53 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -2148,7 +2148,7 @@ def _read_dmi_syspath(key):
# uninitialized dmi values show as all \xff and /sys appends a '\n'.
# in that event, return a string of '.' in the same length.
if key_data == b'\xff' * (len(key_data) - 1) + b'\n':
- key_data = b'.' * (len(key_data) - 1) + b'\n'
+ key_data = b""
str_data = key_data.decode('utf8').strip()
LOG.debug("dmi data %s returned %s", dmi_key_path, str_data)
@@ -2168,6 +2168,9 @@ def _call_dmidecode(key, dmidecode_path):
cmd = [dmidecode_path, "--string", key]
(result, _err) = subp(cmd)
LOG.debug("dmidecode returned '%s' for '%s'", result, key)
+ result = result.strip()
+ if result.replace(".", "") == "":
+ return ""
return result
except (IOError, OSError) as _err:
LOG.debug('failed dmidecode cmd: %s\n%s', cmd, _err.message)
diff --git a/tests/unittests/test_util.py b/tests/unittests/test_util.py
index 0a986fec..37a984ac 100644
--- a/tests/unittests/test_util.py
+++ b/tests/unittests/test_util.py
@@ -389,7 +389,7 @@ class TestReadDMIData(helpers.FilesystemMockingTestCase):
# uninitialized dmi values show as \xff, return those as .
my_len = 32
dmi_value = b'\xff' * my_len + b'\n'
- expected = '.' * my_len
+ expected = ""
dmi_key = 'system-product-name'
sysfs_key = 'product_name'
self._create_sysfs_file(sysfs_key, dmi_value)