Skip to content

Commit

Permalink
Merge pull request #568 from oohal/reworks
Browse files Browse the repository at this point in the history
Reworks
  • Loading branch information
oohal authored Dec 17, 2019
2 parents 969c41b + dc43f79 commit 0eff377
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 74 deletions.
118 changes: 67 additions & 51 deletions OpTestConfiguration.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from common.OpTestOpenBMC import OpTestOpenBMC
from common.OpTestQemu import OpTestQemu
from common.OpTestMambo import OpTestMambo
from common.OpTestSystem import OpSystemState
import common.OpTestSystem
import common.OpTestHost
from common.OpTestIPMI import OpTestIPMI, OpTestSMCIPMI
Expand Down Expand Up @@ -161,6 +162,8 @@ def get_parser():
help="List available suites to run")
tgroup.add_argument("--list-tests", action='store_true',
help="List each test that would have been run")
tgroup.add_argument("--list-all-tests", action='store_true',
help="List all defined tests")
tgroup.add_argument("--run-suite", action='append',
help="Run a test suite(s)")
tgroup.add_argument("--run", action='append',
Expand Down Expand Up @@ -413,6 +416,14 @@ def get_parser():
hmcgroup.add_argument(
"--lpar-vios", help="Lpar VIOS to boot before other LPARS", default=None)

misc_group = parser.add_argument_group("Misc")
misc_group.add_argument("--check-ssh-keys", action='store_true', default=False,
help="Check remote host keys when using SSH (auto-yes on new)")
misc_group.add_argument("--known-hosts-file",
help="Specify a custom known_hosts file")
misc_group.add_argument("--accept-unknown-args", default=False, action='store_true',
help="Don't exit if we find unknown command line arguments")

return parser


Expand Down Expand Up @@ -455,46 +466,49 @@ def cleanup(self):
# attribute errors thrown in cleanup, e.g. ./op-test -h
self.util.cleanup()


def parse_config_file(self, filename, optional=False):
config = configparser.ConfigParser()

if not os.access(filename, os.R_OK):
if optional:
return {}
raise OSError(errno.ENOENT, os.strerror(errno.ENOENT), filename)

config.read(filename)

if config.has_section('op-test'):
d = dict(config.items('op-test'))
else:
msg = "{} is missing an an [op-test] section header".format(filename)
raise configparser.NoSectionError(msg)

return dict(config.items('op-test'))

def parse_args(self, argv=None):
conf_parser = argparse.ArgumentParser(add_help=False)
conf_parser.add_argument("-c", "--config-file", metavar="FILE")
config_args, _ = conf_parser.parse_known_args(argv)

# We have two parsers so we have correct --help, we need -c in both
conf_parser.add_argument("-c", "--config-file", help="Configuration File",
metavar="FILE")

args, remaining_args = conf_parser.parse_known_args(argv)
defaults = {}
config = configparser.SafeConfigParser()
config.read([os.path.expanduser("~/.op-test-framework.conf")])
if args.config_file:
if os.access(args.config_file, os.R_OK):
config.read([args.config_file])
else:
raise OSError(errno.ENOENT, os.strerror(
errno.ENOENT), args.config_file)
try:
defaults = dict(config.items('op-test'))
except configparser.NoSectionError:
pass

parser = get_parser()
parser.set_defaults(**defaults)
userfile = os.path.expanduser("~/.op-test-framework.conf")
self.defaults = self.parse_config_file(userfile, True)

if defaults.get('qemu_binary'):
qemu_default = defaults['qemu_binary']
# parse specified config file
if config_args.config_file:
cfg = self.parse_config_file(config_args.config_file)
self.defaults.update(cfg)

if defaults.get('mambo_binary'):
mambo_default = defaults['mambo_binary']
if defaults.get('mambo_initial_run_script'):
mambo_default = defaults['mambo_initial_run_script']
parser = get_parser()
parser.set_defaults(**self.defaults)

parser.add_argument("--check-ssh-keys", action='store_true', default=False,
help="Check remote host keys when using SSH (auto-yes on new)")
parser.add_argument("--known-hosts-file",
help="Specify a custom known_hosts file")
# don't parse argv[0]
self.args, self.remaining_args = parser.parse_known_args(argv[1:])

self.args, self.remaining_args = parser.parse_known_args(
remaining_args)
# we use parse_known_args() and generate our own usage because the number
# of args makes the default usage string... unwieldy
if len(self.remaining_args) > 0 and not self.args.accept_unknown_args:
raise Exception("Unknown command line argument(s): {}"
.format(str(self.remaining_args)))

args_dict = vars(self.args)

Expand All @@ -510,18 +524,30 @@ def parse_args(self, argv=None):
if args_dict.get(key) is None:
args_dict[key] = default_val[key]

stateMap = {'UNKNOWN': common.OpTestSystem.OpSystemState.UNKNOWN,
'UNKNOWN_BAD': common.OpTestSystem.OpSystemState.UNKNOWN_BAD,
'OFF': common.OpTestSystem.OpSystemState.OFF,
'PETITBOOT': common.OpTestSystem.OpSystemState.PETITBOOT,
'PETITBOOT_SHELL': common.OpTestSystem.OpSystemState.PETITBOOT_SHELL,
'OS': common.OpTestSystem.OpSystemState.OS
}

# Some quick sanity checking
if self.args.known_hosts_file and not self.args.check_ssh_keys:
parser.error("--known-hosts-file requires --check-ssh-keys")

# FIXME: Passing machine_state doesn't work at all with qemu or mambo
if self.args.machine_state == None:
if self.args.bmc_type in ['qemu', 'mambo']:
# Force UNKNOWN_BAD so that we don't try to setup the console early
self.startState = OpSystemState.UNKNOWN_BAD
else:
self.startState = OpSystemState.UNKNOWN
else:
stateMap = {'UNKNOWN': OpSystemState.UNKNOWN,
'UNKNOWN_BAD': OpSystemState.UNKNOWN_BAD,
'OFF': OpSystemState.OFF,
'PETITBOOT': OpSystemState.PETITBOOT,
'PETITBOOT_SHELL': OpSystemState.PETITBOOT_SHELL,
'OS': OpSystemState.OS
}
self.startState = stateMap[self.args.machine_state]
return self.args, self.remaining_args

def do_testing_setup(self):
# Setup some defaults for the output options
# Order of precedence
# 1. cmdline arg
Expand Down Expand Up @@ -602,7 +628,7 @@ def parse_args(self, argv=None):
self.atexit_ready = True
# now that we have loggers, dump conf file to help debug later
OpTestLogger.optest_logger_glob.optest_logger.debug(
"conf file defaults={}".format(defaults))
"conf file defaults={}".format(self.defaults))
cmd = "git describe --always"
try:
git_output = subprocess.check_output(cmd.split())
Expand Down Expand Up @@ -661,16 +687,6 @@ def parse_args(self, argv=None):
.format(self.args.locker_wait))
time.sleep(60)

