~ubuntu-branches/ubuntu/quantal/virtinst/quantal-proposed

« back to all changes in this revision

Viewing changes to tests/clitest.py

  • Committer: Bazaar Package Importer
  • Author(s): Jean-Louis Dupond
  • Date: 2010-05-05 03:32:42 UTC
  • mfrom: (1.3.13 sid)
  • Revision ID: james.westby@ubuntu.com-20100505033242-um6f6pjcc89i07m0
Tags: 0.500.3-1ubuntu1
* Merge from debian unstable. (LP: #590068)  Remaining changes:
  - debian/patches/9001_Ubuntu.patch:
     + Added lucid and maverick to OS list and enable virtio for it.
  - debian/patches/0003-Fix-patch-to-keyboard-configuration.patch: disable
    as the keyboard config in Ubuntu is still in /etc/default/console-setup
    and this was causing virt-manager to always default to a en-us
    keyboard. (LP: #524318)
  - debian/control: added acl package to depends. (LP: #533048)
  - Demote virt-viewer to Suggests, as it's in universe.
  - Recommends libvirt-bin (LP: #215084)
* debian/patches/9002-add-ca-keymap.patch: dropped, its now in upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
# Set DISPLAY if it isn't already set
21
21
os.environ["DISPLAY"] = "testdisplay"
 
22
os.environ["VIRTCONV_TEST_NO_DISK_CONVERSION"] = "1"
22
23
 
23
24
testuri = "test:///`pwd`/tests/testdriver.xml"
24
25
 
28
29
 
29
30
# Location
30
31
xmldir = "tests/cli-test-xml"
31
 
treedir = "tests/cli-test-xml/faketree"
32
 
ro_img = "cli_exist3ro.img"
 
32
treedir = "%s/faketree" % xmldir
 
33
vcdir = "%s/virtconv" % xmldir
 
34
ro_dir = "clitest_rodir"
 
35
ro_img = "%s/cli_exist3ro.img" % ro_dir
 
36
ro_noexist_img = "%s/idontexist.img" % ro_dir
 
37
virtconv_out = "virtconv-outdir"
33
38
 
34
39
# Images that will be created by virt-install/virt-clone, and removed before
35
40
# each run
45
50
# Images created by virt-image
46
51
virtimage_new = [os.path.join(xmldir, "cli_scratch.raw")]
47
52
 
 
53
# virt-convert output dirs
 
54
virtconv_dirs = [virtconv_out]
 
55
 
48
56
exist_files = exist_images + virtimage_exist
49
 
new_files   = new_images + virtimage_new
50
 
clean_files = new_images + exist_images + virtimage_exist + virtimage_new
 
57
new_files   = new_images + virtimage_new + virtconv_dirs
 
58
clean_files = (new_images + exist_images +
 
59
               virtimage_exist + virtimage_new + virtconv_dirs + [ro_dir])
51
60
 
52
61
test_files = {
53
62
    'TESTURI'           : testuri,
54
63
    'REMOTEURI'         : remoteuri,
55
64
    'CLONE_DISK_XML'    : "%s/clone-disk.xml" % xmldir,
56
65
    'CLONE_STORAGE_XML' : "%s/clone-disk-managed.xml" % xmldir,
 
66
    'CLONE_NOEXIST_XML' : "%s/clone-disk-noexist.xml" % xmldir,
57
67
    'IMAGE_XML'         : "%s/image.xml" % xmldir,
58
68
    'NEWIMG1'           : new_images[0],
59
69
    'NEWIMG2'           : new_images[1],
61
71
    'EXISTIMG1'         : exist_images[0],
62
72
    'EXISTIMG2'         : exist_images[1],
63
73
    'ROIMG'             : ro_img,
 
74
    'ROIMGNOEXIST'      : ro_noexist_img,
64
75
    'POOL'              : "default-pool",
65
76
    'VOL'               : "testvol1.img",
 
77
    'DIR'               : os.getcwd(),
66
78
    'MANAGEDEXIST1'     : "/default-pool/testvol1.img",
67
79
    'MANAGEDEXIST2'     : "/default-pool/testvol2.img",
68
80
    'MANAGEDNEW1'       : "/default-pool/clonevol",
69
81
    'MANAGEDNEW2'       : "/default-pool/clonevol",
70
82
    'MANAGEDDISKNEW1'   : "/disk-pool/newvol1.img",
 
83
    'COLLIDE'           : "/default-pool/collidevol1.img",
 
84
    'SHARE'             : "/default-pool/sharevol.img",
 
85
 
 
86
    'VIRTCONV_OUT'      : "%s/test.out" % virtconv_out,
 
87
    'VC_IMG1'           : "%s/virtimage/test1.virt-image" % vcdir,
 
88
    'VMX_IMG1'          : "%s/vmx/test1.vmx" % vcdir,
71
89
}
72
90
 
73
91
debug = False
150
168
        "--disk %(EXISTIMG1)s",
151
169
        # Not specifying path= but creating storage
152
170
        "--disk %(NEWIMG1)s,format=raw,size=.0000001",
 
171
        # Colliding storage with --force
 
172
        "--disk %(COLLIDE)s --force",
 
173
        # Colliding shareable storage
 
174
        "--disk %(SHARE)s,perms=sh",
 
175
        # Two IDE cds
 
176
        "--disk path=%(EXISTIMG1)s,device=cdrom --disk path=%(EXISTIMG1)s,device=cdrom",
 
177
        # Dir with a floppy dev
 
178
        "--disk %(DIR)s,device=floppy",
153
179
      ],
154
180
 
155
181
      "invalid": [
161
187
        "--file %(NEWIMG1)s",
162
188
        # Too many IDE
163
189
        "--file %(EXISTIMG1)s --file %(EXISTIMG1)s --file %(EXISTIMG1)s --file %(EXISTIMG1)s --file %(EXISTIMG1)s",
164
 
        # Two IDE cds
165
 
        "--disk path=%(EXISTIMG1)s,device=cdrom --disk path=%(EXISTIMG1)s,device=cdrom",
166
190
        # Size, no file
167
191
        "--file-size .0001",
168
192
        # Specify a nonexistent pool
181
205
        "--disk path=%(MANAGEDDISKNEW1)s,format=raw,size=.0000001",
182
206
        # Not specifying path= and non existent storage w/ no size
183
207
        "--disk %(NEWIMG1)s",
 
208
        # Colliding storage without --force
 
209
        "--disk %(COLLIDE)s",
 
210
        # Dir without floppy
 
211
        "--disk %(DIR)s,device=cdrom",
184
212
      ]
185
213
     }, # category "storage"
186
214
 
199
227
        # Explicity fullvirt + arch
200
228
        "--arch i686 --pxe",
201
229
        # Convert i*86 -> i686
202
 
        #"--arch i486 --pxe",
 
230
        "--arch i486 --pxe",
203
231
        # Directory tree URL install
204
232
        "--hvm --location %s" % treedir,
 
233
        # Directory tree URL install with extra-args
 
234
        "--hvm --location %s --extra-args console=ttyS0" % treedir,
205
235
        # Directory tree CDROM install
206
236
        "--hvm --cdrom %s" % treedir,
207
237
        # Paravirt location
324
354
        "--hvm --import --disk path=virt-install",
325
355
        # PV Import install
326
356
        "--paravirt --import --disk path=virt-install",
 
357
        # --autostart flag
 
358
        "--hvm --nodisks --pxe --autostart",
 
359
        # --description
 
360
        "--hvm --nodisks --pxe --description \"foobar & baz\"",
 
361
        # HVM windows install with disk
 
362
        "--hvm --cdrom %(EXISTIMG2)s --file %(EXISTIMG1)s --os-variant win2k3 --wait 0",
 
363
        # --watchdog dev default
 
364
        "--hvm --nodisks --pxe --watchdog default",
 
365
        # --watchdog opts
 
366
        "--hvm --nodisks --pxe --watchdog ib700,action=pause",
 
367
        # --sound option
 
368
        "--hvm --nodisks --pxe --sound",
 
369
        # --soundhw option
 
370
        "--hvm --nodisks --pxe --soundhw default --soundhw ac97",
 
371
        # --security dynamic
 
372
        "--hvm --nodisks --pxe --security type=dynamic",
 
373
        # --security implicit static
 
374
        "--hvm --nodisks --pxe --security label=foobar.label",
327
375
      ],
328
376
 
329
377
      "invalid": [
330
378
        # pxe and nonetworks
331
379
        "--nodisks --pxe --nonetworks",
 
380
        # Colliding name
 
381
        "--nodisks --pxe --name test",
 
382
        # Busted --watchdog
 
383
        "--hvm --nodisks --pxe --watchdog default,action=foobar",
 
384
        # Busted --soundhw
 
385
        "--hvm --nodisks --pxe --soundhw default --soundhw foobar",
 
386
        # Busted --security
 
387
        "--hvm --nodisks --pxe --security type=foobar",
332
388
      ],
333
389
     }, # category "misc"
