From 866fa6cde3b3493db4d7ee4811940ae82e04da51 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Tue, 21 Jul 2020 16:30:56 -0700 Subject: [PATCH] container: unstable: Handle interface naming for systemd < 245 systemd-nspawn versions < 245 seem to truncate the interface name from 've-fbx-unstable' to 've-fbx-unstabl'. See: - https://github.com/systemd/systemd/pull/12865 - https://salsa.debian.org/freedombox-team/freedombox/-/merge_requests/1856 Tests: - On Debian Buster with systemd version 241, start testing and unstable containers. For testing the interface name is ve-fbx-testing and for unstable it is ve-fbx-unstabl. The containers are brought up and provisioned successfully. Running 'nmcli c show fbx-${distribution}-shared' shows the correct interface name assigned. Signed-off-by: Sunil Mohan Adapa Reviewed-by: Veiko Aasa --- container | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/container b/container index 429d6c5c2..5c0f8e2e1 100755 --- a/container +++ b/container @@ -451,6 +451,18 @@ def _runc(image_file, command, **kwargs): **kwargs) +def _get_interface_name(distribution): + """Return the name of the interface.""" + interface = f've-fbx-{distribution}' + process = subprocess.run(['systemd-nspawn', '--version'], + stdout=subprocess.PIPE, check=True) + version = process.stdout.decode().splitlines()[0].split()[1] + if int(float(version)) < 245: + return interface[:14] + + return interface + + def _setup_nm_connection(distribution): """Create a network manager conn. on host for DHCP/DNS with container.""" connection_name = f'fbx-{distribution}-shared' @@ -465,7 +477,7 @@ def _setup_nm_connection(distribution): properties = { 'connection.id': connection_name, 'connection.type': '802-3-ethernet', - 'connection.interface-name': f've-fbx-{distribution}', + 'connection.interface-name': _get_interface_name(distribution), 'connection.autoconnect': 'yes', 'ipv4.method': 'shared', } @@ -757,7 +769,7 @@ def _get_ssh_command(ip_address, distribution): """Exec an SSH command.""" public_key = work_directory / 'ssh' / 'id_ed25519' if ipaddress.ip_address(ip_address).is_link_local: - ip_address = f'{ip_address}%ve-fbx-{distribution}' + ip_address = f'{ip_address}%' + _get_interface_name(distribution) return [ 'ssh', '-i',