本文整理汇总了Python中virttest.data_dir.get_root_dir函数的典型用法代码示例。如果您正苦于以下问题:Python get_root_dir函数的具体用法?Python get_root_dir怎么用?Python get_root_dir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_root_dir函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: prepare_repos
def prepare_repos(self):
"""
Prepare repos for the tests.
"""
def merge_pulls(repo_name, pull_nos):
branch_name = ','.join(pull_nos)
cmd = 'git checkout -b %s' % branch_name
res = utils.run(cmd, ignore_status=True)
if res.exit_status:
print res
raise Exception('Failed to create branch %s' % branch_name)
for pull_no in pull_nos:
patch_url = ('https://github.com/autotest'
'/%s/pull/%s.patch' % (repo_name, pull_no))
patch_file = "/tmp/%s.patch" % pull_no
urllib.urlretrieve(patch_url, patch_file)
try:
cmd = 'git am -3 %s' % patch_file
res = utils.run(cmd, ignore_status=True)
except:
print res
raise Exception('Failed applying patch %s' % pull_no)
finally:
os.remove(patch_file)
return branch_name
def file_changed(repo_name):
cmd = 'git diff master --name-only'
res = utils.run(cmd, ignore_status=True)
if res.exit_status:
print res
raise Exception("Failed to get diff info against master")
return res.stdout.strip().splitlines()
self.virt_branch_name, self.libvirt_branch_name = None, None
if self.args.virt_test_pull:
os.chdir(data_dir.get_root_dir())
self.virt_branch_name = merge_pulls(
"virt-test",
self.args.virt_test_pull.split(','))
self.virt_file_changed = file_changed("virt-test")
if self.args.libvirt_pull:
os.chdir(data_dir.get_test_provider_dir(
'io-github-autotest-libvirt'))
self.libvirt_branch_name = merge_pulls(
"tp-libvirt",
self.args.libvirt_pull.split(','))
self.libvirt_file_changed = file_changed("tp-libvirt")
os.chdir(data_dir.get_root_dir())
示例2: setup_or_cleanup_nfs
def setup_or_cleanup_nfs(is_setup, mount_dir="", is_mount=False):
"""
Set up or clean up nfs service on localhost.
:param is_setup: Boolean value, true for setup, false for cleanup
:param mount_dir: NFS mount point
:param is_mount: Boolean value, true for mount, false for umount
:return: export nfs path or nothing
"""
tmpdir = os.path.join(data_dir.get_root_dir(), 'tmp')
mount_src = os.path.join(tmpdir, 'nfs-export')
if not mount_dir:
mount_dir = os.path.join(tmpdir, 'nfs-mount')
nfs_params = {"nfs_mount_dir": mount_dir,
"nfs_mount_options": "rw",
"nfs_mount_src": mount_src,
"setup_local_nfs": "yes",
"export_options": "rw,no_root_squash"}
_nfs = nfs.Nfs(nfs_params)
if is_setup:
_nfs.setup()
if not is_mount:
_nfs.umount()
return mount_src
else:
_nfs.unexportfs_in_clean = True
_nfs.cleanup()
return ""
示例3: __init__
def __init__(self, methodName='runTest', name=None, params=None,
base_logdir=None, job=None, runner_queue=None,
vt_params=None):
"""
:note: methodName, name, base_logdir, job and runner_queue params
are inherited from test.Test
:param params: avocado/multiplexer params stored as
`self.avocado_params`.
:param vt_params: avocado-vt/cartesian_config params stored as
`self.params`.
"""
self.bindir = data_dir.get_root_dir()
self.virtdir = os.path.join(self.bindir, 'shared')
self.iteration = 0
self.resultsdir = None
self.file_handler = None
self.background_errors = Queue.Queue()
super(VirtTest, self).__init__(methodName=methodName, name=name,
params=params,
base_logdir=base_logdir, job=job,
runner_queue=runner_queue)
self.builddir = os.path.join(self.workdir, 'backends',
vt_params.get("vm_type"))
self.tmpdir = os.path.dirname(self.workdir)
# Move self.params to self.avocado_params and initialize virttest
# (cartesian_config) params
self.__params = utils_params.Params(vt_params)
self.debugdir = self.logdir
self.resultsdir = self.logdir
self.timeout = vt_params.get("test_timeout", self.timeout)
utils_misc.set_log_file_dir(self.logdir)
示例4: setup_or_cleanup_iscsi
def setup_or_cleanup_iscsi(is_setup, is_login=True,
emulated_image="emulated_iscsi", image_size="1G"):
"""
Set up(and login iscsi target) or clean up iscsi service on localhost.
:param is_setup: Boolean value, true for setup, false for cleanup
:param is_login: Boolean value, true for login, false for not login
:param emulated_image: name of iscsi device
:param image_size: emulated image's size
:return: iscsi device name or iscsi target
"""
try:
utils_misc.find_command("tgtadm")
utils_misc.find_command("iscsiadm")
except ValueError:
raise error.TestNAError("Missing command 'tgtadm' and/or 'iscsiadm'.")
tmpdir = os.path.join(data_dir.get_root_dir(), 'tmp')
emulated_path = os.path.join(tmpdir, emulated_image)
emulated_target = "iqn.2001-01.com.virttest:%s.target" % emulated_image
iscsi_params = {"emulated_image": emulated_path, "target": emulated_target,
"image_size": image_size, "iscsi_thread_id": "virt"}
_iscsi = iscsi.Iscsi(iscsi_params)
if is_setup:
sv_status = None
if utils_misc.selinux_enforcing():
sv_status = utils_selinux.get_status()
utils_selinux.set_status("permissive")
_iscsi.export_target()
if sv_status is not None:
utils_selinux.set_status(sv_status)
if is_login:
_iscsi.login()
# The device doesn't necessarily appear instantaneously, so give
# about 5 seconds for it to appear before giving up
iscsi_device = utils_misc.wait_for(_iscsi.get_device_name, 5, 0, 1,
"Searching iscsi device name.")
if iscsi_device:
logging.debug("iscsi device: %s", iscsi_device)
return iscsi_device
if not iscsi_device:
logging.error("Not find iscsi device.")
# Cleanup and return "" - caller needs to handle that
# _iscsi.export_target() will have set the emulated_id and
# export_flag already on success...
_iscsi.cleanup()
utils.run("rm -f %s" % emulated_path)
else:
return emulated_target
else:
_iscsi.export_flag = True
_iscsi.emulated_id = _iscsi.get_target_id()
_iscsi.cleanup()
utils.run("rm -f %s" % emulated_path)
return ""
示例5: run
def run(test, params, env):
"""
Run a dropin test.
"""
dropin_path = params.get("dropin_path")
dropin_path = os.path.join(data_dir.get_root_dir(), "dropin",
dropin_path)
try:
utils.system(dropin_path)
except error.CmdError:
raise error.TestFail("Drop in test %s failed" % dropin_path)
示例6: env_setup
def env_setup(session, ip_addr, username, shell_port, password):
"""
Test env setup
"""
error.context("Setup env for %s" % ip_addr)
ssh_cmd(session, "service iptables stop; true")
netperf_dir = os.path.join(data_dir.get_root_dir(), "shared/deps")
for i in params.get("netperf_files").split():
remote.scp_to_remote(ip_addr, shell_port, username, password,
"%s/%s" % (netperf_dir, i), "/tmp/")
ssh_cmd(session, params.get("setup_cmd"))
示例7: env_setup
def env_setup(session, ip, user, port, password):
error.context("Setup env for %s" % ip)
ssh_cmd(session, "service iptables stop")
ssh_cmd(session, "echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore")
netperf_dir = os.path.join(data_dir.get_root_dir(), "shared/deps")
for i in params.get("netperf_files").split():
remote.scp_to_remote(ip, shell_port, username, password, "%s/%s" % (netperf_dir, i), "/tmp/")
ssh_cmd(session, params.get("setup_cmd"))
agent_path = os.path.join(test.virtdir, "scripts/netperf_agent.py")
remote.scp_to_remote(ip, shell_port, username, password, agent_path, "/tmp/")
示例8: restore_repos
def restore_repos(self):
"""
Checkout master branch and remove test branch.
"""
def restore_repo(branch_name):
cmd = 'git checkout master'
res = utils.run(cmd, ignore_status=True)
if res.exit_status:
print res
cmd = 'git branch -D %s' % branch_name
res = utils.run(cmd, ignore_status=True)
if res.exit_status:
print res
if self.virt_branch_name:
os.chdir(data_dir.get_root_dir())
restore_repo(self.virt_branch_name)
if self.libvirt_branch_name:
os.chdir(data_dir.get_test_provider_dir(
'io-github-autotest-libvirt'))
restore_repo(self.libvirt_branch_name)
os.chdir(data_dir.get_root_dir())
示例9: manipulate_domain
def manipulate_domain(vm_name, vm_operation, recover=False):
"""
Operate domain to given state or recover it.
"""
tmpdir = os.path.join(data_dir.get_root_dir(), 'tmp')
save_file = os.path.join(tmpdir, vm_name + ".save")
if not recover:
if vm_operation == "save":
save_option = ""
result = virsh.save(vm_name, save_file, save_option,
ignore_status=True, debug=True)
libvirt.check_exit_status(result)
elif vm_operation == "managedsave":
managedsave_option = ""
result = virsh.managedsave(vm_name, managedsave_option,
ignore_status=True, debug=True)
libvirt.check_exit_status(result)
elif vm_operation == "s3":
suspend_target = "mem"
result = virsh.dompmsuspend(vm_name, suspend_target,
ignore_status=True, debug=True)
libvirt.check_exit_status(result)
elif vm_operation == "s4":
suspend_target = "disk"
result = virsh.dompmsuspend(vm_name, suspend_target,
ignore_status=True, debug=True)
libvirt.check_exit_status(result)
# Wait domain state change: 'in shutdown' -> 'shut off'
utils_misc.wait_for(lambda: virsh.is_dead(vm_name), 5)
else:
logging.debug("No operation for the domain")
else:
if vm_operation == "save":
if os.path.exists(save_file):
result = virsh.restore(save_file, ignore_status=True, debug=True)
libvirt.check_exit_status(result)
os.remove(save_file)
else:
raise error.TestError("No save file for domain restore")
elif vm_operation in ["managedsave", "s4"]:
result = virsh.start(vm_name, ignore_status=True, debug=True)
libvirt.check_exit_status(result)
elif vm_operation == "s3":
suspend_target = "mem"
result = virsh.dompmwakeup(vm_name, ignore_status=True, debug=True)
libvirt.check_exit_status(result)
else:
logging.debug("No need recover the domain")
示例10: __init__
def __init__(self, methodName='runTest', name=None, params=None,
base_logdir=None, tag=None, job=None, runner_queue=None):
del name
options = job.args
self.bindir = data_dir.get_root_dir()
self.virtdir = os.path.join(self.bindir, 'shared')
self.iteration = 0
name = None
if options.vt_config:
name = params.get("shortname")
elif options.vt_type == 'spice':
short_name_map_file = params.get("_short_name_map_file")
if "tests-variants.cfg" in short_name_map_file:
name = short_name_map_file["tests-variants.cfg"]
if name is None:
name = params.get("_short_name_map_file")["subtests.cfg"]
self.outputdir = None
self.resultsdir = None
self.logfile = None
self.file_handler = None
self.background_errors = Queue.Queue()
self.whiteboard = None
super(VirtTest, self).__init__(methodName=methodName, name=name,
params=params, base_logdir=base_logdir,
tag=tag, job=job,
runner_queue=runner_queue)
self.builddir = os.path.join(self.workdir, 'backends',
params.get("vm_type"))
self.tmpdir = os.path.dirname(self.workdir)
self.params = utils_params.Params(params)
# Here we turn the data the multiplexer injected into the params and
# turn it into an AvocadoParams object, that will allow users to
# access data from it. Example:
# sleep_length = test.avocado_params.get('sleep_length', default=1)
p = params.get('avocado_params', None)
if p is not None:
params, mux_path = p[0], p[1]
else:
params, mux_path = [], []
self.avocado_params = multiplexer.AvocadoParams(params, self.name,
self.tag,
mux_path,
self.default_params)
self.debugdir = self.logdir
self.resultsdir = self.logdir
utils_misc.set_log_file_dir(self.logdir)
示例11: run
def run(test, params, env):
"""
Run qemu_iotests.sh script:
1) Do some qemu_io operations(write & read etc.)
2) Check whether qcow image file is corrupted
:param test: QEMU test object
:param params: Dictionary with the test parameters
:param env: Dictionary with test environment.
"""
test_type = params.get("test_type")
qemu_io_config = None
if test_type == "lvm":
qemu_io_config = QemuIOConfig(test, params)
qemu_io_config.setup()
test_script = os.path.join(data_dir.get_root_dir(),
'shared/scripts/qemu_iotests.sh')
logging.info("Running script now: %s" % test_script)
test_image = params.get("test_image", "/tmp/test.qcow2")
s, test_result = aexpect.run_fg("sh %s %s" % (test_script,
test_image),
logging.debug, timeout=1800)
err_string = {
"err_nums": "\d errors were found on the image.",
"an_err": "An error occurred during the check",
"unsupt_err": "This image format does not support checks",
"mem_err": "Not enough memory",
"open_err": "Could not open",
"fmt_err": "Unknown file format",
"commit_err": "Error while committing image",
"bootable_err": "no bootable device",
}
try:
for err_type in err_string.keys():
msg = re.findall(err_string.get(err_type), test_result)
if msg:
raise error.TestFail(msg)
finally:
try:
if qemu_io_config:
qemu_io_config.cleanup()
except Exception, e:
logging.warn(e)
示例12: __init__
def __init__(self, methodName='runTest', name=None, params=None,
base_logdir=None, job=None, runner_queue=None,
vt_params=None):
"""
:note: methodName, name, base_logdir, job and runner_queue params
are inherited from test.Test
:param params: avocado/multiplexer params stored as
`self.avocado_params`.
:param vt_params: avocado-vt/cartesian_config params stored as
`self.params`.
"""
self.__params_vt = None
self.__avocado_params = None
self.bindir = data_dir.get_root_dir()
self.virtdir = os.path.join(self.bindir, 'shared')
# self.__params_vt must be initialized after super
params_vt = utils_params.Params(vt_params)
# for timeout use Avocado-vt timeout as default but allow
# overriding from Avocado params (varianter)
self.timeout = params_vt.get("test_timeout", self.timeout)
self.iteration = 0
self.resultsdir = None
self.file_handler = None
self.background_errors = error_event.error_events_bus
# clear existing error events
self.background_errors.clear()
super(VirtTest, self).__init__(methodName=methodName, name=name,
params=params,
base_logdir=base_logdir, job=job,
runner_queue=runner_queue)
self.builddir = os.path.join(self.workdir, 'backends',
vt_params.get("vm_type", ""))
self.tmpdir = os.path.dirname(self.workdir)
# Move self.params to self.avocado_params and initialize virttest
# (cartesian_config) params
try:
self.__avocado_params = super(VirtTest, self).params
except AttributeError:
# 36LTS set's `self.params` instead of having it as a property
# which stores the avocado params in `self.__params`
self.__avocado_params = self.__params
self.__params_vt = params_vt
self.debugdir = self.logdir
self.resultsdir = self.logdir
utils_misc.set_log_file_dir(self.logdir)
self.__status = None
示例13: __init__
def __init__(self, methodName='runTest', name=None, params=None,
base_logdir=None, tag=None, job=None, runner_queue=None,
vt_params=None):
"""
:note: methodName, name, base_logdir, tag, job and runner_queue params
are inherited from test.Test
:param params: avocado/multiplexer params stored as
`self.avocado_params`.
:param vt_params: avocado-vt/cartesian_config params stored as
`self.params`.
"""
del name
options = job.args
self.bindir = data_dir.get_root_dir()
self.virtdir = os.path.join(self.bindir, 'shared')
self.iteration = 0
name = None
if options.vt_config:
name = vt_params.get("shortname")
elif options.vt_type == 'spice':
short_name_map_file = vt_params.get("_short_name_map_file")
if "tests-variants.cfg" in short_name_map_file:
name = short_name_map_file["tests-variants.cfg"]
if name is None:
name = vt_params.get("_short_name_map_file")["subtests.cfg"]
self.outputdir = None
self.resultsdir = None
self.logfile = None
self.file_handler = None
self.background_errors = Queue.Queue()
self.whiteboard = None
super(VirtTest, self).__init__(methodName=methodName, name=name,
params=params,
base_logdir=base_logdir,
tag=tag, job=job,
runner_queue=runner_queue)
self.builddir = os.path.join(self.workdir, 'backends',
vt_params.get("vm_type"))
self.tmpdir = os.path.dirname(self.workdir)
# Move self.params to self.avocado_params and initialize virttest
# (cartesian_config) params
self.avocado_params = self.params
self.params = utils_params.Params(vt_params)
self.debugdir = self.logdir
self.resultsdir = self.logdir
utils_misc.set_log_file_dir(self.logdir)
示例14: bootstrap
def bootstrap(self):
from virttest import bootstrap
test_dir = data_dir.get_backend_dir('libvirt')
default_userspace_paths = ["/usr/bin/qemu-kvm", "/usr/bin/qemu-img"]
bootstrap.bootstrap(test_name='libvirt', test_dir=test_dir,
base_dir=data_dir.get_data_dir(),
default_userspace_paths=default_userspace_paths,
check_modules=[],
online_docs_url=None,
interactive=False,
download_image=False,
selinux=True,
restore_image=False,
verbose=True,
update_providers=False)
os.chdir(data_dir.get_root_dir())
示例15: env_setup
def env_setup(session, ip_addr, username, shell_port, password):
"""
Test env setup
"""
error.context("Setup env for %s" % ip_addr)
ssh_cmd(session, "service iptables stop; true")
netperf_links = params["netperf_links"].split()
remote_dir = params.get("remote_dir", "/var/tmp")
for netperf_link in netperf_links:
if utils.is_url(netperf_link):
download_dir = data_dir.get_download_dir()
md5sum = params.get("pkg_md5sum")
netperf_dir = utils.unmap_url_cache(download_dir,
netperf_link, md5sum)
elif netperf_link:
netperf_dir = os.path.join(data_dir.get_root_dir(),
"shared/%s" % netperf_link)
remote.scp_to_remote(ip_addr, shell_port, username, password,
netperf_dir, remote_dir)
ssh_cmd(session, params.get("setup_cmd"))