Merge lp:~smoser/curtin/trunk.lp1649652 into lp:~curtin-dev/curtin/trunk

Proposed by Scott Moser
Status: Merged
Merged at revision: 441
Proposed branch: lp:~smoser/curtin/trunk.lp1649652
Merge into: lp:~curtin-dev/curtin/trunk
Diff against target: 190 lines (+148/-1)
5 files modified
curtin/net/__init__.py (+1/-1)
examples/tests/network_static_routes.yaml (+27/-0)
tests/unittests/test_net.py (+47/-0)
tests/vmtests/test_network.py (+23/-0)
tests/vmtests/test_network_static_routes.py (+50/-0)
To merge this branch: bzr merge lp:~smoser/curtin/trunk.lp1649652
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Ryan Harper (community) Approve
Wesley Wiedenmeier (community) Needs Fixing
Review via email: mp+313474@code.launchpad.net

Commit message

add new lines after rendered static routes.

Static routes were being rendered in /etc/network/interfaces
without a trailing newline after the 'pre-down' line.

To post a comment you must log in.
Revision history for this message
Wesley Wiedenmeier (wesley-wiedenmeier) wrote :

The fix makes sense to me, it achieves the same formatting fix in the output as the user's patch.
There's a couple tox issues in the unittest, patch below fixes them:
http://paste.ubuntu.com/23656927/

review: Needs Fixing
lp:~smoser/curtin/trunk.lp1649652 updated
437. By Scott Moser

formatting fixes

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

FAILED: Continuous integration, rev:437
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~smoser/curtin/trunk.lp1649652/+merge/313474/+edit-commit-message

https://jenkins.ubuntu.com/server/job/curtin-ci/284/
Executed test runs:
    SUCCESS: https://jenkins.ubuntu.com/server/job/curtin-ci/nodes=vm-amd64/284
    SUCCESS: https://jenkins.ubuntu.com/server/job/curtin-ci/nodes=vm-i386/284
    SUCCESS: https://jenkins.ubuntu.com/server/job/curtin-ci/nodes=vm-ppc64el/284
    SUCCESS: https://jenkins.ubuntu.com/server/job/curtin-ci/nodes=vm-s390x/284

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/curtin-ci/284/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Ryan Harper (raharper) :
review: Approve
lp:~smoser/curtin/trunk.lp1649652 updated
438. By Scott Moser

merge with trunk

439. By Scott Moser

merge from rharper, adding a vmtest

440. By Scott Moser

