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:
parent
5995b1e056
commit
19beb9d339
1 changed files with 14 additions and 7 deletions
|
|
@ -91,16 +91,23 @@ class NatPort(object):
|
||||||
self._upnp = None
|
self._upnp = None
|
||||||
|
|
||||||
def _discover(self):
|
def _discover(self):
|
||||||
devices = self._upnp.discover()
|
try:
|
||||||
if devices:
|
devices = self._upnp.discover()
|
||||||
|
if not devices:
|
||||||
|
raise exceptions.NotFound()
|
||||||
log.info("{nb} UPnP-IGD device(s) found".format(nb=devices))
|
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")
|
log.info("Can't find UPnP-IGD device on the local network")
|
||||||
raise failure.Failure(exceptions.NotFound())
|
raise failure.Failure(exceptions.NotFound())
|
||||||
self._upnp.selectigd()
|
except Exception as e:
|
||||||
try:
|
# the miniupnpc binding raises Exception("Success") when no device is found,
|
||||||
self._external_ip = self._upnp.externalipaddress()
|
# instead of returning 0
|
||||||
except Exception:
|
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())
|
raise failure.Failure(exceptions.FeatureNotFound())
|
||||||
|
|
||||||
def get_ip(self, local=False):
|
def get_ip(self, local=False):
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue