Merge ~rjschwei/cloud-init:netV1ToTranslate into cloud-init:master

Proposed by Robert Schweikert
Status: Work in progress
Proposed branch: ~rjschwei/cloud-init:netV1ToTranslate
Merge into: cloud-init:master
Diff against target: 158 lines (+126/-1)
2 files modified
cloudinit/distros/net_util.py (+23/-1)
tests/unittests/test_distros/test_net_util.py (+103/-0)
Reviewer Review Type Date Requested Status
Chad Smith Abstain
Server Team CI bot continuous-integration Approve
Scott Moser Pending
Review via email: mp+333904@code.launchpad.net

Description of the change

Handle network configuration translation for the legacy path, do not drop gateway information

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

FAILED: Continuous integration, rev:0acc956dc470fa201577c2b1267585217ed972d1
https://jenkins.ubuntu.com/server/job/cloud-init-ci/510/
Executed test runs:
    SUCCESS: Checkout
    FAILED: Unit & Style Tests

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

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

FAILED: Continuous integration, rev:4d3028d8d083b3781335d5a062038a4ca3cd92b5
https://jenkins.ubuntu.com/server/job/cloud-init-ci/515/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    FAILED: MAAS Compatability Testing

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

review: Needs Fixing (continuous-integration)
Revision history for this message
Ryan Harper (raharper) :
Revision history for this message
Chad Smith (chad.smith) wrote :

Looking over the failure, that MAAS compatibility testing hit an issue with an include url test unrelated to your branch. Can you git fetch on master and git rebase your branch against master and re-push that branch up. It will contain the fix 6ad23fe9b11f07e4404c8a1f2f1e9cba2640dceb which should resolve integration test issues hit on this branch.

Revision history for this message
Chad Smith (chad.smith) :
Revision history for this message
Chad Smith (chad.smith) :
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

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

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

review: Approve (continuous-integration)
Revision history for this message
Robert Schweikert (rjschwei) wrote :

@raharper and @chad.smith

Thanks for review and comments.

Fixed: Test location and IPv4 regular expression.

Comments and questions on the other info you provided.

As far as the test data is concerned, I kind of did a cut and paste from existing tests based on network configuration for the distros. I really have no idea what the various data sources can and cannot produce and what the debian/ubuntu format looks like. So test data that conforms to what the data sources produce would be better. If there is concrete data, that I should be using and have not used, please point me in that direction. Same can be applied to the suggested change of the search for "default gw", I agree that the proposed expression is more flexible, but does it need to be, i.e. do we have a data source where there is a varying space?

Yes there is always the risk that a new data source may format things differently, but the question would then be if we should compensate for such potential future discretions now or not.

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

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

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

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

Robert, I agree on your suggestion to not be too flexible for future formats etc. So +1 on dropping my other re.match suggestion on 'default gw' handling. Yeah no need to waste resources planning for future-formats if we don't need to. Per your handling is duplicate (list type) entries in post-up, did you have specific use-cases in mind where multiple post-up commands are specified in /etc/network/interfaces in a single iface stanza?

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

FAILED: Continuous integration, rev:34066c255db64a3979c152764d16fa4cbcc55eb1
https://jenkins.ubuntu.com/server/job/cloud-init-ci/2/
Executed test runs:
    SUCCESS: Checkout
    FAILED: Unit & Style Tests

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

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

FAILED: Continuous integration, rev:f6e23e59b0b9d6763c15d1781895fde0f0251239
https://jenkins.ubuntu.com/server/job/cloud-init-ci/4/
Executed test runs:
    SUCCESS: Checkout
    FAILED: Unit & Style Tests

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

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

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

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

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

We think this involves a rework pending the chages discussed at the summit which resulted in Ryan's branch https://code.launchpad.net/~raharper/cloud-init/+git/cloud-init/+merge/353740. Will mark 'work in progress' on this as the sysconfig rendering changes Ryan addresses will impact this branch.

review: Abstain
Revision history for this message
Chad Smith (chad.smith) wrote :

Awaiting the following branch landing which should affect the approach used in this branch https://code.launchpad.net/~raharper/cloud-init/+git/cloud-init/+merge/353740

Revision history for this message
Robert Schweikert (rjschwei) wrote :

> Awaiting the following branch landing which should affect the approach used in
> this branch https://code.launchpad.net/~raharper/cloud-init/+git/cloud-
> init/+merge/353740

Agreed that is what we discussed at the summit. One thing I am not certain about, is the following:

For distros where the old implementation (_write_network) has been superseeded by the new implementation that uses the renderer approach the _write_network implementation has not been removed or rigged to throw and exception, i.e. I would expect a

def _write_network(self, settings):
    raise "You should not be here"

implementation. This is not the case.

So my question is, is there any code path where once the rendered approach is implemented we could still enter _write_network() ?

- If the answer is yes than this change would still be needed.
- If the answer is no, than my follow up question will be, is it OK to then implement the _write_network() with the exception as shown in pseudo code above?

  - If the answer is no, then we'd still want this change.

I do currently carry this patch in the package. I can carry it for a while until https://code.launchpad.net/~raharper/cloud-init/+git/cloud-init/+merge/353740 and the necessary follow up changes are merged pending the answers to the questions above.

Revision history for this message
Scott Moser (smoser) wrote :

Robert,

Please see
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/354962

I think that is what you were after.

Revision history for this message
Robert Schweikert (rjschwei) wrote :

Scott,

Yes thanks that answers my question.

Then yes as agreed at the summit lets hang on to this with no changes, when

https://code.launchpad.net/~raharper/cloud-init/+git/cloud-init/+merge/353740

landed and I have the follow up changes for the config options done, this can just go away :)

