summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2017-06-29 13:32:15 -0400
committerScott Moser <smoser@brickies.net>2017-06-29 17:33:33 -0400
commit4d9f24f5c385cb7fa21d87a097ccd9a297613a75 (patch)
treebd40b67fddf420cac5631e18dc7b85420b73f225 /cloudinit
parent17bad421b79c3e18978f942321e9865379b09321 (diff)
downloadvyos-cloud-init-4d9f24f5c385cb7fa21d87a097ccd9a297613a75.tar.gz
vyos-cloud-init-4d9f24f5c385cb7fa21d87a097ccd9a297613a75.zip
read_dmi_data: always return None when inside a container.
This fixes stacktrace and warning message that would be printed to the log if running inside a container and read_dmi_data tried to access a key that was not present. In a container, the /sys/class/dmi/id data is not relevant to the but to the host. Additionally an unpriviledged container might see strange behavior: # cd /sys/class/dmi/id/ # id -u 0 # ls -l chassis_serial -r-------- 1 nobody nogroup 4096 Jun 29 16:49 chassis_serial # cat chassis_serial cat: /sys/class/dmi/id/chassis_serial: Permission denied The solution here is to just always return None when running in a container. LP: #1701325
Diffstat (limited to 'cloudinit')
-rw-r--r--cloudinit/util.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index c93b6d7e..b486e182 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -2397,6 +2397,10 @@ def read_dmi_data(key):
"""
Wrapper for reading DMI data.
+ If running in a container return None. This is because DMI data is
+ assumed to be not useful in a container as it does not represent the
+ container but rather the host.
+
This will do the following (returning the first that produces a
result):
1) Use a mapping to translate `key` from dmidecode naming to
@@ -2407,6 +2411,9 @@ def read_dmi_data(key):
If all of the above fail to find a value, None will be returned.
"""
+ if is_container():
+ return None
+
syspath_value = _read_dmi_syspath(key)
if syspath_value is not None:
return syspath_value