9
9
from common .OpTestOpenBMC import OpTestOpenBMC
10
10
from common .OpTestQemu import OpTestQemu
11
11
from common .OpTestMambo import OpTestMambo
12
+ from common .OpTestSystem import OpSystemState
12
13
import common .OpTestSystem
13
14
import common .OpTestHost
14
15
from common .OpTestIPMI import OpTestIPMI , OpTestSMCIPMI
@@ -161,6 +162,8 @@ def get_parser():
161
162
help = "List available suites to run" )
162
163
tgroup .add_argument ("--list-tests" , action = 'store_true' ,
163
164
help = "List each test that would have been run" )
165
+ tgroup .add_argument ("--list-all-tests" , action = 'store_true' ,
166
+ help = "List all defined tests" )
164
167
tgroup .add_argument ("--run-suite" , action = 'append' ,
165
168
help = "Run a test suite(s)" )
166
169
tgroup .add_argument ("--run" , action = 'append' ,
@@ -413,6 +416,14 @@ def get_parser():
413
416
hmcgroup .add_argument (
414
417
"--lpar-vios" , help = "Lpar VIOS to boot before other LPARS" , default = None )
415
418
419
+ misc_group = parser .add_argument_group ("Misc" )
420
+ misc_group .add_argument ("--check-ssh-keys" , action = 'store_true' , default = False ,
421
+ help = "Check remote host keys when using SSH (auto-yes on new)" )
422
+ misc_group .add_argument ("--known-hosts-file" ,
423
+ help = "Specify a custom known_hosts file" )
424
+ misc_group .add_argument ("--accept-unknown-args" , default = False , action = 'store_true' ,
425
+ help = "Don't exit if we find unknown command line arguments" )
426
+
416
427
return parser
417
428
418
429
@@ -455,46 +466,49 @@ def cleanup(self):
455
466
# attribute errors thrown in cleanup, e.g. ./op-test -h
456
467
self .util .cleanup ()
457
468
469
+
470
+ def parse_config_file (self , filename , optional = False ):
471
+ config = configparser .ConfigParser ()
472
+
473
+ if not os .access (filename , os .R_OK ):
474
+ if optional :
475
+ return {}
476
+ raise OSError (errno .ENOENT , os .strerror (errno .ENOENT ), filename )
477
+
478
+ config .read (filename )
479
+
480
+ if config .has_section ('op-test' ):
481
+ d = dict (config .items ('op-test' ))
482
+ else :
483
+ msg = "{} is missing an an [op-test] section header" .format (filename )
484
+ raise configparser .NoSectionError (msg )
485
+
486
+ return dict (config .items ('op-test' ))
487
+
458
488
def parse_args (self , argv = None ):
459
489
conf_parser = argparse .ArgumentParser (add_help = False )
490
+ conf_parser .add_argument ("-c" , "--config-file" , metavar = "FILE" )
491
+ config_args , _ = conf_parser .parse_known_args (argv )
460
492
461
- # We have two parsers so we have correct --help, we need -c in both
462
- conf_parser .add_argument ("-c" , "--config-file" , help = "Configuration File" ,
463
- metavar = "FILE" )
464
-
465
- args , remaining_args = conf_parser .parse_known_args (argv )
466
- defaults = {}
467
- config = configparser .SafeConfigParser ()
468
- config .read ([os .path .expanduser ("~/.op-test-framework.conf" )])
469
- if args .config_file :
470
- if os .access (args .config_file , os .R_OK ):
471
- config .read ([args .config_file ])
472
- else :
473
- raise OSError (errno .ENOENT , os .strerror (
474
- errno .ENOENT ), args .config_file )
475
- try :
476
- defaults = dict (config .items ('op-test' ))
477
- except configparser .NoSectionError :
478
- pass
479
-
480
- parser = get_parser ()
481
- parser .set_defaults (** defaults )
493
+ userfile = os .path .expanduser ("~/.op-test-framework.conf" )
494
+ self .defaults = self .parse_config_file (userfile , True )
482
495
483
- if defaults .get ('qemu_binary' ):
484
- qemu_default = defaults ['qemu_binary' ]
496
+ # parse specified config file
497
+ if config_args .config_file :
498
+ cfg = self .parse_config_file (config_args .config_file )
499
+ self .defaults .update (cfg )
485
500
486
- if defaults .get ('mambo_binary' ):
487
- mambo_default = defaults ['mambo_binary' ]
488
- if defaults .get ('mambo_initial_run_script' ):
489
- mambo_default = defaults ['mambo_initial_run_script' ]
501
+ parser = get_parser ()
502
+ parser .set_defaults (** self .defaults )
490
503
491
- parser .add_argument ("--check-ssh-keys" , action = 'store_true' , default = False ,
492
- help = "Check remote host keys when using SSH (auto-yes on new)" )
493
- parser .add_argument ("--known-hosts-file" ,
494
- help = "Specify a custom known_hosts file" )
504
+ # don't parse argv[0]
505
+ self .args , self .remaining_args = parser .parse_known_args (argv [1 :])
495
506
496
- self .args , self .remaining_args = parser .parse_known_args (
497
- remaining_args )
507
+ # we use parse_known_args() and generate our own usage because the number
508
+ # of args makes the default usage string... unwieldy
509
+ if len (self .remaining_args ) > 0 and not self .args .accept_unknown_args :
510
+ raise Exception ("Unknown command line argument(s): {}"
511
+ .format (str (self .remaining_args )))
498
512
499
513
args_dict = vars (self .args )
500
514
@@ -510,18 +524,30 @@ def parse_args(self, argv=None):
510
524
if args_dict .get (key ) is None :
511
525
args_dict [key ] = default_val [key ]
512
526
513
- stateMap = {'UNKNOWN' : common .OpTestSystem .OpSystemState .UNKNOWN ,
514
- 'UNKNOWN_BAD' : common .OpTestSystem .OpSystemState .UNKNOWN_BAD ,
515
- 'OFF' : common .OpTestSystem .OpSystemState .OFF ,
516
- 'PETITBOOT' : common .OpTestSystem .OpSystemState .PETITBOOT ,
517
- 'PETITBOOT_SHELL' : common .OpTestSystem .OpSystemState .PETITBOOT_SHELL ,
518
- 'OS' : common .OpTestSystem .OpSystemState .OS
519
- }
520
527
521
528
# Some quick sanity checking
522
529
if self .args .known_hosts_file and not self .args .check_ssh_keys :
523
530
parser .error ("--known-hosts-file requires --check-ssh-keys" )
524
531
532
+ # FIXME: Passing machine_state doesn't work at all with qemu or mambo
533
+ if self .args .machine_state == None :
534
+ if self .args .bmc_type in ['qemu' , 'mambo' ]:
535
+ # Force UNKNOWN_BAD so that we don't try to setup the console early
536
+ self .startState = OpSystemState .UNKNOWN_BAD
537
+ else :
538
+ self .startState = OpSystemState .UNKNOWN
539
+ else :
540
+ stateMap = {'UNKNOWN' : OpSystemState .UNKNOWN ,
541
+ 'UNKNOWN_BAD' : OpSystemState .UNKNOWN_BAD ,
542
+ 'OFF' : OpSystemState .OFF ,
543
+ 'PETITBOOT' : OpSystemState .PETITBOOT ,
544
+ 'PETITBOOT_SHELL' : OpSystemState .PETITBOOT_SHELL ,
545
+ 'OS' : OpSystemState .OS
546
+ }
547
+ self .startState = stateMap [self .args .machine_state ]
548
+ return self .args , self .remaining_args
549
+
550
+ def do_testing_setup (self ):
525
551
# Setup some defaults for the output options
526
552
# Order of precedence
527
553
# 1. cmdline arg
@@ -602,7 +628,7 @@ def parse_args(self, argv=None):
602
628
self .atexit_ready = True
603
629
# now that we have loggers, dump conf file to help debug later
604
630
OpTestLogger .optest_logger_glob .optest_logger .debug (
605
- "conf file defaults={}" .format (defaults ))
631
+ "conf file defaults={}" .format (self . defaults ))
606
632
cmd = "git describe --always"
607
633
try :
608
634
git_output = subprocess .check_output (cmd .split ())
@@ -661,16 +687,6 @@ def parse_args(self, argv=None):
661
687
.format (self .args .locker_wait ))
662
688
time .sleep (60 )
663
689
664
- if self .args .machine_state == None :
665
- if self .args .bmc_type in ['qemu' , 'mambo' ]:
666
- # Force UNKNOWN_BAD so that we don't try to setup the console early
667
- self .startState = common .OpTestSystem .OpSystemState .UNKNOWN_BAD
668
- else :
669
- self .startState = common .OpTestSystem .OpSystemState .UNKNOWN
670
- else :
671
- self .startState = stateMap [self .args .machine_state ]
672
- return self .args , self .remaining_args
673
-
674
690
def get_suffix (self ):
675
691
# Grab the suffix, if not given use current time
676
692
if (self .args .suffix ):
0 commit comments