未验证 提交 6eeeedc7 编写于 作者: Q Qianqian Zhu 提交者: GitHub

Merge pull request #1453 from balamuruhans/os_update

generic/tests/os_update: refactor and have MultiVM support
- os_update: install setup image_copy unattended_install.cdrom
virt_test_type = qemu libvirt
no Windows
no SLES
type = os_update
os_update_timeout = 600
shell_prompt = r"[\#\$]\s*$"
- yum_update: install setup image_copy unattended_install.cdrom
virt_test_type = qemu libvirt
only Fedora, RHEL, CentOS
type = yum_update
shell_prompt = "Is this ok"
yum_update_timeout = 600
import logging
def run(test, params, env):
"""
Runs yum update and yum update kernel on RHEL or apt
update and apt upgrade on Ubuntu based multi VM environment.
:param test: kvm test object.
:param params: Dictionary with test parameters.
:param env: Dictionary with the test environment.
"""
vms = env.get_all_vms()
timeout = int(params.get("os_update_timeout"))
for vm in vms:
if not vm.is_alive():
vm.start()
cmd = "yum update -y"
if "ubuntu" in vm.get_distro().lower():
cmd = "apt update && apt upgrade -y"
session = vm.wait_for_login()
logging.debug("Performing %s on VM %s", cmd, vm.name)
if session.cmd_status(cmd, timeout=timeout) != 0:
test.fail("Failed to update VM %s using %s" % (vm.name, cmd))
session.close()
import logging
import time
def internal_yum_update(session, command, prompt, timeout):
"""
Helper function to perform the yum update test.
:param session: shell session stablished to the host
:param command: Command to be sent to the shell session
:param prompt: Machine prompt
:param timeout: How long to wait until we get an appropriate output from
the shell session.
"""
session.sendline(command)
end_time = time.time() + timeout
while time.time() < end_time:
match = session.read_until_last_line_matches(
["[Ii]s this [Oo][Kk]", prompt],
timeout=timeout)[0]
if match == 0:
logging.info("Got 'Is this ok'; sending 'y'")
session.sendline("y")
elif match == 1:
logging.info("Got shell prompt")
return True
else:
logging.info("Timeout or process exited")
return False
def run(test, params, env):
"""
Runs yum update and yum update kernel on the remote host (yum enabled
hosts only).
:param test: kvm test object.
:param params: Dictionary with test parameters.
:param env: Dictionary with the test environment.
"""
vm = env.get_vm(params["main_vm"])
vm.verify_alive()
timeout = int(params.get("login_timeout", 360))
session = vm.wait_for_login(timeout=timeout)
update_timeout = int(params.get("yum_update_timeout"))
internal_yum_update(session, "yum update --nogpgcheck",
params.get("shell_prompt"), update_timeout)
internal_yum_update(session, "yum update kernel --nogpgcheck",
params.get("shell_prompt"), update_timeout)
session.close()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册