334
390
 
337
393
 
338
394
      "valid": [
339
395
        # Just a macaddr
340
 
        "--mac 11:22:33:44:55:66",
 
396
        "--mac 11:22:33:44:55:AF",
341
397
        # user networking
342
398
        "--network=user",
343
399
        # Old bridge option
344
400
        "--bridge mybr0",
345
401
        # Old bridge w/ mac
346
 
        "--bridge mybr0 --mac 11:22:33:44:55:66",
 
402
        "--bridge mybr0 --mac 11:22:33:44:55:AF",
347
403
        # --network bridge:
348
404
        "--network bridge:mybr0,model=e1000",
349
405
        # VirtualNetwork with a random macaddr
355
411
        # with NIC model
356
412
        "--network=user,model=e1000",
357
413
        # several networks
358
 
        "--network=network:default,model=e1000 --network=user,model=virtio,mac=11:22:33:44:55:66",
 
414
        "--network=network:default,model=e1000 --network=user,model=virtio,mac=11:22:33:44:55:AF",
359
415
      ],
360
416
      "invalid": [
361
417
        # Nonexistent network
363
419
        # Invalid mac
364
420
        "--network=network:default --mac 1234",
365
421
        # More mac addrs than nics
366
 
        "--network user --mac 00:11:22:33:44:55 --mac 00:11:22:33:44:66",
 
422
        "--network user --mac 00:11:22:33:44:EF --mac 00:11:22:33:44:AB",
367
423
        # Mixing bridge and network
368
424
        "--network user --bridge foo0",
 
425
        # Colliding macaddr
 
426
        "--mac 11:22:33:44:55:66",
369
427
      ],
