Edward Haas has uploaded a new change for review.
Change subject: net: dhcp reporting based on dhclient daemon state
......................................................................
net: dhcp reporting based on dhclient daemon state
dhcp state has passed several changes in the reporting logic.
Started by checking leased entries, followed by checking the ip source
(static or dynamic).
Both solutions have linked the dhcp state to the IP address assigned.
This aproach has required some faking to be introduced, in order to
handle cases where the dhcp has been activated but the address took some
time to be assigned.
This patch introduces a new approach, decoupling dhcp from the ip
address.
The dhcp state is now checked against the dhclient daemon existance.
This patch also resolves dhcp6 false report.
An IPv6 address may be assigned dynamically through autoconf, previously
we have reported it as dhcp6 enabled.
Change-Id: I346b8d2d52a457a3cffd543a8da800edd53ce186
Signed-off-by: Edward Haas <edwardh(a)redhat.com>
---
M lib/vdsm/network/ip/dhclient.py
M lib/vdsm/network/netinfo/cache.py
M lib/vdsm/network/netinfo/dhcp.py
M lib/vdsm/network/ovs/info.py
M tests/functional/networkTests.py
M vdsm_hooks/ovs/ovs_after_get_caps.py
6 files changed, 18 insertions(+), 39 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/58/61458/1
diff --git a/lib/vdsm/network/ip/dhclient.py b/lib/vdsm/network/ip/dhclient.py
index 318217c..d69e70b 100644
--- a/lib/vdsm/network/ip/dhclient.py
+++ b/lib/vdsm/network/ip/dhclient.py
@@ -28,10 +28,10 @@
from vdsm import cmdutils
from vdsm.network import errors as ne
-from vdsm.network import netinfo
from vdsm.commands import execCmd
from vdsm.utils import CommandPath, memoized, pgrep, kill_and_rm_pid
+NET_PATH = '/sys/class/net'
DHCLIENT_BINARY = CommandPath('dhclient', '/sbin/dhclient')
DHCLIENT_CGROUP = 'vdsm-dhclient'
LEASE_DIR = '/var/lib/dhclient'
@@ -57,7 +57,7 @@
def _dhclient(self):
# Ask dhclient to stop any dhclient running for the device
- if os.path.exists(os.path.join(netinfo.NET_PATH, self.iface)):
+ if os.path.exists(os.path.join(NET_PATH, self.iface)):
kill(self.iface, self.family)
cmd = [DHCLIENT_BINARY.cmd, '-%s' % self.family, '-1',
'-pf',
self.pidFile, '-lf', self.leaseFile, self.iface]
diff --git a/lib/vdsm/network/netinfo/cache.py b/lib/vdsm/network/netinfo/cache.py
index e55f8f8..4df4026 100644
--- a/lib/vdsm/network/netinfo/cache.py
+++ b/lib/vdsm/network/netinfo/cache.py
@@ -28,6 +28,7 @@
from vdsm.network import libvirt
from vdsm.network import netinfo
from vdsm.network.ip.address import ipv6_supported
+from vdsm.network.ip import dhclient
from vdsm.network.ipwrapper import getLinks
from vdsm.network.netconfpersistence import RunningConfig
from vdsm.network.netlink import link as nl_link
@@ -35,7 +36,7 @@
from .addresses import getIpAddrs, getIpInfo, is_ipv6_local_auto
from . import bonding
from . import bridges
-from .dhcp import set_netdev_dhcp_info, dhcp_status, dhcp_faked_status
+from .dhcp import set_netdev_dhcp_info
from .dns import get_host_nameservers
from .mtus import getMtu
from . import nics
@@ -138,7 +139,8 @@
ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs = getIpInfo(
link.name, ipaddrs, gateway)
- is_dhcpv4, is_dhcpv6 = dhcp_status(link.name, ipaddrs)
+ is_dhcpv4 = dhclient.is_active(link.name, family=4)
+ is_dhcpv6 = dhclient.is_active(link.name, family=6)
return {'addr': ipv4addr,
'ipv4addrs': ipv4addrs,
@@ -186,7 +188,8 @@
ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs = getIpInfo(
iface, ipaddrs, gateway)
- is_dhcpv4, is_dhcpv6 = dhcp_faked_status(iface, ipaddrs, net_attrs)
+ is_dhcpv4 = dhclient.is_active(iface, family=4)
+ is_dhcpv6 = dhclient.is_active(iface, family=6)
data.update({'iface': iface, 'bridged': bridged,
'addr': ipv4addr, 'netmask': ipv4netmask,
diff --git a/lib/vdsm/network/netinfo/dhcp.py b/lib/vdsm/network/netinfo/dhcp.py
index 892f46b..efa7d8b 100644
--- a/lib/vdsm/network/netinfo/dhcp.py
+++ b/lib/vdsm/network/netinfo/dhcp.py
@@ -18,37 +18,12 @@
# Refer to the README and COPYING files for full details of the license
from __future__ import absolute_import
-from . import addresses
-
def set_netdev_dhcp_info(network_info, networking):
dev_info = _device_lookup(network_info['iface'], networking)
if dev_info:
dev_info['dhcpv4'] = network_info['dhcpv4']
dev_info['dhcpv6'] = network_info['dhcpv6']
-
-
-def dhcp_status(iface, ipaddrs):
- is_dhcpv4 = False
- is_dhcpv6 = False
- for ipaddr in ipaddrs[iface]:
- if addresses.is_ipv4(ipaddr):
- is_dhcpv4 |= addresses.is_dynamic(ipaddr)
- elif addresses.is_ipv6(ipaddr):
- is_dhcpv6 |= addresses.is_dynamic(ipaddr)
- return is_dhcpv4, is_dhcpv6
-
-
-def dhcp_faked_status(iface, ipaddrs, net_attrs):
- # If running config exists for this network, fake dhcp status
- # and report the request (not the actual)
- # Engine expects this behaviour.
- if net_attrs is None:
- is_dhcpv4, is_dhcpv6 = dhcp_status(iface, ipaddrs)
- else:
- is_dhcpv4 = (net_attrs.get('bootproto', None) == 'dhcp')
- is_dhcpv6 = net_attrs.get('dhcpv6', False)
- return is_dhcpv4, is_dhcpv6
def _device_lookup(netdev, networking):
diff --git a/lib/vdsm/network/ovs/info.py b/lib/vdsm/network/ovs/info.py
index f77d17b..4e604a8 100644
--- a/lib/vdsm/network/ovs/info.py
+++ b/lib/vdsm/network/ovs/info.py
@@ -20,9 +20,9 @@
import six
+from vdsm.network.ip import dhclient
from vdsm.network.netinfo.addresses import (
getIpAddrs, getIpInfo, is_ipv6_local_auto)
-from vdsm.network.netinfo.dhcp import dhcp_status
from vdsm.network.netinfo.mtus import getMtu
from vdsm.network.netinfo.routes import get_routes, get_gateway
from vdsm.utils import rget
@@ -328,7 +328,8 @@
ipv4gateway = get_gateway(routes, iface, family=4)
ipv4addr, ipv4netmask, ipv4addrs, ipv6addrs = getIpInfo(
iface, addresses, ipv4gateway)
- is_dhcpv4, is_dhcpv6 = dhcp_status(iface, addresses)
+ is_dhcpv4 = dhclient.is_active(iface, family=4)
+ is_dhcpv6 = dhclient.is_active(iface, family=6)
return {'mtu': getMtu(iface), 'addr': ipv4addr, 'ipv4addrs':
ipv4addrs,
'gateway': ipv4gateway, 'netmask': ipv4netmask,
diff --git a/tests/functional/networkTests.py b/tests/functional/networkTests.py
index c10a7cc..833e46f 100644
--- a/tests/functional/networkTests.py
+++ b/tests/functional/networkTests.py
@@ -30,6 +30,7 @@
import vdsm.config
from vdsm.constants import EXT_BRCTL, EXT_IFUP, EXT_IFDOWN
from vdsm.network import ipwrapper
+from vdsm.network.ip import dhclient
from vdsm.network.ipwrapper import (
routeExists, ruleExists, addrFlush, LinkType, getLinks, routeShowTable,
linkDel, linkSet, addrAdd)
@@ -2219,10 +2220,8 @@
client, family, dir, dateFormat)
try:
with running(dhclient_runner):
- _netinfo = vdsm.network.netinfo
- ipaddrs = _netinfo.addresses.getIpAddrs()
- is_dhcpv4, is_dhcpv6 = (
- _netinfo.dhcp.dhcp_status(client, ipaddrs))
+ is_dhcpv4 = dhclient.is_active(client, family=4)
+ is_dhcpv6 = dhclient.is_active(client, family=6)
except dhcp.ProcessCannotBeKilled:
raise SkipTest('dhclient could not be killed')
diff --git a/vdsm_hooks/ovs/ovs_after_get_caps.py b/vdsm_hooks/ovs/ovs_after_get_caps.py
index c626f13..ab50d16 100755
--- a/vdsm_hooks/ovs/ovs_after_get_caps.py
+++ b/vdsm_hooks/ovs/ovs_after_get_caps.py
@@ -21,9 +21,9 @@
import sys
import traceback
+from vdsm.network.ip import dhclient
from vdsm.network.netconfpersistence import RunningConfig
-from vdsm.network.netinfo import (dhcp, routes as netinfo_routes, addresses,
- mtus)
+from vdsm.network.netinfo import routes as netinfo_routes, addresses, mtus
from vdsm.network.netinfo.bonding import parse_bond_options
from hooking import execCmd
@@ -59,7 +59,8 @@
ipaddrs = addresses.getIpAddrs()
addr, netmask, ipv4addrs, ipv6addrs = addresses.getIpInfo(interface,
ipaddrs)
- dhcpv4, dhcpv6 = dhcp.dhcp_status(interface, ipaddrs)
+ dhcpv4 = dhclient.is_active(interface, family=4)
+ dhcpv6 = dhclient.is_active(interface, family=6)
gateway = netinfo_routes.get_gateway(routes, interface)
ipv6gateway = netinfo_routes.get_gateway(routes, interface, family=6)
--
To view, visit
https://gerrit.ovirt.org/61458
To unsubscribe, visit
https://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I346b8d2d52a457a3cffd543a8da800edd53ce186
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Edward Haas <edwardh(a)redhat.com>