Ido Barkan has uploaded a new change for review.
Change subject: net: simplify _get_gateway ......................................................................
net: simplify _get_gateway
Using the default value of _RT_TABLE_UNSPEC is meaningless since it can be any default value chosen by the writer of this function. None is more concise. It is also worth testing for none first since in most cases the default value is used. Also noted a few untested case for future work.
Change-Id: I6867576955a7769dd733e85a0ae3b4e111cdcb0b Signed-off-by: Ido Barkan ibarkan@redhat.com --- M lib/vdsm/netinfo.py M tests/netinfoTests.py 2 files changed, 6 insertions(+), 4 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/66/42966/1
diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py index 716c21a..81f2619 100644 --- a/lib/vdsm/netinfo.py +++ b/lib/vdsm/netinfo.py @@ -634,8 +634,7 @@ return addrs
-def _get_gateway(routes_by_dev, dev, family=4, - table=nl_route._RT_TABLE_UNSPEC): +def _get_gateway(routes_by_dev, dev, family=4, table=None): """ Return the default gateway for a device and an address family :param routes_by_dev: dictionary from device names to a list of routes. @@ -647,8 +646,7 @@ # currently from an IPv4 address) for each device so we have to look for # the gateway in all tables (RT_TABLE_UNSPEC), not just the 'main' one. gateways = [r for r in routes if r['destination'] == 'none' and - (r.get('table') == table or - table == nl_route._RT_TABLE_UNSPEC) and + (table is None or r.get('table') == table) and r['scope'] == 'global' and r['family'] == ('inet6' if family == 6 else 'inet') ] diff --git a/tests/netinfoTests.py b/tests/netinfoTests.py index 94bf924..0824d98 100644 --- a/tests/netinfoTests.py +++ b/tests/netinfoTests.py @@ -308,6 +308,10 @@ bonds.write('-' + bondName)
def test_get_gateway(self): + # TODO: test ipv6 gateway + # TODO: test more then one gateway + # TODO: test specific table + # TODO: test multiple gateway per device (error flow) TEST_IFACE = 'test_iface' # different tables but the gateway is the same so it should be reported DUPLICATED_GATEWAY = {TEST_IFACE: [
automation@ovirt.org has posted comments on this change.
Change subject: net: simplify _get_gateway ......................................................................
Patch Set 1:
* Update tracker::IGNORE, no Bug-Url found * Check Bug-Url::WARN, no bug url found, make sure header matches 'Bug-Url: ' and is a valid url. * Check merged to previous::IGNORE, Not in stable branch (['ovirt-3.5', 'ovirt-3.4', 'ovirt-3.3'])
Ido Barkan has posted comments on this change.
Change subject: net: simplify _get_gateway ......................................................................
Patch Set 1: Verified+1
Ido Barkan has abandoned this change.
Change subject: net: simplify _get_gateway ......................................................................
Abandoned
this incorrect
automation@ovirt.org has posted comments on this change.
Change subject: net: simplify _get_gateway ......................................................................
Patch Set 1:
* Update tracker::IGNORE, no Bug-Url found
vdsm-patches@lists.fedorahosted.org