~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): Laurent Léonard
  • Date: 2011-01-29 21:41:21 UTC
  • mto: (1.6.3 sid)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: james.westby@ubuntu.com-20110129214121-pjuxf2xz08l5zqew
Tags: upstream-0.500.5
Import upstream version 0.500.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# MA 02110-1301 USA.
16
16
 
17
17
import commands
18
 
import os, sys
19
 
 
20
 
# Set DISPLAY if it isn't already set
21
 
os.environ["DISPLAY"] = "testdisplay"
 
18
import os
 
19
import sys
 
20
 
 
21
import utils
 
22
 
22
23
os.environ["VIRTCONV_TEST_NO_DISK_CONVERSION"] = "1"
 
24
os.environ["LANG"] = "en_US.UTF-8"
23
25
 
24
26
testuri = "test:///`pwd`/tests/testdriver.xml"
25
27
 
26
28
# There is a hack in virtinst/cli.py to find this magic string and
27
29
# convince virtinst we are using a remote connection.
28
 
remoteuri = "__virtinst_test_remote__test:///`pwd`/tests/testdriver.xml"
 
30
fakeuri     = "__virtinst_test__" + testuri + ",predictable"
 
31
remoteuri   = fakeuri + ",remote"
 
32
kvmuri      = fakeuri + ",caps=`pwd`/tests/capabilities-xml/libvirt-0.7.6-qemu-caps.xml,qemu"
 
33
xenuri      = fakeuri + ",caps=`pwd`/tests/capabilities-xml/rhel5.4-xen-caps-virt-enabled.xml,xen"
 
34
xenia64uri  = fakeuri + ",caps=`pwd`/tests/capabilities-xml/xen-ia64-hvm.xml,xen"
29
35
 
30
36
# Location
 
37
image_prefix = "/tmp/__virtinst_cli_"
31
38
xmldir = "tests/cli-test-xml"
32
39
treedir = "%s/faketree" % xmldir
33
40
vcdir = "%s/virtconv" % xmldir
34
 
ro_dir = "clitest_rodir"
 
41
ro_dir = image_prefix + "clitest_rodir"
35
42
ro_img = "%s/cli_exist3ro.img" % ro_dir
36
43
ro_noexist_img = "%s/idontexist.img" % ro_dir
 
44
compare_xmldir = "%s/compare" % xmldir
37
45
virtconv_out = "virtconv-outdir"
38
46
 
39
47
# Images that will be created by virt-install/virt-clone, and removed before
40
48
# each run
41
 
new_images =    [ "cli_new1.img", "cli_new2.img", "cli_new3.img",
42
 
                  "cli_exist1-clone.img", "cli_exist2-clone.img"]
 
49
new_images = [
 
50
    image_prefix + "new1.img",
 
51
    image_prefix + "new2.img",
 
52
    image_prefix + "new3.img",
 
53
    image_prefix + "exist1-clone.img",
 
54
    image_prefix + "exist2-clone.img",
 
55
]
43
56
 
44
57
# Images that are expected to exist before a command is run
45
 
exist_images =  [ "cli_exist1.img", "cli_exist2.img", ro_img]
 
58
exist_images = [
 
59
    image_prefix + "exist1.img",
 
60
    image_prefix + "exist2.img",
 
61
    ro_img,
 
62
]
46
63
 
47
64
# Images that need to exist ahead of time for virt-image
48
 
virtimage_exist = [os.path.join(xmldir, "cli_root.raw")]
 
65
virtimage_exist = ["/tmp/__virtinst__cli_root.raw"]
49
66
 
50
67
# Images created by virt-image
51
 
virtimage_new = [os.path.join(xmldir, "cli_scratch.raw")]
 
68
virtimage_new = ["/tmp/__virtinst__cli_scratch.raw"]
52
69
 
