Use persistent MAC address instead clone / don't touch default (#2317)

This commit is contained in:
Pascal Vizeli 2020-12-01 09:27:49 +01:00 committed by GitHub
parent 2d294f6841
commit fb4386a7ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 9 deletions

View File

@ -32,6 +32,7 @@ class ConnectionProperties:
id: Optional[str] = attr.ib() id: Optional[str] = attr.ib()
uuid: Optional[str] = attr.ib() uuid: Optional[str] = attr.ib()
type: Optional[str] = attr.ib() type: Optional[str] = attr.ib()
interface_name: Optional[str] = attr.ib()
@attr.s(slots=True) @attr.s(slots=True)

View File

@ -31,6 +31,7 @@ ATTR_ASSIGNED_MAC = "assigned-mac-address"
ATTR_POWERSAVE = "powersave" ATTR_POWERSAVE = "powersave"
ATTR_AUTH_ALGO = "auth-algo" ATTR_AUTH_ALGO = "auth-algo"
ATTR_KEY_MGMT = "key-mgmt" ATTR_KEY_MGMT = "key-mgmt"
ATTR_INTERFACE_NAME = "interface-name"
class NetworkSetting(DBusInterfaceProxy): class NetworkSetting(DBusInterfaceProxy):
@ -109,6 +110,7 @@ class NetworkSetting(DBusInterfaceProxy):
data[CONF_ATTR_CONNECTION].get(ATTR_ID), data[CONF_ATTR_CONNECTION].get(ATTR_ID),
data[CONF_ATTR_CONNECTION].get(ATTR_UUID), data[CONF_ATTR_CONNECTION].get(ATTR_UUID),
data[CONF_ATTR_CONNECTION].get(ATTR_TYPE), data[CONF_ATTR_CONNECTION].get(ATTR_TYPE),
data[CONF_ATTR_CONNECTION].get(ATTR_INTERFACE_NAME),
) )
if CONF_ATTR_802_ETHERNET in data: if CONF_ATTR_802_ETHERNET in data:

View File

@ -61,7 +61,7 @@
, ,
'802-3-ethernet': '802-3-ethernet':
{ {
'assigned-mac-address': <'stable'> 'assigned-mac-address': <'preserve'>
} }
{% endif %} {% endif %}
@ -78,7 +78,7 @@
, ,
'802-11-wireless': '802-11-wireless':
{ {
'assigned-mac-address': <'stable'>, 'assigned-mac-address': <'preserve'>,
'ssid': <[byte {{ interface.wifi.ssid }}]>, 'ssid': <[byte {{ interface.wifi.ssid }}]>,
'mode': <'{{ interface.wifi.mode.value }}'>, 'mode': <'{{ interface.wifi.mode.value }}'>,
'powersave': <uint32 1> 'powersave': <uint32 1>

View File

@ -111,7 +111,12 @@ class NetworkManager(CoreSysAttributes):
inet = self.sys_dbus.network.interfaces.get(interface.name) inet = self.sys_dbus.network.interfaces.get(interface.name)
# Update exist configuration # Update exist configuration
if inet and inet.settings and interface.enabled: if (
inet
and inet.settings
and inet.settings.connection.interface_name == interface.name
and interface.enabled
):
settings = interface_update_payload( settings = interface_update_payload(
interface, interface,
name=inet.settings.connection.id, name=inet.settings.connection.id,
@ -279,7 +284,7 @@ class Interface:
inet.connection.ipv4.nameservers, inet.connection.ipv4.nameservers,
) )
if inet.connection and inet.connection.ipv4 if inet.connection and inet.connection.ipv4
else None, else IpConfig(InterfaceMethod.DISABLED, [], None, []),
IpConfig( IpConfig(
Interface._map_nm_method(inet.settings.ipv6.method), Interface._map_nm_method(inet.settings.ipv6.method),
inet.connection.ipv6.address, inet.connection.ipv6.address,
@ -287,7 +292,7 @@ class Interface:
inet.connection.ipv6.nameservers, inet.connection.ipv6.nameservers,
) )
if inet.connection and inet.connection.ipv6 if inet.connection and inet.connection.ipv6
else None, else IpConfig(InterfaceMethod.DISABLED, [], None, []),
Interface._map_nm_wifi(inet), Interface._map_nm_wifi(inet),
Interface._map_nm_vlan(inet), Interface._map_nm_vlan(inet),
) )

View File

@ -26,8 +26,18 @@ async def test_api_network_info(api_client, coresys):
assert interface["ipv4"]["gateway"] == "192.168.2.1" assert interface["ipv4"]["gateway"] == "192.168.2.1"
if interface["interface"] == TEST_INTERFACE_WLAN: if interface["interface"] == TEST_INTERFACE_WLAN:
assert not interface["primary"] assert not interface["primary"]
assert interface["ipv4"] is None assert interface["ipv4"] == {
assert interface["ipv6"] is None "address": [],
"gateway": None,
"method": "disabled",
"nameservers": [],
}
assert interface["ipv6"] == {
"address": [],
"gateway": None,
"method": "disabled",
"nameservers": [],
}
assert result["data"]["docker"]["interface"] == DOCKER_NETWORK assert result["data"]["docker"]["interface"] == DOCKER_NETWORK
assert result["data"]["docker"]["address"] == str(DOCKER_NETWORK_MASK) assert result["data"]["docker"]["address"] == str(DOCKER_NETWORK_MASK)

View File

@ -21,7 +21,8 @@ async def test_interface_update_payload_ethernet(coresys):
assert DBus.parse_gvariant(data)["ipv6"]["method"] == "auto" assert DBus.parse_gvariant(data)["ipv6"]["method"] == "auto"
assert ( assert (
DBus.parse_gvariant(data)["802-3-ethernet"]["assigned-mac-address"] == "stable" DBus.parse_gvariant(data)["802-3-ethernet"]["assigned-mac-address"]
== "preserve"
) )
assert DBus.parse_gvariant(data)["connection"]["mdns"] == 2 assert DBus.parse_gvariant(data)["connection"]["mdns"] == 2
@ -243,7 +244,8 @@ async def test_interface_update_payload_wireless_open(coresys):
assert DBus.parse_gvariant(data)["802-11-wireless"]["ssid"] == [84, 101, 115, 116] assert DBus.parse_gvariant(data)["802-11-wireless"]["ssid"] == [84, 101, 115, 116]
assert DBus.parse_gvariant(data)["802-11-wireless"]["mode"] == "infrastructure" assert DBus.parse_gvariant(data)["802-11-wireless"]["mode"] == "infrastructure"
assert ( assert (
DBus.parse_gvariant(data)["802-11-wireless"]["assigned-mac-address"] == "stable" DBus.parse_gvariant(data)["802-11-wireless"]["assigned-mac-address"]
== "preserve"
) )
assert "802-11-wireless-security" not in DBus.parse_gvariant(data) assert "802-11-wireless-security" not in DBus.parse_gvariant(data)