Skip to content

Commit 4b94e8f

Browse files
hkhatebkhateh
authored andcommitted
Fix NetworkManagerSettings.get_connections_by_id not using the bus it was initialized with
The get_connections_by_id does not work properly with explicitly passed bus, and raises the following exception: settings_paths = await nm_settings.get_connections_by_id("eth0") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../networkmanager/objects.py", line 177, in get_connections_by_id settings_properties = await settings.get_settings() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File ".../dbus_proxy_async_method.py", line 108, in _dbus_async_call reply_message = await bus.call_async(call_message) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ sdbus.dbus_exceptions.DbusServiceUnknownError: The name org.freedesktop.NetworkManager was not provided by any .service files This exception was discovered with the following test code: import asyncio from sdbus import sd_bus_open_system from sdbus_async.networkmanager import NetworkManagerSettings async def test_get_connections_by_id(): system_bus = sd_bus_open_system() nm_settings = NetworkManagerSettings(system_bus) settings_paths = await nm_settings.get_connections_by_id("eth0") print(settings_paths) if __name__ == "__main__": asyncio.run(test_get_connections_by_id()) After this fix, the issue is resolved and get_connections_by_id works correctly without raising an exception.
1 parent ff0567f commit 4b94e8f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

sdbus_async/networkmanager/objects.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ def __init__(self, bus: Optional[SdBus] = None) -> None:
159159
NETWORK_MANAGER_SERVICE_NAME,
160160
'/org/freedesktop/NetworkManager/Settings',
161161
bus)
162+
self._nm_used_bus = bus
162163

163164
async def get_connections_by_id(self, connection_id: str) -> List[str]:
164165
"""Helper method to get a list of connection profile paths
@@ -171,7 +172,7 @@ async def get_connections_by_id(self, connection_id: str) -> List[str]:
171172
connection_paths_with_matching_id = []
172173
connection_paths: List[str] = await self.connections
173174
for connection_path in connection_paths:
174-
settings = NetworkConnectionSettings(connection_path)
175+
settings = NetworkConnectionSettings(connection_path, self._nm_used_bus)
175176
settings_properites = await settings.get_settings()
176177
# settings_properites["connection"]["id"][1] gives the id value:
177178
if settings_properites["connection"]["id"][1] == connection_id:

sdbus_block/networkmanager/objects.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ def __init__(self, bus: Optional[SdBus] = None) -> None:
154154
NETWORK_MANAGER_SERVICE_NAME,
155155
'/org/freedesktop/NetworkManager/Settings',
156156
bus)
157+
self._nm_used_bus = bus
157158

158159
def get_connections_by_id(self, connection_id: str) -> List[str]:
159160
"""Helper method to get a list of connection profile paths
@@ -165,7 +166,7 @@ def get_connections_by_id(self, connection_id: str) -> List[str]:
165166
"""
166167
connection_paths_with_matching_id = []
167168
for connection_path in self.connections:
168-
profile = NetworkConnectionSettings(connection_path)
169+
profile = NetworkConnectionSettings(connection_path, self._nm_used_bus)
169170
# profile.get_settings()["connection"]["id"][1] gives the id value:
170171
if profile.get_settings()["connection"]["id"][1] == connection_id:
171172
connection_paths_with_matching_id.append(connection_path)

0 commit comments

Comments
 (0)