Antoni Segura Puimedon has uploaded a new change for review. Change subject: Fix multiple default gateways reporting ......................................................................
Fix multiple default gateways reporting Up until now there was just a default gateway per host, defining default as going towards 0.0.0.0/0. If more than one device received a default gateway setting, only the latest to be configured kept its configuration as host default configuration. Now, thanks to multiple gateways, we have a routing table for each network, which allows us to have multiple default gateways to report. The only issue is that /proc/net/route only reports information for table 254, while we are using several. For this reason, we change the implementation to use ipwrapper to get the information from all the tables. Change-Id: Iacd6328a938b955a63bbc0d5c0fb9bfcc7de6d44 Signed-off-by: Antoni S. Puimedon <[email protected]> --- R lib/vdsm/ipwrapper.py M lib/vdsm/netinfo.py M tests/ipwrapperTests.py M vdsm.spec.in M vdsm/Makefile.am M vdsm/netconf/iproute2.py M vdsm/sourceRoute.py 7 files changed, 26 insertions(+), 31 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/90/15890/1 diff --git a/vdsm/ipwrapper.py b/lib/vdsm/ipwrapper.py similarity index 97% rename from vdsm/ipwrapper.py rename to lib/vdsm/ipwrapper.py index 4ccffb7..5b89a0d 100644 --- a/vdsm/ipwrapper.py +++ b/lib/vdsm/ipwrapper.py @@ -194,6 +194,12 @@ return _execCmd(command) +def routeShowAllDefaultGateways(): + command = [_IP_BINARY.cmd, 'route', 'show', 'to', '0.0.0.0/0', 'table', + 'all'] + return _execCmd(command) + + def routeShowTable(table): command = [_IP_BINARY.cmd, 'route', 'show', 'table', table] return _execCmd(command) diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py index 964d30d..71e8495 100644 --- a/lib/vdsm/netinfo.py +++ b/lib/vdsm/netinfo.py @@ -30,10 +30,11 @@ from xml.dom import minidom from itertools import chain -import libvirtconnection - -import constants from config import config +from ipwrapper import Route +from ipwrapper import routeShowAllDefaultGateways +import constants +import libvirtconnection NET_CONF_DIR = '/etc/sysconfig/network-scripts/' NET_CONF_BACK_DIR = constants.P_VDSM_LIB + 'netconfback/' @@ -277,21 +278,10 @@ def getRoutes(): - """Return the interface default gateway or None if not found.""" - - gateways = dict() - - with open("/proc/net/route") as route_file: - route_file.readline() # skip header line - - for route_line in route_file.xreadlines(): - route_parm = route_line.rstrip().split('\t') - - if route_parm[1] == '00000000' and route_parm[2] != '00000000': - ip_num = int(route_parm[2], 16) - gateways[route_parm[0]] = intToAddress(ip_num) - - return gateways + """Return the default gateway for each interface that has one.""" + default_routes = (Route.fromText(text) for text in + routeShowAllDefaultGateways) + return dict((route.device, route.ipaddr) for route in default_routes) def ipv6StrToAddress(ipv6_str): diff --git a/tests/ipwrapperTests.py b/tests/ipwrapperTests.py index 0c5978e..36a1ee1 100644 --- a/tests/ipwrapperTests.py +++ b/tests/ipwrapperTests.py @@ -18,8 +18,8 @@ # Refer to the README and COPYING files for full details of the license # -from ipwrapper import Route -from ipwrapper import Rule +from vdsm.ipwrapper import Route +from vdsm.ipwrapper import Rule from testrunner import VdsmTestCase as TestCaseBase diff --git a/vdsm.spec.in b/vdsm.spec.in index af88828..ff1feb4 100644 --- a/vdsm.spec.in +++ b/vdsm.spec.in @@ -779,7 +779,6 @@ %{_datadir}/%{vdsm_name}/API.py* %{_datadir}/%{vdsm_name}/hooking.py* %{_datadir}/%{vdsm_name}/hooks.py* -%{_datadir}/%{vdsm_name}/ipwrapper.py* %{_datadir}/%{vdsm_name}/lsblk.py* %{_datadir}/%{vdsm_name}/md_utils.py* %{_datadir}/%{vdsm_name}/mk_sysprep_floppy @@ -976,6 +975,7 @@ %{python_sitearch}/%{vdsm_name}/constants.py* %{python_sitearch}/%{vdsm_name}/define.py* %{python_sitearch}/%{vdsm_name}/exception.py* +%{python_sitearch}/%{vdsm_name}/ipwrapper.py* %{python_sitearch}/%{vdsm_name}/libvirtconnection.py* %{python_sitearch}/%{vdsm_name}/netinfo.py* %{python_sitearch}/%{vdsm_name}/qemuImg.py* diff --git a/vdsm/Makefile.am b/vdsm/Makefile.am index 4016be5..0ccf417 100644 --- a/vdsm/Makefile.am +++ b/vdsm/Makefile.am @@ -35,7 +35,6 @@ guestIF.py \ hooking.py \ hooks.py \ - ipwrapper.py \ kaxmlrpclib.py \ ksm.py \ logUtils.py \ diff --git a/vdsm/netconf/iproute2.py b/vdsm/netconf/iproute2.py index ce668ab..f4de146 100644 --- a/vdsm/netconf/iproute2.py +++ b/vdsm/netconf/iproute2.py @@ -18,10 +18,10 @@ # -from ipwrapper import routeAdd -from ipwrapper import routeDel -from ipwrapper import ruleAdd -from ipwrapper import ruleDel +from vdsm.ipwrapper import routeAdd +from vdsm.ipwrapper import routeDel +from vdsm.ipwrapper import ruleAdd +from vdsm.ipwrapper import ruleDel class Iproute2(object): diff --git a/vdsm/sourceRoute.py b/vdsm/sourceRoute.py index 83d7279..524c9a7 100644 --- a/vdsm/sourceRoute.py +++ b/vdsm/sourceRoute.py @@ -24,11 +24,11 @@ from netconf.ifcfg import Ifcfg, ConfigWriter from netconf.iproute2 import Iproute2 from vdsm import netinfo -from ipwrapper import Route -from ipwrapper import routeShowTable -from ipwrapper import routeLinkNetForDevice -from ipwrapper import Rule -from ipwrapper import ruleList +from vdsm.ipwrapper import Route +from vdsm.ipwrapper import routeLinkNetForDevice +from vdsm.ipwrapper import routeShowTable +from vdsm.ipwrapper import Rule +from vdsm.ipwrapper import ruleList class SourceRoute(object): -- To view, visit http://gerrit.ovirt.org/15890 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iacd6328a938b955a63bbc0d5c0fb9bfcc7de6d44 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Antoni Segura Puimedon <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