if self.args.machine_state == None:
if self.args.bmc_type in ['qemu', 'mambo']:
# Force UNKNOWN_BAD so that we don't try to setup the console early
self.startState = common.OpTestSystem.OpSystemState.UNKNOWN_BAD
else:
self.startState = common.OpTestSystem.OpSystemState.UNKNOWN
else:
self.startState = stateMap[self.args.machine_state]
return self.args, self.remaining_args

def get_suffix(self):
# Grab the suffix, if not given use current time
if (self.args.suffix):
Expand Down
50 changes: 34 additions & 16 deletions op-test
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ import re
import signal
import logging
import OpTestLogger
import importlib
# op-test is the parent logger
optestlog = logging.getLogger(OpTestLogger.optest_logger_glob.parent_logger)

Expand Down Expand Up @@ -149,9 +148,39 @@ signal.signal(signal.SIGSEGV, optest_handler)
signal.signal(signal.SIGTERM, optest_handler)
signal.signal(signal.SIGUSR1, optest_handler)
signal.signal(signal.SIGUSR2, optest_handler)
args, remaining_args = OpTestConfiguration.conf.parse_args(sys.argv)
OpTestConfiguration.conf.objs()

# parse config options and create log files, take the host lock, etc.
try:
args, remaining_args = OpTestConfiguration.conf.parse_args(sys.argv)
except Exception as e:
print("Config error: {}".format(e));
sys.exit(1)

def print_tests(s):
for test in s:
if isinstance(test, unittest.TestSuite):
print_tests(test)
else:
test_id = test.id()
print('{0:40}'.format(test_id))

if OpTestConfiguration.conf.args.list_all_tests:
print_tests(unittest.TestLoader().discover('testcases', '*.py'))
exit(0)

