15
15
# MA 02110-1301 USA.
20
# Set DISPLAY if it isn't already set
21
os.environ["DISPLAY"] = "testdisplay"
22
23
os.environ["VIRTCONV_TEST_NO_DISK_CONVERSION"] = "1"
24
os.environ["LANG"] = "en_US.UTF-8"
24
26
testuri = "test:///`pwd`/tests/testdriver.xml"
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"
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"
39
47
# Images that will be created by virt-install/virt-clone, and removed before
41
new_images = [ "cli_new1.img", "cli_new2.img", "cli_new3.img",
42
"cli_exist1-clone.img", "cli_exist2-clone.img"]
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",
44
57
# Images that are expected to exist before a command is run
45
exist_images = [ "cli_exist1.img", "cli_exist2.img", ro_img]
59
image_prefix + "exist1.img",
60
image_prefix + "exist2.img",
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"]
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"]
53
70
# virt-convert output dirs
54
71
virtconv_dirs = [virtconv_out]
100
"global_args" : Arguments to be passed to every app invocation
122
"globalargs" : Arguments to be passed to every app invocation
102
124
"categoryfoo" : { Some descriptive test catagory name (e.g. storage)
104
"categoryfoo_args" : Args to be applied to all invocations in category
126
"args" : Args to be applied to all invocations in category
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
112
134
"invalid" : { # Argument strings that should fail
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",
131
"storage_args": "--pxe --nographics --noautoconsole --hvm",
153
"args": "--pxe --nographics --noautoconsole --hvm",
134
156
# Existing file, other opts
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
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",
250
276
"--hvm --pxe --boot menu=on",
277
303
}, # category "install"
280
"graphics_args": "--noautoconsole --nodisks --pxe",
306
"args": "--noautoconsole --nodisks --pxe",
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",
288
322
"--vnc --video vga",
324
"--graphics spice --video qxl",
289
325
# --keymap local,
290
326
"--vnc --keymap local",
297
333
"--vnc --keymap ZZZ",
299
335
"--vnc --vncport -50",
337
"--graphics spice,tlsport=-50",
300
338
# Invalid --video
301
339
"--vnc --video foobar",
341
"--graphics vnc,foobar=baz",
343
"--graphics vnc --vnclisten 1.2.3.4",
304
346
}, # category "graphics"
307
"char_args": "--hvm --nographics --noautoconsole --nodisks --pxe",
349
"args": "--hvm --nographics --noautoconsole --nodisks --pxe",
361
403
"--vcpus 4 --cpuset=auto",
363
405
"--ram 100000000000",
407
"--vcpus 5,maxvcpus=10",
409
"--vcpus 4,cores=2,threads=2,sockets=2",
413
"--vcpus sockets=2,threads=2",
417
"--cpu foobar,+x2apic,+x2apicagain,-distest,forbid=foo,forbid=bar,disable=distest2,optional=opttest,require=reqtest,match=strict,vendor=meee",
370
424
"--vcpus 32 --cpuset=autofoo",
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
433
# --cpu host, but no host CPU in caps
375
437
}, # category 'cpuram'
378
"misc_args": "--nographics --noautoconsole",
440
"args": "--nographics --noautoconsole",
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
421
489
"--hvm --nodisks --pxe --soundhw default --soundhw foobar",
422
490
# Busted --security
423
491
"--hvm --nodisks --pxe --security type=foobar",
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",
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"),
425
507
}, # category "misc"
428
"network_args": "--pxe --nographics --noautoconsole --nodisks",
510
"args": "--pxe --nographics --noautoconsole --nodisks",
509
591
}, # category "remote"
595
"args": "--connect %(KVMURI)s --noautoconsole",
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"
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",
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"),
622
("--os-variant fedora14 --nodisks --boot hd --paravirt", "kvm-xenner"),
624
("--os-variant fedora14 --nodisks --boot cdrom --virt-type qemu",
627
("--os-variant fedora14 --nodisks --boot network --nographics --arch i686",
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",
639
"args": "--connect %(XENURI)s --noautoconsole",
643
"--nodisks --cdrom %(EXISTIMG1)s --livecd --hvm",
645
"--nodisks --boot hd --paravirt",
647
"--nodisks --boot hd --paravirt --arch i686",
655
("--disk %(EXISTIMG1)s --import", "xen-default"),
657
("--disk %(EXISTIMG1)s --location %(TREEDIR)s --paravirt", "xen-pv"),
659
("--disk %(EXISTIMG1)s --cdrom %(EXISTIMG1)s --livecd --hvm", "xen-hvm"),
661
("--connect %(XENIA64URI)s --disk %(EXISTIMG1)s --import",
664
("--connect %(XENIA64URI)s --disk %(EXISTIMG1)s --location %(TREEDIR)s --paravirt", "xen-ia64-pv"),
666
("--connect %(XENIA64URI)s --disk %(EXISTIMG1)s --location %(TREEDIR)s --hvm", "xen-ia64-hvm"),
511
670
"prompt" : [ " --connect %(TESTURI)s --debug --prompt" ]
586
747
# Auto flag, actual VM, without state skip
587
748
"-o test-for-clone --auto-clone",
752
("-o test-for-clone --auto-clone --clone-running", "clone-auto1"),
753
("-o test-clone-simple --name newvm --auto-clone --clone-running",
589
756
}, # category "misc"
592
"remote_args": "--connect %(REMOTEURI)s",
759
"args": "--connect %(REMOTEURI)s",
595
762
# Auto flag, no storage
604
771
}, # categort "remote"
606
"prompt" : [ " --connect %(TESTURI) --debug --prompt",
607
" --connect %(TESTURI) --debug --original-xml %(CLONE_DISK_XML)s --prompt" ]
774
" --connect %(TESTURI) --debug --prompt",
775
" --connect %(TESTURI) --debug --original-xml %(CLONE_DISK_XML)s --prompt" ]
608
776
}, # app 'virt-clone'
614
"global_args" : " --connect %(TESTURI)s -d %(IMAGE_XML)s",
782
"globalargs" : " --connect %(TESTURI)s -d %(IMAGE_XML)s",
617
"general_args" : "--name test-image",
785
"args" : "--name test-image",
620
788
# All default values
622
792
# Manual boot idx 0
624
794
# Manual boot idx 1
765
948
"Command was: %s\n" % (comm) + \
766
949
"Error code : %d\n" % ret[0] + \
767
950
"Output was:\n%s" % ret[1])
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)
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]
787
972
elif option == "prompt":
788
973
prompts = args_dict[app][option]
791
976
# Default is a unique cmd string
792
unique[option]= args_dict[app][option]
977
unique[option] = args_dict[app][option]
794
979
# Build up prompt cases
798
983
run_prompt_comm(cmd)
986
if do_category and do_category not in unique.keys():
987
raise ValueError("Unknown category %s" % do_category)
801
989
# Build up unique command line cases
802
990
for category in unique.keys():
991
if do_category and category != do_category:
803
993
catdict = unique[category]
804
category_args = catdict["%s_args" % category]
994
category_args = catdict["args"]
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)
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)
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
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"
1020
elif app == "virt-image":
1021
if not cmdstr.count("--print"):
1022
cmdstr += " --print"
1024
elif app == "virt-clone":
1025
if not cmdstr.count("--print-xml"):
1026
cmdstr += " --print-xml"
1028
if not cmdstr.count(fakeuri):
1029
cmdstr += " --connect %s" % fakeuri
1031
check_fail = filename.endswith("fail.xml")
1035
ignore, output = assertFail(cmdstr)
1037
ignore, output = assertPass(cmdstr)
1039
# Uncomment to generate new test files
1040
if not os.path.exists(filename):
1041
file(filename, "w").write(output)
1043
utils.diff_compare(output, filename)
819
1051
global testprompt
823
1056
if len(sys.argv) > 1:
824
1057
for i in range(1, len(sys.argv)):