[libvirt] [test-API][PATCH v2 4/4] Add qemu_hang test case under libvirtd

Guannan Ren gren at redhat.com
Thu Sep 15 07:32:21 UTC 2011


On 09/14/2011 06:31 PM, Wayne Sun wrote:
>    * repos/libvirtd/qemu_hang.py
>
>      qemu process get hang should not cause libvirtd hang or dead
> ---
>   repos/libvirtd/qemu_hang.py |  142 +++++++++++++++++++++++++++++++++++++++++++
>   1 files changed, 142 insertions(+), 0 deletions(-)
>   create mode 100644 repos/libvirtd/qemu_hang.py
>
> diff --git a/repos/libvirtd/qemu_hang.py b/repos/libvirtd/qemu_hang.py
> new file mode 100644
> index 0000000..f377df3
> --- /dev/null
> +++ b/repos/libvirtd/qemu_hang.py
> @@ -0,0 +1,142 @@
> +#!/usr/bin/env python
> +""" QEMU get hang should not cause libvirtd hang or dead. This test stop
> +    a qemu process and check whether libvird get hang. For doing this
> +    test, a running domain is required.
> +    libvirtd:qemu_hang
> +        guestname
> +            #GUESTNAME#
> +"""
> +
> +__author__ = 'Wayne Sun: gsun at redhat.com'
> +__date__ = 'Thu Sep 2, 2011'
> +__version__ = '0.1.0'
> +__credits__ = 'Copyright (C) 2011 Red Hat, Inc.'
> +__all__ = ['qemu_hang']
> +
> +import os
> +import re
> +import sys
> +
> +def append_path(path):
> +    """Append root path of package"""
> +    if path not in sys.path:
> +        sys.path.append(path)
> +
> +pwd = os.getcwd()
> +result = re.search('(.*)libvirt-test-API', pwd)
> +append_path(result.group(0))
> +
> +from lib import connectAPI
> +from lib import domainAPI
> +from utils.Python import utils
> +
> +VIRSH_LIST = "virsh list --all"
> +RESTART_CMD = "service libvirtd restart"
> +
> +def check_params(params):
> +    """Verify inputing parameter dictionary"""
> +    logger = params['logger']
> +    keys = ['guestname']
> +    for key in keys:
> +        if key not in params:
> +            logger.error("%s is required" %key)
> +            return 1
> +    return 0
> +
> +def check_domain_running(domobj, guestname, logger):
> +    """ check if the domain exists, may or may not be active """
> +    guest_names = domobj.get_list()
> +
> +    if guestname not in guest_names:
> +        logger.error("%s doesn't exist or not running" % guestname)
> +        return 1
> +    else:
> +        return 0
> +
> +def libvirtd_check(util, logger):
> +    """check libvirtd status
> +    """
> +    cmd = "service libvirtd status"
> +    ret, out = util.exec_cmd(cmd, shell=True)
> +    if ret != 0:
> +        logger.error("failed to get libvirtd status")
> +        return 1
> +    else:
> +        logger.info(out[0])
> +
> +    logger.info(VIRSH_LIST)
> +    ret, out = util.exec_cmd(VIRSH_LIST, shell=True)
> +    if ret != 0:
> +        logger.error("failed to get virsh list result")
> +        return 1
> +    else:
> +        for i in range(len(out)):
> +            logger.info(out[i])
> +
> +    return 0
> +
> +def get_domain_pid(util, logger, guestname):
> +    """get the pid of running domain"""
> +    logger.info("get the pid of running domain %s"  % guestname)
> +    get_pid_cmd = "cat /var/run/libvirt/qemu/%s.pid" % guestname
> +    ret, pid = util.exec_cmd(get_pid_cmd, shell=True)
> +    if ret:
> +        logger.error("fail to get the pid of runnings domain %s" % \
> +                     guestname)
> +        return 1, ""
> +    else:
> +        logger.info("the pid of domain %s is %s" % \
> +                    (guestname, pid[0]))
> +        return 0, pid[0]
> +
> +def qemu_hang(params):
> +    """Hang qemu process, check libvirtd status"""
> +    # Initiate and check parameters
> +    params_check_result = check_params(params)
> +    if params_check_result:
> +        return 1
> +
> +    logger = params['logger']
> +    guestname = params['guestname']
> +    util = utils.Utils()
> +    uri = util.get_uri('127.0.0.1')
> +
> +    conn = connectAPI.ConnectAPI()
> +    virconn = conn.open(uri)
> +    domobj = domainAPI.DomainAPI(virconn)
> +
> +    logger.info("check the domain state")
> +    ret = check_domain_running(domobj, guestname, logger)
> +    if ret:
> +        return 1
> +
> +    conn.close()
> +
> +    logger.info("check the libvirtd status:")
> +    result = libvirtd_check(util, logger)
> +    if result:
> +        return 1
> +
> +    ret, pid = get_domain_pid(util, logger, guestname)
> +    if ret:
> +        return 1
> +
> +    cmd = "kill -STOP %s" % pid
> +    logger.info(cmd)
> +    ret, out = util.exec_cmd(cmd, shell=True)
> +    if ret:
> +        logger.error("failed to stop qemu process of %s" % guestname)
> +        return 1
> +

         It should be "kill -SIGSTOP  $pid"
         The better to check the state of a process is by "ps aufx | 
grep qemu"
         In the ps output, the stopped processes will have a status 
containing "T" like;
         qemu     28653  0.2  0.5 771468 21596 ?        Tl   Sep13   
7:17 /usr/libexec/qemu-kvm ...


> +    logger.info("recheck libvirtd status:")
> +    result = libvirtd_check(util, logger)
> +    if result:
> +        return 1
> +
> +    return 0
> +
> +def qemu_hang_cleanup(params):
> +    """ clean testing environment """
> +    pass
> +
> +

        ACK and pushed with these fixed.




More information about the libvir-list mailing list