# create loggers, take hostlocks, etc
try:
OpTestConfiguration.conf.do_testing_setup()
except Exception as e:
print()
print("Test setup error! {}".format(e));
print()
print(traceback.format_exc())
print()
OpTestConfiguration.conf.util.cleanup()
sys.exit(1)

OpTestConfiguration.conf.objs()

class SystemAccessSuite():
'''
Expand Down Expand Up @@ -837,8 +866,6 @@ try:
OpTestConfiguration.conf.util.cleanup()
exit(0)

importlib.reload(sys)

t = unittest.TestSuite()

if OpTestConfiguration.conf.args.run_suite:
Expand All @@ -860,18 +887,9 @@ try:
t.addTest(suites['default'].suite())

if OpTestConfiguration.conf.args.list_tests:
print('{0:40}'.format('Test'))
print('{0:40}'.format('Tests'))
print('{0:40}'.format('----------'))

def print_suite(s):
for test in s:
if isinstance(test, unittest.TestSuite):
print_suite(test)
else:
test_id = test.id()
print('{0:40}'.format(test_id))

print_suite(t)
print_tests(t)
OpTestConfiguration.conf.util.cleanup()
exit(0)

Expand Down
13 changes: 6 additions & 7 deletions testcases/OpTestInbandUsbInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@

import OpTestConfiguration
from common.OpTestSystem import OpSystemState
from testcases.OpTestInbandIPMI import BasicInbandIPMI, OpTestInbandIPMI, ExperimentalInbandIPMI
from testcases.OpTestInbandIPMI import SkirootBasicInbandIPMI, SkirootFullInbandIPMI
import testcases.OpTestInbandIPMI as ib


def experimental_suite():
Expand All @@ -71,7 +70,7 @@ def skiroot_full_suite():
return unittest.defaultTestLoader.loadTestsFromTestCase(SkirootInbandUSB)


class BasicInbandUSB(BasicInbandIPMI):
class BasicInbandUSB(ib.BasicInbandIPMI):
def setUp(self, ipmi_method=BMC_CONST.IPMITOOL_USB):
self.bmc_type = OpTestConfiguration.conf.args.bmc_type
if "FSP" in self.bmc_type:
Expand All @@ -81,7 +80,7 @@ def setUp(self, ipmi_method=BMC_CONST.IPMITOOL_USB):
super(BasicInbandUSB, self).setUp(ipmi_method=ipmi_method)


class InbandUSB(OpTestInbandIPMI):
class InbandUSB(ib.OpTestInbandIPMI):
def setUp(self, ipmi_method=BMC_CONST.IPMITOOL_USB):
self.bmc_type = OpTestConfiguration.conf.args.bmc_type
if "FSP" in self.bmc_type:
Expand All @@ -91,7 +90,7 @@ def setUp(self, ipmi_method=BMC_CONST.IPMITOOL_USB):
super(InbandUSB, self).setUp(ipmi_method=ipmi_method)


class SkirootBasicInbandUSB(SkirootBasicInbandIPMI):
class SkirootBasicInbandUSB(ib.SkirootBasicInbandIPMI):
def setUp(self, ipmi_method=BMC_CONST.IPMITOOL_USB):
self.bmc_type = OpTestConfiguration.conf.args.bmc_type
if "FSP" in self.bmc_type:
Expand All @@ -101,7 +100,7 @@ def setUp(self, ipmi_method=BMC_CONST.IPMITOOL_USB):
super(SkirootBasicInbandUSB, self).setUp(ipmi_method=ipmi_method)


class SkirootInbandUSB(SkirootFullInbandIPMI):
class SkirootInbandUSB(ib.SkirootFullInbandIPMI):
def setUp(self, ipmi_method=BMC_CONST.IPMITOOL_USB):
self.bmc_type = OpTestConfiguration.conf.args.bmc_type
if "FSP" in self.bmc_type:
Expand All @@ -111,7 +110,7 @@ def setUp(self, ipmi_method=BMC_CONST.IPMITOOL_USB):
super(SkirootInbandUSB, self).setUp(ipmi_method=ipmi_method)


class ExperimentalInbandUSB(ExperimentalInbandIPMI):
class ExperimentalInbandUSB(ib.ExperimentalInbandIPMI):
def setUp(self, ipmi_method=BMC_CONST.IPMITOOL_USB):
self.bmc_type = OpTestConfiguration.conf.args.bmc_type
if "FSP" in self.bmc_type:
Expand Down

0 comments on commit 0eff377

Please sign in to comment.