53
70
# virt-convert output dirs
54
71
virtconv_dirs = [virtconv_out]
61
78
test_files = {
62
79
    'TESTURI'           : testuri,
63
80
    'REMOTEURI'         : remoteuri,
 
81
    'KVMURI'            : kvmuri,
 
82
    'XENURI'            : xenuri,
 
83
    'XENIA64URI'        : xenia64uri,
64
84
    'CLONE_DISK_XML'    : "%s/clone-disk.xml" % xmldir,
65
85
    'CLONE_STORAGE_XML' : "%s/clone-disk-managed.xml" % xmldir,
66
86
    'CLONE_NOEXIST_XML' : "%s/clone-disk-noexist.xml" % xmldir,
75
95
    'POOL'              : "default-pool",
76
96
    'VOL'               : "testvol1.img",
77
97
    'DIR'               : os.getcwd(),
 
98
    'TREEDIR'           : treedir,
78
99
    'MANAGEDEXIST1'     : "/default-pool/testvol1.img",
79
100
    'MANAGEDEXIST2'     : "/default-pool/testvol2.img",
80
101
    'MANAGEDNEW1'       : "/default-pool/clonevol",
85
106
 
86
107
    'VIRTCONV_OUT'      : "%s/test.out" % virtconv_out,
87
108
    'VC_IMG1'           : "%s/virtimage/test1.virt-image" % vcdir,
 
109
    'VC_IMG2'           : "tests/image-xml/image-format.xml",
88
110
    'VMX_IMG1'          : "%s/vmx/test1.vmx" % vcdir,
89
111
}
90
112
 
97
119
Format:
98
120
 
