forked from spiceqa/virt-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run
executable file
·979 lines (863 loc) · 42.3 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
#!/usr/bin/python
"""
Run virt tests outside the autotest client harness.
:copyright: Red Hat 2012
"""
import os
import sys
import traceback
import signal
import optparse
import logging
class StreamProxy(object):
"""
Mechanism to redirect a stream to a file, allowing the original stream to
be restored later.
"""
def __init__(self, filename='/dev/null', stream=sys.stdout):
"""
Keep 2 streams to write to, and eventually switch.
"""
self.terminal = stream
if filename is None:
self.log = stream
else:
self.log = open(filename, "a")
self.redirect()
def write(self, message):
"""
Write to the current stream.
"""
self.stream.write(message)
def flush(self):
"""
Flush the current stream.
"""
self.stream.flush()
def restore(self):
"""Restore original stream"""
self.stream = self.terminal
def redirect(self):
"""Redirect stream to log file"""
self.stream = self.log
def _silence_stderr():
"""
Points the stderr FD (2) to /dev/null, silencing it.
"""
out_fd = os.open('/dev/null', os.O_WRONLY | os.O_CREAT)
try:
os.dup2(out_fd, 2)
finally:
os.close(out_fd)
sys.stderr = os.fdopen(2, 'w')
def _handle_stdout(options):
"""
Replace stdout with a proxy object.
Depending on self.options.verbose, make proxy print to /dev/null, or
original sys.stdout stream.
"""
if not options.vt_verbose:
_silence_stderr()
# Replace stdout with our proxy pointing to /dev/null
sys.stdout = StreamProxy(filename="/dev/null", stream=sys.stdout)
else:
# Retain full stdout
sys.stdout = StreamProxy(filename=None, stream=sys.stdout)
def _restore_stdout():
"""
Restore stdout. Used to re-enable stdout on error paths.
"""
try:
sys.stdout.restore()
except AttributeError:
pass
def _import_autotest_modules():
"""
Import the autotest modules.
Two methods will be attempted:
1) If $AUTOTEST_PATH is set, import the libraries from an autotest checkout
at $AUTOTEST_PATH.
2) Import the libraries system wide. For this to work, the
autotest-framework package for the given distro must be installed.
"""
autotest_dir = os.environ.get('AUTOTEST_PATH')
if autotest_dir is not None:
autotest_dir = os.path.expanduser(autotest_dir)
autotest_dir = os.path.abspath(autotest_dir)
client_dir = os.path.join(autotest_dir, 'client')
setup_modules_path = os.path.join(client_dir, 'setup_modules.py')
import imp
try:
setup_modules = imp.load_source('autotest_setup_modules',
setup_modules_path)
except:
print "Failed to import autotest modules from $AUTOTEST_PATH"
print "Could not load Python module %s" % (setup_modules_path)
sys.exit(1)
setup_modules.setup(base_path=client_dir,
root_module_name="autotest.client")
try:
from autotest.client import setup_modules
except ImportError:
print "Couldn't import autotest.client module"
if autotest_dir is None:
print("Environment variable $AUTOTEST_PATH not set. "
"please set it to a path containing an autotest checkout")
print("Or install autotest-framework for your distro")
sys.exit(1)
def _find_default_qemu_paths(options_qemu=None, options_dst_qemu=None):
qemu_bin_path = None
from virttest import utils_misc
if options_qemu:
if not os.path.isfile(options_qemu):
raise RuntimeError("Invalid qemu binary provided (%s)" %
options_qemu)
qemu_bin_path = options_qemu
else:
try:
qemu_bin_path = utils_misc.find_command('qemu-kvm')
except ValueError:
qemu_bin_path = utils_misc.find_command('kvm')
if options_dst_qemu is not None:
if not os.path.isfile(options_dst_qemu):
raise RuntimeError("Invalid dst qemu binary provided (%s)" %
options_dst_qemu)
qemu_dst_bin_path = options_dst_qemu
else:
qemu_dst_bin_path = None
qemu_dirname = os.path.dirname(qemu_bin_path)
qemu_img_path = os.path.join(qemu_dirname, 'qemu-img')
qemu_io_path = os.path.join(qemu_dirname, 'qemu-io')
if not os.path.exists(qemu_img_path):
qemu_img_path = utils_misc.find_command('qemu-img')
if not os.path.exists(qemu_io_path):
qemu_io_path = utils_misc.find_command('qemu-io')
return [qemu_bin_path, qemu_img_path, qemu_io_path, qemu_dst_bin_path]
SUPPORTED_LOG_LEVELS = [
"debug", "info", "warning", "error", "critical"]
SUPPORTED_TEST_TYPES = [
'qemu', 'libvirt', 'libguestfs', 'openvswitch', 'v2v', 'lvsb']
SUPPORTED_LIBVIRT_URIS = ['qemu:///system', 'lxc:///']
SUPPORTED_LIBVIRT_DRIVERS = ['qemu', 'lxc', 'xen']
SUPPORTED_IMAGE_TYPES = ['raw', 'qcow2', 'qed', 'vmdk']
SUPPORTED_DISK_BUSES = ['ide', 'scsi', 'virtio_blk', 'virtio_scsi', 'lsi_scsi',
'ahci', 'usb2', 'xenblk']
SUPPORTED_NIC_MODELS = ["virtio_net", "e1000", "rtl8139", "spapr-vlan"]
SUPPORTED_NET_TYPES = ["bridge", "user", "none"]
class VirtTestRunParser(optparse.OptionParser):
def __init__(self):
optparse.OptionParser.__init__(self, usage='Usage: %prog [options]')
from virttest import data_dir
import virttest.defaults
self.default_guest_os = virttest.defaults.DEFAULT_GUEST_OS
try:
qemu_bin_path = _find_default_qemu_paths()[0]
except ValueError:
qemu_bin_path = "Could not find one"
if os.getuid() == 0:
nettype_default = 'bridge'
else:
nettype_default = 'user'
debug = optparse.OptionGroup(self, 'Debug Options')
debug.add_option("-v", "--verbose", action="store_true",
dest="vt_verbose", help=("Exhibit test "
"messages in the console "
"(used for debugging)"))
debug.add_option("--console-level", action="store",
dest="vt_console_level",
default="debug",
help=("Log level of test messages in the console. Only valid "
"with --verbose. "
"Supported levels: " +
", ".join(SUPPORTED_LOG_LEVELS) +
". Default: %default"))
debug.add_option("--show-open-fd", action="store_true",
dest="vt_show_open_fd", help=("Show how many "
"open fds at the end of "
"each test "
"(used for debugging)"))
self.add_option_group(debug)
general = optparse.OptionGroup(self, 'General Options')
general.add_option("-b", "--bootstrap", action="store_true",
dest="vt_bootstrap", help=("Perform test suite setup "
"procedures, such as "
"downloading JeOS and check "
"required programs and "
"libs. Requires -t to be set"))
general.add_option("--update-config", action="store_true",
default=False,
dest="vt_update_config", help=("Forces configuration "
"updates (all manual "
"config file editing "
"will be lost). "
"Requires -t to be set"))
general.add_option("--update-providers", action="store_true",
default=False,
dest="vt_update_providers", help=("Forces test "
"providers to be "
"updated (git repos "
"will be pulled)"))
general.add_option("-t", "--type", action="store", dest="vt_type",
help="Choose test type (%s)" %
", ".join(SUPPORTED_TEST_TYPES))
general.add_option("--connect-uri", action="store", dest="vt_connect_uri",
help="Choose test connect uri for libvirt (E.g: %s)" %
", ".join(SUPPORTED_LIBVIRT_URIS))
general.add_option("-c", "--config", action="store", dest="vt_config",
help=("Explicitly choose a cartesian config. "
"When choosing this, some options will be "
"ignored"))
general.add_option("--no-downloads", action="store_true",
dest="vt_no_downloads", default=False,
help="Do not attempt to download JeOS images")
general.add_option("--selinux-setup", action="store_true",
dest="vt_selinux_setup", default=False,
help="Define default contexts of directory.")
general.add_option("-k", "--keep-image", action="store_true",
dest="vt_keep_image",
help=("Don't restore the JeOS image from pristine "
"at the beginning of the test suite run "
"(faster but unsafe)"))
general.add_option("--keep-image-between-tests",
action="store_true", default=False,
dest="vt_keep_image_between_tests",
help=("Don't restore the JeOS image from pristine "
"between tests (faster but unsafe)"))
general.add_option("-g", "--guest-os", action="store", dest="vt_guest_os",
default=None,
help=("Select the guest OS to be used. "
"If -c is provided, this will be ignored. "
"Default: %s" % self.default_guest_os))
general.add_option("--arch", action="store", dest="vt_arch",
default=None,
help=("Architecture under test. "
"If -c is provided, this will be ignored. "
"Default: any that supports the given machine type"))
general.add_option("--machine-type", action="store", dest="vt_machine_type",
default=None,
help=("Machine type under test. "
"If -c is provided, this will be ignored. "
"Default: all for the chosen guests, %s if "
"--guest-os not given." % virttest.defaults.DEFAULT_MACHINE_TYPE))
general.add_option("--tests", action="store", dest="vt_tests",
default="",
help=('List of space separated tests to be '
'executed. '
'If -c is provided, this will be ignored.'
' - example: --tests "boot reboot shutdown"'))
general.add_option("--list-tests", action="store_true", dest="vt_list_tests",
help="List tests available")
general.add_option("--list-guests", action="store_true",
dest="vt_list_guests",
help="List guests available")
general.add_option("--logs-dir", action="store", dest="vt_log_dir",
help=("Path to the logs directory. "
"Default path: %s" %
os.path.join(data_dir.get_backing_data_dir(),
'logs')))
general.add_option("--data-dir", action="store", dest="vt_data_dir",
help=("Path to a data dir. "
"Default path: %s" %
data_dir.get_backing_data_dir()))
general.add_option("--keep-guest-running", action="store_true",
dest="vt_keep_guest_running", default=False,
help=("Don't shut down guests at the end of each "
"test (faster but unsafe)"))
general.add_option("-m", "--mem", action="store", dest="vt_mem",
default="1024",
help=("RAM dedicated to the main VM. Default:"
"%default"))
general.add_option("--no", action="store", dest="vt_no_filter", default="",
help=("List of space separated no filters to be "
"passed to the config parser. If -c is "
"provided, this will be ignored"))
general.add_option("--type-specific", action="store_true",
dest="vt_type_specific", default=False,
help=("Enable only type specific tests. Shared"
" tests will not be tested."))
general.add_option("--run-dropin", action="store_true", dest="vt_dropin",
default=False,
help=("Run tests present on the drop in dir on the "
"host. Incompatible with --tests."))
general.add_option("--log-level", action="store", dest="vt_log_level",
default="debug",
help=("Set log level for top level log file."
" Supported levels: " +
", ".join(SUPPORTED_LOG_LEVELS) +
". Default: %default"))
general.add_option("--no-cleanup", action="store_true",
dest="vt_no_cleanup",
default=False,
help=("Don't clean up tmp files or VM processes at "
"the end of a virt-test execution (useful "
"for debugging)"))
self.add_option_group(general)
qemu = optparse.OptionGroup(self, 'Options specific to the qemu test')
qemu.add_option("--qemu-bin", action="store", dest="vt_qemu_bin",
default=None,
help=("Path to a custom qemu binary to be tested. "
"If -c is provided and this flag is omitted, "
"no attempt to set the qemu binaries will be made. "
"Default path: %s" % qemu_bin_path))
qemu.add_option("--qemu-dst-bin", action="store", dest="vt_dst_qemu_bin",
default=None,
help=("Path to a custom qemu binary to be tested for "
"the destination of a migration, overrides "
"--qemu-bin. "
"If -c is provided and this flag is omitted, "
"no attempt to set the qemu binaries will be made. "
"Default path: %s" % qemu_bin_path))
qemu.add_option("--use-malloc-perturb", action="store",
dest="vt_malloc_perturb", default="yes",
help=("Use MALLOC_PERTURB_ env variable set to 1 "
"to help catch memory allocation problems on "
"qemu (yes or no). Default: %default"))
qemu.add_option("--accel", action="store", dest="vt_accel", default="kvm",
help=("Accelerator used to run qemu (kvm or tcg). "
"Default: kvm"))
help_msg = "QEMU network option (%s). " % ", ".join(
SUPPORTED_NET_TYPES)
help_msg += "Default: %default"
qemu.add_option("--nettype", action="store", dest="vt_nettype",
default=nettype_default, help=help_msg)
qemu.add_option("--netdst", action="store", dest="vt_netdst",
default="virbr0",
help=("Bridge name to be used "
"(if you chose bridge as nettype). "
"Default: %default"))
qemu.add_option("--vhost", action="store", dest="vt_vhost",
default="off",
help=("Whether to enable vhost for qemu "
"(on/off/force). Depends on nettype=bridge. "
"If -c is provided, this will be ignored. "
"Default: %default"))
qemu.add_option("--monitor", action="store", dest="vt_monitor",
default='human',
help="Monitor type (human or qmp). Default: %default")
qemu.add_option("--smp", action="store", dest="vt_smp",
default='2',
help=("Number of virtual cpus to use. "
"If -c is provided, this will be ignored. "
"Default: %default"))
qemu.add_option("--image-type", action="store", dest="vt_image_type",
default="qcow2",
help=("Image format type to use "
"(any valid qemu format). "
"If -c is provided, this will be ignored. "
"Default: %default"))
qemu.add_option("--nic-model", action="store", dest="vt_nic_model",
default="virtio_net",
help=("Guest network card model. "
"If -c is provided, this will be ignored. "
"(any valid qemu format). Default: %default"))
qemu.add_option("--disk-bus", action="store", dest="vt_disk_bus",
default="virtio_blk",
help=("Guest main image disk bus. One of " +
" ".join(SUPPORTED_DISK_BUSES) +
". If -c is provided, this will be ignored. "
"Default: %default"))
qemu.add_option("--qemu_sandbox", action="store", dest="vt_qemu_sandbox",
default="on",
help=("Enable qemu sandboxing "
"(on/off). Default: %default"))
qemu.add_option("--defconfig", action="store", dest="vt_defconfig",
default="yes",
help=("Prevent qemu from loading sysconfdir/qemu.conf "
"and sysconfdir/target-ARCH.conf at startup. "
"(yes/no). Default: %default"))
self.add_option_group(qemu)
libvirt = optparse.OptionGroup(self, 'Options specific to the libvirt test')
libvirt.add_option("--install", action="store_true", dest="vt_install_guest",
help=("Install the guest using import method before "
"the tests are run."))
libvirt.add_option("--remove", action="store_true", dest="vt_remove_guest",
help=("Remove the guest from libvirt. This will not "
"delete the guest's disk file."))
self.add_option_group(libvirt)
def variant_only_file(filename):
"""
Parse file containing flat list of items to append on an 'only' filter
"""
from virttest import data_dir
result = []
if not os.path.isabs(filename):
fullpath = os.path.realpath(os.path.join(data_dir.get_root_dir(),
filename))
for line in open(fullpath).readlines():
line = line.strip()
if line.startswith('#') or len(line) < 3:
continue
result.append(line)
return ", ".join(result)
QEMU_DEFAULT_SET = "migrate..tcp, migrate..unix, migrate..exec, migrate..fd"
LIBVIRT_DEFAULT_SET = variant_only_file('backends/libvirt/cfg/default_tests')
LVSB_DEFAULT_SET = ("lvsb_date")
OVS_DEFAULT_SET = ("load_module, ovs_basic")
LIBVIRT_INSTALL = "unattended_install.import.import.default_install.aio_native"
LIBVIRT_REMOVE = "remove_guest.without_disk"
class VirtTestApp(object):
"""
Class representing the execution of the virt test runner.
"""
@staticmethod
def system_setup():
"""Set up things that affect the whole process
Initialize things that will affect the whole process, such as
environment variables, setting up Python module paths, or redirecting
stdout and/or stderr.
"""
# workaround for a but in some Autotest versions, that call
# logging.basicConfig() with DEBUG loglevel as soon as the modules
# are imported
logging.basicConfig(loglevel=logging.ERROR)
_import_autotest_modules()
# set English environment
# (command output might be localized, need to be safe)
os.environ['LANG'] = 'en_US.UTF-8'
def __init__(self):
"""
Parses options and initializes attributes.
@attribute option_parser: option parser instance with app options.
@attribute options: options resulted from option parser.
@attribute cartesian_parser: specialized test config parser, it's going
to be set to something useful later.
"""
self.system_setup()
self.option_parser = VirtTestRunParser()
self.options, self.args = self.option_parser.parse_args()
self.cartesian_parser = None
def _process_qemu_bin(self):
"""
Puts the value of the qemu bin option in the cartesian parser command.
"""
if self.options.vt_config and self.options.vt_qemu_bin is None:
logging.info("Config provided and no --qemu-bin set. Not trying "
"to automatically set qemu bin.")
else:
(qemu_bin_path, qemu_img_path, qemu_io_path,
qemu_dst_bin_path) = _find_default_qemu_paths(self.options.vt_qemu_bin,
self.options.vt_dst_qemu_bin)
self.cartesian_parser.assign("qemu_binary", qemu_bin_path)
self.cartesian_parser.assign("qemu_img_binary", qemu_img_path)
self.cartesian_parser.assign("qemu_io_binary", qemu_io_path)
if qemu_dst_bin_path is not None:
self.cartesian_parser.assign("qemu_dst_binary",
qemu_dst_bin_path)
def _process_qemu_img(self):
"""
Puts the value of the qemu bin option in the cartesian parser command.
"""
if self.options.vt_config and self.options.vt_qemu_bin is None:
logging.info("Config provided and no --qemu-bin set. Not trying "
"to automatically set qemu bin.")
else:
(_, qemu_img_path,
_, _) = _find_default_qemu_paths(self.options.vt_qemu_bin,
self.options.vt_dst_qemu_bin)
self.cartesian_parser.assign("qemu_img_binary", qemu_img_path)
def _process_qemu_accel(self):
"""
Puts the value of the qemu bin option in the cartesian parser command.
"""
if self.options.vt_accel == 'tcg':
self.cartesian_parser.assign("disable_kvm", "yes")
def _process_bridge_mode(self):
if self.options.vt_nettype not in SUPPORTED_NET_TYPES:
_restore_stdout()
print("Invalid --nettype option '%s'. Valid options are: (%s)" %
(self.options.vt_nettype, ", ".join(SUPPORTED_NET_TYPES)))
sys.exit(1)
if self.options.vt_nettype == 'bridge':
if os.getuid() != 0:
_restore_stdout()
print("In order to use bridge, you need to be root, "
"aborting...")
sys.exit(1)
self.cartesian_parser.assign("nettype", "bridge")
self.cartesian_parser.assign("netdst", self.options.vt_netdst)
elif self.options.vt_nettype == 'user':
self.cartesian_parser.assign("nettype", "user")
elif self.options.vt_nettype == 'none':
self.cartesian_parser.assign("nettype", "none")
def _process_monitor(self):
if self.options.vt_monitor == 'qmp':
self.cartesian_parser.assign("monitors", "qmp1")
self.cartesian_parser.assign("monitor_type_qmp1", "qmp")
def _process_smp(self):
if not self.options.vt_config:
if self.options.vt_smp == '1':
self.cartesian_parser.only_filter("up")
elif self.options.vt_smp == '2':
self.cartesian_parser.only_filter("smp2")
else:
try:
self.cartesian_parser.only_filter("up")
self.cartesian_parser.assign(
"smp", int(self.options.vt_smp))
except ValueError:
_restore_stdout()
print("Invalid option for smp: %s, aborting..." %
self.options.vt_smp)
sys.exit(1)
else:
logging.info("Config provided, ignoring --smp option")
def _process_arch(self):
if self.options.vt_arch is None:
pass
elif not self.options.vt_config:
self.cartesian_parser.only_filter(self.options.vt_arch)
else:
logging.info("Config provided, ignoring --arch option")
def _process_machine_type(self):
if not self.options.vt_config:
if self.options.vt_machine_type is None:
# TODO: this is x86-specific, instead we can get the default
# arch from qemu binary and run on all supported machine types
if self.options.vt_arch is None and self.options.vt_guest_os is None:
import virttest.defaults
self.cartesian_parser.only_filter(
virttest.defaults.DEFAULT_MACHINE_TYPE)
else:
self.cartesian_parser.only_filter(self.options.vt_machine_type)
else:
logging.info("Config provided, ignoring --machine-type option")
def _process_image_type(self):
if not self.options.vt_config:
if self.options.vt_image_type in SUPPORTED_IMAGE_TYPES:
self.cartesian_parser.only_filter(self.options.vt_image_type)
else:
self.cartesian_parser.only_filter("raw")
# The actual param name is image_format.
self.cartesian_parser.assign("image_format",
self.options.vt_image_type)
else:
logging.info("Config provided, ignoring --image-type option")
def _process_nic_model(self):
if not self.options.vt_config:
if self.options.vt_nic_model in SUPPORTED_NIC_MODELS:
self.cartesian_parser.only_filter(self.options.vt_nic_model)
else:
self.cartesian_parser.only_filter("nic_custom")
self.cartesian_parser.assign(
"nic_model", self.options.vt_nic_model)
else:
logging.info("Config provided, ignoring --nic-model option")
def _process_disk_buses(self):
if not self.options.vt_config:
if self.options.vt_disk_bus in SUPPORTED_DISK_BUSES:
self.cartesian_parser.only_filter(self.options.vt_disk_bus)
else:
_restore_stdout()
print("Option %s is not in the list %s, aborting..." %
(self.options.vt_disk_bus, SUPPORTED_DISK_BUSES))
sys.exit(1)
else:
logging.info("Config provided, ignoring --disk-bus option")
def _process_vhost(self):
if not self.options.vt_config:
if self.options.vt_nettype == "bridge":
if self.options.vt_vhost == "on":
self.cartesian_parser.assign("vhost", "on")
elif self.options.vt_vhost == "force":
self.cartesian_parser.assign("netdev_extra_params",
'",vhostforce=on"')
self.cartesian_parser.assign("vhost", "on")
else:
if self.options.vt_vhost in ["on", "force"]:
_restore_stdout()
print("Nettype %s is incompatible with vhost %s, "
"aborting..." %
(self.options.vt_nettype, self.options.vt_vhost))
sys.exit(1)
else:
logging.info("Config provided, ignoring --vhost option")
def _process_qemu_sandbox(self):
if not self.options.vt_config:
if self.options.vt_qemu_sandbox:
self.cartesian_parser.assign("qemu_sandbox",
self.options.vt_qemu_sandbox)
else:
logging.info(
"Config provided, ignoring \"--sandbox <on|off>\" option")
def _process_qemu_defconfig(self):
if not self.options.vt_config:
if self.options.vt_defconfig == "no":
self.cartesian_parser.assign("defconfig", "no")
else:
logging.info(
"Config provided, ignoring \"--defconfig <yes|no>\" option")
def _process_malloc_perturb(self):
self.cartesian_parser.assign("malloc_perturb",
self.options.vt_malloc_perturb)
def _process_qemu_specific_options(self):
"""
Calls for processing all options specific to the qemu test.
This method modifies the cartesian set by parsing additional lines.
"""
self._process_qemu_bin()
self._process_qemu_accel()
self._process_monitor()
self._process_smp()
self._process_image_type()
self._process_nic_model()
self._process_disk_buses()
self._process_vhost()
self._process_malloc_perturb()
self._process_qemu_sandbox()
self._process_qemu_defconfig()
def _process_lvsb_specific_options(self):
"""
Calls for processing all options specific to lvsb test
"""
self.options.vt_no_downloads = True
def _process_libvirt_specific_options(self):
"""
Calls for processing all options specific to libvirt test.
"""
if self.options.vt_connect_uri:
driver_found = False
for driver in SUPPORTED_LIBVIRT_DRIVERS:
if self.options.vt_connect_uri.count(driver):
driver_found = True
self.cartesian_parser.only_filter(driver)
if not driver_found:
print("Not supported uri: %s." % self.options.vt_connect_uri)
sys.exit(1)
else:
self.cartesian_parser.only_filter("qemu")
def _process_guest_os(self):
if not self.options.vt_config:
from virttest import standalone_test
if len(standalone_test.get_guest_name_list(self.options)) == 0:
_restore_stdout()
print("Guest name %s is not on the known guest os list "
"(see --list-guests), aborting..." %
self.options.vt_guest_os)
sys.exit(1)
self.cartesian_parser.only_filter(
self.options.vt_guest_os or self.option_parser.default_guest_os)
else:
logging.info("Config provided, ignoring --guest-os option")
def _process_list(self):
from virttest import standalone_test
if self.options.vt_list_tests:
standalone_test.print_test_list(self.options,
self.cartesian_parser)
sys.exit(0)
if self.options.vt_list_guests:
standalone_test.print_guest_list(self.options)
sys.exit(0)
def _process_tests(self):
if not self.options.vt_config:
if self.options.vt_type:
if self.options.vt_tests and self.options.vt_dropin:
print("Option --tests and --run-dropin can't be set at "
"the same time")
sys.exit(1)
elif self.options.vt_tests:
tests = self.options.vt_tests.split(" ")
if self.options.vt_type == 'libvirt':
if self.options.vt_install_guest:
tests.insert(0, LIBVIRT_INSTALL)
if self.options.vt_remove_guest:
tests.append(LIBVIRT_REMOVE)
self.cartesian_parser.only_filter(", ".join(tests))
elif self.options.vt_dropin:
from virttest import data_dir
dropin_tests = os.listdir(
os.path.join(data_dir.get_root_dir(), "dropin"))
if len(dropin_tests) <= 1:
_restore_stdout()
print("No drop in tests detected, aborting. "
"Make sure you have scripts on the 'dropin' "
"directory")
sys.exit(1)
self.cartesian_parser.only_filter("dropin")
else:
if self.options.vt_type == 'qemu':
self.cartesian_parser.only_filter(QEMU_DEFAULT_SET)
self.cartesian_parser.no_filter("with_reboot")
elif self.options.vt_type == 'libvirt':
self.cartesian_parser.only_filter(LIBVIRT_DEFAULT_SET)
elif self.options.vt_type == 'lvsb':
self.cartesian_parser.only_filter(LVSB_DEFAULT_SET)
elif self.options.vt_type == 'openvswitch':
self.cartesian_parser.only_filter(OVS_DEFAULT_SET)
else:
logging.info("Config provided, ignoring --tests option")
def _process_restart_vm(self):
if not self.options.vt_config:
if not self.options.vt_keep_guest_running:
self.cartesian_parser.assign("kill_vm", "yes")
def _process_restore_image_between_tests(self):
if not self.options.vt_config:
if not self.options.vt_keep_image_between_tests:
self.cartesian_parser.assign("restore_image", "yes")
def _process_mem(self):
self.cartesian_parser.assign("mem", self.options.vt_mem)
def _process_tcpdump(self):
"""
Verify whether we can run tcpdump. If we can't, turn it off.
"""
from virttest import utils_misc
try:
tcpdump_path = utils_misc.find_command('tcpdump')
except ValueError:
tcpdump_path = None
non_root = os.getuid() != 0
if tcpdump_path is None or non_root:
self.cartesian_parser.assign("run_tcpdump", "no")
def _process_no_filter(self):
if not self.options.vt_config:
if self.options.vt_no_filter:
no_filter = ", ".join(self.options.vt_no_filter.split(' '))
self.cartesian_parser.no_filter(no_filter)
def _process_only_type_specific(self):
if not self.options.vt_config:
if self.options.vt_type_specific:
self.cartesian_parser.only_filter("(subtest=type_specific)")
def _process_general_options(self):
"""
Calls for processing all generic options.
This method modifies the cartesian set by parsing additional lines.
"""
self._process_guest_os()
self._process_arch()
self._process_machine_type()
self._process_restart_vm()
self._process_restore_image_between_tests()
self._process_mem()
self._process_tcpdump()
self._process_no_filter()
self._process_qemu_img()
self._process_bridge_mode()
self._process_only_type_specific()
def _process_options(self):
"""
Process the options given in the command line.
"""
from virttest import cartesian_config, standalone_test
from virttest import data_dir, bootstrap, arch
if (not self.options.vt_type) and (not self.options.vt_config):
_restore_stdout()
print("No type (-t) or config (-c) options specified, aborting...")
sys.exit(1)
if self.options.vt_update_config:
from autotest.client.shared import logging_manager
from virttest import utils_misc
_restore_stdout()
logging_manager.configure_logging(utils_misc.VirtLoggingConfig(),
verbose=True)
test_dir = data_dir.get_backend_dir(self.options.vt_type)
shared_dir = os.path.join(data_dir.get_root_dir(), "shared")
bootstrap.create_config_files(test_dir, shared_dir,
interactive=False,
force_update=True)
bootstrap.create_subtests_cfg(self.options.vt_type)
bootstrap.create_guest_os_cfg(self.options.vt_type)
sys.exit(0)
if self.options.vt_bootstrap:
_restore_stdout()
bootstrap.bootstrap(options=self.options,
interactive=True)
sys.exit(0)
if self.options.vt_type:
if self.options.vt_type not in SUPPORTED_TEST_TYPES:
_restore_stdout()
print("Invalid test type %s. Valid test types: %s. "
"Aborting..." % (self.options.vt_type,
" ".join(SUPPORTED_TEST_TYPES)))
sys.exit(1)
if self.options.vt_log_level not in SUPPORTED_LOG_LEVELS:
_restore_stdout()
print("Invalid log level '%s'. Valid log levels: %s. "
"Aborting..." % (self.options.vt_log_level,
" ".join(SUPPORTED_LOG_LEVELS)))
sys.exit(1)
num_level = getattr(logging, self.options.vt_log_level.upper(), None)
self.options.vt_log_level = num_level
if self.options.vt_console_level not in SUPPORTED_LOG_LEVELS:
_restore_stdout()
print("Invalid console level '%s'. Valid console levels: %s. "
"Aborting..." % (self.options.vt_console_level,
" ".join(SUPPORTED_LOG_LEVELS)))
sys.exit(1)
num_level_console = getattr(logging,
self.options.vt_console_level.upper(),
None)
self.options.vt_console_level = num_level_console
if self.options.vt_data_dir:
data_dir.set_backing_data_dir(self.options.vt_data_dir)
standalone_test.create_config_files(self.options)
self.cartesian_parser = cartesian_config.Parser(debug=False)
if self.options.vt_config:
cfg = os.path.abspath(self.options.vt_config)
if not self.options.vt_config:
cfg = data_dir.get_backend_cfg_path(
self.options.vt_type, 'tests.cfg')
self.cartesian_parser.parse_file(cfg)
if self.options.vt_type != 'lvsb':
self._process_general_options()
if self.options.vt_type == 'qemu':
self._process_qemu_specific_options()
elif self.options.vt_type == 'lvsb':
self._process_lvsb_specific_options()
elif self.options.vt_type == 'openvswitch':
self._process_qemu_specific_options()
elif self.options.vt_type == 'libvirt':
self._process_libvirt_specific_options()
# List and tests have to be the last things to be processed
self._process_list()
self._process_tests()
def main(self):
"""
Main point of execution of the test runner.
1) Handle stdout/err according to the options given.
2) Import the autotest modules.
3) Sets the console logging for tests.
4) Runs the tests according to the options given.
"""
_handle_stdout(self.options)
try:
from virttest import standalone_test
self._process_options()
standalone_test.reset_logging()
standalone_test.configure_console_logging(
loglevel=self.options.vt_console_level)
standalone_test.bootstrap_tests(self.options)
ok = standalone_test.run_tests(self.cartesian_parser, self.options)
except KeyboardInterrupt:
standalone_test.cleanup_env(self.cartesian_parser, self.options)
pid = os.getpid()
os.kill(pid, signal.SIGTERM)
except StopIteration:
_restore_stdout()
print("Empty config set generated ")
if self.options.vt_type:
print("Tests chosen: '%s'" % self.options.vt_tests)
print("Check that you typed the tests "
"names correctly, and double "
"check that tests show "
"in --list-tests for guest '%s'" %
(self.options.vt_guest_os or
self.option_parser.default_guest_os))
sys.exit(1)
if self.options.vt_config:
print("Please check your custom config file %s" %
self.options.vt_config)
sys.exit(1)
except Exception:
_restore_stdout()
print("Internal error, traceback follows...")
exc_type, exc_value, exc_traceback = sys.exc_info()
tb_info = traceback.format_exception(exc_type, exc_value,
exc_traceback.tb_next)
tb_info = "".join(tb_info)
for e_line in tb_info.splitlines():
print(e_line)
sys.exit(1)
if not ok:
sys.exit(1)
if __name__ == '__main__':
app = VirtTestApp()
app.main()