Merge ~raharper/cloud-init:fix/netinfo-scope6-from-address into cloud-init:master

Proposed by Ryan Harper
Status: Merged
Approved by: Chad Smith
Approved revision: 9ad6de52fff2b145630dd9a6c972df1471a2e154
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~raharper/cloud-init:fix/netinfo-scope6-from-address
Merge into: cloud-init:master
Diff against target: 104 lines (+47/-2)
4 files modified
cloudinit/netinfo.py (+5/-2)
cloudinit/tests/test_netinfo.py (+14/-0)
tests/data/netinfo/freebsd-ifconfig-output (+17/-0)
tests/data/netinfo/freebsd-netdev-formatted-output (+11/-0)
Reviewer Review Type Date Requested Status
Chad Smith Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+362813@code.launchpad.net

Commit message

netinfo: Adjust ifconfig output parsing for FreeBSD ipv6 entries

FreeBSD ifconfig output for ipv6 addrs doesn't find scopeid values
when present in the output and the pformat rendering assumes that
an ipv6 address will have a 'scope6' entry in the netdev info
dictionary. This patch finds the scopeid value, which is not
always inside <>, and in some cases v6 addrs don't have a scopeid
value in the output, so when rendering the table, allow scope6 value
to be replaced with the empty value.

LP: #1779672

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:a2b7a846294ffba67385cad39831b33e2902ab37
https://jenkins.ubuntu.com/server/job/cloud-init-ci/556/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/556/rebuild

review: Approve (continuous-integration)
9ad6de5... by Ryan Harper

netinfo: add freebsd ifconfig output unittest

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:9ad6de52fff2b145630dd9a6c972df1471a2e154
https://jenkins.ubuntu.com/server/job/cloud-init-ci/557/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/557/rebuild

review: Approve (continuous-integration)
Revision history for this message
Chad Smith (chad.smith) wrote :

