[libvirt] [libvirt-test-api][PATCH] Add a new test case for getMemoryParameters

hongming honzhang at redhat.com
Tue May 5 06:08:51 UTC 2015


ACK and Pushed

Thanks
Hongming
On 05/04/2015 04:09 PM, Luyao Huang wrote:
> Signed-off-by: Luyao Huang <lhuang at redhat.com>
> ---
>   cases/test_connection.conf                      |  4 ++
>   repos/virconn/connection_getMemoryParameters.py | 61 +++++++++++++++++++++++++
>   2 files changed, 65 insertions(+)
>   create mode 100644 repos/virconn/connection_getMemoryParameters.py
>
> diff --git a/cases/test_connection.conf b/cases/test_connection.conf
> index 914acac..3c08a95 100644
> --- a/cases/test_connection.conf
> +++ b/cases/test_connection.conf
> @@ -69,3 +69,7 @@ storage:pool_uuid
>   virconn:connection_getCellsFreeMemory
>       conn
>           qemu:///system
> +
> +virconn:connection_getMemoryParameters
> +    conn
> +        qemu:///system
> diff --git a/repos/virconn/connection_getMemoryParameters.py b/repos/virconn/connection_getMemoryParameters.py
> new file mode 100644
> index 0000000..9b88fc3
> --- /dev/null
> +++ b/repos/virconn/connection_getMemoryParameters.py
> @@ -0,0 +1,61 @@
> +#!/usr/bin/env python
> +
> +import libvirt
> +from libvirt import libvirtError
> +from  utils import utils
> +
> +required_params = ()
> +optional_params = {'conn': ''}
> +node_memory = ['full_scans',
> +               'merge_across_nodes',
> +               'pages_shared',
> +               'pages_sharing',
> +               'pages_to_scan',
> +               'pages_unshared',
> +               'pages_volatile',
> +               'sleep_millisecs']
> +
> +SYSFS_MEMORY_SHARED_PATH = '/sys/kernel/mm/ksm/'
> +LIBVIRT_API_PATH = '/usr/share/libvirt/api/libvirt-api.xml'
> +flags=0
> +
> +def check_memory_parameter(libvirt_dict, parameter_name):
> +    a = libvirt_dict.get('shm_%s' % parameter_name)
> +    try:
> +        b = long(open('%s%s' % (SYSFS_MEMORY_SHARED_PATH, parameter_name)).read())
> +    except IOError:
> +        logger.info("Cannot get file in path %s%s" \
> +                    % (SYSFS_MEMORY_SHARED_PATH, parameter_name))
> +        return 1
> +    logger.info("equal %s : libvirt get %u and we get %u"\
> +                % (parameter_name, a, b))
> +    if a == b:
> +        return 0
> +    else:
> +        return 1
> +
> +def connection_getMemoryParameters(params):
> +    """
> +       test API for getMemoryParameters in class virConnect
> +    """
> +    global logger
> +    logger = params['logger']
> +    fail=0
> +
> +    try:
> +        conn=libvirt.open(params['conn'])
> +
> +        logger.info("get connection to libvirtd")
> +
> +        if utils.check_flags('getMemoryParameters', LIBVIRT_API_PATH) == 1:
> +            return 1
> +
> +        param_dict=conn.getMemoryParameters()
> +
> +        for n in node_memory:
> +            fail=check_memory_parameter(param_dict, n)
> +
> +    except libvirtError, e:
> +        logger.error("API error message: %s" % e.message)
> +        fail=1
> +    return fail




More information about the libvir-list mailing list