Comment 3 for bug 2027584

Revision history for this message
Lukas Märdian (slyon) wrote (last edit ):

So I found a minimal reproducer and prepared a unit-test case:

```
#!/bin/bash
# setup
netplan set network.renderer=NetworkManager --origin-hint=00-no-netdefs-just-globals
netplan set network.ethernets.eth99.dhcp4=true --origin-hint=90-some-netdefs
ls -l /etc/netplan/
# test
netplan set network.ethernets.eth99=NULL
# result
cat /etc/netplan/00-no-netdefs-just-globals.yaml
```

```
    def test_set_no_netdefs_just_globals(self): # LP: #2027584
        keepme1 = os.path.join(self.workdir.name, 'etc', 'netplan',
                              '00-no-netdefs-just-renderer.yaml')
        with open(keepme1, 'w') as f:
            f.write('''network: {renderer: NetworkManager}''')
        deleteme = os.path.join(self.workdir.name, 'etc', 'netplan',
                                '90-some-netdefs.yaml')
        with open(deleteme, 'w') as f:
            f.write('''network: {ethernets: {eth99: {dhcp4: true}}}''')

        self._set(['ethernets.eth99=NULL'])
        self.assertFalse(os.path.isfile(deleteme))
        self.assertTrue(os.path.isfile(keepme1))
        with open(keepme1, 'r') as f:
            yml = yaml.safe_load(f)
            self.assertEqual('NetworkManager', yml['network']['renderer'])
```

The issue seems to happen in Jammy+ so it's not necessarily a regression.

I'm fairly sure it's related to the combination of (as SRUed into Jammy via 0.105-0ubuntu2~22.04.2):
https://github.com/canonical/netplan/pull/254
https://github.com/canonical/netplan/pull/299

Especially, the "unlink" part at the bottom of netplan.c:netplan_state_update_yaml_hierarchy seems to ignore any global values (such as "renderer" or "version") and operates on netdefs only.

=> It should probably be fixed in conjunction with https://bugs.launchpad.net/netplan/+bug/2003727