LGTM! thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/netinfo.py b/cloudinit/netinfo.py
2index 9ff929c..e91cd26 100644
3--- a/cloudinit/netinfo.py
4+++ b/cloudinit/netinfo.py
5@@ -141,6 +141,9 @@ def _netdev_info_ifconfig(ifconfig_data):
6 res = re.match(r'.*<(\S+)>', toks[i + 1])
7 if res:
8 devs[curdev]['ipv6'][-1]['scope6'] = res.group(1)
9+ else:
10+ devs[curdev]['ipv6'][-1]['scope6'] = toks[i + 1]
11+
12 return devs
13
14
15@@ -389,8 +392,8 @@ def netdev_pformat():
16 addr.get('scope', empty), data["hwaddr"]))
17 for addr in data.get('ipv6'):
18 tbl.add_row(
19- (dev, data["up"], addr["ip"], empty, addr["scope6"],
20- data["hwaddr"]))
21+ (dev, data["up"], addr["ip"], empty,
22+ addr.get("scope6", empty), data["hwaddr"]))
23 if len(data.get('ipv6')) + len(data.get('ipv4')) == 0:
24 tbl.add_row((dev, data["up"], empty, empty, empty,
25 data["hwaddr"]))
26diff --git a/cloudinit/tests/test_netinfo.py b/cloudinit/tests/test_netinfo.py
27index d76e768..1c8a791 100644
28--- a/cloudinit/tests/test_netinfo.py
29+++ b/cloudinit/tests/test_netinfo.py
30@@ -11,6 +11,7 @@ from cloudinit.tests.helpers import CiTestCase, mock, readResource
31 # Example ifconfig and route output
32 SAMPLE_OLD_IFCONFIG_OUT = readResource("netinfo/old-ifconfig-output")
33 SAMPLE_NEW_IFCONFIG_OUT = readResource("netinfo/new-ifconfig-output")
34+SAMPLE_FREEBSD_IFCONFIG_OUT = readResource("netinfo/freebsd-ifconfig-output")
35 SAMPLE_IPADDRSHOW_OUT = readResource("netinfo/sample-ipaddrshow-output")
36 SAMPLE_ROUTE_OUT_V4 = readResource("netinfo/sample-route-output-v4")
37 SAMPLE_ROUTE_OUT_V6 = readResource("netinfo/sample-route-output-v6")
38@@ -18,6 +19,7 @@ SAMPLE_IPROUTE_OUT_V4 = readResource("netinfo/sample-iproute-output-v4")
39 SAMPLE_IPROUTE_OUT_V6 = readResource("netinfo/sample-iproute-output-v6")
40 NETDEV_FORMATTED_OUT = readResource("netinfo/netdev-formatted-output")
41 ROUTE_FORMATTED_OUT = readResource("netinfo/route-formatted-output")
42+FREEBSD_NETDEV_OUT = readResource("netinfo/freebsd-netdev-formatted-output")
43
44
45 class TestNetInfo(CiTestCase):
46@@ -45,6 +47,18 @@ class TestNetInfo(CiTestCase):
47
48 @mock.patch('cloudinit.netinfo.util.which')
49 @mock.patch('cloudinit.netinfo.util.subp')
50+ def test_netdev_freebsd_nettools_pformat(self, m_subp, m_which):
51+ """netdev_pformat properly rendering netdev new nettools info."""
52+ m_subp.return_value = (SAMPLE_FREEBSD_IFCONFIG_OUT, '')
53+ m_which.side_effect = lambda x: x if x == 'ifconfig' else None
54+ content = netdev_pformat()
55+ print()
56+ print(content)
57+ print()
58+ self.assertEqual(FREEBSD_NETDEV_OUT, content)
59+
60+ @mock.patch('cloudinit.netinfo.util.which')
61+ @mock.patch('cloudinit.netinfo.util.subp')
62 def test_netdev_iproute_pformat(self, m_subp, m_which):
63 """netdev_pformat properly rendering ip route info."""
64 m_subp.return_value = (SAMPLE_IPADDRSHOW_OUT, '')
65diff --git a/tests/data/netinfo/freebsd-ifconfig-output b/tests/data/netinfo/freebsd-ifconfig-output
66new file mode 100644
67index 0000000..3de15a5
68--- /dev/null
69+++ b/tests/data/netinfo/freebsd-ifconfig-output
70@@ -0,0 +1,17 @@
71+vtnet0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
72+ options=6c07bb<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,TSO4,TSO6,LRO,VLAN_HWTSO,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
73+ ether fa:16:3e:14:1f:99
74+ hwaddr fa:16:3e:14:1f:99
75+ inet 10.1.80.61 netmask 0xfffff000 broadcast 10.1.95.255
76+ nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
77+ media: Ethernet 10Gbase-T <full-duplex>
78+ status: active
79+pflog0: flags=0<> metric 0 mtu 33160
80+pfsync0: flags=0<> metric 0 mtu 1500
81+ syncpeer: 0.0.0.0 maxupd: 128 defer: off
82+lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
83+ options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
84+ inet6 ::1 prefixlen 128
85+ inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
86+ inet 127.0.0.1 netmask 0xff000000
87+ nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
88diff --git a/tests/data/netinfo/freebsd-netdev-formatted-output b/tests/data/netinfo/freebsd-netdev-formatted-output
89new file mode 100644
90index 0000000..a9d2ac1
91--- /dev/null
92+++ b/tests/data/netinfo/freebsd-netdev-formatted-output
93@@ -0,0 +1,11 @@
94++++++++++++++++++++++++++++++++Net device info+++++++++++++++++++++++++++++++
95++---------+-------+----------------+------------+-------+-------------------+
96+| Device | Up | Address | Mask | Scope | Hw-Address |
97++---------+-------+----------------+------------+-------+-------------------+
98+| lo0 | True | 127.0.0.1 | 0xff000000 | . | . |
99+| lo0 | True | ::1/128 | . | . | . |
100+| lo0 | True | fe80::1%lo0/64 | . | 0x4 | . |
101+| pflog0 | False | . | . | . | . |
102+| pfsync0 | False | . | . | . | . |
103+| vtnet0 | True | 10.1.80.61 | 0xfffff000 | . | fa:16:3e:14:1f:99 |
104++---------+-------+----------------+------------+-------+-------------------+

Subscribers

People subscribed via source and target branches