Merge ~smoser/cloud-init:fix/1836949-mtu-lost-in-translation into cloud-init:master

Proposed by Scott Moser
Status: Merged
Approved by: Ryan Harper
Approved revision: 9f683c0221a7f926b86292b49882b2fe36f6fabe
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~smoser/cloud-init:fix/1836949-mtu-lost-in-translation
Merge into: cloud-init:master
Diff against target: 123 lines (+95/-0)
2 files modified
cloudinit/net/network_state.py (+4/-0)
tests/unittests/test_net.py (+91/-0)
Reviewer Review Type Date Requested Status
Ryan Harper Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+370280@code.launchpad.net

Commit message

Fix bug rendering MTU on bond or vlan when input was netplan.

If input to network_state.parse_net_config_data was netplan (v2 yaml)
then the network state would lose the mtu information on bond or vlan.

LP: #1836949

Description of the change

see commit message

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:9f683c0221a7f926b86292b49882b2fe36f6fabe
https://jenkins.ubuntu.com/server/job/cloud-init-ci/796/
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/796/rebuild

review: Approve (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :

Thanks. I swear I just was working on a branch for this very issue but I can't find any duplicate bugs.

Inline question on what to do if bond/vlan sets MTU > than underlying device?

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

Thanks Scott!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/net/network_state.py b/cloudinit/net/network_state.py
2index 3702130..0ca576b 100644
3--- a/cloudinit/net/network_state.py
4+++ b/cloudinit/net/network_state.py
5@@ -673,6 +673,8 @@ class NetworkStateInterpreter(object):
6 'vlan_id': cfg.get('id'),
7 'vlan_link': cfg.get('link'),
8 }
9+ if 'mtu' in cfg:
10+ vlan_cmd['mtu'] = cfg['mtu']
11 subnets = self._v2_to_v1_ipcfg(cfg)
12 if len(subnets) > 0:
13 vlan_cmd.update({'subnets': subnets})
14@@ -722,6 +724,8 @@ class NetworkStateInterpreter(object):
15 'params': dict((v2key_to_v1[k], v) for k, v in
16 item_params.get('parameters', {}).items())
17 }
18+ if 'mtu' in item_cfg:
19+ v1_cmd['mtu'] = item_cfg['mtu']
20 subnets = self._v2_to_v1_ipcfg(item_cfg)
21 if len(subnets) > 0:
22 v1_cmd.update({'subnets': subnets})
23diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
24index de4e7f4..e2bbb84 100644
25--- a/tests/unittests/test_net.py
26+++ b/tests/unittests/test_net.py
27@@ -2856,6 +2856,97 @@ USERCTL=no
28 self._compare_files_to_expected(entry['expected_sysconfig'], found)
29 self._assert_headers(found)
30
31+ def test_from_v2_vlan_mtu(self):
32+ """verify mtu gets rendered on bond when source is netplan."""
33+ v2data = {
34+ 'version': 2,
35+ 'ethernets': {'eno1': {}},
36+ 'vlans': {
37+ 'eno1.1000': {
38+ 'addresses': ["192.6.1.9/24"],
39+ 'id': 1000, 'link': 'eno1', 'mtu': 1495}}}
40+ expected = {
41+ 'ifcfg-eno1': textwrap.dedent("""\
42+ BOOTPROTO=none
43+ DEVICE=eno1
44+ NM_CONTROLLED=no
45+ ONBOOT=yes
46+ STARTMODE=auto
47+ TYPE=Ethernet
48+ USERCTL=no
49+ """),
50+ 'ifcfg-eno1.1000': textwrap.dedent("""\
51+ BOOTPROTO=none
52+ DEVICE=eno1.1000
53+ IPADDR=192.6.1.9
54+ MTU=1495
55+ NETMASK=255.255.255.0
56+ NM_CONTROLLED=no
57+ ONBOOT=yes
58+ PHYSDEV=eno1
59+ STARTMODE=auto
60+ TYPE=Ethernet
61+ USERCTL=no
62+ VLAN=yes
63+ """)
64+ }
65+ self._compare_files_to_expected(
66+ expected, self._render_and_read(network_config=v2data))
67+
68+ def test_from_v2_bond_mtu(self):
69+ """verify mtu gets rendered on bond when source is netplan."""
70+ v2data = {
71+ 'version': 2,
72+ 'bonds': {
73+ 'bond0': {'addresses': ['10.101.8.65/26'],
74+ 'interfaces': ['enp0s0', 'enp0s1'],
75+ 'mtu': 1334,
76+ 'parameters': {}}}
77+ }
78+ expected = {
79+ 'ifcfg-bond0': textwrap.dedent("""\
80+ BONDING_MASTER=yes
81+ BONDING_SLAVE0=enp0s0
82+ BONDING_SLAVE1=enp0s1
83+ BOOTPROTO=none
84+ DEVICE=bond0
85+ IPADDR=10.101.8.65
86+ MTU=1334
87+ NETMASK=255.255.255.192
88+ NM_CONTROLLED=no
89+ ONBOOT=yes
90+ STARTMODE=auto
91+ TYPE=Bond
92+ USERCTL=no
93+ """),
94+ 'ifcfg-enp0s0': textwrap.dedent("""\
95+ BONDING_MASTER=yes
96+ BOOTPROTO=none
97+ DEVICE=enp0s0
98+ MASTER=bond0
99+ NM_CONTROLLED=no
100+ ONBOOT=yes
101+ SLAVE=yes
102+ STARTMODE=auto
103+ TYPE=Bond
104+ USERCTL=no
105+ """),
106+ 'ifcfg-enp0s1': textwrap.dedent("""\
107+ BONDING_MASTER=yes
108+ BOOTPROTO=none
109+ DEVICE=enp0s1
110+ MASTER=bond0
111+ NM_CONTROLLED=no
112+ ONBOOT=yes
113+ SLAVE=yes
114+ STARTMODE=auto
115+ TYPE=Bond
116+ USERCTL=no
117+ """)
118+ }
119+ self._compare_files_to_expected(
120+ expected, self._render_and_read(network_config=v2data))
121+
122
123 class TestOpenSuseSysConfigRendering(CiTestCase):
124

Subscribers

People subscribed via source and target branches