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 <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Sunil Mohan Adapa 2020-07-21 16:30:56 -07:00 committed by Veiko Aasa
parent 2773c4737e
commit 866fa6cde3
No known key found for this signature in database
GPG Key ID: 478539CAE680674E

View File

@ -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',