[libvirt] [libvirt-test-api][PATCH 1/3] introduce 2 functions in utils

get_standard_deviation() is to get Standard Deviation, and param_to_tuple_nolength() allow do not pass lengh when use param_to_tuple(). Signed-off-by: Luyao Huang <lhuang@redhat.com> --- utils/utils.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/utils/utils.py b/utils/utils.py index c3e46f6..954b2bf 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -31,6 +31,7 @@ import string import subprocess import hashlib import libvirt +import math from xml.dom import minidom from urlparse import urlparse @@ -896,3 +897,30 @@ def validate_remote_blk_type(hostname, username, password, else: logger.info("lspci and lsmod return nothing") return 1 + +def get_standard_deviation(cb1, cb2, opaque1, opaque2, number = 1000): + """ pass two callback functions and opaque return Standard Deviation, + this function will be useful when need equal some quick change + value (like memory, cputime), default loop times are 1000, + and notice callback functions cb1 and cb2 should allways success + """ + D = 0 + for i in range(number): + a = cb1(opaque1) + b = cb2(opaque2) + D += (int(a) - int(b))**2 + return math.sqrt(D/number) + +def param_to_tuple_nolength(paramlist): + """paramlist contains numbers which can be divided by '-', '^' and + ',', return tuple only have True or False value + """ + d = [] + a = paramlist.split(',') + for i in range(len(a)): + if a[i].find('^') >= 0: + continue + d += a[i].split('-') + lengh = max(d) + + return param_to_tuple(paramlist, int(lengh) + 1) -- 1.8.3.1

It is hard to check if the free memory for each node is right, because memory change too fast in most machine (even machine in low load). Get this free memory 1000 times and get the Standard Deviation via get_standard_deviation(). 177 is a expectations get from 1000 times test in a low load machine, so this case may still get fail in some big machine. Signed-off-by: Luyao Huang <lhuang@redhat.com> --- cases/test_connection.conf | 4 ++ repos/virconn/connection_getCellsFreeMemory.py | 53 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 repos/virconn/connection_getCellsFreeMemory.py diff --git a/cases/test_connection.conf b/cases/test_connection.conf index 5719937..1dc98e7 100644 --- a/cases/test_connection.conf +++ b/cases/test_connection.conf @@ -57,3 +57,7 @@ virconn:connection_getDomainCapabilities pc-i440fx-rhel7.0.0 virttype kvm + +virconn:connection_getCellsFreeMemory + conn + qemu:///system diff --git a/repos/virconn/connection_getCellsFreeMemory.py b/repos/virconn/connection_getCellsFreeMemory.py new file mode 100644 index 0000000..a14e5aa --- /dev/null +++ b/repos/virconn/connection_getCellsFreeMemory.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +import libvirt +from libvirt import libvirtError +from utils import utils + +required_params = () +optional_params = {'conn': ''} + +NODE_ONLINE = '/sys/devices/system/node/online' + +def getnodemem(path): + return open(path).read().splitlines()[1].split()[3] + +def virtgetmem(a): + return a[0].getCellsFreeMemory(a[1], a[1] + 1)[0]/1024 + +def connection_getCellsFreeMemory(params): + """ + test API for getCellsFreeMemory in class virConnect + """ + logger = params['logger'] + fail=0 + + nodeset = utils.file_read(NODE_ONLINE) + logger.info("host exist node is %s" % nodeset) + + node_tuple = utils.param_to_tuple_nolength(nodeset) + if not node_tuple: + logger.info("error in function param_to_tuple_nolength") + return 1 + + try: + conn=libvirt.open(params['conn']) + + logger.info("get connection cells free memory") + for n in range(len(node_tuple)): + if not node_tuple[n]: + continue + + D = utils.get_standard_deviation(getnodemem, virtgetmem, \ + '/sys/devices/system/node/node%d/meminfo' % n, [conn,n]) + logger.info("Standard Deviation for node %d is %d" % (n, D)) + + """ expectations 177 is a average collected in a x86_64 low load machine""" + if D > 177*5: + fail=1 + logger.info("FAIL: Standard Deviation is too big \ + (biger than %d) for node %d" % (177*5, n)) + + except libvirtError, e: + logger.error("API error message: %s" % e.message) + fail=1 + return fail -- 1.8.3.1

On 22/04/15 21:00, Luyao Huang wrote:
It is hard to check if the free memory for each node is right, because memory change too fast in most machine (even machine in low load). Get this free memory 1000 times and get the Standard Deviation via get_standard_deviation().
177 is a expectations get from 1000 times test in a low load machine, so this case may still get fail in some big machine.
Signed-off-by: Luyao Huang <lhuang@redhat.com> --- cases/test_connection.conf | 4 ++ repos/virconn/connection_getCellsFreeMemory.py | 53 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 repos/virconn/connection_getCellsFreeMemory.py
diff --git a/cases/test_connection.conf b/cases/test_connection.conf index 5719937..1dc98e7 100644 --- a/cases/test_connection.conf +++ b/cases/test_connection.conf @@ -57,3 +57,7 @@ virconn:connection_getDomainCapabilities pc-i440fx-rhel7.0.0 virttype kvm + +virconn:connection_getCellsFreeMemory + conn + qemu:///system diff --git a/repos/virconn/connection_getCellsFreeMemory.py b/repos/virconn/connection_getCellsFreeMemory.py new file mode 100644 index 0000000..a14e5aa --- /dev/null +++ b/repos/virconn/connection_getCellsFreeMemory.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python +import libvirt +from libvirt import libvirtError +from utils import utils + +required_params = () +optional_params = {'conn': ''} + +NODE_ONLINE = '/sys/devices/system/node/online' + +def getnodemem(path): + return open(path).read().splitlines()[1].split()[3] + +def virtgetmem(a): + return a[0].getCellsFreeMemory(a[1], a[1] + 1)[0]/1024 + +def connection_getCellsFreeMemory(params): + """ + test API for getCellsFreeMemory in class virConnect + """ + logger = params['logger'] + fail=0 + + nodeset = utils.file_read(NODE_ONLINE) + logger.info("host exist node is %s" % nodeset) + + node_tuple = utils.param_to_tuple_nolength(nodeset) + if not node_tuple: + logger.info("error in function param_to_tuple_nolength") + return 1 + + try: + conn=libvirt.open(params['conn']) + + logger.info("get connection cells free memory") + for n in range(len(node_tuple)): + if not node_tuple[n]: + continue + + D = utils.get_standard_deviation(getnodemem, virtgetmem, \ + '/sys/devices/system/node/node%d/meminfo' % n, [conn,n]) + logger.info("Standard Deviation for node %d is %d" % (n, D)) + + """ expectations 177 is a average collected in a x86_64 low load machine""" + if D > 177*5: + fail=1 + logger.info("FAIL: Standard Deviation is too big \ + (biger than %d) for node %d" % (177*5, n)) I don't think a const 177 is here, could you generate a** value **dynamically based on a specified machine? And percent is recommended.*//* + + except libvirtError, e: + logger.error("API error message: %s" % e.message) + fail=1 + return fail

Signed-off-by: Luyao Huang <lhuang@redhat.com> --- repos/virconn/connection_getDomainCapabilities.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/repos/virconn/connection_getDomainCapabilities.py b/repos/virconn/connection_getDomainCapabilities.py index f0cfa1f..566d3ed 100644 --- a/repos/virconn/connection_getDomainCapabilities.py +++ b/repos/virconn/connection_getDomainCapabilities.py @@ -228,9 +228,7 @@ def check_os(arch, logger): ovmf1 = os.getElementsByTagName('value')[0] ovmf1 = ovmf1.childNodes[0].data logger.debug("Got OVMF path is %s" % ovmf1) - if ovmf_f and ovmf1 == OVMF: - pass - else: + if ovmf_f and ovmf1 != OVMF: return False enum = loader.getElementsByTagName('enum') for item in enum: -- 1.8.3.1

ACKed, thanks. ----- Original Message ----- From: "Luyao Huang" <lhuang@redhat.com> To: libvir-list@redhat.com Cc: "Luyao Huang" <lhuang@redhat.com> Sent: Wednesday, April 22, 2015 9:00:57 PM Subject: [libvirt] [libvirt-test-api][PATCH 3/3] fix the logic in getDomainCapabilities Signed-off-by: Luyao Huang <lhuang@redhat.com> --- repos/virconn/connection_getDomainCapabilities.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/repos/virconn/connection_getDomainCapabilities.py b/repos/virconn/connection_getDomainCapabilities.py index f0cfa1f..566d3ed 100644 --- a/repos/virconn/connection_getDomainCapabilities.py +++ b/repos/virconn/connection_getDomainCapabilities.py @@ -228,9 +228,7 @@ def check_os(arch, logger): ovmf1 = os.getElementsByTagName('value')[0] ovmf1 = ovmf1.childNodes[0].data logger.debug("Got OVMF path is %s" % ovmf1) - if ovmf_f and ovmf1 == OVMF: - pass - else: + if ovmf_f and ovmf1 != OVMF: return False enum = loader.getElementsByTagName('enum') for item in enum: -- 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

It's OK to me, please hongming help review it again. BR, Jianwei ----- Original Message ----- From: "Luyao Huang" <lhuang@redhat.com> To: libvir-list@redhat.com Cc: "Luyao Huang" <lhuang@redhat.com> Sent: Wednesday, April 22, 2015 9:00:55 PM Subject: [libvirt] [libvirt-test-api][PATCH 1/3] introduce 2 functions in utils get_standard_deviation() is to get Standard Deviation, and param_to_tuple_nolength() allow do not pass lengh when use param_to_tuple(). Signed-off-by: Luyao Huang <lhuang@redhat.com> --- utils/utils.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/utils/utils.py b/utils/utils.py index c3e46f6..954b2bf 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -31,6 +31,7 @@ import string import subprocess import hashlib import libvirt +import math from xml.dom import minidom from urlparse import urlparse @@ -896,3 +897,30 @@ def validate_remote_blk_type(hostname, username, password, else: logger.info("lspci and lsmod return nothing") return 1 + +def get_standard_deviation(cb1, cb2, opaque1, opaque2, number = 1000): + """ pass two callback functions and opaque return Standard Deviation, + this function will be useful when need equal some quick change + value (like memory, cputime), default loop times are 1000, + and notice callback functions cb1 and cb2 should allways success + """ + D = 0 + for i in range(number): + a = cb1(opaque1) + b = cb2(opaque2) + D += (int(a) - int(b))**2 + return math.sqrt(D/number) + +def param_to_tuple_nolength(paramlist): + """paramlist contains numbers which can be divided by '-', '^' and + ',', return tuple only have True or False value + """ + d = [] + a = paramlist.split(',') + for i in range(len(a)): + if a[i].find('^') >= 0: + continue + d += a[i].split('-') + lengh = max(d) + + return param_to_tuple(paramlist, int(lengh) + 1) -- 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

ACK and Pushed Thanks Hongming On 04/24/2015 12:53 PM, Jianwei Hu wrote:
It's OK to me, please hongming help review it again.
BR, Jianwei ----- Original Message ----- From: "Luyao Huang" <lhuang@redhat.com> To: libvir-list@redhat.com Cc: "Luyao Huang" <lhuang@redhat.com> Sent: Wednesday, April 22, 2015 9:00:55 PM Subject: [libvirt] [libvirt-test-api][PATCH 1/3] introduce 2 functions in utils
get_standard_deviation() is to get Standard Deviation, and param_to_tuple_nolength() allow do not pass lengh when use param_to_tuple().
Signed-off-by: Luyao Huang <lhuang@redhat.com> --- utils/utils.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
diff --git a/utils/utils.py b/utils/utils.py index c3e46f6..954b2bf 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -31,6 +31,7 @@ import string import subprocess import hashlib import libvirt +import math from xml.dom import minidom from urlparse import urlparse
@@ -896,3 +897,30 @@ def validate_remote_blk_type(hostname, username, password, else: logger.info("lspci and lsmod return nothing") return 1 + +def get_standard_deviation(cb1, cb2, opaque1, opaque2, number = 1000): + """ pass two callback functions and opaque return Standard Deviation, + this function will be useful when need equal some quick change + value (like memory, cputime), default loop times are 1000, + and notice callback functions cb1 and cb2 should allways success + """ + D = 0 + for i in range(number): + a = cb1(opaque1) + b = cb2(opaque2) + D += (int(a) - int(b))**2 + return math.sqrt(D/number) + +def param_to_tuple_nolength(paramlist): + """paramlist contains numbers which can be divided by '-', '^' and + ',', return tuple only have True or False value + """ + d = [] + a = paramlist.split(',') + for i in range(len(a)): + if a[i].find('^') >= 0: + continue + d += a[i].split('-') + lengh = max(d) + + return param_to_tuple(paramlist, int(lengh) + 1)
participants (4)
-
hongming
-
hujianwei
-
Jianwei Hu
-
Luyao Huang