← Back to team overview

cloud-init-dev team mailing list archive

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

 

Scott Moser has proposed merging lp:~smoser/cloud-init/trunk.dmidecode-null into lp:cloud-init.

Commit message:
dmi data: fix failure of reading dmi data for unset dmi values

it is not uncommon to find dmi data in /sys full of 'ff'. utf-8
decoding of those would fail, causing warning and stacktrace.

Return '.' instead of \xff.  This maps to what dmidecode would return

$ dmidecode --string system-product-name

Requested reviews:
  cloud init development team (cloud-init-dev)

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/trunk.dmidecode-null/+merge/288676
-- 
Your team cloud init development team is requested to review the proposed merge of lp:~smoser/cloud-init/trunk.dmidecode-null into lp:cloud-init.
=== modified file 'ChangeLog'
--- ChangeLog	2016-03-10 01:47:27 +0000
+++ ChangeLog	2016-03-10 17:28:45 +0000
@@ -86,8 +86,13 @@
  - Enable password changing via a hashed string [Alex Sirbu]
  - Added BigStep datasource [Alex Sirbu]
  - No longer run pollinate in seed_random (LP: #1554152)
+<<<<<<< TREE
  - groups: add defalt user to 'lxd' group.  Create groups listed
    for a user if they do not exist. (LP: #1539317)
+=======
+ - dmi data: fix failure of reading dmi data for unset dmi values
+
+>>>>>>> MERGE-SOURCE
 
 0.7.6:
  - open 0.7.6

=== modified file 'cloudinit/util.py'
--- cloudinit/util.py	2016-03-03 23:16:13 +0000
+++ cloudinit/util.py	2016-03-10 17:28:45 +0000
@@ -2140,13 +2140,20 @@
             LOG.debug("did not find %s", dmi_key_path)
             return None
 
-        key_data = load_file(dmi_key_path)
+        key_data = load_file(dmi_key_path, decode=False)
         if not key_data:
             LOG.debug("%s did not return any data", dmi_key_path)
             return None
 
-        LOG.debug("dmi data %s returned %s", dmi_key_path, key_data)
-        return key_data.strip()
+        # in the event that this is all \xff and a carriage return
+        # then return '.' in its place.
+        if key_data == b'\xff' * (len(key_data) - 1) + b'\n':
+            key_data = b'.' * (len(key_data) - 1) + b'\n'
+
+        str_data = key_data.decode('utf8').strip()
+
+        LOG.debug("dmi data %s returned %s", dmi_key_path, str_data)
+        return str_data
 
     except Exception:
         logexc(LOG, "failed read of %s", dmi_key_path)

=== modified file 'systemd/cloud-init-generator'
--- systemd/cloud-init-generator	2016-03-04 03:46:37 +0000
+++ systemd/cloud-init-generator	2016-03-10 17:28:45 +0000
@@ -3,7 +3,7 @@
 
 LOG=""
 DEBUG_LEVEL=1
-LOG_D="/run"
+LOG_D="/run/cloud-init"
 ENABLE="enabled"
 DISABLE="disabled"
 CLOUD_SYSTEM_TARGET="/lib/systemd/system/cloud-init.target"
@@ -17,7 +17,8 @@
     [ "$lvl" -gt "$DEBUG_LEVEL" ] && return
     if [ -z "$LOG" ]; then
         local log="$LOG_D/${0##*/}.log"
-        { : > "$log"; } >/dev/null 2>&1 && LOG="$log" ||
+        { [ -d "$LOG_D" ] || mkdir -p "$LOG_D"; } &&
+            { : > "$log"; } >/dev/null 2>&1 && LOG="$log" ||
             LOG="/dev/kmsg"
     fi
     echo "$@" >> "$LOG"
@@ -32,15 +33,16 @@
 }
 
 read_proc_cmdline() {
-    if [ "$CONTAINER" = "lxc" ]; then
-        _RET_MSG="ignored: \$container=$CONTAINER"
-        _RET=""
-        return 0
-    fi
-
-    if systemd-detect-virt --container --quiet; then
-        _RET_MSG="ignored: detect-virt is container"
-        _RET=""
+    # return /proc/cmdline for non-container, and /proc/1/cmdline for container
+    local ctname="systemd"
+    if [ -n "$CONTAINER" ] && ctname=$CONTAINER || systemd-detect-virt --container --quiet; then
+        local 
+        if _RET=$(tr '\0' ' ' < /proc/1/cmdline) >/dev/null 2>&1; then
+            _RET_MSG="container[$ctname]: pid 1 cmdline"
+            return
+        fi
+        _RET=""
+        _RET_MSG="container[$ctname]: pid 1 cmdline not available"
         return 0
     fi
 

=== modified file 'systemd/cloud-init-local.service'
--- systemd/cloud-init-local.service	2016-03-01 04:10:44 +0000
+++ systemd/cloud-init-local.service	2016-03-10 17:28:45 +0000
@@ -1,7 +1,11 @@
 [Unit]
 Description=Initial cloud-init job (pre-networking)
+DefaultDependencies=no
 Wants=local-fs.target
 After=local-fs.target
+Conflicts=shutdown.target
+Before=network-pre.target
+Before=shutdown.target
 
 [Service]
 Type=oneshot

=== modified file 'systemd/cloud-init.service'
--- systemd/cloud-init.service	2016-03-01 04:10:44 +0000
+++ systemd/cloud-init.service	2016-03-10 17:28:45 +0000
@@ -1,8 +1,8 @@
 [Unit]
 Description=Initial cloud-init job (metadata service crawler)
-After=local-fs.target network-online.target cloud-init-local.service
-Before=sshd.service sshd-keygen.service systemd-user-sessions.service
-Requires=network-online.target
+After=cloud-init-local.service networking.service
+Before=network-online.target sshd.service sshd-keygen.service systemd-user-sessions.service
+Requires=networking.service
 Wants=local-fs.target cloud-init-local.service sshd.service sshd-keygen.service
 
 [Service]

=== modified file 'tests/unittests/test_util.py'
--- tests/unittests/test_util.py	2015-05-14 21:06:39 +0000
+++ tests/unittests/test_util.py	2016-03-10 17:28:45 +0000
@@ -385,6 +385,15 @@
         self.patch_mapping({})
         self.assertEqual(None, util.read_dmi_data('expect-fail'))
 
+    def test_dots_returned_instead_of_foxfox(self):
+        my_len = 32
+        dmi_value = b'\xff' * my_len + b'\n'
+        expected = '.' * my_len
+        dmi_key = 'system-product-name'
+        sysfs_key = 'product_name'
+        self._create_sysfs_file(sysfs_key, dmi_value)
+        self.assertEqual(expected, util.read_dmi_data(dmi_key))
+
 
 class TestMultiLog(helpers.FilesystemMockingTestCase):
 


References