Unmerged commits

2f69ddd... by Robert Schweikert

- Handle gateway information in the network config translator for
  the apply_network path lp#1732966

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/distros/net_util.py b/cloudinit/distros/net_util.py
2index 1ce1aa7..557a95c 100644
3--- a/cloudinit/distros/net_util.py
4+++ b/cloudinit/distros/net_util.py
5@@ -67,6 +67,11 @@
6 # }
7 # }
8
9+import re
10+
11+ipv4 = re.compile(r"\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}")
12+
13+
14 def translate_network(settings):
15 # Get the standard cmd, args from the ubuntu format
16 entries = []
17@@ -88,7 +93,14 @@ def translate_network(settings):
18 consume = {}
19 consume[cmd] = args
20 else:
21- consume[cmd] = args
22+ if consume.get(cmd):
23+ val = consume[cmd]
24+ if isinstance(val, list):
25+ consume[cmd].append(args)
26+ else:
27+ consume[cmd] = [val, args]
28+ else:
29+ consume[cmd] = args
30 # Check if anything left over to consume
31 absorb = False
32 for (cmd, args) in consume.items():
33@@ -148,6 +160,16 @@ def translate_network(settings):
34 hw_addr = hw_split[1]
35 if hw_addr:
36 iface_info['hwaddress'] = hw_addr
37+ if 'post-up' in info:
38+ routes = info['post-up']
39+ if isinstance(routes, list):
40+ for route_info in routes:
41+ if 'default gw' in route_info:
42+ iface_info['gateway'] = ipv4.search(
43+ route_info).group(0)
44+ elif 'default gw' in routes:
45+ iface_info['gateway'] = ipv4.search(routes).group(0)
46+
47 # If ipv6 is enabled, device will have multiple IPs, so we need to
48 # update the dictionary instead of overwriting it...
49 if dev_name in real_ifaces:
50diff --git a/tests/unittests/test_distros/test_net_util.py b/tests/unittests/test_distros/test_net_util.py
51new file mode 100644
52index 0000000..93426cf
53--- /dev/null
54+++ b/tests/unittests/test_distros/test_net_util.py
55@@ -0,0 +1,103 @@
56+# This file is part of cloud-init. See LICENSE file for license information.
57+
58+from cloudinit.distros import net_util
59+
60+from cloudinit.tests.helpers import CiTestCase
61+
62+
63+class TestNetworkConfigTransform(CiTestCase):
64+
65+ def test_basic_config_ipv4(self):
66+ basic_conf = '''
67+auto lo
68+iface lo inet loopback
69+
70+auto eth0
71+iface eth0 inet static
72+ address 192.168.1.5
73+ broadcast 192.168.1.0
74+ gateway 192.168.1.254
75+ netmask 255.255.255.0
76+ network 192.168.0.0
77+
78+auto eth1
79+iface eth1 inet dhcp
80+'''
81+ sysconfig = net_util.translate_network(basic_conf)
82+ expected = {
83+ 'lo': {'auto': True, 'ipv6': {}},
84+ 'eth0': {
85+ 'auto': True,
86+ 'ipv6': {},
87+ 'broadcast': '192.168.1.0',
88+ 'netmask': '255.255.255.0',
89+ 'bootproto': 'static',
90+ 'address': '192.168.1.5',
91+ 'gateway': '192.168.1.254'
92+ },
93+ 'eth1': {'auto': True, 'bootproto': 'dhcp', 'ipv6': {}}
94+ }
95+ self.assertEqual(sysconfig, expected)
96+
97+ def test_v1_confi_single_route_ipv4(self):
98+ v1_conf = '''
99+auto lo
100+iface lo inet loopback
101+
102+auto eth0
103+iface eth0 inet static
104+ hwaddress fa:16:3e:ee:2b:97
105+ address 192.168.168.30/24
106+ mtu 1500
107+ post-up route add default gw 192.168.168.1 || true
108+ pre-down route del default gw 192.168.168.1 || true
109+'''
110+ sysconfig = net_util.translate_network(v1_conf)
111+ expected = {
112+ 'lo': {'auto': True, 'ipv6': {}},
113+ 'eth0': {
114+ 'auto': True,
115+ 'bootproto': 'static',
116+ 'gateway': '192.168.168.1',
117+ 'address': '192.168.168.30/24',
118+ 'ipv6': {}
119+ }
120+ }
121+ self.assertEqual(sysconfig, expected)
122+
123+ def test_v1_confi_multi_route_multi_nic_ipv4(self):
124+ v1_conf = '''
125+auto lo
126+iface lo inet loopback
127+
128+auto eth0
129+iface eth0 inet static
130+ hwaddress fa:16:3e:ee:2b:97
131+ address 192.168.168.30/24
132+ mtu 1500
133+ post-up route add default gw 192.168.168.1 || true
134+ pre-down route del default gw 192.168.168.1 || true
135+
136+auto eth1
137+iface eth1 inet dhcp
138+ post-up route add 192.168.168.1 || true
139+'''
140+ sysconfig = net_util.translate_network(v1_conf)
141+ expected = {
142+ 'lo': {'auto': True, 'ipv6': {}},
143+ 'eth0': {
144+ 'auto': True,
145+ 'bootproto': 'static',
146+ 'gateway': '192.168.168.1',
147+ 'address': '192.168.168.30/24',
148+ 'ipv6': {}
149+ },
150+ 'eth1': {
151+ 'auto': True,
152+ 'bootproto': 'dhcp',
153+ 'ipv6': {}
154+ }
155+ }
156+ self.assertEqual(sysconfig, expected)
157+
158+# vi: ts=4 expandtab

Subscribers

People subscribed via source and target branches