netplan apply does not remove defunct VLAN interfaces when --state is specificed

Bug #1959706 reported by Brian Turek
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Netplan
Triaged
Medium
Unassigned

Bug Description

"netplan apply" claims that, when invoked using the "--state" parameter, it will remove virtual interfaces when they are not specified in the new config. This functionality does not work for VLAN interfaces. Here's a reproducible:

# cat /etc/netplan/01-vlan.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s8: {} # physical ethernet interface
  vlans:
    enp0s8.998:
      id: 998
      link: enp0s8
    enp0s8.999:
      id: 999
      link: enp0s8

# netplan-apply
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:94:6f:b6 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::a00:27ff:fe94:6fb6/64 scope link
       valid_lft forever preferred_lft forever
3: enp0s8.999@enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 08:00:27:94:6f:b6 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::a00:27ff:fe94:6fb6/64 scope link
       valid_lft forever preferred_lft forever
4: enp0s8.998@enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 08:00:27:94:6f:b6 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::a00:27ff:fe94:6fb6/64 scope link
       valid_lft forever preferred_lft forever

# mkdir /tmp/netplan_state && netplan get | tee /tmp/netplan_state/01-old.yaml
network:
  renderer: networkd
  version: 2
  vlans:
    enp0s8.998:
      id: 998
      link: enp0s8
    enp0s8.999:
      id: 999
      link: enp0s8

Now make edits to /etc/netplan/01-vlan.yaml to remove enp0s8.999

# cat /etc/netplan/01-vlan.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s8: {} # physical ethernet interface
  vlans:
    enp0s8.998:
      id: 998
      link: enp0s8

# netplan apply --state /tmp/netplan_state/
# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 08:00:27:94:6f:b6 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::a00:27ff:fe94:6fb6/64 scope link
       valid_lft forever preferred_lft forever
3: enp0s8.999@enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 08:00:27:94:6f:b6 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::a00:27ff:fe94:6fb6/64 scope link
       valid_lft forever preferred_lft forever
4: enp0s8.998@enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 08:00:27:94:6f:b6 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::a00:27ff:fe94:6fb6/64 scope link
       valid_lft forever preferred_lft forever

I would expect that enp0s8.999 would be removed from the system.

Revision history for this message
Brian Turek (brian-turek) wrote :

I did some digging and the lack of removal can either be called a case of unclear documentation or a bug:

On https://github.com/canonical/netplan/blob/a42eb7860c8bbe69b1a2df695c85a59662898362/netplan/cli/commands/apply.py#L204, it passes self.state (the argument that was passed in on the CLI) as the "prefix" to ConfigManager to parse the old config. However, ConfigManager (https://github.com/canonical/netplan/blob/a42eb7860c8bbe69b1a2df695c85a59662898362/netplan/configmanager.py#L154-L156) is coded to look for YAMLs self.prefix / {lib,etc,run} / netplan.

Thus, in my above example, I needed to place my old YAML in /tmp/netplan_state/etc/netplan rather than directyly in /tmp/netplan_state/

Is this desired behavior?

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

Yes this is intended behaviour.

The --state parameter passes a "rootdir" that contains a previous state of /{lib,etc,run}/netplan/*.yaml. I guess we should probably improve the documentation about that.

Changed in netplan:
status: New → Triaged
importance: Undecided → Medium
tags: added: documentation
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.