Ondřej Svoboda has uploaded a new change for review.
Change subject: netinfo: Do not mix local and universal time, improve tests ......................................................................
netinfo: Do not mix local and universal time, improve tests
Also go back to using dhclient's --bind-interfaces option to stay compatible with RHEL 6.
Change-Id: I1b2a33209b45001c427d5712d57326394cbeb9d0 Bug-Url: https://bugzilla.redhat.com/987813 Signed-off-by: Ondřej Svoboda osvoboda@redhat.com --- M lib/vdsm/netinfo.py M tests/functional/dhcp.py M tests/functional/networkTests.py M tests/netinfoTests.py 4 files changed, 37 insertions(+), 21 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/92/24192/1
diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py index 98e2462..dbacb2f 100644 --- a/lib/vdsm/netinfo.py +++ b/lib/vdsm/netinfo.py @@ -557,7 +557,7 @@
if expiryTime.startswith(EPOCH): since_epoch = expiryTime[len(EPOCH):] - return datetime.fromtimestamp(float(since_epoch)) + return datetime.utcfromtimestamp(float(since_epoch))
else: return datetime.strptime(expiryTime, '%w %Y/%m/%d %H:%M:%S') @@ -583,7 +583,7 @@ continue # the line should always contain a ;
expiryTime = _parseExpiryTime(line[len(EXPIRE):end]) - if datetime.now() > expiryTime: + if datetime.utcnow() > expiryTime: insideLease = False continue
diff --git a/tests/functional/dhcp.py b/tests/functional/dhcp.py index 717b80a..3bd200a 100644 --- a/tests/functional/dhcp.py +++ b/tests/functional/dhcp.py @@ -26,7 +26,8 @@ from time import sleep
_DNSMASQ_BINARY = CommandPath('dnsmasq', '/usr/sbin/dnsmasq') -_DHCLIENT_BINARY = CommandPath('dhclient', '/usr/sbin/dhclient') +_DHCLIENT_BINARY = CommandPath('dhclient', '/usr/sbin/dhclient', + '/sbin/dhclient') _NM_CLI_BINARY = CommandPath('nmcli', '/usr/bin/nmcli') _START_CHECK_TIMEOUT = 0.5 _DHCLIENT_TIMEOUT = 10 @@ -48,7 +49,7 @@ '-p', '0', '--dhcp-range=' + dhcpRangeFrom + ',' + dhcpRangeTo + ',2m', '--dhcp-option=3', '-k', '-i', interface, '-I', 'lo', '-d', - '--bind-dynamic'], sync=False) + '--bind-interfaces'], sync=False) sleep(_START_CHECK_TIMEOUT) if self.proc.returncode: raise DhcpError('Failed to start dnsmasq DHCP server.' + @@ -59,11 +60,11 @@ logging.debug(''.join(self.proc.stderr))
-def runDhclient(interface, leaseFile, pidFile): +def runDhclient(interface, confFile, leaseFile, pidFile): """Starts dhclient and hands the process over after a while.""" rc, out, err = execCmd([_DHCLIENT_BINARY.cmd, '-d', '-lf', leaseFile, '-pf', pidFile, '-timeout', str(_DHCLIENT_TIMEOUT), - '-1', interface]) + '-1', '-cf', confFile, interface])
if rc: # == 2 logging.debug(''.join(err)) diff --git a/tests/functional/networkTests.py b/tests/functional/networkTests.py index 5484e99..d493192 100644 --- a/tests/functional/networkTests.py +++ b/tests/functional/networkTests.py @@ -1686,10 +1686,11 @@ self.assertEqual(status, SUCCESS, msg) self.assertNetworkDoesntExist(NETWORK_NAME)
+ @permutations([['default'], ['local']]) @cleanupNet @RequireVethMod @ValidateRunningAsRoot - def testDhclientLeases(self): + def testDhclientLeases(self, dateFormat=False): dhcp4 = set() with vethIf() as (server, client): with avoidAnotherDhclient(client): @@ -1700,10 +1701,14 @@ with dnsmasqDhcp(server):
with namedTemporaryDir(dir='/var/lib/dhclient') as tmpDir: + confFile = os.path.join(tmpDir, 'test.conf') leaseFile = os.path.join(tmpDir, 'test.lease') pidFile = os.path.join(tmpDir, 'test.pid')
- dhcp.runDhclient(client, leaseFile, pidFile) + with open(confFile, 'w') as f: + f.write('db-time-format {0};'.format(dateFormat)) + + dhcp.runDhclient(client, confFile, leaseFile, pidFile) dhcp4 = getDhclientIfaces([leaseFile])
self.assertIn(client, dhcp4, 'Test iface not found in a lease file.') diff --git a/tests/netinfoTests.py b/tests/netinfoTests.py index cfdf107..4ad79dc 100644 --- a/tests/netinfoTests.py +++ b/tests/netinfoTests.py @@ -19,9 +19,11 @@ # Refer to the README and COPYING files for full details of the license # import os +from datetime import datetime from functools import partial from shutil import rmtree import tempfile +import time from xml.dom import minidom
import ethtool @@ -295,28 +297,36 @@
def testGetDhclientIfaces(self): LEASES = ( - 'lease {\n' + 'lease {{\n' ' interface "valid";\n' - ' expire 3 2037/01/29 18:25:46;\n' - '}\n' - 'lease {\n' + ' expire {0:%w %Y/%m/%d %H:%M:%S};\n' + '}}\n' + 'lease {{\n' ' interface "valid2";\n' - ' expire epoch 2117041460; # Sat Jan 31 20:04:20 2037\n' - '}\n' - 'lease {\n' + ' expire epoch {1:.0f};\n' + '}}\n' + 'lease {{\n' ' interface "expired";\n' - ' expire 3 2014/01/29 18:25:46;\n' - '}\n' - 'lease {\n' + ' expire {2:%w %Y/%m/%d %H:%M:%S};\n' + '}}\n' + 'lease {{\n' ' interface "expired2";\n' - ' expire epoch 1391195060; # Fri Jan 31 20:04:20 2014\n' - '}\n' + ' expire epoch {3:.0f};\n' + '}}\n' )
with namedTemporaryDir() as tmpDir: leaseFile = os.path.join(tmpDir, 'test.lease') with open(leaseFile, 'w') as f: - f.write(LEASES) + lastMinute = time.time() - 60 + nextMinute = time.time() + 60 + + f.write(LEASES.format( + datetime.utcfromtimestamp(nextMinute), + nextMinute, + datetime.utcfromtimestamp(lastMinute), + lastMinute + ))
dhcp4 = getDhclientIfaces([leaseFile])