Revision 803a1a54 util/vm/build.py

View differences:

util/vm/build.py
71 71
    'ubuntu-13.10-server-amd64.iso',
72 72
}
73 73

  
74
logStartTime = time()
74
LogStartTime = time()
75
LogFile = None
75 76

  
76 77
def log( *args, **kwargs ):
77 78
    """Simple log function: log( message along with local and elapsed time
78 79
       cr: False/0 for no CR"""
79 80
    cr = kwargs.get( 'cr', True )
80
    elapsed = time() - logStartTime
81
    elapsed = time() - LogStartTime
81 82
    clocktime = strftime( '%H:%M:%S', localtime() )
82 83
    msg = ' '.join( str( arg ) for arg in args )
83 84
    output = '%s [ %.3f ] %s' % ( clocktime, elapsed, msg )
......
85 86
        print output
86 87
    else:
87 88
        print output,
89
    # Optionally mirror to LogFile
90
    if type( LogFile ) is file:
91
        if cr:
92
            output += '\n'
93
        LogFile.write( output )
88 94

  
89 95

  
90 96
def run( cmd, **kwargs ):
......
350 356
    # Unmount iso and clean up
351 357
    srun( 'umount ' + mnt )
352 358
    run( 'rmdir ' + mnt )
359
    if vm.returncode != 0:
360
        raise Exception( 'Ubuntu installation returned error %d' %
361
                          vm.returncode )
353 362
    log( '* UBUNTU INSTALLATION COMPLETED FOR', image )
354 363
    log( '* Ubuntu installation completed in %.2f seconds ' % elapsed )
355 364

  
......
501 510

  
502 511
def build( flavor='raring32server' ):
503 512
    "Build a Mininet VM"
513
    global LogFile
504 514
    start = time()
505 515
    date = strftime( '%y%m%d-%H-%M-%S', localtime())
506 516
    dir = 'mn-%s-%s' % ( flavor, date )
......
509 519
    except:
510 520
        raise Exception( "Failed to create build directory %s" % dir )
511 521
    os.chdir( dir )
522
    LogFile = open( 'build.log', 'w' )
523
    log( '* Logging to ', abspath( LogFile.name ) )
512 524
    log( '* Created working directory', dir )
513 525
    image, kernel, initrd = findBaseImage( flavor )
514 526
    volume = flavor + '.qcow2'

Also available in: Unified diff