1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391
|
#
# Tests for passthrough config generated via netplan
#
# Copyright (C) 2021 Canonical, Ltd.
# Author: Lukas Märdian <slyon@ubuntu.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from .base import TestBase
# No passthrough mode (yet) for systemd-networkd
class TestNetworkd(TestBase):
pass
class TestNetworkManager(TestBase):
def test_passthrough_basic(self):
self.generate('''network:
version: 2
ethernets:
NM-87749f1d-334f-40b2-98d4-55db58965f5f:
renderer: NetworkManager
match: {}
networkmanager:
uuid: 87749f1d-334f-40b2-98d4-55db58965f5f
name: some NM id
passthrough:
connection.uuid: 87749f1d-334f-40b2-98d4-55db58965f5f
connection.type: ethernet
connection.permissions: ""''')
self.assert_nm({'NM-87749f1d-334f-40b2-98d4-55db58965f5f': '''[connection]
id=some NM id
type=ethernet
uuid=87749f1d-334f-40b2-98d4-55db58965f5f
#Netplan: passthrough setting
permissions=
[ethernet]
wake-on-lan=0
[ipv4]
method=link-local
[ipv6]
method=ignore
'''}, '''[device-netplan.ethernets.NM-87749f1d-334f-40b2-98d4-55db58965f5f]
match-device=type:ethernet
managed=1\n\n''')
def test_passthrough_wifi(self):
self.generate('''network:
version: 2
wifis:
NM-87749f1d-334f-40b2-98d4-55db58965f5f:
renderer: NetworkManager
match: {}
access-points:
"SOME-SSID":
networkmanager:
uuid: 87749f1d-334f-40b2-98d4-55db58965f5f
name: myid with spaces
passthrough:
connection.permissions: ""
wifi.ssid: SOME-SSID
"OTHER-SSID":
hidden: true''')
self.assert_nm({'NM-87749f1d-334f-40b2-98d4-55db58965f5f-SOME-SSID': '''[connection]
id=myid with spaces
type=wifi
uuid=87749f1d-334f-40b2-98d4-55db58965f5f
#Netplan: passthrough setting
permissions=
[ipv4]
method=link-local
[ipv6]
method=ignore
[wifi]
ssid=SOME-SSID
mode=infrastructure
''',
'NM-87749f1d-334f-40b2-98d4-55db58965f5f-OTHER-SSID': '''[connection]
id=netplan-NM-87749f1d-334f-40b2-98d4-55db58965f5f-OTHER-SSID
type=wifi
[ipv4]
method=link-local
[ipv6]
method=ignore
[wifi]
ssid=OTHER-SSID
mode=infrastructure
hidden=true
'''}, '''[device-netplan.wifis.NM-87749f1d-334f-40b2-98d4-55db58965f5f]
match-device=type:wifi
managed=1\n\n''')
def test_passthrough_type_nm_devices(self):
self.generate('''network:
nm-devices:
NM-87749f1d-334f-40b2-98d4-55db58965f5f:
renderer: NetworkManager
match: {}
networkmanager:
passthrough:
connection.uuid: 87749f1d-334f-40b2-98d4-55db58965f5f
connection.type: dummy''') # wokeignore:rule=dummy
self.assert_nm({'NM-87749f1d-334f-40b2-98d4-55db58965f5f': '''[connection]
id=netplan-NM-87749f1d-334f-40b2-98d4-55db58965f5f
#Netplan: passthrough setting
uuid=87749f1d-334f-40b2-98d4-55db58965f5f
#Netplan: passthrough setting
type=dummy # wokeignore:rule=dummy
[ipv4]
method=link-local
[ipv6]
method=ignore
'''}, '''[device-netplan.nm-devices.NM-87749f1d-334f-40b2-98d4-55db58965f5f]
match-device=type:dummy # wokeignore:rule=dummy
managed=1\n\n''')
def test_passthrough_dotted_group(self):
self.generate('''network:
nm-devices:
dotted-group-test:
renderer: NetworkManager
match: {}
networkmanager:
passthrough:
connection.type: "wireguard"
wireguard-peer.some-key.endpoint: 1.2.3.4''')
self.assert_nm({'dotted-group-test': '''[connection]
id=netplan-dotted-group-test
#Netplan: passthrough setting
type=wireguard
[ipv4]
method=link-local
[ipv6]
method=ignore
[wireguard-peer.some-key]
#Netplan: passthrough setting
endpoint=1.2.3.4
'''}, '''[device-netplan.nm-devices.dotted-group-test]
match-device=type:wireguard
managed=1\n\n''')
def test_passthrough_dotted_key(self):
self.generate('''network:
ethernets:
dotted-key-test:
renderer: NetworkManager
match: {}
networkmanager:
passthrough:
tc.qdisc.root: something
tc.qdisc.fff1: ":abc"
tc.filters.test: "test"''')
self.assert_nm({'dotted-key-test': '''[connection]
id=netplan-dotted-key-test
type=ethernet
[ethernet]
wake-on-lan=0
[ipv4]
method=link-local
[ipv6]
method=ignore
[tc]
#Netplan: passthrough setting
qdisc.root=something
#Netplan: passthrough setting
qdisc.fff1=:abc
#Netplan: passthrough setting
filters.test=test
'''}, '''[device-netplan.ethernets.dotted-key-test]
match-device=type:ethernet
managed=1\n\n''')
def test_passthrough_unsupported_setting(self):
self.generate('''network:
wifis:
test:
renderer: NetworkManager
match: {}
access-points:
"SOME-SSID": # implicit "mode: infrasturcutre"
networkmanager:
passthrough:
wifi.mode: "mesh"''')
self.assert_nm({'test-SOME-SSID': '''[connection]
id=netplan-test-SOME-SSID
type=wifi
[ipv4]
method=link-local
[ipv6]
method=ignore
[wifi]
ssid=SOME-SSID
#Netplan: passthrough override
mode=mesh
'''}, '''[device-netplan.wifis.test]
match-device=type:wifi
managed=1\n\n''')
def test_passthrough_empty_group(self):
self.generate('''network:
ethernets:
test:
renderer: NetworkManager
match: {}
networkmanager:
passthrough:
proxy._: ""''')
self.assert_nm({'test': '''[connection]
id=netplan-test
type=ethernet
[ethernet]
wake-on-lan=0
[ipv4]
method=link-local
[ipv6]
method=ignore
[proxy]
'''}, '''[device-netplan.ethernets.test]
match-device=type:ethernet
managed=1\n\n''')
def test_passthrough_interface_rename_existing_id(self):
self.generate('''network:
version: 2
renderer: NetworkManager
ethernets:
# This is the original netdef, generating "netplan-eth0.nmconnection"
eth0:
dhcp4: true
# This is the override netdef, modifying match.original_name (i.e. interface-name)
# it should still generate a "netplan-eth0.nmconnection" file (not netplan-eth33.nmconnection).
eth0:
renderer: NetworkManager
dhcp4: true
match:
name: "eth33"
networkmanager:
uuid: 626dd384-8b3d-3690-9511-192b2c79b3fd
name: "netplan-eth0"
''')
self.assert_nm({'eth0': '''[connection]
id=netplan-eth0
type=ethernet
uuid=626dd384-8b3d-3690-9511-192b2c79b3fd
interface-name=eth33
[ethernet]
wake-on-lan=0
[ipv4]
method=auto
[ipv6]
method=ignore
'''})
def test_passthrough_ip6_privacy_default(self):
self.generate('''network:
version: 2
renderer: NetworkManager
ethernets:
eth0:
dhcp4: true
dhcp6: true
networkmanager:
uuid: 626dd384-8b3d-3690-9511-192b2c79b3fd
name: "netplan-eth0"
passthrough:
"ipv6.ip6-privacy": "-1"
''')
self.assert_nm({'eth0': '''[connection]
id=netplan-eth0
type=ethernet
uuid=626dd384-8b3d-3690-9511-192b2c79b3fd
interface-name=eth0
[ethernet]
wake-on-lan=0
[ipv4]
method=auto
[ipv6]
method=auto
'''})
def test_passthrough_empty_keyfile_group(self):
out = self.generate('''network:
wifis:
wlan0:
access-points:
"SSID":
networkmanager:
name: connection_name
passthrough:
itsmissingadot: abc
nm-devices:
device0:
networkmanager:
name: connection_name
passthrough:
connection.type: vpn
itsmissingadot: abc
renderer: NetworkManager''', expect_fail=True, skip_generated_yaml_validation=True)
self.assertIn("NetworkManager: passthrough key 'itsmissingadot' format is invalid, should be 'group.key'", out)
def test_passthrough_wifi_without_network_manager(self):
out = self.generate('''network:
wifis:
wlan0:
access-points:
"SSID":
networkmanager:
name: connection_name
passthrough:
new.option: abc''', expect_fail=True, skip_generated_yaml_validation=True)
self.assertIn("wlan0: networkmanager backend settings found but renderer is not NetworkManager", out)
def test_passthrough_wifi_empty_group_with_network_manager(self):
out = self.generate('''network:
wifis:
wlan0:
renderer: NetworkManager
access-points:
"SSID":
networkmanager:
name: connection_name
passthrough:
itsmissingadot: abc''', skip_generated_yaml_validation=True)
self.assertIn("NetworkManager: passthrough key 'itsmissingadot' format is invalid, should be 'group.key'", out)
def test_passthrough_empty_keyfile_group_only(self):
out = self.generate('''network:
nm-devices:
device0:
networkmanager:
name: connection_name
passthrough:
itsmissingadot: abc
renderer: NetworkManager''', expect_fail=True, skip_generated_yaml_validation=True)
self.assertIn("device0: network type 'nm-devices:' needs to provide a 'connection.type' via passthrough", out)
|