Skip to content

Commit

Permalink
tests: fix keyfile parser existing tests
Browse files Browse the repository at this point in the history
Also add a few more tests.
  • Loading branch information
daniloegea committed Jun 28, 2023
1 parent c39d96a commit 52ee2f1
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 10 deletions.
59 changes: 59 additions & 0 deletions tests/generator/test_vlans.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ def test_vlan_parent_match(self):
self.assert_nm(None)
self.assert_nm_udev(NM_UNMANAGED % 'lan' + NM_UNMANAGED_MAC % '11:22:33:44:55:66' + NM_UNMANAGED % 'vlan20')

def test_vlan_parent_must_exist(self):
out = self.generate('''network:
version: 2
renderer: networkd
vlans:
vlan20: {id: 20, link: lan}''', expect_fail=True)
self.assertIn('vlan20: interface \'lan\' is not defined', out)


class TestNetworkManager(TestBase):

Expand Down Expand Up @@ -300,3 +308,54 @@ def test_vlan_sriov(self):
ip6-privacy=0
'''})
self.assert_nm_udev(NM_MANAGED % 'en1' + NM_MANAGED % 'enblue' + NM_MANAGED % 'engreen')

def test_vlan_parent_is_allowed_to_be_missing_for_nm(self):
self.generate('''network:
version: 2
renderer: NetworkManager
vlans:
vlan20: {id: 20, link: lan}''')

self.assert_nm({'vlan20': '''[connection]
id=netplan-vlan20
type=vlan
interface-name=vlan20
[vlan]
id=20
parent=lan
[ipv4]
method=link-local
[ipv6]
method=ignore
'''})

def test_vlan_with_missing_netdef_found_in_the_next_file_wont_fail(self):
''' If eth0 was registered as missing (and created as a placeholder netdef)
if shouldn't fail if it's defined in a file that was parsed *after* the file where
the VLAN is defined
'''
out = self.generate('''network:
renderer: NetworkManager
version: 2
vlans:
vlan100:
id: 100
link: eth0''', confs={'b': '''network:
renderer: NetworkManager
version: 2
ethernets: {eth0: {}}'''})

self.assertNotIn('Updated definition \'eth0\' changes device type', out)

def test_vlan_with_parent_uuid(self):
''' Check the generate accepts a link pointing to the NM connection UUID '''
self.generate('''network:
renderer: NetworkManager
version: 2
vlans:
vlan100:
id: 100
link: 53125f52-f9a7-4d2a-a853-5f3b9e02299f''')
15 changes: 5 additions & 10 deletions tests/parser/test_keyfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,6 @@ def test_keyfile_type_bridge(self):
def test_keyfile_type_bond(self):
self._template_keyfile_type('bonds', 'bond')

def test_keyfile_type_vlan(self):
self._template_keyfile_type('nm-devices', 'vlan', False)

def test_keyfile_type_tunnel(self):
self._template_keyfile_type('tunnels', 'ip-tunnel', False)

Expand Down Expand Up @@ -824,20 +821,18 @@ def test_keyfile_vlan(self):
'''.format(UUID))
self.assert_netplan({UUID: '''network:
version: 2
nm-devices:
vlans:
NM-{}:
renderer: NetworkManager
addresses:
- "1.2.3.4/24"
id: 1
link: "en1"
networkmanager:
uuid: "{}"
name: "netplan-enblue"
passthrough:
connection.type: "vlan"
connection.interface-name: "enblue"
vlan.id: "1"
vlan.parent: "en1"
ipv4.method: "manual"
ipv4.address1: "1.2.3.4/24"
ipv6.method: "ignore"
'''.format(UUID, UUID)})

def test_keyfile_bridge(self):
Expand Down

0 comments on commit 52ee2f1

Please sign in to comment.