plugin NAT Port: fix errors handling:

`miniupnpc` raises `Exception("Success")` when no device is found
(instead of returning 0), which was resulting in an exception breaking workflows in
Libervia.

The code now catches unexpected exceptions, and handles `Exception("Success")` as "no
device found".
This commit is contained in:
Goffi 2026-10-19 12:54:21 +02:00
commit 19beb9d339

View file

@ -91,16 +91,23 @@ class NatPort(object):
self._upnp = None
def _discover(self):
devices = self._upnp.discover()
if devices:
try:
devices = self._upnp.discover()
if not devices:
raise exceptions.NotFound()
log.info("{nb} UPnP-IGD device(s) found".format(nb=devices))
else:
self._upnp.selectigd()
self._external_ip = self._upnp.externalipaddress()
except exceptions.NotFound:
log.info("Can't find UPnP-IGD device on the local network")
raise failure.Failure(exceptions.NotFound())
self._upnp.selectigd()
try:
self._external_ip = self._upnp.externalipaddress()
except Exception:
except Exception as e:
# the miniupnpc binding raises Exception("Success") when no device is found,
# instead of returning 0
if str(e) == "Success":
log.info("Can't find UPnP-IGD device on the local network")
raise failure.Failure(exceptions.NotFound())
log.warning(f"UPnP-IGD discovery error: {e!r}")
raise failure.Failure(exceptions.FeatureNotFound())
def get_ip(self, local=False):