99
121
"appname" {
100
 
  "global_args" : Arguments to be passed to every app invocation
 
122
  "globalargs" : Arguments to be passed to every app invocation
101
123
 
102
124
  "categoryfoo" : { Some descriptive test catagory name (e.g. storage)
103
125
 
104
 
    "categoryfoo_args" : Args to be applied to all invocations in category
 
126
    "args" : Args to be applied to all invocations in category
105
127
 
106
128
    "valid" : { # Argument strings that should succeed
107
129
      "--option --string --number1" # Some option string to test. The
108
130
          resulting cmdstr would be:
109
 
          $ appname global_args categoryfoo_args --option --string --number1
 
131
          $ appname globalargs categoryfoo_args --option --string --number1
110
132
    }
111
133
 
112
134
    "invalid" : { # Argument strings that should fail
125
147
 
126
148
 
127
149
  "virt-install" : {
128
 
    "global_args" : " --connect %(TESTURI)s -d --name foobar --ram 64",
 
150
    "globalargs" : " --connect %(TESTURI)s -d --name foobar --ram 64",
129
151
 
130
152
    "storage" : {
131
 
      "storage_args": "--pxe --nographics --noautoconsole --hvm",
 
153
      "args": "--pxe --nographics --noautoconsole --hvm",
132
154
 
133
155
      "valid"  : [
134
156
        # Existing file, other opts
142
164
 
143
165
        # Existing disk, lots of opts
144
166
        "--disk path=%(EXISTIMG1)s,perms=ro,size=.0001,cache=writethrough",
 
167
        # Existing disk, rw perms
 
168
        "--disk path=%(EXISTIMG1)s,perms=rw",
145
169
        # Existing floppy
146
170
        "--disk path=%(EXISTIMG1)s,device=floppy",
147
171
        # Existing disk, no extra options
180
204
        "--disk %(EXISTIMG1)s,driver_name=qemu,driver_type=qcow2",
181
205
        # Unknown driver name and type options
182
206
        "--disk %(EXISTIMG1)s,driver_name=foobar,driver_type=foobaz",
 
207
        # Using a storage pool source as a disk
 
208
        "--disk /dev/hda",
183
209
      ],
184
210
 
185
211
      "invalid": [
217
243
     }, # category "storage"
218
244
 
219
245
     "install" : {
220
 
      "install_args": "--nographics --noautoconsole --nodisks",
 
246
      "args": "--nographics --noautoconsole --nodisks",
221
247
 
222
248
      "valid" : [
223
249
        # Simple cdrom install
233
259
        # Convert i*86 -> i686
234
260
        "--arch i486 --pxe",
235
261
        # Directory tree URL install
236
 
        "--hvm --location %s" % treedir,
 
262
        "--hvm --location %(TREEDIR)s",
237
263
        # Directory tree URL install with extra-args
238
 
        "--hvm --location %s --extra-args console=ttyS0" % treedir,
 
264
        "--hvm --location %(TREEDIR)s --extra-args console=ttyS0",
239
265
        # Directory tree CDROM install
240
 
        "--hvm --cdrom %s" % treedir,
 
266
        "--hvm --cdrom %(TREEDIR)s",
241
267
        # Paravirt location
242
 
        "--paravirt --location %s" % treedir,
 
268
        "--paravirt --location %(TREEDIR)s",
243
269
        # Using ro path as a cd media
244
270
        "--hvm --cdrom %(ROIMG)s",
245
271
        # Paravirt location with --os-variant none
246
 
        "--paravirt --location %s --os-variant none" % treedir,
 
272
        "--paravirt --location %(TREEDIR)s --os-variant none",
247
273
        # URL install with manual os-variant
248
 
        "--hvm --location %s --os-variant fedora12" % treedir,
 
274
        "--hvm --location %(TREEDIR)s --os-variant fedora12",
249
275
        # Boot menu
250
276
        "--hvm --pxe --boot menu=on",
251
277
        # Kernel params
277
303
     }, # category "install"
278
304
 
279
305
     "graphics": {
280
 
      "graphics_args": "--noautoconsole --nodisks --pxe",
 
306
      "args": "--noautoconsole --nodisks --pxe",
281
307
 
282
308
      "valid": [
283
309
        # SDL
284
310
        "--sdl",
 
311
        # --graphics SDL
 
312
        "--graphics sdl",
 
313
        # --graphics none,
 
314
        "--graphics none",
285
315
        # VNC w/ lots of options
286
316
        "--vnc --keymap ja --vncport 5950 --vnclisten 1.2.3.4",
 
317
        # VNC w/ lots of options, new way
 
318
        "--graphics vnc,port=5950,listen=1.2.3.4,keymap=ja,password=foo",
 
319
        # SPICE w/ lots of options
 
320
        "--graphics spice,port=5950,tlsport=5950,listen=1.2.3.4,keymap=ja",
287
321
        # --video option
288
322
        "--vnc --video vga",
 
323
        # --video option
 
324
        "--graphics spice --video qxl",
289
325
        # --keymap local,
290
326
        "--vnc --keymap local",
291
327
        # --keymap none
297
333
        "--vnc --keymap ZZZ",
298
334
        # Invalid port
299
335
        "--vnc --vncport -50",
 
336
        # Invalid port
 
337
        "--graphics spice,tlsport=-50",
300
338
        # Invalid --video
301
339
        "--vnc --video foobar",
 
340
        # --graphics bogus
 
341
        "--graphics vnc,foobar=baz",
 
342
        # mixing old and new
 
343
        "--graphics vnc --vnclisten 1.2.3.4",
302
344
      ],
303
345
 
304
346
     }, # category "graphics"
305
347
 
306
348
    "char" : {
307
 
     "char_args": "--hvm --nographics --noautoconsole --nodisks --pxe",
 
349
     "args": "--hvm --nographics --noautoconsole --nodisks --pxe",
308
350
 
309
351
     "valid": [
310
352
        # Simple devs
348
390
     }, # category 'char'
349
391
 
350
392
     "cpuram" : {
351
 
      "cpuram_args" : "--hvm --nographics --noautoconsole --nodisks --pxe",
 
393
      "args" : "--hvm --nographics --noautoconsole --nodisks --pxe",
352
394
 
353
395
      "valid" : [
354
396
        # Max VCPUS
361
403
        "--vcpus 4 --cpuset=auto",
362
404
        # Ram overcommit
363
405
        "--ram 100000000000",
 
406
        # maxvcpus
 
407
        "--vcpus 5,maxvcpus=10",
 
408
        # Topology
 
409
        "--vcpus 4,cores=2,threads=2,sockets=2",
 
410
        # Topology auto-fill
 
411
        "--vcpus 4,cores=1",
 
412
        # Topology only
 
413
        "--vcpus sockets=2,threads=2",
 
414
        # Simple --cpu
 
415
        "--cpu somemodel",
 
416
        # Crazy --cpu
 
417
        "--cpu foobar,+x2apic,+x2apicagain,-distest,forbid=foo,forbid=bar,disable=distest2,optional=opttest,require=reqtest,match=strict,vendor=meee",
364
418
      ],
365
419
 
366
420
      "invalid" : [
370
424
        "--vcpus 32 --cpuset=autofoo",
371
425
        # Over max vcpus
372
426
        "--vcpus 10000",
 
427
        # Over host vcpus w/ --check-cpu
 
428
        "--vcpus 20 --check-cpu",
 
429
        # maxvcpus less than cpus
 
430
        "--vcpus 5,maxvcpus=1",
 
431
        # vcpus unknown option
 
432
        "--vcpus foo=bar",
 
433
        # --cpu host, but no host CPU in caps
 
434
        "--cpu host",
373
435
      ],
374
436
 
375
437
    }, # category 'cpuram'
376
438
 
377
439
     "misc": {
378
 
      "misc_args": "--nographics --noautoconsole",
 
440
      "args": "--nographics --noautoconsole",
379
441
 
380
442
      "valid": [
381
443
        # Specifying cdrom media via --disk
384
446
        "--hvm --import --disk path=virt-install",
385
447
        # PV Import install
386
448
        "--paravirt --import --disk path=virt-install",
 
449
        # PV Import install, print single XML
 
450
        "--paravirt --import --disk path=virt-install --print-xml",
387
451
        # Import a floppy disk
388
452
        "--hvm --import --disk path=virt-install,device=floppy",
389
453
        # --autostart flag
392
456
        "--hvm --nodisks --pxe --description \"foobar & baz\"",
393
457
        # HVM windows install with disk
394
458
        "--hvm --cdrom %(EXISTIMG2)s --file %(EXISTIMG1)s --os-variant win2k3 --wait 0",
 
459
        # HVM windows install, print 3rd stage XML
 
460
        "--hvm --cdrom %(EXISTIMG2)s --file %(EXISTIMG1)s --os-variant win2k3 --wait 0 --print-step 3",
395
461
        # --watchdog dev default
396
462
        "--hvm --nodisks --pxe --watchdog default",
397
463
        # --watchdog opts
411
477
      ],
412
478
 
413
479
      "invalid": [
 
480
        # Positional arguments error
 
481
        "--hvm --nodisks --pxe foobar",
414
482
        # pxe and nonetworks
415
483
        "--nodisks --pxe --nonetworks",
416
484
        # Colliding name
421
489
        "--hvm --nodisks --pxe --soundhw default --soundhw foobar",
422
490
        # Busted --security
423
491
        "--hvm --nodisks --pxe --security type=foobar",
424
 
      ],
 
492
        # PV Import install, no second XML step
 
493
        "--paravirt --import --disk path=virt-install --print-step 2",
 
494
        # 2 stage install with --print-xml
 
495
        "--hvm --nodisks --pxe --print-xml",
 
496
      ],
 
497
 
 
498
      "compare": [
 
499
        # No arguments
 
500
        ("", "noargs-fail"),
 
501
        # Diskless PXE install
 
502
        ("--hvm --nodisks --pxe --print-step all", "simple-pxe"),
 
503
        # HVM windows install with disk
 
504
        ("--hvm --cdrom %(EXISTIMG2)s --file %(EXISTIMG1)s --os-variant win2k3 --wait 0 --vcpus cores=4", "w2k3-cdrom"),
 
505
      ],
 
506
 
425
507
     }, # category "misc"
426
508
 
427
509
     "network": {
428
 
      "network_args": "--pxe --nographics --noautoconsole --nodisks",
 
510
      "args": "--pxe --nographics --noautoconsole --nodisks",
429
511
 
430
512
      "valid": [
431
513
        # Just a macaddr
465
547
     }, # category "network"
466
548
 
467
549
     "hostdev" : {
468
 
      "hostdev_args": "--noautoconsole --nographics --nodisks --pxe",
 
550
      "args": "--noautoconsole --nographics --nodisks --pxe",
469
551
 
470
552
      "valid" : [
471
553
        # Host dev by libvirt name
485
567
     }, # category "hostdev"
486
568
 
487
569
     "remote" : {
488
 
      "remote_args": "--connect %(REMOTEURI)s --nographics --noautoconsole",
 
570
      "args": "--connect %(REMOTEURI)s --nographics --noautoconsole",
489
571
 
490
572
      "valid" : [
491
573
        # Simple pxe nodisks
508
590
 
509
591
     }, # category "remote"
510
592
 
 
593
 
 
594
"kvm" : {
 
595
  "args": "--connect %(KVMURI)s --noautoconsole",
 
596
 
 
597
  "valid" : [
 
598
    # HVM windows install with disk
 
599
    "--cdrom %(EXISTIMG2)s --file %(EXISTIMG1)s --os-variant win2k3 --wait 0 --sound",
 
600
    # F14 Directory tree URL install with extra-args
 
601
    "--os-variant fedora14 --file %(EXISTIMG1)s --location %(TREEDIR)s --extra-args console=ttyS0 --sound"
 
602
  ],
 
603
 
 
604
  "invalid" : [
 
605
    # Unknown machine type
 
606
    "--nodisks --boot network --machine foobar",
 
607
    # Invalid domain type for arch
 
608
    "--nodisks --boot network --arch mips --virt-type kvm",
 
609
    # Invalid arch/virt combo
 
610
    "--nodisks --boot network --paravirt --arch mips",
 
611
  ],
 
612
 
 
613
  "compare" : [
 
614
    # F14 Directory tree URL install with extra-args
 
615
    ("--os-variant fedora14 --file %(EXISTIMG1)s --location %(TREEDIR)s --extra-args console=ttyS0 --cpu host", "kvm-f14-url"),
 
616
    # Quiet URL install should make no noise
 
617
    ("--os-variant fedora14 --disk %(NEWIMG1)s,size=.01 --location %(TREEDIR)s --extra-args console=ttyS0 --quiet", "quiet-url"),
 
618
    # HVM windows install with disk
 
619
    ("--cdrom %(EXISTIMG2)s --file %(EXISTIMG1)s --os-variant win2k3 --wait 0 --sound", "kvm-win2k3-cdrom"),
 
620
 
 
621
    # xenner
 
622
    ("--os-variant fedora14 --nodisks --boot hd --paravirt", "kvm-xenner"),
 
623
    # plain qemu
 
624
    ("--os-variant fedora14 --nodisks --boot cdrom --virt-type qemu",
 
625
     "qemu-plain"),
 
626
    # 32 on 64
 
627
    ("--os-variant fedora14 --nodisks --boot network --nographics --arch i686",
 
628
     "qemu-32-on-64"),
 
629
    # kvm machine type 'pc'
 
630
    ("--os-variant fedora14 --nodisks --boot fd --graphics spice --machine pc", "kvm-machine"),
 
631
    # exotic arch + machine type
 
632
    ("--os-variant fedora14 --nodisks --boot fd --graphics sdl --arch sparc --machine SS-20",
 
633
     "qemu-sparc"),
 
634
  ],
 
635
 
 
636
}, # category "kvm"
 
637
 
 
638
"xen" : {
 
639
  "args": "--connect %(XENURI)s --noautoconsole",
 
640
 
 
641
  "valid"   : [
 
642
    # HVM
 
643
    "--nodisks --cdrom %(EXISTIMG1)s --livecd --hvm",
 
644
    # PV
 
645
    "--nodisks --boot hd --paravirt",
 
646
    # 32 on 64 xen
 
647
    "--nodisks --boot hd --paravirt --arch i686",
 
648
  ],
 
649
 
 
650
  "invalid" : [
 
651
  ],
 
652
 
 
653
  "compare" : [
 
654
    # Xen default
 
655
    ("--disk %(EXISTIMG1)s --import", "xen-default"),
 
656
    # Xen PV
 
657
    ("--disk %(EXISTIMG1)s --location %(TREEDIR)s --paravirt", "xen-pv"),
 
658
    # Xen HVM
 
659
    ("--disk %(EXISTIMG1)s --cdrom %(EXISTIMG1)s --livecd --hvm", "xen-hvm"),
 
660
    # ia64 default
 
661
    ("--connect %(XENIA64URI)s --disk %(EXISTIMG1)s --import",
 
662
     "xen-ia64-default"),
 
663
    # ia64 pv
 
664
    ("--connect %(XENIA64URI)s --disk %(EXISTIMG1)s --location %(TREEDIR)s --paravirt", "xen-ia64-pv"),
 
665
    # ia64 hvm
 
666
    ("--connect %(XENIA64URI)s --disk %(EXISTIMG1)s --location %(TREEDIR)s --hvm", "xen-ia64-hvm"),
 
667
  ],
 
668
 
 
669
},
511
670
    "prompt" : [ " --connect %(TESTURI)s --debug --prompt" ]
512
671
  },
513
672
 
515
674
 
516
675
 
517
676
  "virt-clone": {
518
 
    "global_args" : " --connect %(TESTURI)s -d",
 
677
    "globalargs" : " --connect %(TESTURI)s -d",
519
678
 
520
679
    "general" : {
521
 
      "general_args": "-n clonetest",
 
680
      "args": "-n clonetest",
522
681
 
523
682
      "valid"  : [
524
683
        # Nodisk guest
543
702
      ],
544
703
 
545
704
      "invalid": [
 
705
        # Positional arguments error
 
706
        "-o test foobar",
546
707
        # Non-existent vm name
547
708
        "-o idontexist",
548
709
        # Non-existent vm name with auto flag,
567
728
     }, # category "general"
568
729
 
569
730
    "misc" : {
570
 
      "misc_args": "",
 
731
      "args": "",
571
732
 
572
733
      "valid" : [
573
734
        # Auto flag, no storage
585
746
        "--auto-clone"
586
747
        # Auto flag, actual VM, without state skip
587
748
        "-o test-for-clone --auto-clone",
588
 
      ]
 
749
      ],
 
750
 
 
751
      "compare" : [
 
752
        ("-o test-for-clone --auto-clone --clone-running", "clone-auto1"),
 
753
        ("-o test-clone-simple --name newvm --auto-clone --clone-running",
 
754
         "clone-auto2"),
 
755
      ],
589
756
    }, # category "misc"
590
757
 
591
758
     "remote" : {
592
 
      "remote_args": "--connect %(REMOTEURI)s",
 
759
      "args": "--connect %(REMOTEURI)s",
593
760
 
594
761
      "valid"  : [
595
762
        # Auto flag, no storage
603
770
      ],
604
771
    }, # categort "remote"
605
772
 
606
 
    "prompt" : [ " --connect %(TESTURI) --debug --prompt",
607
 
                 " --connect %(TESTURI) --debug --original-xml %(CLONE_DISK_XML)s --prompt" ]
 
773
    "prompt" : [
 
774
        " --connect %(TESTURI) --debug --prompt",
 
775
        " --connect %(TESTURI) --debug --original-xml %(CLONE_DISK_XML)s --prompt" ]
608
776
  }, # app 'virt-clone'
609
777
 
610
778
 
611
779
 
612
780
 
613
781
  'virt-image': {
614
 
    "global_args" : " --connect %(TESTURI)s -d %(IMAGE_XML)s",
 
782
    "globalargs" : " --connect %(TESTURI)s -d %(IMAGE_XML)s",
615
783
 
616
784
    "general" : {
617
 
      "general_args" : "--name test-image",
 
785
      "args" : "--name test-image",
618
786
 
619
787
      "valid": [
620
788
        # All default values
621
789
        "",
 
790
        # Print default
 
791
        "--print",
622
792
        # Manual boot idx 0
623
793
        "--boot 0",
624
794
        # Manual boot idx 1
636
806
     }, # category 'general'
637
807
 
638
808
    "graphics" : {
639
 
      "graphics_args" : "--name test-image --boot 0",
 
809
      "args" : "--name test-image --boot 0",
640
810
 
641
811
      "valid": [
642
812
        # SDL
649
819
    },
650
820
 
651
821
    "misc": {
652
 
     "misc_args" : "",
 
822
     "args" : "",
653
823
 
654
824
      "valid" : [
655
825
        # Colliding VM name w/ --replace
662
832
        "--name test",
663
833
      ],
664
834
 
 
835
      "compare" : [
 
836
        ("--name foobar --ram 64 --os-variant winxp --boot 0", "image-boot0"),
 
837
        ("--name foobar --ram 64 --network user,model=e1000 --boot 1",
 
838
         "image-boot1"),
 
839
      ]
 
840
 
665
841
     }, # category 'misc'
666
842
 
667
843
     "network": {
668
 
      "network_args": "--name test-image --boot 0 --nographics",
 
844
      "args": "--name test-image --boot 0 --nographics",
669
845
 
670
846
      "valid": [
671
847
        # user networking
695
871
 
696
872
 
697
873
  "virt-convert" : {
698
 
    "global_args" : "--debug",
 
874
    "globalargs" : "--debug",
699
875
 
700
876
    "misc" : {
701
 
     "misc_args": "",
 
877
     "args": "",
702
878
 
703
879
     "valid": [
704
880
        # virt-image to default (virt-image) w/ no convert
715
891
        "%(VC_IMG1)s -o vmx -D qcow2 %(VIRTCONV_OUT)s",
716
892
        # vmx to vmx no convert
717
893
        "%(VMX_IMG1)s -o vmx -D none %(VIRTCONV_OUT)s",
 
894
        # virt-image with exotic formats specified
 
895
        "%(VC_IMG2)s -o vmx -D vmdk %(VIRTCONV_OUT)s"
718
896
     ],
719
897
 
720
898
     "invalid": [
742
920
            print ret[1]
743
921
            print "\n"
744
922
 
 
923
        if not debug:
 
924
            sys.stdout.write(".")
 
925
            sys.stdout.flush()
 
926
 
745
927
        return ret
746
928
    except Exception, e:
747
929
        return (-1, str(e))
757
939
                             "Command was: %s\n" % (comm) + \
758
940
                             "Error code : %d\n" % ret[0] + \
759
941
                             "Output was:\n%s" % ret[1])
 
942
    return ret
760
943
 
761
944
def assertFail(comm):
762
945
    ret = runcomm(comm)
765
948
                             "Command was: %s\n" % (comm) + \
766
949
                             "Error code : %d\n" % ret[0] + \
767
950
                             "Output was:\n%s" % ret[1])
 
951
    return ret
 
952
 
768
953
 
769
954
# Setup: build cliarg dict, which uses
770
 
def run_tests(do_app):
 
955
def run_tests(do_app, do_category):
771
956
    if do_app and do_app not in args_dict.keys():
772
957
        raise ValueError("Unknown app '%s'" % do_app)
773
958
 
777
962
 
778
963
        unique = {}
779
964
        prompts = []
780
 
        global_args = ""
 
965
        globalargs = ""
781
966
 
782
967
        # Build default command line dict
783
968
        for option in args_dict.get(app):
784
 
            if option == "global_args":
785
 
                global_args = args_dict[app][option]
 
969
            if option == "globalargs":
 
970
                globalargs = args_dict[app][option]
786
971
                continue
787
972
            elif option == "prompt":
788
973
                prompts = args_dict[app][option]
789
974
                continue
790
975
 
791
976
            # Default is a unique cmd string
792
 
            unique[option]= args_dict[app][option]
 
977
            unique[option] = args_dict[app][option]
793
978
 
794
979
        # Build up prompt cases
795
980
        if testprompt:
798
983
                run_prompt_comm(cmd)
799
984
            continue
800
985
 
 
986
        if do_category and do_category not in unique.keys():
 
987
            raise ValueError("Unknown category %s" % do_category)
 
988
 
801
989
        # Build up unique command line cases
802
990
        for category in unique.keys():
 
991
            if do_category and category != do_category:
 
992
                continue
803
993
            catdict = unique[category]
804
 
            category_args = catdict["%s_args" % category]
 
994
            category_args = catdict["args"]
805
995
 
806
996
            for optstr in catdict["valid"]:
807
 
                cmdstr = "./%s %s %s %s" % (app, global_args,
 
997
                cmdstr = "./%s %s %s %s" % (app, globalargs,
808
998
                                            category_args, optstr)
809
999
                assertPass(cmdstr)
810
1000
 
811
1001
            for optstr in catdict["invalid"]:
812
 
                cmdstr = "./%s %s %s %s" % (app, global_args,
 
1002
                cmdstr = "./%s %s %s %s" % (app, globalargs,
813
1003
                                            category_args, optstr)
814
1004
                assertFail(cmdstr)
815
1005
 
 
1006
            for optstr, filename in catdict.get("compare") or []:
 
1007
                filename = "%s/%s.xml" % (compare_xmldir, filename)
 
1008
                cmdstr = "./%s %s %s %s" % (app, globalargs,
 
1009
                                            category_args, optstr)
 
1010
                cmdstr = cmdstr % test_files
 
1011
 
 
1012
                # Strip --debug to get reasonable output
 
1013
                cmdstr = cmdstr.replace("--debug ", "").replace("-d ", "")
 
1014
                if app == "virt-install":
 
1015
                    if (not cmdstr.count("--print-xml") and
 
1016
                        not cmdstr.count("--print-step") and
 
1017
                        not cmdstr.count("--quiet")):
 
1018
                        cmdstr += " --print-step all"
 
1019
 
 
1020
                elif app == "virt-image":
 
1021
                    if not cmdstr.count("--print"):
 
1022
                        cmdstr += " --print"
 
1023
 
 
1024
                elif app == "virt-clone":
 
1025
                    if not cmdstr.count("--print-xml"):
 
1026
                        cmdstr += " --print-xml"
 
1027
 
 
1028
                if not cmdstr.count(fakeuri):
 
1029
                    cmdstr += " --connect %s" % fakeuri
 
1030
 
 
1031
                check_fail = filename.endswith("fail.xml")
 
1032
 
 
1033
                try:
 
1034
                    if check_fail:
 
1035
                        ignore, output = assertFail(cmdstr)
 
1036
                    else:
 
1037
                        ignore, output = assertPass(cmdstr)
 
1038
 
 
1039
                    # Uncomment to generate new test files
 
1040
                    if not os.path.exists(filename):
 
1041
                        file(filename, "w").write(output)
 
1042
 
 
1043
                    utils.diff_compare(output, filename)
 
1044
                except:
 
1045
                    print cmdstr
 
1046
                    raise
 
1047
 
816
1048
def main():
817
1049
    # CLI Args
818
1050
    global debug
819
1051
    global testprompt
820
1052
 
821
1053
    do_app = None
 
1054
    do_category = None
822
1055
 
823
1056
    if len(sys.argv) > 1:
824
1057
        for i in range(1, len(sys.argv)):
827
1060
            elif sys.argv[i].count("prompt"):
828
1061
                testprompt = True
829
1062
            elif sys.argv[i].count("--app"):
830
 
                do_app = sys.argv[i+1]
 
1063
                do_app = sys.argv[i + 1]
 
1064
            elif sys.argv[i].count("--category"):
 
1065
                do_category = sys.argv[i + 1]
831
1066
 
832
1067
    # Setup needed files
833
1068
    for i in exist_files:
845
1080
    os.system("chmod 555 %s" % ro_dir)
846
1081
 
847
1082
    try:
848
 
        run_tests(do_app)
 
1083
        run_tests(do_app, do_category)
849
1084
    finally:
850
1085
        cleanup()
851
1086
 
 
1087
    print "\nAll tests completed successfully."
 
1088
 
852
1089
def cleanup():
853
1090
    # Cleanup files
854
1091
    for i in clean_files: