Merge ~chad.smith/cloud-init:ubuntu/xenial into cloud-init:ubuntu/xenial

Proposed by Chad Smith
Status: Merged
Merged at revision: 6f251fd2ec80ad14712b28d748518b3a67ac26e8
Proposed branch: ~chad.smith/cloud-init:ubuntu/xenial
Merge into: cloud-init:ubuntu/xenial
Diff against target: 177 lines (+118/-5)
5 files modified
cloudinit/netinfo.py (+1/-1)
cloudinit/simpletable.py (+1/-1)
cloudinit/tests/test_netinfo.py (+106/-0)
cloudinit/tests/test_simpletable.py (+7/-1)
debian/changelog (+3/-2)
Reviewer Review Type Date Requested Status
Scott Moser Pending
Review via email: mp+332078@code.launchpad.net

Description of the change

Merge request of upstream snapshot for SRU include simpletable fix

To post a comment you must log in.

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 8f99d99..993b26c 100644
3--- a/cloudinit/netinfo.py
4+++ b/cloudinit/netinfo.py
5@@ -171,7 +171,7 @@ def netdev_pformat():
6 else:
7 fields = ['Device', 'Up', 'Address', 'Mask', 'Scope', 'Hw-Address']
8 tbl = SimpleTable(fields)
9- for (dev, d) in netdev.items():
10+ for (dev, d) in sorted(netdev.items()):
11 tbl.add_row([dev, d["up"], d["addr"], d["mask"], ".", d["hwaddr"]])
12 if d.get('addr6'):
13 tbl.add_row([dev, d["up"],
14diff --git a/cloudinit/simpletable.py b/cloudinit/simpletable.py
15index 9060322..ca663cc 100644
16--- a/cloudinit/simpletable.py
17+++ b/cloudinit/simpletable.py
18@@ -59,4 +59,4 @@ class SimpleTable(object):
19 return '\n'.join(lines)
20
21 def get_string(self):
22- return repr(self)
23+ return self.__str__()
24diff --git a/cloudinit/tests/test_netinfo.py b/cloudinit/tests/test_netinfo.py
25new file mode 100644
26index 0000000..7dea2e4
27--- /dev/null
28+++ b/cloudinit/tests/test_netinfo.py
29@@ -0,0 +1,106 @@
30+# This file is part of cloud-init. See LICENSE file for license information.
31+
32+"""Tests netinfo module functions and classes."""
33+
34+from cloudinit.netinfo import netdev_pformat, route_pformat
35+from cloudinit.tests.helpers import CiTestCase, mock
36+
37+
38+# Example ifconfig and route output
39+SAMPLE_IFCONFIG_OUT = """\
40+enp0s25 Link encap:Ethernet HWaddr 50:7b:9d:2c:af:91
41+ inet addr:192.168.2.18 Bcast:192.168.2.255 Mask:255.255.255.0
42+ inet6 addr: fe80::8107:2b92:867e:f8a6/64 Scope:Link
43+ UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
44+ RX packets:8106427 errors:55 dropped:0 overruns:0 frame:37
45+ TX packets:9339739 errors:0 dropped:0 overruns:0 carrier:0
46+ collisions:0 txqueuelen:1000
47+ RX bytes:4953721719 (4.9 GB) TX bytes:7731890194 (7.7 GB)
48+ Interrupt:20 Memory:e1200000-e1220000
49+
50+lo Link encap:Local Loopback
51+ inet addr:127.0.0.1 Mask:255.0.0.0
52+ inet6 addr: ::1/128 Scope:Host
53+ UP LOOPBACK RUNNING MTU:65536 Metric:1
54+ RX packets:579230851 errors:0 dropped:0 overruns:0 frame:0
55+ TX packets:579230851 errors:0 dropped:0 overruns:0 carrier:0
56+ collisions:0 txqueuelen:1
57+"""
58+
59+SAMPLE_ROUTE_OUT = '\n'.join([
60+ '0.0.0.0 192.168.2.1 0.0.0.0 UG 0 0 0'
61+ ' enp0s25',
62+ '0.0.0.0 192.168.2.1 0.0.0.0 UG 0 0 0'
63+ ' wlp3s0',
64+ '192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0'
65+ ' enp0s25'])
66+
67+
68+NETDEV_FORMATTED_OUT = '\n'.join([
69+ '+++++++++++++++++++++++++++++++++++++++Net device info+++++++++++++++++++'
70+ '++++++++++++++++++++',
71+ '+---------+------+------------------------------+---------------+-------+'
72+ '-------------------+',
73+ '| Device | Up | Address | Mask | Scope |'
74+ ' Hw-Address |',
75+ '+---------+------+------------------------------+---------------+-------+'
76+ '-------------------+',
77+ '| enp0s25 | True | 192.168.2.18 | 255.255.255.0 | . |'
78+ ' 50:7b:9d:2c:af:91 |',
79+ '| enp0s25 | True | fe80::8107:2b92:867e:f8a6/64 | . | link |'
80+ ' 50:7b:9d:2c:af:91 |',
81+ '| lo | True | 127.0.0.1 | 255.0.0.0 | . |'
82+ ' . |',
83+ '| lo | True | ::1/128 | . | host |'
84+ ' . |',
85+ '+---------+------+------------------------------+---------------+-------+'
86+ '-------------------+'])
87+
88+ROUTE_FORMATTED_OUT = '\n'.join([
89+ '+++++++++++++++++++++++++++++Route IPv4 info++++++++++++++++++++++++++'
90+ '+++',
91+ '+-------+-------------+-------------+---------------+-----------+-----'
92+ '--+',
93+ '| Route | Destination | Gateway | Genmask | Interface | Flags'
94+ ' |',
95+ '+-------+-------------+-------------+---------------+-----------+'
96+ '-------+',
97+ '| 0 | 0.0.0.0 | 192.168.2.1 | 0.0.0.0 | wlp3s0 |'
98+ ' UG |',
99+ '| 1 | 192.168.2.0 | 0.0.0.0 | 255.255.255.0 | enp0s25 |'
100+ ' U |',
101+ '+-------+-------------+-------------+---------------+-----------+'
102+ '-------+',
103+ '++++++++++++++++++++++++++++++++++++++++Route IPv6 info++++++++++'
104+ '++++++++++++++++++++++++++++++',
105+ '+-------+-------------+-------------+---------------+---------------+'
106+ '-----------------+-------+',
107+ '| Route | Proto | Recv-Q | Send-Q | Local Address |'
108+ ' Foreign Address | State |',
109+ '+-------+-------------+-------------+---------------+---------------+'
110+ '-----------------+-------+',
111+ '| 0 | 0.0.0.0 | 192.168.2.1 | 0.0.0.0 | UG |'
112+ ' 0 | 0 |',
113+ '| 1 | 192.168.2.0 | 0.0.0.0 | 255.255.255.0 | U |'
114+ ' 0 | 0 |',
115+ '+-------+-------------+-------------+---------------+---------------+'
116+ '-----------------+-------+'])
117+
118+
119+class TestNetInfo(CiTestCase):
120+
121+ maxDiff = None
122+
123+ @mock.patch('cloudinit.netinfo.util.subp')
124+ def test_netdev_pformat(self, m_subp):
125+ """netdev_pformat properly rendering network device information."""
126+ m_subp.return_value = (SAMPLE_IFCONFIG_OUT, '')
127+ content = netdev_pformat()
128+ self.assertEqual(NETDEV_FORMATTED_OUT, content)
129+
130+ @mock.patch('cloudinit.netinfo.util.subp')
131+ def test_route_pformat(self, m_subp):
132+ """netdev_pformat properly rendering network device information."""
133+ m_subp.return_value = (SAMPLE_ROUTE_OUT, '')
134+ content = route_pformat()
135+ self.assertEqual(ROUTE_FORMATTED_OUT, content)
136diff --git a/cloudinit/tests/test_simpletable.py b/cloudinit/tests/test_simpletable.py
137index 96bc24c..a12a62a 100644
138--- a/cloudinit/tests/test_simpletable.py
139+++ b/cloudinit/tests/test_simpletable.py
140@@ -97,4 +97,10 @@ class TestSimpleTable(CiTestCase):
141 table = SimpleTable(AUTHORIZED_KEYS_FIELDS)
142 for row in AUTHORIZED_KEYS_ROWS:
143 table.add_row(row)
144- self.assertEqual(str(table), AUTHORIZED_KEYS_TABLE)
145+
146+ def test_get_string(self):
147+ """get_string() method returns the same content as str()."""
148+ table = SimpleTable(AUTHORIZED_KEYS_FIELDS)
149+ for row in AUTHORIZED_KEYS_ROWS:
150+ table.add_row(row)
151+ self.assertEqual(table.get_string(), str(table))
152diff --git a/debian/changelog b/debian/changelog
153index 837cc3f..e006629 100644
154--- a/debian/changelog
155+++ b/debian/changelog
156@@ -1,4 +1,4 @@
157-cloud-init (17.1-17-g45d361cb-0ubuntu1~16.04.1) xenial-proposed; urgency=medium
158+cloud-init (17.1-18-gd4f70470-0ubuntu1~16.04.1) xenial-proposed; urgency=medium
159
160 * drop the following cherry picks, now incorporated in snapshot.
161 + debian/patches/cpick-a2f8ce9c-Do-not-provide-systemd-fsck-drop...
162@@ -8,6 +8,7 @@ cloud-init (17.1-17-g45d361cb-0ubuntu1~16.04.1) xenial-proposed; urgency=medium
163 * debian/rules: install rsyslog file with 0644 mode instead of 0755.
164 * debian/rules, debian/apport-launcher.py: add an apport hook. (LP: #1607345)
165 * New upstream snapshot. (LP: #1721847)
166+ - simpletable: Fix get_string method to return table-formatted string
167 - net: Handle bridge stp values of 0 and convert to boolean type
168 [Chad Smith]
169 - tools: Give specific --abbrev=8 to "git describe"
170@@ -121,7 +122,7 @@ cloud-init (17.1-17-g45d361cb-0ubuntu1~16.04.1) xenial-proposed; urgency=medium
171 [Ryan Harper]
172 - archlinux: Fix bug with empty dns, do not render 'lo' devices.
173
174- -- Chad Smith <chad.smith@canonical.com> Fri, 06 Oct 2017 13:56:05 -0600
175+ -- Chad Smith <chad.smith@canonical.com> Tue, 10 Oct 2017 14:13:24 -0600
176
177 cloud-init (0.7.9-233-ge586fe35-0ubuntu1~16.04.2) xenial-proposed; urgency=medium
178

Subscribers

People subscribed via source and target branches