From 2aeed38ea5574ae8d12df6bb0c32aea3942f53e5 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 13 Jun 2018 20:01:41 +0200 Subject: [PATCH] Disable predictable network interface names to avoid cases where devices don't reboot properly because interface name changed... --- .../0003_migrate_to_stretch.py | 20 +++++++++++++++++++ src/yunohost/utils/network.py | 6 +++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/yunohost/data_migrations/0003_migrate_to_stretch.py b/src/yunohost/data_migrations/0003_migrate_to_stretch.py index 8b8d37447..105480241 100644 --- a/src/yunohost/data_migrations/0003_migrate_to_stretch.py +++ b/src/yunohost/data_migrations/0003_migrate_to_stretch.py @@ -15,6 +15,7 @@ from yunohost.service import (_run_service_command, manually_modified_files_compared_to_debian_default) from yunohost.utils.filesystem import free_space_in_directory from yunohost.utils.packages import get_installed_version +from yunohost.utils.network import get_network_interfaces logger = getActionLogger('yunohost.migration') @@ -68,6 +69,8 @@ class MyMigration(Migration): self.apt_dist_upgrade(conf_flags=["new", "miss", "def"]) _run_service_command("restart", "fail2ban") + self.disable_predicable_interface_names() + # Clean the mess os.system("apt autoremove --assume-yes") os.system("apt clean --assume-yes") @@ -352,3 +355,20 @@ class MyMigration(Migration): # command showing in the terminal, since 'info' channel is only # enabled if the user explicitly add --verbose ... os.system(command) + + def disable_predicable_interface_names(self): + + # Try to see if currently used interface names are predictable ones or not... + # If we ain't using "eth0" or "wlan0", assume we are using predictable interface + # names and therefore they shouldnt be disabled + network_interfaces = get_network_interfaces().keys() + if "eth0" not in network_interfaces and "wlan0" not in network_interfaces: + return + + interfaces_config = read_file("/etc/network/interfaces") + if "eth0" not in interfaces_config and "wlan0" not in interfaces_config: + return + + # Disable predictive interface names + # c.f. https://unix.stackexchange.com/a/338730 + os.system("ln -s /dev/null /etc/systemd/network/99-default.link") diff --git a/src/yunohost/utils/network.py b/src/yunohost/utils/network.py index 470354f63..dec0384bf 100644 --- a/src/yunohost/utils/network.py +++ b/src/yunohost/utils/network.py @@ -56,7 +56,7 @@ def get_network_interfaces(): # Parse relevant informations for each of them devices = {name: _extract_inet(addrs) for name, addrs in devices_raw.items() if name != "lo"} - return devices or "unknown" + return devices def get_gateway(): @@ -64,10 +64,10 @@ def get_gateway(): output = subprocess.check_output('ip route show'.split()) m = re.search('default via (.*) dev ([a-z]+[0-9]?)', output) if not m: - return "unknown" + return None addr = _extract_inet(m.group(1), True) - return addr.popitem()[1] if len(addr) == 1 else "unknown" + return addr.popitem()[1] if len(addr) == 1 else None ###############################################################################