Set VM date based on host date.
This should fix #398 for real; note that if we try to shut down ntpd right at boot, it doesn't work! ;-( However, setting the Unix time in the traditional manner using seconds since 1970 should do the trick!
This commit is contained in:
+9
-10
@@ -487,17 +487,16 @@ def login( vm, user='mininet', password='mininet' ):
|
|||||||
log( '* Waiting for login...' )
|
log( '* Waiting for login...' )
|
||||||
|
|
||||||
|
|
||||||
def disableNtpd( vm, prompt=Prompt ):
|
def setClock( vm, prompt=Prompt ):
|
||||||
"Turn off ntpd and set clock immediately"
|
"Turn off ntpd and set clock immediately"
|
||||||
log( '* Turning off ntpd' )
|
log( '* Attempting to shut down ntpd' )
|
||||||
vm.sendline( 'sudo -n service ntp stop' )
|
vm.sendline( 'sudo -n service ntp stop' )
|
||||||
vm.expect( prompt )
|
vm.expect( prompt )
|
||||||
log( '* Setting clock' )
|
log( '* Getting seconds since epoch from this server' )
|
||||||
# -gq: set and quit immediately
|
# Note r'date +%s' specifies a format for 'date', not python!
|
||||||
vm.sendline( 'sudo -n ntpd -gq' )
|
seconds = int( run( r'date +%s' ) )
|
||||||
vm.expect( prompt )
|
log( '* Setting VM clock' )
|
||||||
log( '* Waiting one second and running date command' )
|
vm.sendline( 'sudo date -s @%d' % seconds )
|
||||||
vm.sendline( 'sleep 1 && date ' )
|
|
||||||
|
|
||||||
|
|
||||||
def sanityTest( vm ):
|
def sanityTest( vm ):
|
||||||
@@ -832,9 +831,9 @@ def build( flavor='raring32server', tests=None, pre='', post='', memory=1024 ):
|
|||||||
|
|
||||||
def runTests( vm, tests=None, pre='', post='', prompt=Prompt ):
|
def runTests( vm, tests=None, pre='', post='', prompt=Prompt ):
|
||||||
"Run tests (list) in vm (pexpect object)"
|
"Run tests (list) in vm (pexpect object)"
|
||||||
# We disable ntpd and set the time so that it won't be
|
# We disable ntpd and set the time so that ntpd won't be
|
||||||
# messing with the time during tests
|
# messing with the time during tests
|
||||||
disableNtpd( vm )
|
setClock( vm )
|
||||||
vm.expect( prompt )
|
vm.expect( prompt )
|
||||||
if Branch:
|
if Branch:
|
||||||
checkOutBranch( vm, branch=Branch )
|
checkOutBranch( vm, branch=Branch )
|
||||||
|
|||||||
Reference in New Issue
Block a user