370
428
 
371
429
     }, # category "network"
372
430
 
 
431
     "hostdev" : {
 
432
      "hostdev_args": "--noautoconsole --nographics --nodisks --pxe",
 
433
 
 
434
      "valid" : [
 
435
        # Host dev by libvirt name
 
436
        "--host-device usb_device_781_5151_2004453082054CA1BEEE",
 
437
        # Many hostdev parsing types
 
438
        "--host-device 001.003 --host-device 15:0.1 --host-device 2:15:0.2 --host-device 0:15:0.3 --host-device 0x0781:0x5151 --host-device 1d6b:2",
 
439
      ],
 
440
 
 
441
      "invalid" : [
 
442
        # Unsupported hostdev type
 
443
        "--host-device pci_8086_2850_scsi_host_scsi_host",
 
444
        # Unknown hostdev
 
445
        "--host-device foobarhostdev",
 
446
        # Parseable hostdev, but unknown digits
 
447
        "--host-device 300:400",
 
448
      ],
 
449
     }, # category "hostdev"
 
450
 
373
451
     "remote" : {
374
452
      "remote_args": "--connect %(REMOTEURI)s --nographics --noautoconsole",
375
453
 
423
501
        # XML w/ managed storage, specify managed path
424
502
        "--original-xml %(CLONE_STORAGE_XML)s --file %(MANAGEDNEW1)s",
425
503
        # XML w/ managed storage, specify managed path across pools
426
 
        #"--original-xml %(CLONE_STORAGE_XML)s --file /cross-pool/clonevol",
 
504
        "--original-xml %(CLONE_STORAGE_XML)s --file /cross-pool/clonevol",
 
505
        # XML w/ non-existent storage, with --preserve
 
506
        "--original-xml %(CLONE_NOEXIST_XML)s --file %(EXISTIMG1)s --preserve",
427
507
      ],
428
508
 
429
509
      "invalid": [
441
521
        "--original-xml %(CLONE_DISK_XML)s --file %(NEWIMG1)s --file %(NEWIMG2)s --force-copy=hdc",
442
522
        # XML w/ managed storage, specify unmanaged path (should fail)
443
523
        "--original-xml %(CLONE_STORAGE_XML)s --file /tmp/clonevol",
 
524
        # XML w/ non-existent storage, WITHOUT --preserve
 
525
        "--original-xml %(CLONE_NOEXIST_XML)s --file %(EXISTIMG1)s",
 
526
        # XML w/ managed storage, specify RO image without preserve
 
527
        "--original-xml %(CLONE_DISK_XML)s --file %(ROIMG)s --file %(ROIMG)s --force",
 
528
        # XML w/ managed storage, specify RO non existent
 
529
        "--original-xml %(CLONE_DISK_XML)s --file %(ROIMG)s --file %(ROIMGNOEXIST)s --force",
444
530
      ]
445
531
     }, # category "general"
446
532
 
525
611
    "misc": {
526
612
     "misc_args" : "",
527
613
 
528
 
      "valid" : [],
 
614
      "valid" : [
 
615
        # Colliding VM name w/ --replace
 
616
        "--name test --replace",
 
617
      ],
529
618
      "invalid" : [
530
619
        # No name specified, and no prompt flag
531
620
        "",
 
621
        # Colliding VM name without --replace
 
622
        "--name test",
532
623
      ],
533
624
 
534
625
     }, # category 'misc'