fix to be a valid cidr

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'curtin/net/__init__.py'
2--- curtin/net/__init__.py 2016-08-26 15:12:01 +0000
3+++ curtin/net/__init__.py 2017-01-25 20:57:24 +0000
4@@ -402,7 +402,7 @@
5 route_line += " %s %s" % (mapping[k], route[k])
6 content.append(up + route_line + or_true)
7 content.append(down + route_line + or_true)
8- return "\n".join(content)
9+ return "\n".join(content) + "\n"
10
11
12 def iface_start_entry(iface):
13
14=== added file 'examples/tests/network_static_routes.yaml'
15--- examples/tests/network_static_routes.yaml 1970-01-01 00:00:00 +0000
16+++ examples/tests/network_static_routes.yaml 2017-01-25 20:57:24 +0000
17@@ -0,0 +1,27 @@
18+# examples/tests/network_static_routes.yaml
19+showtrace: true
20+network:
21+ version: 1
22+ config:
23+ - type: physical
24+ name: interface0
25+ mac_address: "52:54:00:12:34:00"
26+ subnets:
27+ - address: 172.23.31.42/26
28+ gateway: 172.23.31.2
29+ type: static
30+ - type: route
31+ id: 4
32+ metric: 0
33+ destination: 10.0.0.0/12
34+ gateway: 172.23.31.1
35+ - type: route
36+ id: 5
37+ metric: 0
38+ destination: 192.168.0.0/16
39+ gateway: 172.23.31.1
40+ - type: route
41+ id: 6
42+ metric: 1
43+ destination: 10.200.0.0/16
44+ gateway: 172.23.31.1
45
46=== modified file 'tests/unittests/test_net.py'
47--- tests/unittests/test_net.py 2016-08-25 23:09:51 +0000
48+++ tests/unittests/test_net.py 2017-01-25 20:57:24 +0000
49@@ -654,5 +654,52 @@
50 self.assertEqual(sorted(ifaces.split('\n')),
51 sorted(net_ifaces.split('\n')))
52
53+ def test_routes_rendered(self):
54+ # as reported in bug 1649652
55+ conf = [
56+ {'name': 'eth0', 'type': 'physical',
57+ 'subnets': [{
58+ 'address': '172.23.31.42/26',
59+ 'dns_nameservers': [], 'gateway': '172.23.31.2',
60+ 'type': 'static'}]},
61+ {'type': 'route', 'id': 4,
62+ 'metric': 0, 'destination': '10.0.0.0/12',
63+ 'gateway': '172.23.31.1'},
64+ {'type': 'route', 'id': 5,
65+ 'metric': 0, 'destination': '192.168.2.0/24',
66+ 'gateway': '172.23.31.1'},
67+ {'type': 'route', 'id': 6,
68+ 'metric': 1, 'destination': '10.0.200.0/16',
69+ 'gateway': '172.23.31.1'},
70+ ]
71+
72+ expected = [
73+ 'auto lo',
74+ 'iface lo inet loopback',
75+ 'auto eth0',
76+ 'iface eth0 inet static',
77+ ' address 172.23.31.42/26',
78+ ' gateway 172.23.31.2',
79+ ('post-up route add -net 10.0.0.0 netmask 255.240.0.0 gw '
80+ '172.23.31.1 metric 0 || true'),
81+ ('pre-down route del -net 10.0.0.0 netmask 255.240.0.0 gw '
82+ '172.23.31.1 metric 0 || true'),
83+ ('post-up route add -net 192.168.2.0 netmask 255.255.255.0 gw '
84+ '172.23.31.1 metric 0 || true'),
85+ ('pre-down route del -net 192.168.2.0 netmask 255.255.255.0 gw '
86+ '172.23.31.1 metric 0 || true'),
87+ ('post-up route add -net 10.0.200.0 netmask 255.255.0.0 gw '
88+ '172.23.31.1 metric 1 || true'),
89+ ('pre-down route del -net 10.0.200.0 netmask 255.255.0.0 gw '
90+ '172.23.31.1 metric 1 || true'),
91+ 'source /etc/network/interfaces.d/*.cfg',
92+ ]
93+
94+ ns = network_state.NetworkState(version=1, config=conf)
95+ ns.parse_config()
96+ found = net.render_interfaces(ns.network_state).split('\n')
97+ self.assertEqual(
98+ sorted([line for line in expected if line]),
99+ sorted([line for line in found if line]))
100
101 # vi: ts=4 expandtab syntax=python
102
103=== modified file 'tests/vmtests/test_network.py'
104--- tests/vmtests/test_network.py 2016-08-25 23:32:11 +0000
105+++ tests/vmtests/test_network.py 2017-01-25 20:57:24 +0000
106@@ -111,6 +111,29 @@
107 logger.debug('dns_line:%s', dns_line)
108 self.assertTrue(dns_line in resolv_lines)
109
110+ def test_static_routes(self):
111+ '''check routing table'''
112+ network_state = self.get_network_state()
113+ ip_route_show = self.load_collect_file("ip_route_show")
114+ route_n = self.load_collect_file("route_n")
115+
116+ print("ip route show:\n%s" % ip_route_show)
117+ print("route -n:\n%s" % route_n)
118+ routes = network_state.get('routes')
119+ for route in routes:
120+ print('Checking static route: %s' % route)
121+ destnet = (
122+ ipaddress.IPv4Network("%s/%s" % (route.get('network'),
123+ route.get('netmask'))))
124+ route['destination'] = destnet.with_prefixlen
125+ expected_string = (
126+ "{destination} via {gateway} dev.*".format(**route))
127+ if route.get('metric', 0) > 0:
128+ expected_string += "metric {metric}".format(**route)
129+ print('searching for: %s' % expected_string)
130+ m = re.search(expected_string, ip_route_show, re.MULTILINE)
131+ self.assertTrue(m is not None)
132+
133 def test_ip_output(self):
134 '''check iproute2 'ip a' output with test input'''
135 network_state = self.get_network_state()
136
137=== added file 'tests/vmtests/test_network_static_routes.py'
138--- tests/vmtests/test_network_static_routes.py 1970-01-01 00:00:00 +0000
139+++ tests/vmtests/test_network_static_routes.py 2017-01-25 20:57:24 +0000
140@@ -0,0 +1,50 @@
141+from .releases import base_vm_classes as relbase
142+from .test_network import TestNetworkBaseTestsAbs
143+
144+
145+class TestNetworkStaticRoutesAbs(TestNetworkBaseTestsAbs):
146+ """ Static network routes testing with ipv4
147+ """
148+ conf_file = "examples/tests/network_static_routes.yaml"
149+
150+
151+class PreciseHWETTestNetworkStaticRoutes(relbase.precise_hwe_t,
152+ TestNetworkStaticRoutesAbs):
153+ # FIXME: off due to hang at test: Starting execute cloud user/final scripts
154+ __test__ = False
155+
156+
157+class TrustyTestNetworkStaticRoutes(relbase.trusty,
158+ TestNetworkStaticRoutesAbs):
159+ __test__ = True
160+
161+
162+class TrustyHWEUTestNetworkStaticRoutes(relbase.trusty_hwe_u,
163+ TrustyTestNetworkStaticRoutes):
164+ # Working, off by default to save test suite runtime, covered by
165+ # TrustyTestNetworkStaticRoutes
166+ __test__ = False
167+
168+
169+class TrustyHWEVTestNetworkStaticRoutes(relbase.trusty_hwe_v,
170+ TrustyTestNetworkStaticRoutes):
171+ # Working, off by default to save test suite runtime, covered by
172+ # TrustyTestNetworkStaticRoutes
173+ __test__ = False
174+
175+
176+class TrustyHWEWTestNetworkStaticRoutes(relbase.trusty_hwe_w,
177+ TrustyTestNetworkStaticRoutes):
178+ # Working, off by default to save test suite runtime, covered by
179+ # TrustyTestNetworkStaticRoutes
180+ __test__ = False
181+
182+
183+class XenialTestNetworkStaticRoutes(relbase.xenial,
184+ TestNetworkStaticRoutesAbs):
185+ __test__ = True
186+
187+
188+class YakketyTestNetworkStaticRoutes(relbase.yakkety,
189+ TestNetworkStaticRoutesAbs):
190+ __test__ = True

Subscribers

People subscribed via source and target branches