From f056dbce5991d447472cfe84f858b789126bf316 Mon Sep 17 00:00:00 2001 From: Anton Chaporgin Date: Sun, 3 Jan 2021 19:46:10 +0300 Subject: [PATCH 1/3] key error on network debug info This fixes KeyError on specific network configuration when running cloud-init on "network" stage. ```(sh) ~ # ip -o route list default via 192.168.1.1 dev eth0 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.21 ~ # ip --oneline -6 -o route list table all default dev eth1 table 8 metric 1024 pref medium ::1 dev lo proto kernel metric 256 pref medium 2a02:6b8:c02:901:0:f804:0:25 dev eth1 proto kernel metric 256 pref medium 2a02:6b8::/32 dev eth1 metric 1024 pref medium 2a0d:d6c0::/32 dev eth1 metric 1024 pref medium fe80::/64 dev eth1 proto kernel metric 256 pref medium fe80::/64 dev eth0 proto kernel metric 256 pref medium local ::1 dev lo table local proto kernel metric 0 pref medium local 2a02:6b8:c02:901:0:f804:0:25 dev eth1 table local proto kernel metric 0 pref medium local fe80::d20d:1cff:fede:db82 dev eth0 table local proto kernel metric 0 pref medium local fe80::d21d:1cff:fede:db82 dev eth1 table local proto kernel metric 0 pref medium ff00::/8 dev eth1 table local metric 256 pref medium ff00::/8 dev eth0 table local metric 256 pref medium ~ # cloud-init init Cloud-init v. 20.3-2-g371b392c-0ubuntu1~18.04.1 running 'init' at Sun, 03 Jan 2021 15:24:15 +0000. Up 3897.48 seconds. 2021-01-03 15:24:15,517 - util.py[WARNING]: failed stage init failed run of stage init ------------------------------------------------------------ Traceback (most recent call last): File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 653, in status_wrapper ret = functor(name, args) File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 284, in main_init sys.stderr.write("%s\n" % (netinfo.debug_info())) File "/usr/lib/python3/dist-packages/cloudinit/netinfo.py", line 495, in debug_info route_lines = route_pformat().splitlines() File "/usr/lib/python3/dist-packages/cloudinit/netinfo.py", line 479, in route_pformat r['gateway'], r['iface'], r['flags']]) KeyError: 'gateway' .... applied the patch ... ~ # cloud-init init Cloud-init v. 20.3-2-g371b392c-0ubuntu1~18.04.1 running 'init' at Sun, 03 Jan 2021 16:21:30 +0000. Up 7332.45 seconds. ci-info: +++++++++++++++++++++++++++++++++++++++++Net device info+++++++++++++++++++++++++++++++++++++++++ ci-info: +--------+------+----------------------------------+---------------+--------+-------------------+ ci-info: | Device | Up | Address | Mask | Scope | Hw-Address | ci-info: +--------+------+----------------------------------+---------------+--------+-------------------+ ci-info: | eth0 | True | 192.168.1.21 | 255.255.255.0 | global | d0:0d:1c:de:db:82 | ci-info: | eth0 | True | fe80::d20d:1cff:fede:db82/64 | . | link | d0:0d:1c:de:db:82 | ci-info: | eth1 | True | 2a02:6b8:c02:901:0:f804:0:25/128 | . | global | d0:1d:1c:de:db:82 | ci-info: | eth1 | True | fe80::d21d:1cff:fede:db82/64 | . | link | d0:1d:1c:de:db:82 | ci-info: | lo | True | 127.0.0.1 | 255.0.0.0 | host | . | ci-info: | lo | True | ::1/128 | . | host | . | ci-info: +--------+------+----------------------------------+---------------+--------+-------------------+ ci-info: +++++++++++++++++++++++++++++Route IPv4 info+++++++++++++++++++++++++++++ ci-info: +-------+-------------+-------------+---------------+-----------+-------+ ci-info: | Route | Destination | Gateway | Genmask | Interface | Flags | ci-info: +-------+-------------+-------------+---------------+-----------+-------+ ci-info: | 0 | 0.0.0.0 | 192.168.1.1 | 0.0.0.0 | eth0 | UG | ci-info: | 1 | 192.168.1.0 | 0.0.0.0 | 255.255.255.0 | eth0 | U | ci-info: +-------+-------------+-------------+---------------+-----------+-------+ ci-info: +++++++++++++++++++++++++++Route IPv6 info++++++++++++++++++++++++++++ ci-info: +-------+------------------------------+---------+-----------+-------+ ci-info: | Route | Destination | Gateway | Interface | Flags | ci-info: +-------+------------------------------+---------+-----------+-------+ ci-info: | 0 | ::/0 | | eth1 | UG | ci-info: | 2 | 2a02:6b8:c02:901:0:f804:0:25 | :: | eth1 | U | ci-info: | 3 | 2a02:6b8::/32 | :: | eth1 | U | ci-info: | 4 | 2a0d:d6c0::/32 | :: | eth1 | U | ci-info: | 5 | fe80::/64 | :: | eth1 | U | ci-info: | 6 | fe80::/64 | :: | eth0 | U | ci-info: | 8 | local | :: | eth1 | U | ci-info: | 9 | local | :: | eth0 | U | ci-info: | 10 | local | :: | eth1 | U | ci-info: | 11 | ff00::/8 | :: | eth1 | U | ci-info: | 12 | ff00::/8 | :: | eth0 | U | ci-info: +-------+------------------------------+---------+-----------+-------+ .... exits with 0 ``` --- cloudinit/netinfo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloudinit/netinfo.py b/cloudinit/netinfo.py index 628e2908f12..ffe65657db3 100644 --- a/cloudinit/netinfo.py +++ b/cloudinit/netinfo.py @@ -476,7 +476,7 @@ def route_pformat(): if r['iface'] == 'lo': continue tbl_v6.add_row([route_id, r['destination'], - r['gateway'], r['iface'], r['flags']]) + r.get('gateway', 'undefined'), r['iface'], r['flags']]) route_s = tbl_v6.get_string() max_len = len(max(route_s.splitlines(), key=len)) header = util.center("Route IPv6 info", "+", max_len) From 5073659030e0cfe35c8289cea88bd5ad11924f87 Mon Sep 17 00:00:00 2001 From: Anton Chaporgin Date: Mon, 4 Jan 2021 10:37:47 +0300 Subject: [PATCH 2/3] Update netinfo.py --- cloudinit/netinfo.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cloudinit/netinfo.py b/cloudinit/netinfo.py index ffe65657db3..2a60d3fdc50 100644 --- a/cloudinit/netinfo.py +++ b/cloudinit/netinfo.py @@ -476,7 +476,8 @@ def route_pformat(): if r['iface'] == 'lo': continue tbl_v6.add_row([route_id, r['destination'], - r.get('gateway', 'undefined'), r['iface'], r['flags']]) + r.get('gateway', 'undefined'), + r['iface'], r['flags']]) route_s = tbl_v6.get_string() max_len = len(max(route_s.splitlines(), key=len)) header = util.center("Route IPv6 info", "+", max_len) From 6ce93a1ae83ce708bc77c1a09365d52d2ef86962 Mon Sep 17 00:00:00 2001 From: Anton Chaporgin Date: Mon, 4 Jan 2021 13:22:12 +0300 Subject: [PATCH 3/3] Update netinfo.py --- cloudinit/netinfo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cloudinit/netinfo.py b/cloudinit/netinfo.py index 2a60d3fdc50..2f5c1ccd3fd 100644 --- a/cloudinit/netinfo.py +++ b/cloudinit/netinfo.py @@ -476,8 +476,8 @@ def route_pformat(): if r['iface'] == 'lo': continue tbl_v6.add_row([route_id, r['destination'], - r.get('gateway', 'undefined'), - r['iface'], r['flags']]) + r.get('gateway', 'undefined'), r['iface'], + r['flags']]) route_s = tbl_v6.get_string() max_len = len(max(route_s.splitlines(), key=len)) header = util.center("Route IPv6 info", "+", max_len)