Revision fce7f5c5

View differences:

util/vm/build.py
52 52
SaveQCOW2 = False           # Save QCOW2 image rather than deleting it
53 53
NoKVM = False               # Don't use kvm and use emulation instead
54 54
Branch = None               # Branch to update and check out before testing
55
Zip = False                  # Archive .ovf and .vmdk into a .zip file
55 56

  
56 57
VMImageDir = os.environ[ 'HOME' ] + '/vm-images'
57 58

  
......
85 86
}
86 87

  
87 88

  
89
def OSVersion( flavor ):
90
    "Return full OS version string for build flavor"
91
    urlbase = path.basename( isoURLs.get( flavor, 'unknown' ) )
92
    return path.splitext( urlbase )[ 0 ]
93

  
94

  
88 95
LogStartTime = time()
89 96
LogFile = None
90 97

  
......
135 142
         ' kvm cloud-utils genisoimage qemu-kvm qemu-utils'
136 143
         ' e2fsprogs '
137 144
         ' landscape-client'
138
         ' python-setuptools mtools' )
145
         ' python-setuptools mtools zip' )
139 146
    run( 'sudo easy_install pexpect' )
140 147

  
141 148

  
......
514 521
    vm.expect( 'Done preparing Mininet', timeout=3600 )
515 522
    log( '* Completed successfully' )
516 523
    vm.expect( prompt )
524
    version = getMininetVersion( vm )
525
    vm.expect( prompt )
526
    log( '* Mininet version: ', version )
517 527
    log( '* Testing Mininet' )
518 528
    runTests( vm )
519 529
    log( '* Shutting down' )
......
521 531
    log( '* Waiting for EOF/shutdown' )
522 532
    vm.read()
523 533
    log( '* Interaction complete' )
534
    return version
524 535

  
525 536

  
526 537
def cleanup():
......
652 663

  
653 664
def build( flavor='raring32server' ):
654 665
    "Build a Mininet VM; return vmdk and vdisk size"
655
    global LogFile
666
    global LogFile, Zip
656 667
    start = time()
657 668
    date = strftime( '%y%m%d-%H-%M-%S', localtime())
658 669
    dir = 'mn-%s-%s' % ( flavor, date )
......
675 686
        logfile = open( flavor + '.log', 'w+' )
676 687
    log( '* Logging results to', abspath( logfile.name ) )
677 688
    vm = boot( volume, kernel, initrd, logfile )
678
    interact( vm )
689
    version = interact( vm )
679 690
    size = qcow2size( volume )
680
    vmdk = convert( volume, basename=basename )
691
    vmdk = convert( volume, basename='mininet-vm' )
681 692
    if not SaveQCOW2:
682 693
        log( '* Removing qcow2 volume', volume )
683 694
        os.remove( volume )
684 695
    log( '* Converted VM image stored as', abspath( vmdk ) )
685
    ovf = generateOVF( diskname=vmdk, disksize=size, name=basename )
696
    ovfname = 'mininet-%s-%s' % ( version, OSVersion( flavor ) )
697
    ovf = generateOVF( diskname=vmdk, disksize=size, name=ovfname )
686 698
    log( '* Generated OVF descriptor file', ovf )
699
    if Zip:
700
        log( '* Generating .zip file' )
701
        run( 'zip %s-ovf.zip %s %s' % ( ovfname, ovf, vmdk ) )
687 702
    end = time()
688 703
    elapsed = end - start
689 704
    log( '* Results logged to', abspath( logfile.name ) )
......
706 721
        vm.expect( prompt )
707 722

  
708 723

  
724
def getMininetVersion( vm ):
725
    "Run mn to find Mininet version in VM"
726
    vm.sendline( '~/mininet/bin/mn --version' )
727
    # Eat command line echo, then read output line
728
    vm.readline()
729
    version = vm.readline().strip()
730
    return version
731

  
732

  
709 733
def bootAndRunTests( image, tests=None ):
710 734
    """Boot and test VM
711 735
       tests: list of tests (default: sanity, core)"""
......
733 757
    if Branch:
734 758
        checkOutBranch( vm, branch=Branch )
735 759
        vm.expect( prompt )
760
    vm.expect( prompt )
736 761
    log( '* Running tests' )
737 762
    runTests( vm, tests=tests )
738 763
    # runTests eats its last prompt, but maybe it shouldn't...
......
769 794

  
770 795
def parseArgs():
771 796
    "Parse command line arguments and run"
772
    global LogToConsole, NoKVM, Branch
797
    global LogToConsole, NoKVM, Branch, Zip
773 798
    parser = argparse.ArgumentParser( description='Mininet VM build script',
774 799
                                      epilog=buildFlavorString() + ' ' +
775 800
                                      testString() )
......
796 821
                         ' this branch before testing' )
797 822
    parser.add_argument( 'flavor', nargs='*',
798 823
                         help='VM flavor(s) to build (e.g. raring32server)' )
824
    parser.add_argument( '-z', '--zip', action='store_true',
825
                        help='archive .ovf and .vmdk into .zip file' )
799 826
    args = parser.parse_args()
800 827
    if args.depend:
801 828
        depend()
......
809 836
        NoKVM = True
810 837
    if args.branch:
811 838
        Branch = args.branch
839
    if args.zip:
840
        Zip = True
812 841
    for flavor in args.flavor:
813 842
        if flavor not in isoURLs:
814 843
            print "Unknown build flavor:", flavor

Also available in: Unified diff