558
649
      ],
559
650
 
560
651
     }, # category "network"
561
 
    "prompt" : [ " --connect %(TESTURI) %(IMAGE_XML)s --debug --prompt" ],
562
 
 
563
 
  } # app 'virt-image'
 
652
    "prompt" : [ " --connect %(TESTURI)s %(IMAGE_XML)s --debug --prompt" ],
 
653
 
 
654
  }, # app 'virt-image'
 
655
 
 
656
 
 
657
  "virt-convert" : {
 
658
    "global_args" : "--debug",
 
659
 
 
660
    "misc" : {
 
661
     "misc_args": "",
 
662
 
 
663
     "valid": [
 
664
        # virt-image to default (virt-image) w/ no convert
 
665
        "%(VC_IMG1)s -D none %(VIRTCONV_OUT)s",
 
666
        # virt-image to virt-image w/ no convert
 
667
        "%(VC_IMG1)s -o virt-image -D none %(VIRTCONV_OUT)s",
 
668
        # virt-image to vmx w/ no convert
 
669
        "%(VC_IMG1)s -o vmx -D none %(VIRTCONV_OUT)s",
 
670
        # virt-image to vmx w/ raw
 
671
        "%(VC_IMG1)s -o vmx -D raw %(VIRTCONV_OUT)s",
 
672
        # virt-image to vmx w/ vmdk
 
673
        "%(VC_IMG1)s -o vmx -D vmdk %(VIRTCONV_OUT)s",
 
674
        # virt-image to vmx w/ qcow2
 
675
        "%(VC_IMG1)s -o vmx -D qcow2 %(VIRTCONV_OUT)s",
 
676
        # vmx to vmx no convert
 
677
        "%(VMX_IMG1)s -o vmx -D none %(VIRTCONV_OUT)s",
 
678
     ],
 
679
 
 
680
     "invalid": [
 
681
        # virt-image to virt-image with invalid format
 
682
        "%(VC_IMG1)s -o virt-image -D foobarfmt %(VIRTCONV_OUT)s",
 
683
        # virt-image to ovf (has no output formatter)
 
684
        "%(VC_IMG1)s -o ovf %(VIRTCONV_OUT)s",
 
685
     ]
 
686
 
 
687
    }, # category 'misc'
 
688
 
 
689
  }, # app 'virt-conver'
564
690
}
565
691
 
566
692
def runcomm(comm):
601
727
                             "Output was:\n%s" % ret[1])
602
728
 
603
729
# Setup: build cliarg dict, which uses
604
 
def run_tests():
 
730
def run_tests(do_app):
 
731
    if do_app and do_app not in args_dict.keys():
 
732
        raise ValueError("Unknown app '%s'" % do_app)
 
733
 
605
734
    for app in args_dict:
 
735
        if do_app and app != do_app:
 
736
            continue
 
737
 
606
738
        unique = {}
607
739
        prompts = []
608
740
        global_args = ""
646
778
    global debug
647
779
    global testprompt
648
780
 
 
781
    do_app = None
 
782
 
649
783
    if len(sys.argv) > 1:
650
784
        for i in range(1, len(sys.argv)):
651
785
            if sys.argv[i].count("debug"):
652
786
                debug = True
653
787
            elif sys.argv[i].count("prompt"):
654
788
                testprompt = True
 
789
            elif sys.argv[i].count("--app"):
 
790
                do_app = sys.argv[i+1]
655
791
 
656
792
    # Setup needed files
657
793
    for i in exist_files:
658
794
        if os.path.exists(i):
659
795
            raise ValueError("'%s' will be used by testsuite, can not already"
660
796
                             " exist." % i)
 
797
 
 
798
    os.system("mkdir %s" % ro_dir)
 
799
 
661
800
    for i in exist_files:
662
801
        os.system("touch %s" % i)
663
802
 
664
803
    # Set ro_img to readonly
665
804
    os.system("chmod 444 %s" % ro_img)
 
805
    os.system("chmod 555 %s" % ro_dir)
666
806
 
667
807
    try:
668
 
        run_tests()
 
808
        run_tests(do_app)
669
809
    finally:
670
 
        # Cleanup files
671
 
        for i in clean_files:
672
 
            os.system("rm -f %s > /dev/null 2>&1" % i)
 
810
        cleanup()
 
811
 
 
812
def cleanup():
 
813
    # Cleanup files
 
814
    for i in clean_files:
 
815
        os.system("chmod 777 %s > /dev/null 2>&1" % i)
 
816
        os.system("rm -rf %s > /dev/null 2>&1" % i)
673
817
 
674
818
if __name__ == "__main__":
675
819
    main()