2) Ubuntu Core being slow (probably due to the repeated 'run configure hook of "core" snap' action). When first calling into nmcli, the NM service is not yet up and running, thus crashing the subprocess.check_output(nmcli...) command. When patched to handle nmcli's "not running" return code (8) gracefully, giving some more time generally and adding some debug output, I can see the following output:
```diff utils.systemctl_network_manager('start', sync=sync)
if sync:
# wait up to 2 sec for 'STATE=connected (site/local-only)' or
# 'STATE=connected' to appear in 'nmcli general' STATE env = dict(os.environ, LC_ALL='C') cmd = ['nmcli', 'general', 'status'] for _ in range(20):
- if b'\nconnected' in subprocess.check_output(cmd, env=env):
+ sys.stderr.write("ITER\n")
+ out = subprocess.run(cmd, capture_output=True, universal_newlines=True, env=env)
+ sys.stderr.write(str(out.returncode)+": "+str(out.stdout)+"\n"+str(out.stderr)+"\n")
+ sys.stderr.flush()
+ if out.returncode == 8:
+ time.sleep(1)
+ continue
+ if '\nconnected' in str(out.stdout): break
- time.sleep(0.1)
+ time.sleep(0.5)
```
OUTPUT:
slyon@ubuntu:~$ sudo snap set system system.network.netplan.network.bridges.br54.dhcp4=false
Run configure hook of "core" snap \
ITER
Run configure hook of "core" snap |
8:
Error: NetworkManager is not running.
Run configure hook of "core" snap –
ITER
Run configure hook of "core" snap /
0: STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN
disconnected none enabled enabled enabled enabled
Run configure hook of "core" snap –
ITER
Run configure hook of "core" snap \
0: STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN
connected full enabled enabled enabled enabled
PS: launched `netplan-dbus` manually (to make the PATH & environment from my shell available) and patched the apply.py command to add debug output in a running core20 snap, by using `sudo mount -o bind apply.py /usr/share/netplan/netplan/cli/commands/apply.py`
After some more investigation in snappy land, I think we have two stacked problems here:
1) The netplan-dbus daemon doesn't have PATH set in its environment, thus not finding the `nmcli` or `network- manager. nmlci` binary:
slyon@ubuntu:~$ ps faux | grep netplan netplan- dbus ADDRESS= unix:path= /var/run/ dbus/system_ bus_socketDBUS_ STARTER_ BUS_TYPE= system
slyon 938 0.0 0.0 5188 720 pts/0 S+ 16:55 0:00 \_ grep --color=auto netplan
root 830 0.0 0.2 11200 4440 ? S 16:54 0:00 /lib/netplan/
slyon@ubuntu:~$ sudo cat /proc/830/environ
DBUS_STARTER_
2) Ubuntu Core being slow (probably due to the repeated 'run configure hook of "core" snap' action). When first calling into nmcli, the NM service is not yet up and running, thus crashing the subprocess. check_output( nmcli.. .) command. When patched to handle nmcli's "not running" return code (8) gracefully, giving some more time generally and adding some debug output, I can see the following output:
```diff
utils. systemctl_ network_ manager( 'start' , sync=sync)
env = dict(os.environ, LC_ALL='C')
cmd = ['nmcli', 'general', 'status']
for _ in range(20): check_output( cmd, env=env): write(" ITER\n" ) output= True, universal_ newlines= True, env=env) write(str( out.returncode) +": "+str(out. stdout) +"\n"+str( out.stderr) +"\n")
break
if sync:
# wait up to 2 sec for 'STATE=connected (site/local-only)' or
# 'STATE=connected' to appear in 'nmcli general' STATE
- if b'\nconnected' in subprocess.
+ sys.stderr.
+ out = subprocess.run(cmd, capture_
+ sys.stderr.
+ sys.stderr.flush()
+ if out.returncode == 8:
+ time.sleep(1)
+ continue
+ if '\nconnected' in str(out.stdout):
- time.sleep(0.1)
+ time.sleep(0.5)
```
OUTPUT:
slyon@ubuntu:~$ sudo snap set system system. network. netplan. network. bridges. br54.dhcp4= false
Run configure hook of "core" snap \
ITER
Run configure hook of "core" snap |
8:
Error: NetworkManager is not running.
Run configure hook of "core" snap –
ITER
Run configure hook of "core" snap /
0: STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN
disconnected none enabled enabled enabled enabled
Run configure hook of "core" snap –
ITER
Run configure hook of "core" snap \
0: STATE CONNECTIVITY WIFI-HW WIFI WWAN-HW WWAN
connected full enabled enabled enabled enabled
PS: launched `netplan-dbus` manually (to make the PATH & environment from my shell available) and patched the apply.py command to add debug output in a running core20 snap, by using `sudo mount -o bind apply.py /usr/share/ netplan/ netplan/ cli/commands/ apply.py`