From edfc2c75fb681be4a9907f4ace49448f06cd4eab Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Wed, 19 Nov 2014 12:45:04 -0500 Subject: [PATCH] Improve error reporting in _get_my_ipv4_address() Provide more detailed error reporting when we cannot figure out what the IPv4 address of the server is. Change-Id: Ifac8a2109ae00c9c2624e03725f41b6052890f77 --- oslo/utils/netutils.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/oslo/utils/netutils.py b/oslo/utils/netutils.py index ecb8d7df..d054c666 100644 --- a/oslo/utils/netutils.py +++ b/oslo/utils/netutils.py @@ -139,9 +139,19 @@ def _get_my_ipv4_address(): gtw = netifaces.gateways() try: interface = gtw['default'][netifaces.AF_INET][1] + except (KeyError, IndexError): + LOG.info(_LI('Could not determine default network interface, ' + 'using 127.0.0.1 for IPv4 address')) + try: return netifaces.ifaddresses(interface)[netifaces.AF_INET][0]['addr'] - except Exception: - LOG.info(_LI("Couldn't get IPv4")) + except (KeyError, IndexError): + LOG.info(_LI('Could not determine IPv4 address for interface %s, ' + 'using 127.0.0.1'), + interface) + except Exception as e: + LOG.info(_LI('Could not determine IPv4 address for ' + 'interface %(interface)s: %(error)s'), + {'interface': interface, 'error': e}) return LOCALHOST