Ondřej Svoboda has uploaded a new change for review.

Change subject: netinfo: rework reporting of DHCPv4/6 on network devices
......................................................................

netinfo: rework reporting of DHCPv4/6 on network devices

This patch addresses the same problem [1] as commit b92edb but
hopefully in a more readable way.

[1] DHCP still being reported for hours after a network got static
IP configuration, because reporting is based on dhclient's leases.

Change-Id: Iaffdc836f8f64ecdc0a7e37ef50c228032f99696
Bug-Url: https://bugzilla.redhat.com/1184497
Signed-off-by: Ondřej Svoboda <[email protected]>
---
M lib/vdsm/netinfo.py
1 file changed, 19 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/30/46430/1

diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py
index 1ca5c06..a2c0eab 100644
--- a/lib/vdsm/netinfo.py
+++ b/lib/vdsm/netinfo.py
@@ -481,10 +481,6 @@
     else:
         try:
             if family == 4:
-                # Read dhcpv4 from an associated network's reported information
-                if 'dhcpv4' in net_attrs:
-                    return net_attrs['dhcpv4']
-                # Read the same information from RunningConfig
                 return net_attrs['bootproto'] == 'dhcp'
             else:
                 return net_attrs['dhcpv6']
@@ -531,12 +527,20 @@
     return data
 
 
-def _netinfo_by_device(networks):
-    netinfo_by_device = {}
-    for net_attrs in networks.itervalues():
-        device = net_attrs['iface']
-        netinfo_by_device[device] = net_attrs
-    return netinfo_by_device
+def _update_reported_dhcp(net_attrs, netinfo):
+    """
+    Report DHCPv4/6 of a network's underlying device based on the network's
+    configuration, to fix bug #1184497 (DHCP still being reported for hours
+    after a network got static IP configuration, because reporting is based on
+    dhclient's leases).
+    """
+    underlying_device = net_attrs['iface']
+    for devices in ('bridges', 'vlans', 'bondings', 'nics'):
+        devinfo = netinfo[devices].get(underlying_device)
+        if devinfo:
+            devinfo['dhcpv4'] = net_attrs['dhcpv4']
+            devinfo['dhcpv6'] = net_attrs['dhcpv6']
+            break
 
 
 def _bridgeinfo(link):
@@ -577,7 +581,7 @@
     return {'iface': link.device, 'vlanid': link.vlanid}
 
 
-def _devinfo(link, routes, ipaddrs, dhcpv4_ifaces, dhcpv6_ifaces, net_attrs):
+def _devinfo(link, routes, ipaddrs, dhcpv4_ifaces, dhcpv6_ifaces):
     gateway = _get_gateway(routes, link.name)
     ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs = getIpInfo(
         link.name, ipaddrs, gateway)
@@ -587,9 +591,8 @@
             'ipv6addrs': ipv6addrs,
             'gateway': gateway,
             'ipv6gateway': _get_gateway(routes, link.name, family=6),
-            'dhcpv4': _dhcp_used(link.name, dhcpv4_ifaces, net_attrs),
-            'dhcpv6': _dhcp_used(link.name, dhcpv6_ifaces, net_attrs,
-                                 family=6),
+            'dhcpv4': link.name in dhcpv4_ifaces,  # to be refined if a network
+            'dhcpv6': link.name in dhcpv6_ifaces,  # is not configured for DHCP
             'mtu': str(link.mtu),
             'netmask': ipv4netmask}
     if 'BOOTPROTO' not in info['cfg']:
@@ -784,8 +787,6 @@
     else:
         d['networks'] = vdsmnets
 
-    netinfo_by_device = _netinfo_by_device(d['networks'])
-
     for dev in (link for link in getLinks() if not link.isHidden()):
         if dev.isBRIDGE():
             devinfo = d['bridges'][dev.name] = _bridgeinfo(dev)
@@ -798,8 +799,7 @@
         else:
             continue
         devinfo.update(_devinfo(dev, routes, ipaddrs, dhcpv4_ifaces,
-                                dhcpv6_ifaces,
-                                netinfo_by_device.get(dev.name, None)))
+                                dhcpv6_ifaces))
         if dev.isBOND():
             _bondOptsCompat(devinfo)
             _bondCustomOpts(dev, devinfo, running_config)
@@ -807,6 +807,7 @@
     for net, attrs in d['networks'].iteritems():
         if attrs['bridged']:
             attrs['cfg'] = d['bridges'][net]['cfg']
+            _update_reported_dhcp(attrs, d)
 
     return d
 


-- 
To view, visit https://gerrit.ovirt.org/46430
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaffdc836f8f64ecdc0a7e37ef50c228032f99696
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Ondřej Svoboda <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to