** Description changed:
+ [ Impact ]
+
+ * netplan.io CLI commands that fail with errors incorrectly exit with status
+ code 0. This breaks scripts that rely on the exit status, and also impacts
+ netplan-dbus.
+
+ * The fix makes these errors exit with status code 1.
+
+ [ Test Plan ]
+
+ * Run the following script
+
+ set -x
+
+ netplan set network.bridges.br1=invalid; echo $?
+ netplan set network.bridges.br1='{"interfaces":["missing"]}'; echo $?
+ netplan get >/dev/null; echo $?
+
+ * With the bug fixed, the first two commands should exit with status
+ code 1.
+
+ + netplan set network.bridges.br1=invalid
+ Command failed: Error in network definition: expected mapping (check
indentation)
+ + echo 1
+ 1
+ + netplan set network.bridges.br1={"interfaces":["missing"]}
+ Command failed: Error in network definition: br1: interface 'missing' is not
defined
+ + echo 1
+ 1
+ + netplan get
+ + echo 0
+ 0
+
+ [ Where problems could occur ]
+
+ * Callers that incorrectly relied on failed commands returning 0 will observe
+ a behavior change, including users that manipulate netplan via
netplan-dbus.
+
+ * Successfull commands and error messages are unaffected.
+
+ [ Other Info ]
+
+ * Fixed upstream in
+
https://github.com/canonical/netplan/commit/1f9e69ba919c38d52df718fe31a80e8e1b58b109
+
+ * Already fixed in Stonking by netplan.io 1.2.2-1.
+
+ [ Original Bug ]
+
Hello,
Me and my colleagues encountered a bug in Netplan that was introduced in
Ubuntu 24.04.
When `netplan set` is executed, for example to add bridge that
references non-existing interface, the error code (return value of the
cmd $?) is `0` in Ubuntu 24.04. In Ubuntu 22.04 the error code is proper
`1` (non-zero).
Here are generic steps that can be done with any Ubuntu 22.04 and 24.04
VM to reproduce the issue:
Get an Ubuntu 22.04 VM - this is example of proper behavior:
```bash
root@ubuntu-22-machine:~# netplan set --debug --origin-hint 10-test.network
network.bridges.br1='{"interfaces":["nonexisting-interface"]}'
Traceback (most recent call last):
File "/usr/sbin/netplan", line 23, in <module>
netplan.main()
File "/usr/share/netplan/netplan/cli/core.py", line 56, in main
self.run_command()
File "/usr/share/netplan/netplan/cli/utils.py", line 243, in run_command
self.func()
File "/usr/share/netplan/netplan/cli/commands/set.py", line 50, in run
self.run_command()
File "/usr/share/netplan/netplan/cli/utils.py", line 243, in run_command
self.func()
File "/usr/share/netplan/netplan/cli/commands/set.py", line 85, in
command_set
parser.load_yaml(tmp)
File "/usr/share/netplan/netplan/libnetplan.py", line 119, in load_yaml
_checked_lib_call(lib.netplan_parser_load_yaml_from_fd, self._ptr,
input_file.fileno())
File "/usr/share/netplan/netplan/libnetplan.py", line 79, in
_checked_lib_call
raise LibNetplanException(err.contents.message.decode('utf-8'))
netplan.libnetplan.LibNetplanException: Error in network definition: br1:
interface 'nonexisting-interface' is not defined
root@ubuntu-22-machine:~# echo $?
1
root@ubuntu-22-machine:~# dpkg -l | grep netplan
- hi libnetplan0:amd64 0.106.1-7ubuntu0.22.04.4
amd64 YAML network configuration abstraction runtime library
- hi netplan.io 0.106.1-7ubuntu0.22.04.4
amd64 YAML network configuration abstraction for various backends
+ hi libnetplan0:amd64 0.106.1-7ubuntu0.22.04.4 amd64 YAML network
configuration abstraction runtime library
+ hi netplan.io 0.106.1-7ubuntu0.22.04.4 amd64 YAML network configuration
abstraction for various backends
root@ubuntu-22-machine:~# lsb_release -a
No LSB modules are available.
- Distributor ID: Ubuntu
- Description: Ubuntu 22.04.5 LTS
- Release: 22.04
- Codename: jammy
+ Distributor ID: Ubuntu
+ Description: Ubuntu 22.04.5 LTS
+ Release: 22.04
+ Codename: jammy
```
Get an Ubuntu 24.04 VM - this is wrong behavior introduced in this
Ubuntu version. The return value of `netplan set` must be different than
`0` because there is an error and command failed:
```bash
root@ubuntu-24-machine:~# netplan set --debug --origin-hint 10-test.network
network.bridges.br1='{"interfaces":["nonexisting-interface"]}'
Command failed: Error in network definition: br1: interface
'nonexisting-interface' is not defined
eroot@ubuntu-24-machine:~# echo $?
0
root@ubuntu-24-machine:~# dpkg -l | grep netplan
- hi libnetplan1:amd64 1.1.1-1~ubuntu24.04.1
amd64 Declarative network configuration runtime library
- hi netplan-generator 1.1.1-1~ubuntu24.04.1
amd64 Declarative network configuration for various backends at
boot
- hi netplan.io 1.1.1-1~ubuntu24.04.1
amd64 Declarative network configuration for various backends at
runtime
- hi python3-netplan 1.1.1-1~ubuntu24.04.1
amd64 Declarative network configuration Python bindings
+ hi libnetplan1:amd64 1.1.1-1~ubuntu24.04.1 amd64 Declarative network
configuration runtime library
+ hi netplan-generator 1.1.1-1~ubuntu24.04.1 amd64 Declarative network
configuration for various backends at boot
+ hi netplan.io 1.1.1-1~ubuntu24.04.1 amd64 Declarative network configuration
for various backends at runtime
+ hi python3-netplan 1.1.1-1~ubuntu24.04.1 amd64 Declarative network
configuration Python bindings
root@ubuntu-24-machine:~# lsb_release -a
No LSB modules are available.
- Distributor ID: Ubuntu
- Description: Ubuntu 24.04.2 LTS
- Release: 24.04
- Codename: noble
+ Distributor ID: Ubuntu
+ Description: Ubuntu 24.04.2 LTS
+ Release: 24.04
+ Codename: noble
```
Based on a troubleshooting session with my colleagues we think we may found
out what the issue is (please verify - we are not experts on netplan codebase):
- The bug was introduced probably in commit
https://github.com/canonical/netplan/commit/d06c73d09f6081419bd423526b3d4516f14f523a
where in file `src/error.c` branching in `yaml_error` function has changed.
- In the `else` branch the return code is `NETPLAN_ERROR_CONFIG_GENERIC`
which is `0` (see this diff
https://github.com/canonical/netplan/commit/d06c73d09f6081419bd423526b3d4516f14f523a#diff-0785f4cf8a2cc06d90d511879d9b43ff9f69858fceb83bc13a5f78bd8b3a9187R162-R177).
-
+
Impact scope:
- - This wrong behavior breaks manual CLI commands, scripts and tooling that
depends on netplan CLI.
+ - This wrong behavior breaks manual CLI commands, scripts and tooling that
depends on netplan CLI.
- Additionally the error code is also not reflected to netplan-dbus. When you
execute the same command as above to add bridge using netplan-dbus - it will
not report error even though netplan command fails.
--
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/2104373
Title:
[Bug] Failed 'netplan set' operation doesn't return non-0 error
(Netplan 1.1.1 in Ubuntu 24.04)
To manage notifications about this bug go to:
https://bugs.launchpad.net/netplan/+bug/2104373/+subscriptions
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs