Fix network vlan api (#3865)

This commit is contained in:
Mike Degatano 2022-09-13 15:23:13 -04:00 committed by GitHub
parent 5f98ab7e3e
commit b8249548ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 3 deletions

View File

@ -196,12 +196,14 @@ class APINetwork(CoreSysAttributes):
for key, config in body.items():
if key == ATTR_IPV4:
interface.ipv4 = attr.evolve(
interface.ipv4 or IpConfig(InterfaceMethod.STATIC, [], None, []),
interface.ipv4
or IpConfig(InterfaceMethod.STATIC, [], None, [], None),
**config,
)
elif key == ATTR_IPV6:
interface.ipv6 = attr.evolve(
interface.ipv6 or IpConfig(InterfaceMethod.STATIC, [], None, []),
interface.ipv6
or IpConfig(InterfaceMethod.STATIC, [], None, [], None),
**config,
)
elif key == ATTR_WIFI:
@ -259,6 +261,7 @@ class APINetwork(CoreSysAttributes):
body[ATTR_IPV4].get(ATTR_ADDRESS, []),
body[ATTR_IPV4].get(ATTR_GATEWAY, None),
body[ATTR_IPV4].get(ATTR_NAMESERVERS, []),
None,
)
ipv6_config = None
@ -268,6 +271,7 @@ class APINetwork(CoreSysAttributes):
body[ATTR_IPV6].get(ATTR_ADDRESS, []),
body[ATTR_IPV6].get(ATTR_GATEWAY, None),
body[ATTR_IPV6].get(ATTR_NAMESERVERS, []),
None,
)
vlan_interface = Interface(

View File

@ -301,7 +301,7 @@ class IpConfig:
address: list[IPv4Interface | IPv6Interface] = attr.ib()
gateway: IPv4Address | IPv6Address | None = attr.ib()
nameservers: list[IPv4Address | IPv6Address] = attr.ib()
ready: bool = attr.ib()
ready: bool | None = attr.ib()
@attr.s(slots=True)

View File

@ -214,3 +214,17 @@ async def test_api_network_reload(api_client, coresys, dbus: list[str]):
"/org/freedesktop/NetworkManager-org.freedesktop.NetworkManager.CheckConnectivity"
in dbus
)
async def test_api_network_vlan(api_client, coresys: CoreSys, dbus: list[str]):
"""Test creating a vlan."""
dbus.clear()
resp = await api_client.post(
f"/network/interface/{TEST_INTERFACE}/vlan/1", json={"ipv4": {"method": "auto"}}
)
result = await resp.json()
assert result["result"] == "ok"
assert (
"/org/freedesktop/NetworkManager/Settings-org.freedesktop.NetworkManager.Settings.AddConnection"
in dbus
)