提交 f2b44d5c 编写于 作者: C Cleber Rosa

Avocado compatibility: introduce get_settings_values()

Which is a common interface for getting values from the current
settings implementation.  On systems using older Avocado, it will
use the old API, and on systems with more recent Avocado, the new
settings interface.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 231003ea
......@@ -20,12 +20,12 @@ import os
from avocado.core.loader import loader
from avocado.core.plugin_interfaces import CLI
from avocado.core.settings import settings
from avocado.utils import path as utils_path
from virttest import data_dir
from virttest import defaults
from virttest import standalone_test
from virttest.compat import get_settings_value
from virttest.standalone_test import SUPPORTED_TEST_TYPES
from virttest.standalone_test import SUPPORTED_LIBVIRT_URIS
......@@ -54,11 +54,11 @@ def add_basic_vt_options(parser):
", ".join(SUPPORTED_TEST_TYPES))
parser.add_argument("--vt-type", action="store", dest="vt.type",
help=msg, default=SUPPORTED_TEST_TYPES[0])
arch = settings.get_value('vt.common', 'arch', default=None)
arch = get_settings_value('vt.common', 'arch', default=None)
parser.add_argument("--vt-arch", help="Choose the VM architecture. "
"Default: %(default)s", default=arch,
dest='vt.common.arch')
machine = settings.get_value('vt.common', 'machine_type',
machine = get_settings_value('vt.common', 'machine_type',
default=defaults.DEFAULT_MACHINE_TYPE)
parser.add_argument("--vt-machine-type", help="Choose the VM machine type."
" Default: %(default)s", default=machine,
......@@ -102,7 +102,7 @@ def add_qemu_bin_vt_option(parser):
qemu_bin_path = standalone_test.find_default_qemu_paths()[0]
except (RuntimeError, utils_path.CmdNotFoundError):
qemu_bin_path = None
qemu_bin = settings.get_value('vt.qemu', 'qemu_bin',
qemu_bin = get_settings_value('vt.qemu', 'qemu_bin',
default=None)
if qemu_bin is None: # Allow default to be None when not set in setting
default_qemu_bin = None
......@@ -115,10 +115,10 @@ def add_qemu_bin_vt_option(parser):
" this flag is omitted, no attempt to set the qemu "
"binaries will be made. Current: %s"
% _str_or_none(qemu_bin))
qemu_dst = settings.get_value('vt.qemu', 'qemu_dst_bin',
qemu_dst = get_settings_value('vt.qemu', 'qemu_dst_bin',
default=qemu_bin_path)
parser.add_argument("--vt-qemu-dst-bin", action="store", default=qemu_dst,
dest="vt.qemu.qemu_dst_bin", help="Path "
parser.add_argument("--vt-qemu-dst-bin", action="store",
dest="vt.qemu.qemu_dst_bin", default=qemu_dst, help="Path "
"to a custom qemu binary to be tested for the "
"destination of a migration, overrides --vt-qemu-bin. "
"If --vt-config is provided and this flag is omitted, "
......@@ -161,7 +161,7 @@ class VTRun(CLI):
supported_uris = ", ".join(SUPPORTED_LIBVIRT_URIS)
msg = ("Choose test connect uri for libvirt (E.g: %s). "
"Current: %%(default)s" % supported_uris)
uri_current = settings.get_value('vt.libvirt', 'connect_uri',
uri_current = get_settings_value('vt.libvirt', 'connect_uri',
default=None)
vt_compat_group_libvirt.add_argument("--vt-connect-uri",
action="store",
......
......@@ -7,7 +7,6 @@ import string
import sys
from avocado.core import exit_codes
from avocado.core.settings import settings
from avocado.utils.process import pid_exists
from avocado.utils.stacktrace import log_exc_info
......@@ -16,6 +15,8 @@ from avocado.core.plugin_interfaces import JobPostTests as Post
from ..test import VirtTest
from virttest.compat import get_settings_value
from six.moves import xrange
......@@ -41,11 +42,9 @@ class VTJobLock(Pre, Post):
def __init__(self, **kwargs):
self.log = logging.getLogger("avocado.app")
self.lock_dir = os.path.expanduser(settings.get_value(
section="plugins.vtjoblock",
key="dir",
key_type=str,
default='/tmp'))
lock_dir = get_settings_value("plugins.vtjoblock", "dir",
key_type=str, default='/tmp')
self.lock_dir = os.path.expanduser(lock_dir)
self.lock_file = None
def _create_self_lock_file(self, job):
......
......@@ -20,9 +20,9 @@ import os
import sys
from avocado.core.loader import loader
from avocado.core.settings import settings
from avocado.core.plugin_interfaces import CLI
from virttest.compat import get_settings_value
from .vt import add_basic_vt_options, add_qemu_bin_vt_option
from ..loader import VirtTestLoader
......@@ -55,7 +55,7 @@ VIRT_TEST_PATH = None
if 'VIRT_TEST_PATH' in os.environ:
VIRT_TEST_PATH = os.environ['VIRT_TEST_PATH']
else:
VIRT_TEST_PATH = settings.get_value(section='virt_test',
VIRT_TEST_PATH = get_settings_value(section='virt_test',
key='virt_test_path', default=None)
if VIRT_TEST_PATH is not None:
......
......@@ -43,6 +43,10 @@ if is_registering_settings_required():
def set_opt_from_settings(opt, section, key, **kwargs):
"""No-op, default values are set at settings.register_option()."""
pass
def get_settings_value(section, key, **kwargs):
namespace = '%s.%s' % (section, key)
return settings.as_dict().get(namespace)
else:
def get_opt(opt, name):
"""
......@@ -74,3 +78,6 @@ else:
value = settings.get_value(section, key, **kwargs)
namespace = '%s.%s' % (section, key)
set_opt(opt, namespace, value)
def get_settings_value(section, key, **kwargs):
return settings.get_value(section, key, **kwargs)
......@@ -11,10 +11,11 @@ import shutil
import stat
from avocado.core import data_dir
from avocado.core.settings import settings
from avocado.utils import distro
from avocado.utils import path as utils_path
from virttest.compat import get_settings_value
from six.moves import xrange
if hasattr(sys, 'real_prefix'):
......@@ -209,7 +210,7 @@ def get_tmp_dir(public=True):
:param public: If public for all users' access
"""
persistent_dir = settings.get_value('vt.common', 'tmp_dir',
persistent_dir = get_settings_value('vt.common', 'tmp_dir',
default="")
if persistent_dir != "":
return persistent_dir
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册