Skip to content

Commit 51c872d

Browse files
mkjslyon
andauthored
cli: Fix failure with "set-name" and "bridges" (#221)
The code path when a config has set-name as well as bridges doesn't seem to work at present, failure below. This change seems to fix it. Config: ``` network: version: 2 # renderer: networkd # networkd doesn't handle ethernet well... renderer: NetworkManager ethernets: devnet: renderer: networkd match: name: enx00aa11223344 enx00bb11223344: addresses: [ 10.20.0.1/24 ] renderer: networkd wlan: match: macaddress: 00:99:11:22:33:44 set-name: "wlan0" bridges: # ... and NetworkManager doesn't handle bridges well renderer: networkd br0: addresses: [ "10.9.0.1/16" ] interfaces: [ "devnet" ] ``` Failure: ``` netplan try Traceback (most recent call last): File "/usr/share/netplan/netplan/cli/commands/try_command.py", line 84, in command_try NetplanApply().command_apply(run_generate=True, sync=True, exit_on_error=False) File "/usr/share/netplan/netplan/cli/commands/apply.py", line 191, in command_apply changes = NetplanApply.process_link_changes(devices, config_manager) File "/usr/share/netplan/netplan/cli/commands/apply.py", line 281, in process_link_changes if NetplanApply.is_composite_member(composite_interfaces, phy): File "/usr/share/netplan/netplan/cli/commands/apply.py", line 252, in is_composite_member members = settings.get('interfaces', []) AttributeError: 'str' object has no attribute 'get' ``` COMMITS: * cli: Fix handling "set-name" with composites * tests: add CLI unittests Co-authored-by: Lukas Märdian <[email protected]>
1 parent 7844058 commit 51c872d

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

netplan/cli/commands/apply.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,15 @@ def command_apply(self, run_generate=True, sync=False, exit_on_error=True): # p
251251
utils.systemctl_network_manager('start', sync=sync)
252252

253253
@staticmethod
254-
def is_composite_member(composites, phy): # pragma: nocover (covered in autopkgtest)
254+
def is_composite_member(composites, phy):
255255
"""
256256
Is this physical interface a member of a 'composite' virtual
257257
interface? (bond, bridge)
258258
"""
259259
for composite in composites:
260260
for _, settings in composite.items():
261+
if not type(settings) is dict:
262+
continue
261263
members = settings.get('interfaces', [])
262264
for iface in members:
263265
if iface == phy:

tests/test_cli_units.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/python3
2+
# Blackbox tests of netplan CLI. These are run during "make check" and don't
3+
# touch the system configuration at all.
4+
#
5+
# Copyright (C) 2021 Canonical, Ltd.
6+
# Author: Lukas Märdian <[email protected]>
7+
#
8+
# This program is free software; you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation; version 3.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
20+
import unittest
21+
22+
from netplan.cli.commands.apply import NetplanApply
23+
24+
25+
class TestCLI(unittest.TestCase):
26+
'''Netplan CLI unittests'''
27+
28+
def test_is_composite_member(self):
29+
res = NetplanApply.is_composite_member([{'br0': {'interfaces': ['eth0']}}], 'eth0')
30+
self.assertTrue(res)
31+
32+
def test_is_composite_member_false(self):
33+
res = NetplanApply.is_composite_member([
34+
{'br0': {'interfaces': ['eth42']}},
35+
{'bond0': {'interfaces': ['eth1']}}
36+
], 'eth0')
37+
self.assertFalse(res)
38+
39+
def test_is_composite_member_with_renderer(self):
40+
res = NetplanApply.is_composite_member([{'renderer': 'networkd', 'br0': {'interfaces': ['eth0']}}], 'eth0')
41+
self.assertTrue(res)

0 commit comments

Comments
 (0)