tests/vm: Added configuration file support

Changes to tests/vm/basevm.py to allow accepting a configuration file
as a parameter. Allows for specifying VM options such as
cpu, machine, memory, and arbitrary qemu arguments for specifying options
such as NUMA configuration.
Also added an example conf_example_aarch64.yml and conf_example_x86.yml.

Signed-off-by: Robert Foley <robert.foley@linaro.org>
Reviewed-by: Peter Puhov <peter.puhov@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20200601211421.1277-4-robert.foley@linaro.org>
Message-Id: <20200701135652.1366-8-alex.bennee@linaro.org>
This commit is contained in:
Robert Foley 2020-07-01 14:56:19 +01:00 committed by Alex Bennée
parent 5d676197eb
commit 3f1e8137f2
5 changed files with 155 additions and 1 deletions

View file

@ -481,7 +481,6 @@ class BaseVM(object):
cwd=cidir,
stdin=self._devnull, stdout=self._stdout,
stderr=self._stdout)
return os.path.join(cidir, "cloud-init.iso")
def get_qemu_path(arch, build_path=None):
@ -497,6 +496,41 @@ def get_qemu_path(arch, build_path=None):
qemu_path = "qemu-system-" + arch
return qemu_path
def parse_config(config, args):
""" Parse yaml config and populate our config structure.
The yaml config allows the user to override the
defaults for VM parameters. In many cases these
defaults can be overridden without rebuilding the VM."""
if args.config:
config_file = args.config
elif 'QEMU_CONFIG' in os.environ:
config_file = os.environ['QEMU_CONFIG']
else:
return config
if not os.path.exists(config_file):
raise Exception("config file {} does not exist".format(config_file))
# We gracefully handle importing the yaml module
# since it might not be installed.
# If we are here it means the user supplied a .yml file,
# so if the yaml module is not installed we will exit with error.
try:
import yaml
except ImportError:
print("The python3-yaml package is needed "\
"to support config.yaml files")
# Instead of raising an exception we exit to avoid
# a raft of messy (expected) errors to stdout.
exit(1)
with open(config_file) as f:
yaml_dict = yaml.safe_load(f)
if 'qemu-conf' in yaml_dict:
config.update(yaml_dict['qemu-conf'])
else:
raise Exception("config file {} is not valid"\
" missing qemu-conf".format(config_file))
return config
def parse_args(vmcls):
def get_default_jobs():
@ -536,6 +570,9 @@ def parse_args(vmcls):
help="run tests with a snapshot")
parser.add_option("--genisoimage", default="genisoimage",
help="iso imaging tool")
parser.add_option("--config", "-c", default=None,
help="Provide config yaml for configuration. "\
"See config_example.yaml for example.")
parser.disable_interspersed_args()
return parser.parse_args()
@ -547,6 +584,7 @@ def main(vmcls, config=None):
if not argv and not args.build_qemu and not args.build_image:
print("Nothing to do?")
return 1
config = parse_config(config, args)
logging.basicConfig(level=(logging.DEBUG if args.debug
else logging.WARN))
vm = vmcls(args, config=config)