Re: [libvirt] Fwd: DNS for IPv6 addresses?
Hi Yaniv Please refer to the following . [root@localhost images]# virsh net-dumpxml dhcp dhcp 066f0d89-67a6-42c8-bdeb-ed9420aaaf4f [root@localhost images]# virsh dumpxml rhel7.1|grep /interface -B7 function='0x0'/> [root@localhost images]# virsh domifaddr rhel7.1 --source lease Name MAC address Protocol Address --- vnet1 52:54:00:82:49:b1ipv4 192.168.123.171/24 - -ipv6 2001:db8:ca2:2:1::1a/64 [root@localhost images]# cat /var/lib/libvirt/dnsmasq/virbr4.status [ { "ip-address": "192.168.123.171", "mac-address": "52:54:00:82:49:b1", "expiry-time": 1452594968 }, { "iaid": "8538545", "ip-address": "2001:db8:ca2:2:1::1a", "mac-address": "52:54:00:82:49:b1", "client-id": "00:04:ee:53:b7:a8:c7:46:ab:95:d0:86:88:ee:6e:51:a0:2a", "server-duid": "", "expiry-time": 1452594971 } ] Login guest to check ipv6 address . It is the same as the result returned by "domifaddr" Thanks Hongming On 01/11/2016 03:24 PM, Min Zhan wrote: @shyu, Could you help have a look and reply this question? Regards, Min Zhan - Forwarded Message - From: "Yaniv Kaul" To: libvirt-l...@redhat.com Sent: Friday, January 8, 2016 5:40:09 PM Subject: [libvirt] DNS for IPv6 addresses? Is there a way to define DNS for IPv6 addresses? Something like: lago_basic_suite_3_6_storage-iscsi Only for IPv6? I reckon I can't just use an IPv6 address in the 'IP' attribute? TIA, Y. -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-api][PATCH] Add config flag when calling setVcpusFlags with maximum flag
ACK and Pushed On 10/29/2015 04:22 PM, Hongming Zhang wrote: Flag 'VIR_DOMAIN_AFFECT_CONFIG' is required by flag 'VIR_DOMAIN_VCPU_MAXIMUM' modified: set_vcpus_config.py --- repos/setVcpus/set_vcpus_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repos/setVcpus/set_vcpus_config.py b/repos/setVcpus/set_vcpus_config.py index 3bb3984..3ef0992 100644 --- a/repos/setVcpus/set_vcpus_config.py +++ b/repos/setVcpus/set_vcpus_config.py @@ -80,7 +80,7 @@ def set_vcpus_config(params): return 1 if maxvcpu: -flags = libvirt.VIR_DOMAIN_VCPU_MAXIMUM +flags = libvirt.VIR_DOMAIN_VCPU_MAXIMUM|libvirt.VIR_DOMAIN_AFFECT_CONFIG logger.info("the given max vcpu number is %s" % maxvcpu) logger.info("set domain maximum vcpu as %s with flag: %s" % (maxvcpu, flags)) -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-test-api][PATCH] Add config flag when calling setVcpusFlags with maximum flag
Flag 'VIR_DOMAIN_AFFECT_CONFIG' is required by flag 'VIR_DOMAIN_VCPU_MAXIMUM' modified: set_vcpus_config.py --- repos/setVcpus/set_vcpus_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/repos/setVcpus/set_vcpus_config.py b/repos/setVcpus/set_vcpus_config.py index 3bb3984..3ef0992 100644 --- a/repos/setVcpus/set_vcpus_config.py +++ b/repos/setVcpus/set_vcpus_config.py @@ -80,7 +80,7 @@ def set_vcpus_config(params): return 1 if maxvcpu: -flags = libvirt.VIR_DOMAIN_VCPU_MAXIMUM +flags = libvirt.VIR_DOMAIN_VCPU_MAXIMUM|libvirt.VIR_DOMAIN_AFFECT_CONFIG logger.info("the given max vcpu number is %s" % maxvcpu) logger.info("set domain maximum vcpu as %s with flag: %s" % (maxvcpu, flags)) -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-test-api][PATCH 0/2]Fix issues in the method of getting vcpu thread id of vcpupin_live and cpu_affinity
Hongming Zhang (2): Fix the issues in checking method of vcpupin_live Modify the checking method via passing the vcpu thread id repos/domain/cpu_affinity.py | 16 +--- repos/setVcpus/vcpupin_live.py | 36 2 files changed, 29 insertions(+), 23 deletions(-) -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-test-api][PATCH 1/2] Fix the issues in checking method of vcpupin_live
The new method will get the vcpu thread id via qemu-monitor. Then get the Cpus_allowed_list value from /proc using the vcpu's thread id modified: repos/setVcpus/vcpupin_live.py --- repos/setVcpus/vcpupin_live.py | 36 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/repos/setVcpus/vcpupin_live.py b/repos/setVcpus/vcpupin_live.py index c3dfe8e..9f21583 100644 --- a/repos/setVcpus/vcpupin_live.py +++ b/repos/setVcpus/vcpupin_live.py @@ -13,30 +13,34 @@ from utils import utils required_params = ('guestname', 'vcpu', 'cpulist',) optional_params = {} -def vcpupin_check(guestname, vcpu, cpumap): +def vcpupin_check(guestname, vcpu, cpulist): """check vcpu subprocess status of the running virtual machine grep Cpus_allowed_list /proc/PID/task/*/status """ -tmp_str = '' -cmd = "cat /var/run/libvirt/qemu/%s.pid" % guestname -status, pid = utils.exec_cmd(cmd, shell=True) +cmd_pid = "cat /var/run/libvirt/qemu/%s.pid" % guestname +status, pid = utils.exec_cmd(cmd_pid, shell=True) if status: logger.error("failed to get the pid of domain %s" % guestname) return 1 -cmd = "grep Cpus_allowed_list /proc/%s/task/*/status" % pid[0] -status, output = utils.exec_cmd(cmd, shell=True) -logger.debug("command '%s' output is:" % cmd) -for i in range(len(output)): -tmp_str += ''.join(output[i]) + '\n' -logger.debug(tmp_str) +cmd_vcpu_task_id = "virsh qemu-monitor-command %s --hmp info cpus|grep '#%s'|cut -d '=' -f3"\ +% (guestname,vcpu) +status, vcpu_task_id = utils.exec_cmd(cmd_vcpu_task_id, shell=True) +if status: +logger.error("failed to get the threadid of domain %s" % guestname) +return 1 + +logger.debug("vcpu id %s:" % vcpu_task_id[0]) +cmd_cpus_allowed_list = "grep Cpus_allowed_list /proc/%s/task/%s/status" % (pid[0] , vcpu_task_id[0]) +status, output = utils.exec_cmd(cmd_cpus_allowed_list, shell=True) +if status: +logger.error("failed to get the cpu_allowed_list of vcpu %s") +return 1 -task_list = output[1:] -vcpu_task = task_list[int(vcpu)] -cpulist = vcpu_task.split('\t')[1] -ret = utils.param_to_tuple(cpulist, maxcpu) +logger.debug("the output of command 'grep Cpus_allowed_list \ + /proc/%s/task/%s/status' is %s" % (pid[0],vcpu_task_id[0],output)) -if ret == cpumap: +if output[0].split('\t')[1] == cpulist: logger.info("vcpu process cpus allowed list is expected") return 0 else: @@ -92,7 +96,7 @@ def vcpupin_live(params): return 1 logger.info("check vcpu pin status on host") -ret = vcpupin_check(guestname, vcpu, cpumap) +ret = vcpupin_check(guestname, vcpu, cpulist) if ret: logger.error("domain vcpu pin failed") return 1 -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [libvirt-test-api][PATCH 2/2] Modify the checking method via passing the vcpu thread id
modified: repos/domain/cpu_affinity.py --- repos/domain/cpu_affinity.py | 16 +--- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/repos/domain/cpu_affinity.py b/repos/domain/cpu_affinity.py index e710968..8246938 100644 --- a/repos/domain/cpu_affinity.py +++ b/repos/domain/cpu_affinity.py @@ -142,16 +142,18 @@ def vcpu_affinity_check(domain_name, vcpu, expected_pinned_cpu, hypervisor): logger.error("failed to get the pid of \ the running virtual machine process") return 1 -if 'el6' in host_kernel_version: -cmd_get_task_list = "grep Cpus_allowed_list /proc/%s/task/*/status" % pid +if 'el6' or 'el7' in host_kernel_version: +cmd_vcpu_task_id = "virsh qemu-monitor-command %s --hmp info cpus|grep '#%s'|cut -d '=' -f3"\ +% (domain_name,vcpu) +status, output = commands.getstatusoutput(cmd_vcpu_task_id) +vcpu_task_id = output[:output.find("^")] +logger.debug("vcpu id %s:" % vcpu_task_id) +cmd_get_task_list = "grep Cpus_allowed_list /proc/%s/task/%s/status" % (pid , vcpu_task_id) status, output = commands.getstatusoutput(cmd_get_task_list) - logger.debug("the output of command 'grep Cpus_allowed_list \ - /proc/%s/task/*/status' is %s" % (pid, output)) + /proc/%s/task/%s/status' is %s" % (pid,vcpu_task_id,output)) +actual_pinned_cpu = int(output.split('\t')[1]) -task_list = output.split('\n')[1:] -vcpu_task = task_list[int(vcpu)] -actual_pinned_cpu = int(vcpu_task.split('\t')[1]) elif 'el5' in host_kernel_version: cmd_get_task_list = "grep Cpus_allowed /proc/%s/task/*/status" % pid status, output = commands.getstatusoutput(cmd_get_task_list) -- 1.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-API] [PATCH] fix some typo
On 09/29/2015 12:28 PM, Shanzhi Yu wrote: Signed-off-by: Shanzhi Yu --- repos/domain/fsinfo.py | 2 +- repos/domain/install_linux_check.py | 2 +- repos/domain/install_linux_net.py | 2 +- repos/interface/define.py | 2 +- repos/interface/undefine.py | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/repos/domain/fsinfo.py b/repos/domain/fsinfo.py index e6d1bf0..d4614f5 100644 --- a/repos/domain/fsinfo.py +++ b/repos/domain/fsinfo.py @@ -81,7 +81,7 @@ def fsinfo(params): return 1 fsinfo = vm.fsInfo() -logger.info("get geust filesystem information") +logger.info("get guest filesystem information") mac = get_guest_mac(vm) if not mac: diff --git a/repos/domain/install_linux_check.py b/repos/domain/install_linux_check.py index ab1e7db..bb3cc2a 100644 --- a/repos/domain/install_linux_check.py +++ b/repos/domain/install_linux_check.py @@ -99,7 +99,7 @@ def install_linux_check(params): Test_Result = 1 return Test_Result -# Check whether vcpu equals the value set in geust config xml +# Check whether vcpu equals the value set in guest config xml logger.info("check point3: check cpu number in guest equals to \ the value set in domain config xml") vcpunum_expect = int(utils.get_num_vcpus(domain_name)) diff --git a/repos/domain/install_linux_net.py b/repos/domain/install_linux_net.py index 4367d97..7173294 100644 --- a/repos/domain/install_linux_net.py +++ b/repos/domain/install_linux_net.py @@ -239,7 +239,7 @@ def install_linux_net(params): logger.info("booting guest vm off harddisk failed") return 1 else: -logger.info("geust is booting up") +logger.info("guest is booting up") else: interval = 0 while(interval < 3600): diff --git a/repos/interface/define.py b/repos/interface/define.py index 18ba71b..e0dbcf4 100644 --- a/repos/interface/define.py +++ b/repos/interface/define.py @@ -42,7 +42,7 @@ def define(params): try: conn.interfaceDefineXML(xmlstr, 0) if check_define_interface(ifacename): -logger.info("define a interface form xml is successful") +logger.info("define a interface from xml is successful") else: logger.error("fail to check define interface") return 1 diff --git a/repos/interface/undefine.py b/repos/interface/undefine.py index f9b2d74..8b250de 100644 --- a/repos/interface/undefine.py +++ b/repos/interface/undefine.py @@ -39,14 +39,14 @@ def undefine(params): try: ifaceobj.undefine() if check_undefine_interface(ifacename): -logger.info("undefine a interface form xml is successful") +logger.info("undefine a interface is successful") else: logger.error("fail to check undefine interface") return 1 except libvirtError, e: logger.error("API error message: %s, error code is %s" \ % (e.message, e.get_error_code())) -logger.error("fail to undefine a interface from xml") +logger.error("fail to undefine a interface") return 1 return 0 ACK and Pushed Thanks Hongming -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-API] [PATCH] fix two error in script pin_iothread.py and connection_getAllDomainStats.py
On 09/28/2015 05:45 PM, Shanzhi Yu wrote: Signed-off-by: Shanzhi Yu --- repos/domain/pin_iothread.py | 2 +- repos/virconn/connection_getAllDomainStats.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/repos/domain/pin_iothread.py b/repos/domain/pin_iothread.py index 28ee2c4..d2d812f 100644 --- a/repos/domain/pin_iothread.py +++ b/repos/domain/pin_iothread.py @@ -116,7 +116,7 @@ def pin_iothread(params): if not find_iothreadid_fromxml(vm, 1, 1): logger.info("add iothread %d to running guest" % 1) -vm.addIOThread(i, libvirt.VIR_DOMAIN_AFFECT_LIVE) +vm.addIOThread(1, libvirt.VIR_DOMAIN_AFFECT_LIVE) vm.pinIOThread(1, tu_cpu, libvirt.VIR_DOMAIN_AFFECT_LIVE) cpuset = find_iothreadpin_fromxml(vm, 1, 1) diff --git a/repos/virconn/connection_getAllDomainStats.py b/repos/virconn/connection_getAllDomainStats.py index d95004f..3362444 100644 --- a/repos/virconn/connection_getAllDomainStats.py +++ b/repos/virconn/connection_getAllDomainStats.py @@ -164,7 +164,7 @@ def check_each_vcpu(logger,dom_name,dom_active,dom_eles): if not vcpu_cur: for i in range(0,vcpu_max): vcpu_pre = "vcpu."+ str(i) + "." -logger.debug("Checking %sstate: %d" \ +logger.debug("Checking %sstate: %s" \ %(vcpu_pre, dom_eles.get(vcpu_pre + "state"))) if not compare_value(logger,vcpu_stat, \ dom_eles.get(vcpu_pre + "state")): @@ -172,7 +172,7 @@ def check_each_vcpu(logger,dom_name,dom_active,dom_eles): elif int(vcpu_cur.nodeValue) <= vcpu_max: for i in range(0,int(vcpu_cur.nodeValue)): vcpu_pre = "vcpu."+ str(i) + "." -logger.debug("Checking %sstate: %d" \ +logger.debug("Checking %sstate: %s" \ %(vcpu_pre, dom_eles.get(vcpu_pre + "state"))) if not compare_value(logger,vcpu_stat, \ dom_eles.get(vcpu_pre + "state")): ACK and Pushed Thanks Hongming -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-API] [PATCH] Add two cases for API interfaceAddresses and make small changes to global.cfg
On 09/28/2015 05:45 PM, Shanzhi Yu wrote: Signed-off-by: Shanzhi Yu --- cases/linux_domain.conf| 12 +++ global.cfg | 8 +++-- repos/domain/get_guest_network_info.py | 66 ++ 3 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 repos/domain/get_guest_network_info.py diff --git a/cases/linux_domain.conf b/cases/linux_domain.conf index 8440c61..5b216f9 100644 --- a/cases/linux_domain.conf +++ b/cases/linux_domain.conf @@ -66,6 +66,18 @@ domain:set_guest_time flags sync +domain:get_guest_network_info +guestname +$defaultname +flags +lease + +domain:get_guest_network_info +guestname +$defaultname +flags +agent + virconn:connection_getAllDomainStats stats state|cpu|balloon|vcpu|interface|block diff --git a/global.cfg b/global.cfg index 56677a5..1b72119 100644 --- a/global.cfg +++ b/global.cfg @@ -44,6 +44,8 @@ rhel6u1_i386 = http:// rhel6u1_x86_64 = http:// rhel6u2_i386 = http:// rhel6u2_x86_64 = http:// +rhel7u1_x86_64 = http:// +rhel7u2_x86_64 = http:// fedora12_i386 = http:// fedora12_x86_64 = http:// win2008_i386 = http:// @@ -70,6 +72,8 @@ rhel6_i386_http_ks = http:// rhel6_x86_64_http_ks = http:// rhel6u2_i386_http_ks = http:// rhel6u2_x86_64_http_ks = kickstart.cfg +rhel7u1_x86_64_http_ks = http:// +rhel7u2_x86_64_http_ks = http:// fedora12_i386_http_ks = http:// fedora12_x86_64_http_ks = http:// @@ -97,7 +101,7 @@ sourcepath = /media/share # also exercise DNS resolution # [other] -wget_url = http:// +wget_url = http://libvirt.org/index.html # # The variables section is a set of variables used by the @@ -127,7 +131,7 @@ defaulthv = kvm defaultname = libvirt_test_api # default os version to use for installing a new guest # the value of it is the first part of 'rhel6u2_x86_64' in [guest] section above -defaultos = rhel6u2 +defaultos = rhel7u2 # default architecture to use for installing a new guest defaultarch = x86_64 # default the number of vcpu to use for defining or installing a guest diff --git a/repos/domain/get_guest_network_info.py b/repos/domain/get_guest_network_info.py new file mode 100644 index 000..35bba3b --- /dev/null +++ b/repos/domain/get_guest_network_info.py @@ -0,0 +1,66 @@ +#!/usr/bin/python + +import libvirt +from libvirt import libvirtError +from src import sharedmod + +required_params = ('guestname', 'flags',) +optional_params = {} + +def check_guest_status(domobj): +"""check guest current status +""" +state = domobj.info()[0] +if state == libvirt.VIR_DOMAIN_SHUTOFF or \ +state == libvirt.VIR_DOMAIN_SHUTDOWN: +return False +else: +return True + +def get_guest_network_info(params): +"""get guest network interface info +""" + +logger = params['logger'] +guestname = params['guestname'] +flags = params['flags'] + +conn = sharedmod.libvirtobj['conn'] + +domobj = conn.lookupByName(guestname) + +flags = params['flags'] +logger.info("The flags are %s" % flags) +flags_string = flags.split("|") +flags = 0 + +for flag in flags_string: +if flag == 'lease': +flags |= libvirt.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_LEASE +elif flag == 'agent': +flags |= libvirt.VIR_DOMAIN_INTERFACE_ADDRESSES_SRC_AGENT +else: +logger.error("unknow flags") +return 1 + +logger.info("the given flags is %d" % flags) + +# Check domain status +if check_guest_status(domobj): +logger.info("Guest is running") +else: +logger.error("Guest is shut off status") +return 1 + +try: +info = domobj.interfaceAddresses(flags) + logger.info("get guest interface info") + Hi shyu There should be two different method of checking flags "lease" and "agent" It is invalid if only check the domain status Expect your V2 patch cover it Thanks Hongming +except libvirtError, e: +logger.error("API error message: %s, error code is %s" \ +% (e.message, e.get_error_code())) +return 1 + +return 0 + + -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-api][PATCHv2] Add new test case for allocPages API
On 09/22/2015 10:34 AM, Luyao Huang wrote: Signed-off-by: Luyao Huang --- cases/test_connection.conf | 10 repos/virconn/connection_allocPages.py | 84 ++ 2 files changed, 94 insertions(+) create mode 100644 repos/virconn/connection_allocPages.py diff --git a/cases/test_connection.conf b/cases/test_connection.conf index 336b1ad..a4406bf 100644 --- a/cases/test_connection.conf +++ b/cases/test_connection.conf @@ -77,3 +77,13 @@ virconn:connection_getMemoryParameters virconn:connection_getMemoryStats conn qemu:///system + +virconn:connection_allocPages +conn +qemu:///system + +virconn:connection_allocPages +conn +qemu:///system +flags +pageset diff --git a/repos/virconn/connection_allocPages.py b/repos/virconn/connection_allocPages.py new file mode 100644 index 000..de3c071 --- /dev/null +++ b/repos/virconn/connection_allocPages.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python + +import libvirt +from libvirt import libvirtError +import lxml +import lxml.etree + +required_params = () +optional_params = {'conn': '', 'flags': ''} + +HOST_HUGEPAGE = '/sys/devices/system/node/node%d/hugepages/hugepages-%dkB/nr_hugepages' + +def get_host_pagesize(conn): +ret = [] +tree = lxml.etree.fromstring(conn.getCapabilities()) + +set = tree.xpath("/capabilities/host/cpu/pages") +for n in set: +ret.append(int(n.attrib['size'])) + +return ret + +def get_host_pagecount(pagesize): +try: +return int(open(HOST_HUGEPAGE % (0, pagesize)).read()) +except IOError: +return -1 + +def connection_allocPages(params): +""" + test API for allocPages in class virConnect +""" +logger = params['logger'] +fail=0 + +if 'flags' in params: +if params['flags'] == 'pageset': +flags = libvirt.VIR_NODE_ALLOC_PAGES_SET +else: +logger.error("Unknown flags name: %s" % params['flags']) +return 1 +else: +flags = 0 + +try: +if 'conn' in params: +conn=libvirt.open(params['conn']) +else: +conn=libvirt.open(optional_params['conn']) +logger.info("get connection to libvirtd") +list1 = get_host_pagesize(conn) + +except libvirtError, e: +logger.error("API error message: %s" % e.message) +return 1 + +for i in list1: +logger.info("test hugepage size %d" % i) + +if get_host_pagecount(i) == -1: +logger.info("Skip system page size %d" % i) +continue + +try: +cur_count = get_host_pagecount(i) +if flags == libvirt.VIR_NODE_ALLOC_PAGES_SET: +conn.allocPages({i : cur_count + 1}, 0, 1, flags) +else: +conn.allocPages({i : 1}, 0, 1, flags) +if get_host_pagecount(i) != cur_count + 1: +logger.error("libvirt set a wrong page count to %dKiB hugepage" % i) +fail = 1 +except libvirtError, e: +if "Allocated only" in e.message: +tmp_count = int(e.message.split()[-1]) + +if tmp_count != get_host_pagecount(i): +logger.error("libvirt output %dKiB hugepage count is not right" % i) +fail = 1 +else: +logger.error("API error message: %s" % e.message) +return 1 + +return fail ACK and Pushed Thanks Hongming -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-api][PATCH] Add a new test case for setUserPassword
On 09/21/2015 03:43 PM, Luyao Huang wrote: Signed-off-by: Luyao Huang --- cases/linux_domain.conf | 22 repos/domain/set_user_passwd.py | 111 2 files changed, 133 insertions(+) create mode 100644 repos/domain/set_user_passwd.py diff --git a/cases/linux_domain.conf b/cases/linux_domain.conf index 19daded..9a65cf3 100644 --- a/cases/linux_domain.conf +++ b/cases/linux_domain.conf @@ -299,6 +299,28 @@ domain:info_iothread conn qemu:///system +domain:set_user_passwd +guestname +$defaultname +username +$username +userpassword +$password +conn +qemu:///system + +domain:set_user_passwd +guestname +$defaultname +username +$username +userpassword +$password +conn +qemu:///system +flags +encrypted + domain:destroy guestname $defaultname diff --git a/repos/domain/set_user_passwd.py b/repos/domain/set_user_passwd.py new file mode 100644 index 000..bf9bd06 --- /dev/null +++ b/repos/domain/set_user_passwd.py @@ -0,0 +1,111 @@ +#!/usr/bin/env python + +import libvirt +from libvirt import libvirtError +import lxml +import lxml.etree +import crypt +from utils import utils + +required_params = ('guestname', 'username', 'userpassword',) +optional_params = {'conn': 'qemu:///system', 'flags': '',} + +def get_guest_mac(vm): +tree = lxml.etree.fromstring(vm.XMLDesc(0)) +set = tree.xpath("/domain/devices/interface/mac") + +for n in set: +return n.attrib['address'] + +return False + + +def check_agent_status(vm): +""" make sure agent is okay to use """ + +tree = lxml.etree.fromstring(vm.XMLDesc(0)) + +set = tree.xpath("//channel[@type='unix']/target[@name='org.qemu.guest_agent.0']") +for n in set: +if n.attrib['state'] == 'connected': +return True + +return False + +def create_new_user(ipaddr, newusername, username, userpasswd, logger): +cmd = "useradd %s" % newusername +ret, retinfo = utils.remote_exec_pexpect(ipaddr, username, userpasswd, cmd) +if ret == 0 or "already exists" in retinfo: +return 0 +else: +logger.error("Fail: cannot create a new user: %s" % retinfo) +return 1 + +def verify_cur_user(ipaddr, username, userpasswd): +cmd = "whoami" +ret, retinfo = utils.remote_exec_pexpect(ipaddr, username, userpasswd, cmd) + +return ret + +def set_user_passwd(params): +""" + test API for setUserPassword in class virDomain +""" + +logger = params['logger'] +guest = params['guestname'] +username = params['username'] +userpasswd = params['userpassword'] + +if 'flags' in params: +if params['flags'] == 'encrypted': +flags = libvirt.VIR_DOMAIN_PASSWORD_ENCRYPTED +else: +flags = 0 +else: +flags = 0 + +try: +if 'conn' in params: +conn = libvirt.open(params['conn']) +else: +conn = libvirt.open(optional_params['conn']) + +logger.info("get connection to libvirtd") +vm = conn.lookupByName(guest) +logger.info("test guest name: %s" % guest) + +if not check_agent_status(vm): +logger.error("guest agent is not connected") +return 1 + +mac = get_guest_mac(vm) +if not mac: +logger.error("cannot get guest interface mac") +return 1 + +ipaddr = utils.mac_to_ip(mac, 180) +if not ipaddr: +logger.error("cannot get guest IP") +return 1 + +if flags > 0: +passwd = crypt.crypt("123456", crypt.mksalt(crypt.METHOD_SHA512)) +else: +passwd = "123456" + + +if create_new_user(ipaddr, "usertestapi", username, userpasswd, logger) != 0: +return 1 + +vm.setUserPassword("usertestapi", passwd, flags) + +if verify_cur_user(ipaddr, "usertestapi", "123456") != 0: +logger.error("cannot login guest via new user") +return 1 + +except libvirtError, e: +logger.error("API error message: %s" % e.message) +return 1 + +return 0 ACK and Pushed Thanks Hongming -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-api][PATCH 2/2] Add a new test case for fsinfo API
On 09/14/2015 11:43 AM, Luyao Huang wrote: Signed-off-by: Luyao Huang --- cases/linux_domain.conf | 10 + repos/domain/fsinfo.py | 103 2 files changed, 113 insertions(+) create mode 100644 repos/domain/fsinfo.py diff --git a/cases/linux_domain.conf b/cases/linux_domain.conf index 19daded..faa9df9 100644 --- a/cases/linux_domain.conf +++ b/cases/linux_domain.conf @@ -299,6 +299,16 @@ domain:info_iothread conn qemu:///system +domain:fsinfo +guestname +$defaultname +username +$username +userpassword +$password +conn +qemu:///system + domain:destroy guestname $defaultname diff --git a/repos/domain/fsinfo.py b/repos/domain/fsinfo.py new file mode 100644 index 000..e6d1bf0 --- /dev/null +++ b/repos/domain/fsinfo.py @@ -0,0 +1,103 @@ +#!/usr/bin/env python + +import libvirt +from libvirt import libvirtError +import lxml +import lxml.etree +from utils import utils + +required_params = ('guestname', 'username', 'userpassword',) +optional_params = {'conn': 'qemu:///system'} + +def get_guest_mac(vm): +tree = lxml.etree.fromstring(vm.XMLDesc(0)) +set = tree.xpath("/domain/devices/interface/mac") + +for n in set: +return n.attrib['address'] + +return False + + +def check_agent_status(vm): +""" make sure agent is okay to use """ + +tree = lxml.etree.fromstring(vm.XMLDesc(0)) + +set = tree.xpath("//channel[@type='unix']/target[@name='org.qemu.guest_agent.0']") +for n in set: +if n.attrib['state'] == 'connected': +return True + +return False + +def check_fsinfo(ipaddr, username, userpasswd, fsinfo, logger): +""" equal the fsinfo from libvirt and we get in guest mountinfo """ + +cmd = "cat /proc/self/mountinfo" +ret, mounts_needparse = utils.remote_exec_pexpect(ipaddr, username, userpasswd, cmd) +mounts = utils.parse_mountinfo(mounts_needparse) + +for n in fsinfo: +mountdir = n[0] +name = n[1] +type1 = n[2] +target = n[3][0] +found = 0 + +for i in mounts: +if mountdir == i['mountdir']: +found = 1 +if i['mounttype'] != type1: +logger.error("Fail: mount type is not equal: libvirt: %s but we get: %s" % (type1, i['mounttype'])) +return False + +if found == 0: +logger.error("Fail: cannot find %s in guest mount info" % mountdir) +return False + +return True + + +def fsinfo(params): +""" + test API for fsInfo in class virDomain +""" + +logger = params['logger'] +guest = params['guestname'] +username = params['username'] +userpasswd = params['userpassword'] + +try: +conn = libvirt.open(params['conn']) + +logger.info("get connection to libvirtd") +vm = conn.lookupByName(guest) +logger.info("test guest name: %s" % guest) + +if not check_agent_status(vm): +logger.error("guest agent is not connected") +return 1 + +fsinfo = vm.fsInfo() +logger.info("get geust filesystem information") + +mac = get_guest_mac(vm) +if not mac: +logger.error("cannot get guest interface mac") +return 1 + +ipaddr = utils.mac_to_ip(mac, 180) +if not ipaddr: +logger.error("cannot get guest IP") +return 1 + +if not check_fsinfo(ipaddr, username, userpasswd, fsinfo, logger): +return 1 + +except libvirtError, e: +logger.error("API error message: %s" % e.message) +return 1 + +return 0 ACK and Pushed Thanks Hongming -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-api][PATCH] Add new test case for allocPages API
On 08/28/2015 05:02 PM, Luyao Huang wrote: Signed-off-by: Luyao Huang --- cases/test_connection.conf | 4 ++ repos/virconn/connection_allocPages.py | 88 ++ 2 files changed, 92 insertions(+) create mode 100644 repos/virconn/connection_allocPages.py diff --git a/cases/test_connection.conf b/cases/test_connection.conf index 336b1ad..600ec32 100644 --- a/cases/test_connection.conf +++ b/cases/test_connection.conf @@ -77,3 +77,7 @@ virconn:connection_getMemoryParameters virconn:connection_getMemoryStats conn qemu:///system + +virconn:connection_allocPages +conn +qemu:///system It is better to specify the flag of API in conf file. for example virconn:connection_allocPages conn qemu:///system flags alloc_pages_add diff --git a/repos/virconn/connection_allocPages.py b/repos/virconn/connection_allocPages.py new file mode 100644 index 000..9ddd474 --- /dev/null +++ b/repos/virconn/connection_allocPages.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python + +import libvirt +from libvirt import libvirtError +import lxml +import lxml.etree + +required_params = () +optional_params = {'conn': ''} + +HOST_HUGEPAGE = '/sys/devices/system/node/node%d/hugepages/hugepages-%dkB/nr_hugepages' + +def get_host_pagesize(conn): +ret = [] +tree = lxml.etree.fromstring(conn.getCapabilities()) + +set = tree.xpath("/capabilities/host/cpu/pages") +for n in set: +ret.append(int(n.attrib['size'])) + +return ret + +def get_host_pagecount(pagesize): +try: +return int(open(HOST_HUGEPAGE % (0, pagesize)).read()) +except IOError: +return -1 + +def connection_allocPages(params): +""" + test API for allocPages in class virConnect +""" +logger = params['logger'] +fail=0 + +try: +conn=libvirt.open(params['conn']) +logger.info("get connection to libvirtd") +list1 = get_host_pagesize(conn) + +except libvirtError, e: +logger.error("API error message: %s" % e.message) +return 1 + +for i in list1: +logger.info("test hugepage size %d" % i) + +if get_host_pagecount(i) == -1: +logger.info("Skip system page size %d" % i) +continue + +""" test flag VIR_NODE_ALLOC_PAGES_SET """ +try: +cur_count = get_host_pagecount(i) +conn.allocPages({i : cur_count + 1}, 0, 1, libvirt.VIR_NODE_ALLOC_PAGES_SET) +if get_host_pagecount(i) != cur_count + 1: +logger.info("libvirt set a wrong page count to %dKiB hugepage" % i) +fail = 1 +except libvirtError, e: +if "Allocated only" in e.message: +tmp_count = int(e.message.replace(" ", "")[-1:]) + +if tmp_count != get_host_pagecount(i): +logger.info("libvirt output %dKiB hugepage count is not right" % i) +fail = 1 +else: +logger.error("API error message: %s" % e.message) +return 1 + +""" test flag VIR_NODE_ALLOC_PAGES_ADD """ +try: +cur_count = get_host_pagecount(i) +conn.allocPages({i : 1}, 0, 1, libvirt.VIR_NODE_ALLOC_PAGES_ADD) +if get_host_pagecount(i) != cur_count + 1: +logger.info("libvirt set a wrong page count to %dKiB hugepage" % i) +fail = 1 +except libvirtError, e: +if "Allocated only" in e.message: +tmp_count = int(e.message.replace(" ", "")[-1:]) + +if tmp_count != get_host_pagecount(i): +logger.info("libvirt output %dKiB hugepage count is not right" % i) +fail = 1 +else: +logger.error("API error message: %s" % e.message) +return 1 + +return fail -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-api][PATCH 3/3] Add a new test case for ioThreadInfo
On 08/13/2015 11:09 AM, Luyao Huang wrote: Signed-off-by: Luyao Huang --- cases/linux_domain.conf | 6 repos/domain/info_iothread.py | 80 +++ 2 files changed, 86 insertions(+) create mode 100644 repos/domain/info_iothread.py diff --git a/cases/linux_domain.conf b/cases/linux_domain.conf index b0bfb24..f8b5663 100644 --- a/cases/linux_domain.conf +++ b/cases/linux_domain.conf @@ -293,6 +293,12 @@ domain:pin_iothread conn qemu:///system +domain:info_iothread +guestname +$defaultname +conn +qemu:///system + domain:destroy guestname $defaultname diff --git a/repos/domain/info_iothread.py b/repos/domain/info_iothread.py new file mode 100644 index 000..74aedac --- /dev/null +++ b/repos/domain/info_iothread.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python + +import libvirt +from libvirt import libvirtError +import lxml +import lxml.etree + +required_params = ('guestname',) +optional_params = {'conn': 'qemu:///system'} + +def find_iothreadid_fromxml(vm, running, iothreadid): +if (running == 1): +tree = lxml.etree.fromstring(vm.XMLDesc(0)) +else: +tree = lxml.etree.fromstring(vm.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE)) + +set = tree.xpath("//iothreadids/iothread") +for n in set: +ids = n.attrib['id'] +if int(ids) == iothreadid: +return True + +return False + +def info_iothread(params): +""" + test API for ioThreadInfo in class virDomain +""" + +logger = params['logger'] +fail=0 + +try: +conn = libvirt.open(params['conn']) + +logger.info("get connection to libvirtd") +guest = params['guestname'] +vm = conn.lookupByName(guest) +logger.info("test guest name: %s" % guest) + +""" test effect guest running XML """ +if vm.isActive() == 1: +logger.info("guest is running test with running guest") + +ret = vm.ioThreadInfo(libvirt.VIR_DOMAIN_AFFECT_LIVE) + +if len(ret) == 0: +vm.addIOThread(1, libvirt.VIR_DOMAIN_AFFECT_LIVE) +if not find_iothreadid_fromxml(vm, 1, 1): +logger.info("FAIL: cannot find iothread id in XML") +return 1 +else: +ret = vm.ioThreadInfo(libvirt.VIR_DOMAIN_AFFECT_LIVE) + +for n in ret: +if not find_iothreadid_fromxml(vm, 1, n[0]): +logger.info("FAIL: cannot find iothread id in XML") +fail=1 + +""" test effect guest config""" +logger.info("test with guest inactive XML") +ret = vm.ioThreadInfo(libvirt.VIR_DOMAIN_AFFECT_CONFIG) + +if len(ret) == 0: +vm.addIOThread(1, libvirt.VIR_DOMAIN_AFFECT_CONFIG) +if not find_iothreadid_fromxml(vm, 0, 1): +logger.info("FAIL: cannot find iothread id in XML") +return 1 +else: +ret = vm.ioThreadInfo(libvirt.VIR_DOMAIN_AFFECT_CONFIG) + +for n in ret: +if not find_iothreadid_fromxml(vm, 0, n[0]): + logger.info("FAIL: cannot find iothread id in XML") +fail=1 + +except libvirtError, e: +logger.error("API error message: %s" % e.message) +fail=1 +return fail ACK and Pushed Thanks Hongming -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-api][PATCH 3/3] Add a new case for getCPUStatus
On 06/02/2015 07:57 AM, hongming wrote: ACK and pushed Don't forget to remove trailing whitespace next time. Thanks Hongming On 05/18/2015 09:28 AM, Luyao Huang wrote: Signed-off-by: Luyao Huang --- cases/linux_domain.conf| 6 +++ repos/domain/cpu_status.py | 113 + 2 files changed, 119 insertions(+) create mode 100644 repos/domain/cpu_status.py diff --git a/cases/linux_domain.conf b/cases/linux_domain.conf index 0a7d134..9f64226 100644 --- a/cases/linux_domain.conf +++ b/cases/linux_domain.conf @@ -269,6 +269,12 @@ virconn:connection_security_model guestname $defaultname +domain:virDomain_getCPUStats The case name is wrong , I have fixed it directly commit 5c433b7c934cd8ac3ad783939c5906b7cbc129a8 Author: Hongming Zhang Date: Mon Aug 24 11:25:04 2015 +0800 Fix a wrong case name in linux_domain.conf Modify the virDomain_getCPUStats as cpu_status modified: cases/linux_domain.conf +guestname +$defaultname +conn +qemu:///system + domain:destroy guestname $defaultname diff --git a/repos/domain/cpu_status.py b/repos/domain/cpu_status.py new file mode 100644 index 000..6e511c0 --- /dev/null +++ b/repos/domain/cpu_status.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python +import libvirt +from libvirt import libvirtError +from utils import utils + +required_params = ('guestname',) +optional_params = {'conn': 'qemu:///system'} + +ONLINE_CPU = '/sys/devices/system/cpu/online' +CGROUP_PERCPU = '/sys/fs/cgroup/cpuacct/machine.slice/machine-qemu\\x2d%s.scope/cpuacct.usage_percpu' +CGROUP_PERVCPU = '/sys/fs/cgroup/cpuacct/machine.slice/machine-qemu\\x2d%s.scope/vcpu%d/cpuacct.usage_percpu' +CGROUP_USAGE = '/sys/fs/cgroup/cpuacct/machine.slice/machine-qemu\\x2d%s.scope/cpuacct.usage' +CGROUP_STAT = '/sys/fs/cgroup/cpuacct/machine.slice/machine-qemu\\x2d%s.scope/cpuacct.stat' + +def getcputime(a): +return open(a[0]).read().split()[a[1]] + +def virtgetcputime(a): +return a[0].getCPUStats(0)[a[1]][a[2]] + +def getvcputime(a): +ret = 0 +for i in range(int(a[0])): +ret += int(open(CGROUP_PERVCPU % (a[1], i)).read().split()[a[2]]) + +return ret + +def virtgettotalcputime(a): +return a[0].getCPUStats(1)[0][a[1]] + +def virtgettotalcputime2(a): +return a[0].getCPUStats(1)[0][a[1]]/1000 + +def cpu_status(params): +""" + test API for getCPUStats in class virDomain +""" +logger = params['logger'] +fail=0 + +cpu = utils.file_read(ONLINE_CPU) +logger.info("host online cpulist is %s" % cpu) + +cpu_tuple = utils.param_to_tuple_nolength(cpu) +if not cpu_tuple: +logger.info("error in function param_to_tuple_nolength") +return 1 + +try: +conn = libvirt.open(params['conn']) + +logger.info("get connection to libvirtd") +guest = params['guestname'] +vm = conn.lookupByName(guest) +vcpus = vm.info()[3] +for n in range(len(cpu_tuple)): +if not cpu_tuple[n]: +continue + +D = utils.get_standard_deviation(getcputime, virtgetcputime, \ +[CGROUP_PERCPU % guest, n], [vm,n,'cpu_time']) +logger.info("Standard Deviation for host cpu %d cputime is %d" % (n, D)) + +""" expectations 403423 is a average collected in a x86_64 low load machine""" +if D > 403423*5: +fail=1 +logger.info("FAIL: Standard Deviation is too big \ + (biger than %d) for host cpu %d" % (403423*5, n)) + +D = utils.get_standard_deviation(getvcputime, virtgetcputime, \ +[vcpus, guest, n], [vm,n,'vcpu_time']) +logger.info("Standard Deviation for host cpu %d vcputime is %d" % (n, D)) + +""" expectations 4034 is a average collected in a x86_64 low load machine""" +if D > 4034*5*vcpus: +fail=1 +logger.info("FAIL: Standard Deviation is too big \ + (biger than %d) for host cpu time %d" % (4034*5*vcpus, n)) + +D = utils.get_standard_deviation(getcputime, virtgettotalcputime, \ +[CGROUP_USAGE % guest, 0], [vm,'cpu_time']) +logger.info("Standard Deviation for host cpu total cputime is %d" % D) + +""" expectations 313451 is a average collected in a x86_64 low load machine""" +if D > 313451*5*len(cpu_tuple): +fail=1 +logger.info("FAIL: Standard Deviation is too big \ +
Re: [libvirt] [libvirt-test-api][PATCH] Introduce new test case for setMemoryStatsPeriod
On 07/02/2015 05:25 PM, Luyao Huang wrote: Signed-off-by: Luyao Huang --- cases/linux_domain.conf | 6 +++ repos/domain/set_memory_period.py | 84 +++ 2 files changed, 90 insertions(+) create mode 100644 repos/domain/set_memory_period.py diff --git a/cases/linux_domain.conf b/cases/linux_domain.conf index 9f64226..fd32aad 100644 --- a/cases/linux_domain.conf +++ b/cases/linux_domain.conf @@ -275,6 +275,12 @@ domain:virDomain_getCPUStats conn qemu:///system +domain:set_memory_period +guestname +$defaultname +conn +qemu:///system + domain:destroy guestname $defaultname diff --git a/repos/domain/set_memory_period.py b/repos/domain/set_memory_period.py new file mode 100644 index 000..56b71ae --- /dev/null +++ b/repos/domain/set_memory_period.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python + +import libvirt +from libvirt import libvirtError +import lxml +import lxml.etree + +required_params = ('guestname',) +optional_params = {'conn': 'qemu:///system'} + +def get_period_fromxml(vm, running): +if (running == 1): +tree = lxml.etree.fromstring(vm.XMLDesc(0)) +else: +tree = lxml.etree.fromstring(vm.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE)) + +set = tree.xpath("//memballoon/stats") +if len(set) == 0: +return 0 +for n in set: +period = n.attrib['period'] +return period + +def check_memoryStats(vm): +memstats = vm.memoryStats() +try: +available = memstats["available"] +if available: +logger.info("can get available from memoryStats()") +return 0 +except KeyError: +logger.info("cannot get available from memoryStats()") +return 1 + +def set_memory_period(params): +""" + test API for setMemoryStatsPeriod in class virDomain +""" +global logger +logger = params['logger'] +fail=0 + +try: +conn = libvirt.open(params['conn']) + +logger.info("get connection to libvirtd") +guest = params['guestname'] +vm = conn.lookupByName(guest) +logger.info("test guest name: %s" % guest) + +""" test with running vm """ +if vm.isActive() == 1: +logger.info("guest is running test with running guest") +period = int(get_period_fromxml(vm, 1)) +if period == 0: +vm.setMemoryStatsPeriod(1, libvirt.VIR_DOMAIN_AFFECT_LIVE) +if int(get_period_fromxml(vm, 1)) != 1: +logger.error("Period value from xml is not right") +fail = 1 +elif check_memoryStats(vm) == 0: +period = 1 +else: +fail = 1 + +if period > 0: +if check_memoryStats(vm) == 0: +vm.setMemoryStatsPeriod(period + 1, libvirt.VIR_DOMAIN_AFFECT_LIVE) +if int(get_period_fromxml(vm, 1)) != period + 1: +logger.error("Period value from xml is not right") +fail = 1 +else: +fail = 1 + +""" test with vm config """ +period = int(get_period_fromxml(vm, 0)) +vm.setMemoryStatsPeriod(period + 1, libvirt.VIR_DOMAIN_AFFECT_CONFIG) +if int(get_period_fromxml(vm, 0)) != period + 1: +logger.error("Period value from xml is not right") +fail = 1 + +except libvirtError, e: +logger.error("API error message: %s" % e.message) +fail=1 +return fail ACK and Pushed Thanks Hongming -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-API][PATCH 2/2] Add new case to test storagePoolLookupByVolume
On 07/02/2015 05:08 PM, jiahu wrote: Added a new case to validate storagePoolLookupByVolume api --- repos/storage/pool_lookup_by_volume.py | 46 ++ 1 file changed, 46 insertions(+) create mode 100644 repos/storage/pool_lookup_by_volume.py diff --git a/repos/storage/pool_lookup_by_volume.py b/repos/storage/pool_lookup_by_volume.py new file mode 100644 index 000..ee5c9c9 --- /dev/null +++ b/repos/storage/pool_lookup_by_volume.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +#test storagePoolLookupByVolume() API for libvirt + +import os +import libvirt +from libvirt import libvirtError +from src import sharedmod + +required_params = ('poolname','volname',) +optional_params = {} + +def pool_lookup_by_volume(params): +""" + test API for storagePoolLookupByVolume in class virStoragePool +""" +logger = params['logger'] +poolname = params['poolname'] +volname = params['volname'] +logger.info("The given pool name is %s" % (poolname)) +logger.info("The given vol name is %s" % (volname)) +conn = sharedmod.libvirtobj['conn'] +pool = conn.storagePoolLookupByName(poolname) +pre_vol = pool.storageVolLookupByName(volname) +volpath = pre_vol.path() +logger.info("The given volume path is %s" % (volpath)) +temp = volpath.split("/") +temp.pop(0) +temp.pop(-1) +temp1 = "/" + "/".join(temp) +if not os.path.exists(temp1): +logger.warning("volume path file %s is not exist" % temp1) + +try: +vol = conn.storageVolLookupByPath(volpath) +pool_name = vol.storagePoolLookupByVolume().name() +logger.info("The pool name is %s from API" % (pool_name)) + +if not pool_name == poolname: + return 1 + +except libvirtError, e: +logger.error("API error message: %s, error code is %s" \ + % (e.message, e.get_error_code())) +return 1 + +return 0 ACK and Pushed Thanks Hongming -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-api][PATCH 3/3] Add a new case for getCPUStatus
ACK and pushed Don't forget to remove trailing whitespace next time. Thanks Hongming On 05/18/2015 09:28 AM, Luyao Huang wrote: Signed-off-by: Luyao Huang --- cases/linux_domain.conf| 6 +++ repos/domain/cpu_status.py | 113 + 2 files changed, 119 insertions(+) create mode 100644 repos/domain/cpu_status.py diff --git a/cases/linux_domain.conf b/cases/linux_domain.conf index 0a7d134..9f64226 100644 --- a/cases/linux_domain.conf +++ b/cases/linux_domain.conf @@ -269,6 +269,12 @@ virconn:connection_security_model guestname $defaultname +domain:virDomain_getCPUStats +guestname +$defaultname +conn +qemu:///system + domain:destroy guestname $defaultname diff --git a/repos/domain/cpu_status.py b/repos/domain/cpu_status.py new file mode 100644 index 000..6e511c0 --- /dev/null +++ b/repos/domain/cpu_status.py @@ -0,0 +1,113 @@ +#!/usr/bin/env python +import libvirt +from libvirt import libvirtError +from utils import utils + +required_params = ('guestname',) +optional_params = {'conn': 'qemu:///system'} + +ONLINE_CPU = '/sys/devices/system/cpu/online' +CGROUP_PERCPU = '/sys/fs/cgroup/cpuacct/machine.slice/machine-qemu\\x2d%s.scope/cpuacct.usage_percpu' +CGROUP_PERVCPU = '/sys/fs/cgroup/cpuacct/machine.slice/machine-qemu\\x2d%s.scope/vcpu%d/cpuacct.usage_percpu' +CGROUP_USAGE = '/sys/fs/cgroup/cpuacct/machine.slice/machine-qemu\\x2d%s.scope/cpuacct.usage' +CGROUP_STAT = '/sys/fs/cgroup/cpuacct/machine.slice/machine-qemu\\x2d%s.scope/cpuacct.stat' + +def getcputime(a): +return open(a[0]).read().split()[a[1]] + +def virtgetcputime(a): +return a[0].getCPUStats(0)[a[1]][a[2]] + +def getvcputime(a): +ret = 0 +for i in range(int(a[0])): +ret += int(open(CGROUP_PERVCPU % (a[1], i)).read().split()[a[2]]) + +return ret + +def virtgettotalcputime(a): +return a[0].getCPUStats(1)[0][a[1]] + +def virtgettotalcputime2(a): +return a[0].getCPUStats(1)[0][a[1]]/1000 + +def cpu_status(params): +""" + test API for getCPUStats in class virDomain +""" +logger = params['logger'] +fail=0 + +cpu = utils.file_read(ONLINE_CPU) +logger.info("host online cpulist is %s" % cpu) + +cpu_tuple = utils.param_to_tuple_nolength(cpu) +if not cpu_tuple: +logger.info("error in function param_to_tuple_nolength") +return 1 + +try: +conn = libvirt.open(params['conn']) + +logger.info("get connection to libvirtd") +guest = params['guestname'] +vm = conn.lookupByName(guest) +vcpus = vm.info()[3] +for n in range(len(cpu_tuple)): +if not cpu_tuple[n]: +continue + +D = utils.get_standard_deviation(getcputime, virtgetcputime, \ +[CGROUP_PERCPU % guest, n], [vm,n,'cpu_time']) +logger.info("Standard Deviation for host cpu %d cputime is %d" % (n, D)) + +""" expectations 403423 is a average collected in a x86_64 low load machine""" +if D > 403423*5: +fail=1 +logger.info("FAIL: Standard Deviation is too big \ + (biger than %d) for host cpu %d" % (403423*5, n)) + +D = utils.get_standard_deviation(getvcputime, virtgetcputime, \ +[vcpus, guest, n], [vm,n,'vcpu_time']) +logger.info("Standard Deviation for host cpu %d vcputime is %d" % (n, D)) + +""" expectations 4034 is a average collected in a x86_64 low load machine""" +if D > 4034*5*vcpus: +fail=1 +logger.info("FAIL: Standard Deviation is too big \ + (biger than %d) for host cpu time %d" % (4034*5*vcpus, n)) + +D = utils.get_standard_deviation(getcputime, virtgettotalcputime, \ +[CGROUP_USAGE % guest, 0], [vm,'cpu_time']) +logger.info("Standard Deviation for host cpu total cputime is %d" % D) + +""" expectations 313451 is a average collected in a x86_64 low load machine""" +if D > 313451*5*len(cpu_tuple): +fail=1 +logger.info("FAIL: Standard Deviation is too big \ + (biger than %d) for host cpu time %d" % (313451*5*len(cpu_tuple), n)) + +D = utils.get_standard_deviation(getcputime, virtgettotalcputime2, \ +[CGROUP_STAT % guest, 3], [vm,'system_time']) +logger.info("Standard Deviation for host cpu total system time is %d" % D) + +""&quo
Re: [libvirt] [libvirt-test-api][PATCH] fix imperfect cleanup cause the case will always fail
ACK and Pushed On 05/15/2015 09:59 AM, Luyao Huang wrote: Remove call undefined function. Signed-off-by: Luyao Huang --- repos/virconn/connection_getMemoryParameters.py | 4 1 file changed, 4 deletions(-) diff --git a/repos/virconn/connection_getMemoryParameters.py b/repos/virconn/connection_getMemoryParameters.py index 9b88fc3..d110b35 100644 --- a/repos/virconn/connection_getMemoryParameters.py +++ b/repos/virconn/connection_getMemoryParameters.py @@ -16,7 +16,6 @@ node_memory = ['full_scans', '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): @@ -47,9 +46,6 @@ def connection_getMemoryParameters(params): 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: -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-api][PATCH] Add a new test case for getMemoryParameters
ACK and Pushed Thanks Hongming On 05/04/2015 04:09 PM, Luyao Huang wrote: Signed-off-by: Luyao Huang --- 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 000..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 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-api][PATCH 1/3] introduce 2 functions in utils
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" To: libvir-list@redhat.com Cc: "Luyao Huang" 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 --- 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) -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-API][PATCH 3/3] Modify the case to cover two new APIs
ACK and Pushed Thanks Hongming On 04/23/2015 03:37 PM, jiahu wrote: Check two new APIs in this case: storagePoolLookupByUUIDString/storagePoolLookupByUUID --- repos/storage/pool_uuid.py | 49 +- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/repos/storage/pool_uuid.py b/repos/storage/pool_uuid.py index bb6bf63..2f371eb 100644 --- a/repos/storage/pool_uuid.py +++ b/repos/storage/pool_uuid.py @@ -1,4 +1,8 @@ #!/usr/bin/env python +#To test "virsh pool-uuid" command and related APIs +#To test 2 APIs in this case: +#storagePoolLookupByUUID +#storagePoolLookupByUUIDString import os import sys @@ -6,7 +10,10 @@ import re import time import commands +import binascii import libvirt + +from xml.dom import minidom from libvirt import libvirtError from src import sharedmod @@ -15,6 +22,7 @@ required_params = ('poolname',) optional_params = {} VIRSH_POOLUUID = "virsh pool-uuid" +POOLPATH = "/etc/libvirt/storage/" def check_pool_uuid(poolname, UUIDString, logger): """ check UUID String of a pool """ @@ -32,10 +40,25 @@ def check_pool_uuid(poolname, UUIDString, logger): else: return False +def checking_uuid(logger,poolname,pooluuid): +"""check two uuid of pool which are from API and pool's XML""" +global POOLPATH +POOLPATH = POOLPATH + poolname + ".xml" +xml = minidom.parse(POOLPATH) +pool = xml.getElementsByTagName('pool')[0] +uuid = pool.getElementsByTagName('uuid')[0].childNodes[0].data +if uuid == pooluuid: +return True +else: + return False + def pool_uuid(params): -""" call appropriate API to generate the UUIDStirng +""" 1. call appropriate API to generate the UUIDStirng of a pool , then compared to the output of command virsh pool-uuid +2. check 2 APIs in the case: + storagePoolLookupByUUID + storagePoolLookupByUUIDString """ logger = params['logger'] poolname = params['poolname'] @@ -53,6 +76,30 @@ def pool_uuid(params): try: UUIDString = poolobj.UUIDString() logger.info("the UUID string of pool %s is %s" % (poolname, UUIDString)) + +#For a transient pool, set another path +if not poolobj.isPersistent() == 1: +logger.info("Can not check a transient pool by now.") +return 0 +#allowing '-' and ' ' anywhere between character pairs,just check +#one of them +UUIDString1 = UUIDString.replace("-"," ") +pool1 = conn.storagePoolLookupByUUIDString(UUIDString1) +pool_name1 = pool1.name() +logger.debug("The given UUID is \"%s\", the pool is \"%s\" using\ + storagePoolLookupByUUIDString" %(UUIDString1,pool_name1)) + +UUIDString2 = UUIDString.replace("-","") +UUID_ascii = binascii.a2b_hex(UUIDString2) +pool2 = conn.storagePoolLookupByUUID(UUID_ascii) +pool_name2 = pool2.name() +logger.debug("The given UUID is \"%s\", the pool is \"%s\" using \ +storagePoolLookupByUUID" %(UUIDString2,pool_name2)) + +if pool_name1 == pool_name2 and checking_uuid(logger,pool_name1,UUIDString): +logger.info("Successed to get pool name \"%s\" using \"%s\""\ + %(pool_name1,UUIDString)) + if check_pool_uuid(poolname, UUIDString, logger): logger.info(VIRSH_POOLUUID + " test succeeded.") return 0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-API][PATCH] Add connection_getDomainCapabilities test case
list: %s" % backend_api) +if not mode_api == allmode: +return False +if not policy_api == allpolicy: +return False +if not subsys_api == allsubsys: +return False +if not backend_api == allbackend: +return False +return True + +def connection_getDomainCapabilities(params): +""" + test API for getDomainCapabilities in class virConnect +""" +global ovmf_f +logger = params['logger'] +emulatorbin = params['emulatorbin'] +arch = params['arch'] +machine = params['machine'] +virttype = params['virttype'] + +try: +logger.info("The specified emulatorbin is %s" \ +% emulatorbin) +logger.info("The specified architecture is %s" \ +% arch) +logger.info("The specified machine is %s" \ +% machine) +logger.info("The specified virttype is %s" \ +% virttype) + +generate_hash(emulatorbin, logger) +if not os.path.exists(QEMU_CAPS): +logger.error("cache file, %s is not exist" % QEMU_CAPS) +return 1 +if os.path.exists(OVMF): +ovmf_f = True +else: +logger.warning("cache file, %s is not exist" % OVMF) +if not get_maxcpu(machine,logger): +logger.debug("get maxcpu: Fail") +return 1 +if not get_os_flags(logger): +logger.debug("get os: Fail") +return 1 +if not get_disk_flags(logger): +logger.debug("get disk: Fail") +return 1 +if not get_hostdev_flags(logger): +logger.debug("get hostdev: Fail") +return 1 +if not validate_caps_from_hv(emulatorbin,logger): +logger.error("Failed to compare caps") +return 1 +else: +logger.debug("Successed to compare caps") + +conn = sharedmod.libvirtobj['conn'] +caps_from_api = conn.getDomainCapabilities\ +(emulatorbin,arch,machine,virttype,0) + +logger.debug("The return of API: %s" % caps_from_api) +fd = open(API_FILE,"w+") +fd.write(caps_from_api) +fd.flush() + +given_list = [emulatorbin,machine,arch,maxcpu] +if not check_common_values(given_list,logger): +logger.info("Failed to validate common elements") +return 1 +else: +logger.info("Successed to validate common elements") +if not check_os(arch,logger): +logger.info("Failed to validate os block") +return 1 +else: +logger.info("Successed to validate os block") +if not check_disk(logger): +logger.info("Failed to validate disk block") +return 1 +else: +logger.info("Successed to validate disk block") +if not check_hostdev(logger): +logger.info("Failed to validate hostdev block") +return 1 +else: +logger.info("Successed to validate hostdev block") + +except libvirtError, e: +logger.error("API error message: %s" % e.message) +clean_env(logger) +return 1 + +clean_env(logger) +return 0 ACK and Pushed Thanks Hongming -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-API][PATCH 2/2] Add cases to basic_network.conf
ACK and Pushed Thanks Hongming On 02/15/2015 03:02 PM, Jincheng Miao wrote: Signed-off-by: Jincheng Miao --- cases/basic_network.conf | 24 1 files changed, 24 insertions(+), 0 deletions(-) diff --git a/cases/basic_network.conf b/cases/basic_network.conf index e9abd57..18997a2 100644 --- a/cases/basic_network.conf +++ b/cases/basic_network.conf @@ -216,3 +216,27 @@ network:destroy networkname $defaultnetname +network:event_callback +networkname +$defaultnetname +action +define + +network:event_callback +networkname +$defaultnetname +action +start + +network:event_callback +networkname +$defaultnetname +action +destroy + +network:event_callback +networkname +$defaultnetname +action +undefine + -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [test-API][PATCH] Add connection_security_model test case
On 03/17/2015 11:49 AM, lcheng wrote: The connection_security_model.py uses getSecurityModel() to validate new API virNodeGetSecurityModel of libvirt. --- cases/linux_domain.conf| 4 ++ repos/virconn/connection_security_model.py | 101 + 2 files changed, 105 insertions(+) create mode 100644 repos/virconn/connection_security_model.py diff --git a/cases/linux_domain.conf b/cases/linux_domain.conf index 903fdb5..a7015f0 100644 --- a/cases/linux_domain.conf +++ b/cases/linux_domain.conf @@ -233,6 +233,10 @@ domain:domain_fsthaw guestname $defaultname +virconn:connection_security_model +guestname +$defaultname + domain:destroy guestname $defaultname diff --git a/repos/virconn/connection_security_model.py b/repos/virconn/connection_security_model.py new file mode 100644 index 000..b44d78c --- /dev/null +++ b/repos/virconn/connection_security_model.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python +# To test "getSecurityModel" + +import libvirt + +from xml.dom import minidom +from libvirt import libvirtError +from src import sharedmod +from utils import utils + +required_params = ('guestname',) +optional_params = {} + +def get_security_driver(logger): +"""get security driver from /etc/libvirt/qemu.conf""" + +cmds = "grep \"^security_driver\" /etc/libvirt/qemu.conf" +(ret, conf) = utils.exec_cmd(cmds, shell=True) +if ret: +cmds = "getenforce" +(ret, policy) = utils.exec_cmd(cmds, shell=True) + +if policy[0] == "Disabled": +return "none" +else: +return "selinux" + +tmp = conf[0].split(' = ') +if len(tmp[1].split(', ')) > 1: +driver = tmp[1].split(', ') +return (filter(str.isalpha, driver[0])) +else: +cmds = "echo '%s' | awk -F '\"' '{print $2}'" % conf[0] +(ret, driver) = utils.exec_cmd(cmds, shell=True) + +if driver[0] == "selinux": +return "selinux" +elif driver[0] == "none": +return "none" +elif driver[0] == "apparmor": +return "apparmor" +elif driver[0] == "stack": +return "stack" +else: +return "" + +def get_security_model(logger, domname): +"""get security model from process""" + +PID = "ps aux | grep -v grep | grep %s | awk '{print $2}'" % domname +ret, pid = utils.exec_cmd(PID, shell=True) +if ret: +logger.error("get domain pid failed.") +return "" + +LABEL = "ls -nZd /proc/%s" % pid[0] +ret, label = utils.exec_cmd(LABEL, shell=True) +if ret: +logger.error("get domain process's label failed.") +return "" + +if "system_u:system_r:svirt_t:s0" in label[0]: +return "selinux" +else: +return "none" + +def check_security_model(logger, domname, model): +""" check security model""" + +dommodel = get_security_model(logger, domname) +driver = get_security_driver(logger) + +logger.info("domain security model is %s." % dommodel) +logger.info("get security driver is %s." % driver) +logger.info("get security model is %s." % model) + +if driver == dommodel and dommodel == model: +return True +else: +return False + +def connection_security_model(params): +"""test API for getSecurityModel""" + +logger = params['logger'] +domname = params['guestname'] +conn = sharedmod.libvirtobj['conn'] + +try: +model = conn.getSecurityModel() + +if not check_security_model(logger, domname, model[0]): +logger.error("Fail : get a error security model.") +return 1 +else: +logger.info("Pass : get security model successful.") +return 0 +except libvirtError, e: +logger.error("API error message: %s" % e.message) +return 1 + ACK and Pushed NOTE: don't add blank line at EOF next time -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-API][PATCH v2 0/2] Add test cases for setTime and getTime
On 03/12/2015 04:10 PM, hujianwei wrote: On 12/03/15 11:11, Jincheng Miao wrote: create some test cases for libvirt-python API setTime and getTime v2: user should pass 'seconds' to set_guest_time, and 'nseconds' is optional. Jincheng Miao (2): Add guest setTime and getTime testing Add test cases for linux_domain cases/linux_domain.conf| 30 ++ repos/domain/guest_time.py | 98 repos/domain/set_guest_time.py | 122 3 files changed, 250 insertions(+), 0 deletions(-) create mode 100644 repos/domain/guest_time.py create mode 100644 repos/domain/set_guest_time.py ACK Please see my comments in the below patch mail. [libvirt] [libvirt-test-API][PATCH v2 2/2] Add test cases for linux_domain ACK and Pushed after adding the seconds param in "domain:set_guest_time" . BR, Jianwei -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-API][PATCH V2 0/2] Add connection_getAllDomainStats test case
ACK and Pushed Thanks Hongming On 03/12/2015 03:10 PM, jiahu wrote: The testing case will validate the getAllDomainStats API in class virConnect V2: Added new domainListGetStats API in this case jiahu (2): Add connection_getAllDomainStats test case to linux_domain.conf Add connection_getAllDomainStats test case cases/linux_domain.conf | 14 + repos/virconn/connection_getAllDomainStats.py | 549 ++ 2 files changed, 563 insertions(+) create mode 100644 repos/virconn/connection_getAllDomainStats.py -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-API][PATCH 2/2] Add coredump_with_format test case to linux_domain conf
ACK and Pushed Thanks Hongming On 02/27/2015 01:52 PM, jiahu wrote: --- cases/linux_domain.conf | 44 1 file changed, 44 insertions(+) diff --git a/cases/linux_domain.conf b/cases/linux_domain.conf index a5ada35..490ee90 100644 --- a/cases/linux_domain.conf +++ b/cases/linux_domain.conf @@ -34,6 +34,50 @@ domain:start guestname $defaultname +domain:coredump_with_format +guestname +$defaultname +topath +/root/test.dump +dumpformat +zlib +flags +mem + +domain:coredump_with_format +guestname +$defaultname +topath +/root/test.dump +dumpformat +raw +flags +mem|live|bypass + +domain:coredump_with_format +guestname +$defaultname +topath +/root/test.dump +dumpformat +snappy +flags +mem|reset + +domain:coredump_with_format +guestname +$defaultname +topath +/root/test.dump +dumpformat +lzo +flags +mem|crash|bypass + +domain:start +guestname +$defaultname + domain:destroy guestname $defaultname -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-API][PATCH] Rewrite case for listAllInterfaces() API
ACK and Pushed Thanks Hongming On 01/08/2015 11:12 PM, jiahu wrote: Using actual python API to validate test case, rather than use virsh iface-* command lines. --- cases/basic_interface.conf| 12 ++ repos/interface/iface_list.py | 299 -- 2 files changed, 99 insertions(+), 212 deletions(-) diff --git a/cases/basic_interface.conf b/cases/basic_interface.conf index e2125bb..43e37e8 100644 --- a/cases/basic_interface.conf +++ b/cases/basic_interface.conf @@ -15,3 +15,15 @@ interface:define interface:create ifacename $testnic + +interface:iface_list +flags +all + +interface:iface_list +flags +active + +interface:iface_list +flags +inactive diff --git a/repos/interface/iface_list.py b/repos/interface/iface_list.py index 49f0c05..85f9df9 100644 --- a/repos/interface/iface_list.py +++ b/repos/interface/iface_list.py @@ -1,65 +1,26 @@ #!/usr/bin/env python +# test listAllInterfaces() API import os -import sys -import re -import commands +import libvirt -required_params = ('ifaceopt',) -optional_params = {} - -VIRSH_QUIET_IFACE_LIST = "virsh --quiet iface-list %s | awk '{print ""$%s""}'" -NETWORK_CONFIG = "/etc/sysconfig/network-scripts/" -IFCONFIG_DRIVER = "ifconfig %s | sed 's/[ \t].*//;/^$/d'" -GET_MAC = "ip link show %s |sed -n '2p'| awk '{print $2}'" -VIRSH_IFACE_LIST = "virsh iface-list %s" - -names = [] -state = [] -macs = [] - -def get_option_list(params): -"""return options we need to test -""" -logger = params['logger'] -option_list=[] +from libvirt import libvirtError +from src import sharedmod +from utils import utils -value = params['ifaceopt'] -if value == 'all': -option_list = [' ', '--all', '--inactive'] -elif value == '--all' or value == '--inactive': -option_list.append(value) -else: -logger.error("value %s is not supported" % value) -return 1, option_list +required_params = ('flags',) +optional_params = {} -return 0, option_list +NETWORK_CONFIG = "/etc/sysconfig/network-scripts/" +IFCONFIG_DRIVER = "ifconfig %s | sed 's/[ \t].*//;/^$/d'| cut -d \":\" -f -1" -def get_output(command, logger): -"""execute shell command +def get_inteface_list_from_ifcfg(logger): +""" + return host interface list from ifcfg-* """ -status, ret = commands.getstatusoutput(command) -if status: -logger.error("executing "+ "\"" + command + "\"" + " failed") -logger.error(ret) -return status, ret - -def get_interface_list(option, logger): -""" return active host interface list """ -interface_list = [] -status, interface_str = get_output(IFCONFIG_DRIVER % option, logger) -if not status: -interface_list = interface_str.split('\n') -return interface_list -else: -logger.error("\"" + IFCONFIG_DRIVER % option + "\"" + "error") -logger.error(interface_str) -return interface_list - -def check_ifacename(names, option, logger): -""" verify the validity of output data """ ifcfg_files = [] +nic_names = [] for f in os.listdir(NETWORK_CONFIG): if f.startswith("ifcfg-"): f_path = os.path.join(NETWORK_CONFIG, f) @@ -67,18 +28,6 @@ def check_ifacename(names, option, logger): ifcfg_files.append(f_path) else: logger.warn("%s is not a regular file" % f_path) - -interface_active = get_interface_list('', logger) -logger.debug("list of active host interface: %s" % interface_active) -if interface_active == None: -return 1 - -interface_all = get_interface_list('-a', logger) -logger.debug("list of all host interface: %s" % interface_all) -if interface_all == None: -return 1 - - for ifcfg_file in ifcfg_files: fp = open(ifcfg_file, 'r') fp.seek(0,0) @@ -87,165 +36,91 @@ def check_ifacename(names, option, logger): device_str = eachLine.rstrip() nic_string = device_str.split("=")[1] if nic_string.startswith("\""): -nic_name = nic_string[1:-1] +nic_names = nic_string[1:-1] else: -nic_name = nic_string +nic_names.append(nic_string) break -
Re: [libvirt] [libvirt-test-API][PATCH 2/2] Add connection_getAllDomainStats test case
Hi jiahu Please add the following api calling to your case, we can test them using the same checking methods . def domainListGetStats(self, doms, stats=0, flags=0): """ Query statistics for given domains. Thanks Hongming On 03/05/2015 04:02 PM, jiahu wrote: The case will validate the getAllDomainStats API in class virConnect --- repos/virconn/connection_getAllDomainStats.py | 528 ++ 1 file changed, 528 insertions(+) create mode 100644 repos/virconn/connection_getAllDomainStats.py diff --git a/repos/virconn/connection_getAllDomainStats.py b/repos/virconn/connection_getAllDomainStats.py new file mode 100644 index 000..023564a --- /dev/null +++ b/repos/virconn/connection_getAllDomainStats.py @@ -0,0 +1,528 @@ +#!/usr/bin/env python +# test getAllDomainStats() API for libvirt + +import libvirt + +from xml.dom import minidom +from libvirt import libvirtError +from src import sharedmod +from utils import utils + +required_params = () +optional_params = {'stats': '','flags': ''} + +ds = {"state": libvirt.VIR_DOMAIN_STATS_STATE, + "cpu": libvirt.VIR_DOMAIN_STATS_CPU_TOTAL, + "balloon": libvirt.VIR_DOMAIN_STATS_BALLOON, + "vcpu": libvirt.VIR_DOMAIN_STATS_VCPU, + "interface": libvirt.VIR_DOMAIN_STATS_INTERFACE, + "block": libvirt.VIR_DOMAIN_STATS_BLOCK} + +fg = {"active": libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE, + "inactive": libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_INACTIVE, + "persistent": libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_PERSISTENT, + "transient": libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_TRANSIENT, + "running": libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_RUNNING, + "paused": libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_PAUSED, + "shutoff": libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_SHUTOFF, + "other": libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_OTHER, + "backing": libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_BACKING, + "enforce": libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_ENFORCE_STATS} + +def filer_domains(logger, flags): +""" + return a filtered domains set +""" +a = set(active_domains(logger)) +d = set(defined_domains(logger)) +if flags & libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_PERSISTENT and \ + flags & libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_TRANSIENT: +domains = a | d +elif flags & libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_PERSISTENT: +domains = d +elif flags & libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_TRANSIENT: +domains = a - d +else: +domains = a | d +if flags & libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE and \ + flags & libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_INACTIVE: +domains &= (a | d) +elif flags & libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_ACTIVE: +domains &= a +elif flags & libvirt.VIR_CONNECT_GET_ALL_DOMAINS_STATS_INACTIVE: +domains &= (d - a) +else: +domains &= a | d +return domains + +def active_domains(logger): +""" + return active domains on current uri +""" +NUM = "ls /run/libvirt/qemu|grep \".xml\"" +status, output = utils.exec_cmd(NUM, shell=True) +output = [item.replace(".xml","") for item in output] +if status == 0: +logger.debug("Got active domains: %s" % output) +return output +else: +logger.debug("Got active domains: %s" % output) +return output + +def defined_domains(logger): +""" + return defined domains on current uri +""" +NUM = "ls /etc/libvirt/qemu|grep \".xml\"" +status, output = utils.exec_cmd(NUM, shell=True) +output = [item.replace(".xml","") for item in output] +if status == 0: +logger.debug("Got defined domains: %s" % output) +return output +else: +logger.debug("Got defined domains: %s" % output) +return output + +def compare_value(logger,op1,op2): +""" + compare 2 variables value +""" +if op1 != op2: +logger.debug("Check %s: Fail" % op2) +return False +else: +logger.debug("Check %s: Pass" % op2) +return True + +def check_vcpu(logger,dom_name,dom_active,dom_eles): +""" + check vcpu info of given domain +""" +iDOM_XML = "/etc/libvirt/qemu/" + dom_name +".xml" +aDOM_XML = "/run/libvirt/qemu/" + dom_name +".xml&quo
Re: [libvirt] [libvirt-test-API][PATCH 2/2] Add securitylabel test case
ACK and Pushed Thanks hongming On 02/15/2015 04:12 PM, jiahu wrote: 2 new APIs securityLabel and securityLabelList will be covered in securitylabel.py --- repos/domain/securitylabel.py | 170 ++ 1 file changed, 170 insertions(+) create mode 100644 repos/domain/securitylabel.py diff --git a/repos/domain/securitylabel.py b/repos/domain/securitylabel.py new file mode 100644 index 000..cf4aaf3 --- /dev/null +++ b/repos/domain/securitylabel.py @@ -0,0 +1,170 @@ +#!/usr/bin/env python +# test securityLabel() and securityLabelList() API for libvirt + +import libvirt + +from libvirt import libvirtError +from src import sharedmod +from utils import utils + +required_params = ('guestname',) +optional_params = {} + +def check_qemu_conf(logger): +""" + If security_driver is not equal to "selinux", report an error +""" +GREP = "grep \"^security_driver\" /etc/libvirt/qemu.conf" +status, output = utils.exec_cmd(GREP, shell=True) +if status: +return True +else: +if "selinux" in output[0]: +return True +else: +logger.error("Not a default setting in qemu.conf") +return False + +def get_security_policy(logger): +""" + get selinux type from host OS +""" +SELINUX = "getenforce" +status, output = utils.exec_cmd(SELINUX, shell=True) +if not status: +if output[0] == "Enforcing": +sevalue = True +elif output[0] == "Permissive": +sevalue = False +elif output[0] == "Disabled": +sevalue = False +else: +logger.error("Can not find any results") +else: +logger.error("\"" + SELINUX + "\"" + "error") +logger.error(output) +return False +return sevalue + +def get_pid(name,logger): +""" + get process id of specified domain. +""" +PID = "ps aux |grep -v grep | grep \" -name %s\" \ + |awk '{print $2}'" +status, output = utils.exec_cmd(PID % name, shell=True) +if not status: +pass +else: +logger.error("\"" + PID + "\"" + "error") +logger.error(output) +return False +return output[0] + +def get_pid_context(domain,logger): +""" + return context of domain's pid +""" +pid = get_pid(domain,logger) +CONTEXT = "ls -nZd /proc/%s" +status, output = utils.exec_cmd(CONTEXT % pid, shell=True) +if not status: +pass +else: +logger.error("\"" + CONTEXT + "\"" + "error") +logger.error(output) +return False +return pid,output[0] + +def check_selinux_label(api,domain,logger): +""" + check vaules in selinux mode +""" +pid,context = get_pid_context(domain,logger) +logger.debug("The context of %d is %s" % (int(pid), context)) +get_enforce = get_security_policy(logger) +if api[0] in context: +if api[1] == get_enforce: +logger.debug("PASS: '%s'" % api) +return True +else: +logger.debug("Fail: '%s'" % api[1]) +return False +else: + logger.debug("Fail: '%s'" % api[0]) + return False + +def check_DAC_label(api,domain,logger): +""" + check vaules in DAC mode +""" +tmp = [] +pid,context = get_pid_context(domain,logger) +logger.debug("The context of %d is %s" % (int(pid), context)) +#enforcing is always false in DAC mode +for item in api: + tmp.append(item) +get_enforce = False +tmp1 = tmp[0].strip().replace("+","") +tmp[0] = tmp1.split(':') +tmp1 = context.split() +context = str(tmp1.pop(1) +" "+ tmp1.pop(1)).split() +if tmp[0] == context: +if tmp[1] == get_enforce: +logger.debug("PASS: '%s'" % api) +return True +else: +logger.debug("Fail: '%s'" % api[1]) +return False +else: + logger.debug("Fail: '%s'" % api[0]) + return False + +def securitylabel(params): +""" + test APIs for securityLabel and securityLabelList in class virDomain +""" +logger = params['logger'] +domain_name = params['guestname'] +if not check_qemu_conf(logger): + return 1 +try: +conn = sharedmod.libvirto
Re: [libvirt] [libvirt-test-API][PATCH V2 1/2] Add freepage test
ACK and Pushed Thanks On 03/10/2015 07:07 PM, jiahu wrote: ACK Please pay attention to below format next time. Applying: Add freepage test /root/libvirt-test-API/.git/rebase-apply/patch:88: trailing whitespace. /root/libvirt-test-API/.git/rebase-apply/patch:90: trailing whitespace. /root/libvirt-test-API/.git/rebase-apply/patch:95: trailing whitespace. warning: 3 lines add whitespace errors. BR, Jianwei On 03/10/2015 05:29 PM, Jincheng Miao wrote: For system default pagesize, it's hard to calculate, and it changes all the time, so just skip it. For others, reading from sysfs to get free pages. Signed-off-by: Jincheng Miao --- repos/virconn/free_pages.py | 97 +++ 1 files changed, 97 insertions(+), 0 deletions(-) create mode 100644 repos/virconn/free_pages.py diff --git a/repos/virconn/free_pages.py b/repos/virconn/free_pages.py new file mode 100644 index 000..516b9f2 --- /dev/null +++ b/repos/virconn/free_pages.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python +# test libvirt free pages + +import os +import resource + +import libvirt +from libvirt import libvirtError + +from src import sharedmod + +required_params = ('cellid', 'pagesize',) +optional_params = {} + +HUGEPAGE_PATH = '/sys/devices/system/node/node%s/hugepages/hugepages-%skB/free_hugepages' + +def parse_unit(pagesz): +""" parse a integer value, its unit is KiB +""" +val = int(pagesz[0:len(pagesz)-1]) +unit = pagesz[-1] +if unit == 'K': +unit = 1 +elif unit == 'M': +unit = 1024 +elif unit == 'G': +unit = 1024*1024 +else: +return None + +return val * unit + +def parse_page_list(pagesize): +""" parse page size +""" +if pagesize == None: +return None + +l = list() +for ps in pagesize.split(','): +ps = ps.strip().upper() +val = parse_unit(ps) +if val == None: +return None +l.append(val) +return l + +def check_free_pages(page_list, cell_id, free_page, logger): +""" check page size +""" +for ps in page_list: +# if pagesize is equal to system pagesize, since it is hard to +# calculate, so we just pass it +if resource.getpagesize()/1024 == ps: +logger.info("skip to check default %sKB-page" % ps) +continue + +sysfs_path = HUGEPAGE_PATH % (cell_id, ps) +if not os.access(sysfs_path, os.R_OK): +logger.error("could not find %s" % sysfs_path) +return False +f= open(sysfs_path) +fp = int(f.read()) +f.close() +if not fp == free_page[0][ps]: +logger.error("Free %sKB page checking failed" % ps) +return False +logger.info("Free %sKB page: %s" % (ps, fp)) + +return True + +def free_pages(params): +""" test libvirt free pages +""" +logger = params['logger'] +cell_id = int(params['cellid']) + +conn = sharedmod.libvirtobj['conn'] + +page_list = parse_page_list(params['pagesize']) +if page_list == None: +logger.error("pagesize could not be recognized") +return 1 + +try: +free_page = conn.getFreePages(page_list, cell_id, 1) + +if check_free_pages(page_list, cell_id, free_page, logger): +logger.info("Success to check free page") +else: +logger.error("Failed to check free page") +return 1 +except libvirtError, e: +logger.error("API error message: %s, error code is %s" % + e.message) +return 1 +return 0 \ No newline at end of file -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 3/3] Add fsfreeze fsthaw test case to linux_domain
On 02/04/2015 05:26 PM, Jincheng Miao wrote: Signed-off-by: Jincheng Miao --- cases/linux_domain.conf | 18 ++ 1 files changed, 18 insertions(+), 0 deletions(-) diff --git a/cases/linux_domain.conf b/cases/linux_domain.conf index 515858a..37d 100644 --- a/cases/linux_domain.conf +++ b/cases/linux_domain.conf @@ -139,6 +139,24 @@ domain:cpu_affinity vcpu $defaultvcpu +domain:domain_fsfreeze +guestname +$defaultname + +domain:domain_fsthaw +guestname +$defaultname + +domain:domain_fsfreeze +guestname +$defaultname +mountpoint +/ + +domain:domain_fsthaw +guestname +$defaultname + domain:destroy guestname $defaultname Thanks ACK and Pushed -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-API][PATCH 2/2] Fix regression issues
On 02/04/2015 06:03 PM, jiahu wrote: 1. Using .get method to get a optional dict value 2. Adjust variables sequence during call mac_to_ip --- repos/domain/destroy.py | 4 ++-- repos/domain/install_linux_cdrom.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/repos/domain/destroy.py b/repos/domain/destroy.py index 154ffaf..36f70db 100644 --- a/repos/domain/destroy.py +++ b/repos/domain/destroy.py @@ -32,7 +32,7 @@ def destroy(params): logger = params['logger'] params.pop('logger') guestname = params['guestname'] -br = params['bridgename'] +br = params.get('bridgename','virbr0') flags = "" if params.has_key('flags'): flags = params['flags'] @@ -59,7 +59,7 @@ def destroy(params): # Get domain ip mac = utils.get_dom_mac_addr(guestname) logger.info("get ip by mac address") -ip = utils.mac_to_ip(mac,br,180) +ip = utils.mac_to_ip(mac,180,br) logger.info("the ip address of guest is %s" % ip) # Destroy domain diff --git a/repos/domain/install_linux_cdrom.py b/repos/domain/install_linux_cdrom.py index 9d3a7e9..412712b 100644 --- a/repos/domain/install_linux_cdrom.py +++ b/repos/domain/install_linux_cdrom.py @@ -147,7 +147,7 @@ def install_linux_cdrom(params): guestname = params.get('guestname') guestos = params.get('guestos') guestarch = params.get('guestarch') -br = params['bridgename'] +br = params.get('bridgename','virbr0') xmlstr = params['xml'] logger.info("the name of guest is %s" % guestname) @@ -304,7 +304,7 @@ def install_linux_cdrom(params): time.sleep(10) timeout -= 10 - ip = utils.mac_to_ip(mac,br,180) +ip = utils.mac_to_ip(mac,180,br) if not ip: logger.info(str(timeout) + "s left") ACK and Pushed. Thanks Hongming -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 1/3] add guest agent configuration to domain xml
hi Jmiao Don't forget to add "[libvirt][libvirt-test-API]" to your patch summary. Thanks Hongming On 02/04/2015 05:26 PM, Jincheng Miao wrote: Signed-off-by: Jincheng Miao --- .../domain/xmls/kvm_linux_guest_install_cdrom.xml |4 repos/domain/xmls/kvm_linux_guest_install_net.xml | 20 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/repos/domain/xmls/kvm_linux_guest_install_cdrom.xml b/repos/domain/xmls/kvm_linux_guest_install_cdrom.xml index cb59e76..8f398bb 100644 --- a/repos/domain/xmls/kvm_linux_guest_install_cdrom.xml +++ b/repos/domain/xmls/kvm_linux_guest_install_cdrom.xml @@ -35,5 +35,9 @@ + + + + diff --git a/repos/domain/xmls/kvm_linux_guest_install_net.xml b/repos/domain/xmls/kvm_linux_guest_install_net.xml index c4a7de7..5fad3a7 100644 --- a/repos/domain/xmls/kvm_linux_guest_install_net.xml +++ b/repos/domain/xmls/kvm_linux_guest_install_net.xml @@ -24,13 +24,17 @@ - - - - - - - - + + + + + + + + + + + + -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-API][PATCH V2 04/11] Add IPv6 section into related network case
On 01/28/2015 03:14 PM, jiahu wrote: Added 4 IPv6 required parameters to case. --- repos/network/define.py | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/repos/network/define.py b/repos/network/define.py index dd054f7..6e50eb7 100644 --- a/repos/network/define.py +++ b/repos/network/define.py @@ -17,7 +17,12 @@ required_params = ('networkname', 'bridgenetmask', 'netstart', 'netend', - 'netmode',) + 'netmode', + 'netip6addr', + 'netip6prefix', + 'netip6start', + 'netip6end', + ) These ipv6 params should be optional . ACK and Pushed after modifying the patch as follows and getting the correct testing result --- repos/network/create.py | 4 1 file changed, 4 insertions(+) diff --git a/repos/network/create.py b/repos/network/create.py index 399328c..b1b3245 100644 --- a/repos/network/create.py +++ b/repos/network/create.py @@ -19,6 +19,10 @@ required_params = ('networkname', 'netend', 'netmode',) optional_params = {'xml' : 'xmls/network.xml', + 'netip6addr' : '2001b8:ca2:98::1', + 'netip6prefix' : '64', + 'netip6start' : '2001b8:ca2:98::11', + 'netip6end' : '2001b8:ca2:98::ff', } def check_network_status(*args): -- 1.8.3.1 optional_params = {'xml' : 'xmls/network.xml', } -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-API][PATCH] Add IPv6 section into network case
Please sent patch V2 rather than generate the patch from your local repo. Also add the v2->v1 changes to the description of patch. Summary likes following [libvirt] [libvirt-test-API][PATCH v2] Add network_dhcp_leases test case On 01/26/2015 11:50 AM, jiahu wrote: Add IPv6 family related scenarios to virtual network case --- cases/basic_network.conf | 8 repos/network/define.py| 7 ++- repos/network/xmls/network.xml | 5 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cases/basic_network.conf b/cases/basic_network.conf index e9abd57..5d1438e 100644 --- a/cases/basic_network.conf +++ b/cases/basic_network.conf @@ -13,6 +13,14 @@ network:define $defaultnetend netmode nat +netip6addr +$netip6addr +netip6prefix +$netip6prefix +netip6start +$netip6start +netip6end +$netip6end network:network_list flags diff --git a/repos/network/define.py b/repos/network/define.py index dd054f7..6e50eb7 100644 --- a/repos/network/define.py +++ b/repos/network/define.py @@ -17,7 +17,12 @@ required_params = ('networkname', 'bridgenetmask', 'netstart', 'netend', - 'netmode',) + 'netmode', + 'netip6addr', + 'netip6prefix', + 'netip6start', + 'netip6end', + ) optional_params = {'xml' : 'xmls/network.xml', } diff --git a/repos/network/xmls/network.xml b/repos/network/xmls/network.xml index 220169b..97e3517 100644 --- a/repos/network/xmls/network.xml +++ b/repos/network/xmls/network.xml @@ -7,4 +7,9 @@ + + + + + -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-API][PATCH] Add connection_cpu_models test case
On 01/09/2015 03:58 PM, jiahu wrote: The connection_cpu_models.py uses getCPUModelNames() to validate new API virConnectGetCPUModelNames of libvirt. --- cases/test_connection.conf | 12 + repos/virconn/connection_cpu_models.py | 82 ++ 2 files changed, 94 insertions(+) create mode 100644 repos/virconn/connection_cpu_models.py diff --git a/cases/test_connection.conf b/cases/test_connection.conf index ccde119..e916886 100644 --- a/cases/test_connection.conf +++ b/cases/test_connection.conf @@ -29,3 +29,15 @@ virconn:connection_nodeinfo virconn:connection_version conn lxc:/// + +virconn:connection_cpu_models +arch +x86_64 + +virconn:connection_cpu_models +arch +i686 + +virconn:connection_cpu_models +arch +ppc64 diff --git a/repos/virconn/connection_cpu_models.py b/repos/virconn/connection_cpu_models.py new file mode 100644 index 000..4588188 --- /dev/null +++ b/repos/virconn/connection_cpu_models.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python +# test getCPUModelNames() API for libvirt + +import os +import libvirt + +from xml.dom import minidom +from libvirt import libvirtError +from src import sharedmod +from utils import utils + +required_params = ('arch',) +optional_params = {} + +CPU_MAP_FILE = "/usr/share/libvirt/cpu_map.xml" + +def get_cpu_archs_from_xml(logger): +""" + return supported cpu archs from cpu_map.xml +""" +cpu_archs_from_xml = [] +xml = minidom.parse(CPU_MAP_FILE) +for arch in xml.getElementsByTagName('arch'): +cpu_archs_from_xml.append(str(arch.getAttribute('name'))) +return cpu_archs_from_xml + +def get_cpu_models_from_xml(arch, logger): +""" + return supported cpu models from cpu_map.xml +""" +cpu_models_from_xml = [] +if arch == 'x86_64' or arch == 'i686': + real_arch = 'x86' +else: + real_arch = arch + +xml = minidom.parse(CPU_MAP_FILE) +for model in xml.getElementsByTagName('model'): +if model.parentNode.getAttribute('name') == real_arch: +cpu_models_from_xml.append(str(model.getAttribute('name'))) +return cpu_models_from_xml + +def connection_cpu_models(params): +""" + test API for getCPUModelNames in class virConnect +""" +logger = params['logger'] +arch_value = params['arch'] +try: +logger.info("get cpu archs from cpu_map.xml") +if not os.path.exists(CPU_MAP_FILE): + logger.error("%s is not exist" % CPU_MAP_FILE) + return 1 +cpu_archs_from_xml = get_cpu_archs_from_xml(logger) +logger.info("The supported cpu archs in xml are %s" \ + % cpu_archs_from_xml) +cpu_models_from_xml = get_cpu_models_from_xml(arch_value, logger) +logger.info("The supported cpu models in xml are %s" \ + % cpu_models_from_xml) + +conn = sharedmod.libvirtobj['conn'] + +cpu_models_from_libvirt = conn.getCPUModelNames(arch_value ,0) +logger.info("The specified architecture is %s" \ +% arch_value) +logger.info("The supported cpu models is %s" \ +% cpu_models_from_libvirt) + +#compare with cpu_map.xml +for cpu_model in cpu_models_from_libvirt: +if cpu_model in cpu_models_from_xml: +logger.debug("'%s' model: PASS" % cpu_model) +else: +logger.debug("'%s' model: FAIL, not in libvirt"\ + % cpu_model) +return 1 +logger.debug("check all cpu models: PASS") +except libvirtError, e: +logger.error("API error message: %s" % e.message) +return 1 + +return 0 ACK and Pushed Please note to remove the trailing spaces next time. Thanks. Appending the following two lines into /etc/vimrc could highlights them, then remove them. "highlight RedundantSpaces ctermbg=red guibg=red match RedundantSpaces /\s\+$\| \+\ze\t/ " -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-API][PATCH] Remove redundant colon in inteface list
On 01/07/2015 10:00 PM, jiahu wrote: The interface list should be: ['em1', 'lo', 'virbr0', 'wlp3s0'] rather than below: ['em1:', 'lo:', 'virbr0:', 'wlp3s0:'] --- repos/interface/iface_list.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/repos/interface/iface_list.py b/repos/interface/iface_list.py index 49f0c05..7041535 100644 --- a/repos/interface/iface_list.py +++ b/repos/interface/iface_list.py @@ -10,7 +10,8 @@ optional_params = {} VIRSH_QUIET_IFACE_LIST = "virsh --quiet iface-list %s | awk '{print ""$%s""}'" NETWORK_CONFIG = "/etc/sysconfig/network-scripts/" -IFCONFIG_DRIVER = "ifconfig %s | sed 's/[ \t].*//;/^$/d'" +IFCONFIG_DRIVER = "ifconfig %s | sed 's/[ \t].*//;/^$/d'\ +|awk -F\":\" '{print $1}'" GET_MAC = "ip link show %s |sed -n '2p'| awk '{print $2}'" VIRSH_IFACE_LIST = "virsh iface-list %s" Actually, the iface_list is a invalid case in libvirt-test-API . The original author of it didn't call any python api , but verify the result of "virsh iface-list". We need to rewrite it to verify python api - listAllInterface -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt-test-API][PATCH V4 0/4] Add test case for virconnect V4
ACK and pushed Thanks On 04/25/2014 04:55 PM, Jincheng Miao wrote: V3->V4: Remove getSysinfo() check for lxc connection. Fix minor problems. V2->V3: Refactor connection_nodeinfo. Change the way of getting version number. V1->V2: Seperate check functions in each test case. Improve log message. V1: Add test case for virconnect Add test case for nodeinfo of virconnect Add connection_version test case Add conf file of virconnect test jmiao (4): Add test case for virConnect Add connection_nodeinfo test case Add connection_version test case Add test_connection.conf cases/test_connection.conf | 31 +++ repos/virconn/__init__.py | 0 repos/virconn/connection_attributes.py | 92 + repos/virconn/connection_nodeinfo.py | 146 + repos/virconn/connection_version.py| 119 +++ 5 files changed, 388 insertions(+) create mode 100644 cases/test_connection.conf create mode 100644 repos/virconn/__init__.py create mode 100644 repos/virconn/connection_attributes.py create mode 100644 repos/virconn/connection_nodeinfo.py create mode 100644 repos/virconn/connection_version.py -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [test-API][PATCH] Fix the repeating display of testcase name issue when generating log.xml
On 08/16/2013 04:04 PM, Guannan Ren wrote: On 08/16/2013 02:36 PM, Hongming Zhang wrote: modified: src/log_generator.py --- src/log_generator.py |3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/src/log_generator.py b/src/log_generator.py index de18654..7685da7 100644 --- a/src/log_generator.py +++ b/src/log_generator.py @@ -70,7 +70,8 @@ class LogGenerator(object): valuedict = test_procedure[casename] test_casename = self.doc.createElement('action') -test_casename.setAttribute('name', casename) +casenamexml = casename[:casename.rfind(":")] +test_casename.setAttribute('name', casenamexml) for arg in valuedict.keys(): test_arg = self.doc.createElement('arg') Hi HongMing you fixed the problem in not right way, you need to change the casename in the source rather than do the string slice in there. Hi Guannan Ok . I see, I will try to fix it in v2. Thanks -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [test-API][PATCH] Fix the repeating display of testcase name issue when generating log.xml
modified: src/log_generator.py --- src/log_generator.py |3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/src/log_generator.py b/src/log_generator.py index de18654..7685da7 100644 --- a/src/log_generator.py +++ b/src/log_generator.py @@ -70,7 +70,8 @@ class LogGenerator(object): valuedict = test_procedure[casename] test_casename = self.doc.createElement('action') -test_casename.setAttribute('name', casename) +casenamexml = casename[:casename.rfind(":")] +test_casename.setAttribute('name', casenamexml) for arg in valuedict.keys(): test_arg = self.doc.createElement('arg') -- 1.7.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [test-API][PATCH] Add display of cases result to log.xml
Hi Guannan You can see the new test report from the following url. http://fileshare.englab.nay.redhat.com/pub/section3/libvirtauto/libvirt-test-API/log.xml Thanks Hongming On 08/15/2013 11:32 AM, Hongming Zhang wrote: The original log.xml only display the testrun result, the patch add display of case result to log.xml. modified: src/generator.py -Perserver case result list and pass it to log_generator class. modified: src/log.xsl -Read from xml and display case result modified: src/log_generator.py -Create case result xml and add it to log.xml --- src/generator.py |5 +++-- src/log.xsl | 23 --- src/log_generator.py | 16 ++-- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/generator.py b/src/generator.py index 0cdc9de..208fa7b 100644 --- a/src/generator.py +++ b/src/generator.py @@ -87,7 +87,6 @@ class FuncGen(object): env_logger = envlog.env_log() casenumber = len(self.case_name_list) start_time = time.strftime("%Y-%m-%d %H:%M:%S") - env_logger.info("Checking Testing Environment... ") envck = env_inspect.EnvInspect(self.env, env_logger) @@ -103,6 +102,7 @@ class FuncGen(object): # retflag: [pass, fail, skip] retflag = [0, 0, 0] +case_retlist = [] for i in range(casenumber): clean_flag = False @@ -165,7 +165,7 @@ class FuncGen(object): retflag[2] += 1 self.fmt.print_end(mod_case, ret, env_logger) - +case_retlist.append(ret) # close hypervisor connection envck.close_hypervisor_connection() end_time = time.strftime("%Y-%m-%d %H:%M:%S") @@ -179,6 +179,7 @@ class FuncGen(object): self.log_xml_parser.add_test_summary(self.testrunid, self.testid, result, + case_retlist, start_time, end_time, self.logfile) diff --git a/src/log.xsl b/src/log.xsl index 577a0a5..0ca6afe 100644 --- a/src/log.xsl +++ b/src/log.xsl @@ -119,9 +119,10 @@ No. Result - Start - End - Test Procedure + Start + End + Test Procedure + Case Result @@ -164,6 +165,22 @@ + + + + + + + + + + + + + + + + diff --git a/src/log_generator.py b/src/log_generator.py index be483d6..de18654 100644 --- a/src/log_generator.py +++ b/src/log_generator.py @@ -93,7 +93,7 @@ class LogGenerator(object): self. __write_to_file(xmldoc, self.logxml) -def add_test_summary(self, testrunid, testid, result, +def add_test_summary(self, testrunid, testid, result, case_retlist, start_time, end_time, path): """ add a test summary xml block into log xml file """ xmldoc = minidom.parse(self.logxml) @@ -101,6 +101,8 @@ class LogGenerator(object): resulttext = self.doc.createTextNode(result) testresult.appendChild(resulttext) +caseresult = self.doc.createElement('caseresult') + teststarttime = self.doc.createElement('start_time') starttimetext = self.doc.createTextNode(start_time) teststarttime.appendChild(starttimetext) @@ -126,10 +128,20 @@ class LogGenerator(object): test.childNodes.insert(0, testendtime) test.childNodes.insert(0, teststarttime) test.childNodes.insert(0, testresult) +test.childNodes.insert(0, caseresult) +for ret in reversed(case_retlist): +retstr = '' +if ret == 0: +retstr = 'PASS' +else: +retstr = 'FAIL' +itemresult = self.doc.createElement('case') +caseresulttext = self.doc.createTextNode(retstr) +itemresult.appendChild(ca
[libvirt] [test-API][PATCH] Add display of cases result to log.xml
The original log.xml only display the testrun result, the patch add display of case result to log.xml. modified: src/generator.py -Perserver case result list and pass it to log_generator class. modified: src/log.xsl -Read from xml and display case result modified: src/log_generator.py -Create case result xml and add it to log.xml --- src/generator.py |5 +++-- src/log.xsl | 23 --- src/log_generator.py | 16 ++-- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/generator.py b/src/generator.py index 0cdc9de..208fa7b 100644 --- a/src/generator.py +++ b/src/generator.py @@ -87,7 +87,6 @@ class FuncGen(object): env_logger = envlog.env_log() casenumber = len(self.case_name_list) start_time = time.strftime("%Y-%m-%d %H:%M:%S") - env_logger.info("Checking Testing Environment... ") envck = env_inspect.EnvInspect(self.env, env_logger) @@ -103,6 +102,7 @@ class FuncGen(object): # retflag: [pass, fail, skip] retflag = [0, 0, 0] +case_retlist = [] for i in range(casenumber): clean_flag = False @@ -165,7 +165,7 @@ class FuncGen(object): retflag[2] += 1 self.fmt.print_end(mod_case, ret, env_logger) - +case_retlist.append(ret) # close hypervisor connection envck.close_hypervisor_connection() end_time = time.strftime("%Y-%m-%d %H:%M:%S") @@ -179,6 +179,7 @@ class FuncGen(object): self.log_xml_parser.add_test_summary(self.testrunid, self.testid, result, + case_retlist, start_time, end_time, self.logfile) diff --git a/src/log.xsl b/src/log.xsl index 577a0a5..0ca6afe 100644 --- a/src/log.xsl +++ b/src/log.xsl @@ -119,9 +119,10 @@ No. Result - Start - End - Test Procedure + Start + End + Test Procedure + Case Result @@ -164,6 +165,22 @@ + + + + + + + + + + + + + + + + diff --git a/src/log_generator.py b/src/log_generator.py index be483d6..de18654 100644 --- a/src/log_generator.py +++ b/src/log_generator.py @@ -93,7 +93,7 @@ class LogGenerator(object): self. __write_to_file(xmldoc, self.logxml) -def add_test_summary(self, testrunid, testid, result, +def add_test_summary(self, testrunid, testid, result, case_retlist, start_time, end_time, path): """ add a test summary xml block into log xml file """ xmldoc = minidom.parse(self.logxml) @@ -101,6 +101,8 @@ class LogGenerator(object): resulttext = self.doc.createTextNode(result) testresult.appendChild(resulttext) +caseresult = self.doc.createElement('caseresult') + teststarttime = self.doc.createElement('start_time') starttimetext = self.doc.createTextNode(start_time) teststarttime.appendChild(starttimetext) @@ -126,10 +128,20 @@ class LogGenerator(object): test.childNodes.insert(0, testendtime) test.childNodes.insert(0, teststarttime) test.childNodes.insert(0, testresult) +test.childNodes.insert(0, caseresult) +for ret in reversed(case_retlist): +retstr = '' +if ret == 0: +retstr = 'PASS' +else: +retstr = 'FAIL' +itemresult = self.doc.createElement('case') +caseresulttext = self.doc.createTextNode(retstr) +itemresult.appendChild(caseresulttext) +caseresult.childNodes.insert(0,itemresult) self. __write_to_file(xmldoc, self.logxml) - def add_testrun_summary(self, testrunid, passnum, failnum, totalnum, start_time, end_time): """ add a testrun summary xml block into log xml file """ -- 1.7.1 -- libvir-list mailing list libvir-list@redhat.com https://www.
[libvirt] [test-API][PATCH] Add network update test case
The patch add network update test case to cover network update api. modified: cases/basic_network.conf - The test suite covers add/modify/delete ip-dhcp-host in network. For other test scenario, they can be test via customing the conf file. new file: repos/network/update.py - So far the network update test case only checking when flag is live or current. new file: repos/network/xmls/ip-dhcp-host.xml - Create the ip-dhcp-host sample xml file for adding/deleting ip-dhcp-host new file: repos/network/xmls/modify-ip-dhcp-host.xml - Create the ip-dhcp-host sample xml file for modifying ip-dhcp-host Known bug: - Bug 985782 - Some flag values of method are missing in libvirt-python bindings --- cases/basic_network.conf | 28 ++ repos/network/update.py| 82 repos/network/xmls/ip-dhcp-host.xml|1 + repos/network/xmls/modify-ip-dhcp-host.xml |1 + 4 files changed, 112 insertions(+), 0 deletions(-) create mode 100644 repos/network/update.py create mode 100644 repos/network/xmls/ip-dhcp-host.xml create mode 100644 repos/network/xmls/modify-ip-dhcp-host.xml diff --git a/cases/basic_network.conf b/cases/basic_network.conf index 91d7f21..e9abd57 100644 --- a/cases/basic_network.conf +++ b/cases/basic_network.conf @@ -32,6 +32,34 @@ network:autostart autostart enable +network:update +networkname + $defaultnetname +command +add-first +section +ip-dhcp-host + +network:update +networkname + $defaultnetname +command +modify +section +ip-dhcp-host +xml + xmls/modify-ip-dhcp-host.xml + +network:update +networkname + $defaultnetname +command +delete +section +ip-dhcp-host +xml + xmls/modify-ip-dhcp-host.xml + network:destroy networkname $defaultnetname diff --git a/repos/network/update.py b/repos/network/update.py new file mode 100644 index 000..0024a5e --- /dev/null +++ b/repos/network/update.py @@ -0,0 +1,82 @@ +#!/usr/bin/evn python +#Update a network + +import libvirt +from libvirt import libvirtError +from src import sharedmod + +COMMANDDICT = {"none":0, "modify":1, "delete":2, "add-first":4} +SECTIONDICT = {"none":0, "bridge":1, "domain":2, "ip":3, "ip-dhcp-host":4, \ + "ip-dhcp-range":5, "forward":6, "forward-interface":7,\ + "forward-pf":8, "portgroup":9, "dns-host":10, "dns-txt":11,\ + "dns-srv":12} +FLAGSDICT = {"current":0, "live":1, "config": 2} + +required_params = ('networkname', ) +optional_params = { + 'command': 'add-first', + 'section': 'ip-dhcp-host', + 'parentIndex': 0, + 'xml': 'xmls/ip-dhcp-host.xml', + 'flag': 'current', + } + +def update(params): +"""Update a network from xml""" +global logger +logger = params['logger'] +networkname = params['networkname'] +conn = sharedmod.libvirtobj['conn'] + +command = params['command'] +logger.info("The specified command is %s" % command) +section = params['section'] +logger.info("The specified section is %s" % section) +parentIndex = int(params.get('parentIndex', 0)) +logger.info("The specified parentIndex is %d" % parentIndex) +xmlstr = params.get('xml', 'xmls/ip-dhcp-host.xml').replace('\"','\'') +logger.info("The specified updatexml is %s" % xmlstr) +flag = params.get('flag', 'current') +logger.info("The specified flag is %s" % flag) + +command_val = 0 +section_val = 0 +flag_val = 0 +if COMMANDDICT.has_key(command): +command_val = COMMANDDICT.get(command) +if SECTIONDICT.has_key(section): +section_val = SECTIONDICT.get(section) +if FLAGSDICT.has_key(flag): +flag_val = FLAGSDICT.get(flag) + +try: +network = conn.networkLookupByName(networkname) +logger.info("The original network xml is %s" % network.XMLDesc(0)) +network.update(command_val, section_val, parentIndex, xmlstr, \ + flag_val) +updated_netxml = network.XMLDesc(0) +logger.info("The updated network xml is %s" % updated_netxml) +#The check only works when flag isn't set as config +if flag_val !=2: +if command_val == 0 or command_val == 2: +if xmlstr not in updated_netxml: +logger.info("Successfully update network") +return 0 +else: +logger.error("Failed to update network") +return 1 + +elif command_val == 1 or command_val == 4: +if xmlstr in updated_netxml: +logger.info("Successfully update network") +return 0 +else: +logger.error("Failed to update network") +return 1 + +exce
[libvirt] [test-API][PATCH V3] Modify repos/network/network_list.py and add network_list case to conf
Modify the old network_list.py. The new network_list.py covers all flags of listAllNetworks and the following api. and add network_list to basic_network.conf. virNetwork: name() isActive() isPersistent() virConnect: listAllNetworks() V1-> V2 1.Change the flag in conf from digit to string 2.Remove the checking method using the result of virsh with flags 3.Add checking method via checking network autostart dir 4.Modify the basic_network.conf V2 -> V3 1.Remove check_bridge_ip method 2.Remove network.bridgeName() call 3.Fix a typo in log --- cases/basic_network.conf | 35 +- repos/network/network_list.py | 260 - 2 files changed, 130 insertions(+), 165 deletions(-) diff --git a/cases/basic_network.conf b/cases/basic_network.conf index 991ad99..91d7f21 100644 --- a/cases/basic_network.conf +++ b/cases/basic_network.conf @@ -14,10 +14,18 @@ network:define netmode nat +network:network_list +flags + inactive + network:start networkname $defaultnetname +network:network_list +flags + active + network:autostart networkname $defaultnetname @@ -28,6 +36,10 @@ network:destroy networkname $defaultnetname +network:network_list +flags + default + network:undefine networkname $defaultnetname @@ -48,6 +60,10 @@ network:create netmode nat +network:network_list +flags +transient + network:destroy networkname $defaultnetname @@ -68,6 +84,10 @@ network:define netmode route +network:network_list +flags + persistent + network:start networkname $defaultnetname @@ -106,7 +126,6 @@ network:destroy networkname $defaultnetname - network:define networkname $defaultnetname @@ -127,12 +146,20 @@ network:start networkname $defaultnetname +network:network_list +flags + noautostart + network:autostart networkname $defaultnetname autostart enable +network:network_list +flags + autostart + network:destroy networkname $defaultnetname @@ -141,7 +168,6 @@ network:undefine networkname $defaultnetname - network:create networkname $defaultnetname @@ -162,8 +188,3 @@ network:destroy networkname $defaultnetname - - - - - diff --git a/repos/network/network_list.py b/repos/network/network_list.py index 7c34f69..b94b505 100644 --- a/repos/network/network_list.py +++ b/repos/network/network_list.py @@ -1,184 +1,128 @@ #!/usr/bin/env python # To test "virsh net-list" command -import os -import sys -import re -import commands - import libvirt from libvirt import libvirtError from src import sharedmod from utils import utils -required_params = ('netlistopt',) +required_params = ('flags',) optional_params = {} -VIRSH_QUIET_NETLIST = "virsh --quiet net-list %s|awk '{print $1}'" -VIRSH_NETLIST = "virsh net-list %s" -GET_BRIDGE_IP = "/sbin/ifconfig %s | grep 'inet addr:' | cut -d: -f2 | awk '{print $1}'" -CONFIG_DIR = "/etc/libvirt/qemu/networks/" +LS_NETWORK_DIR = "ls /etc/libvirt/qemu/networks/" +LS_AUTOSTART_NET = "ls /etc/libvirt/qemu/networks/autostart/" -def get_option_list(params): -"""return options we need to test +def check_persistent_netxml(networkname): """ -logger = params['logger'] -option_list=[] - -value = params['netlistopt'] - -if value == 'all': -option_list = [' ', '--all', '--inactive'] -elif value == '--all' or value == '--inactive': -option_list.append(value) -else: -logger.error("value %s is not supported" % value) -return 1, option_list - -return 0, option_list - -def get_output(logger, command, flag): -"""execute shell command +Check if the network is persistent via checking network xml dir +if the network is persistent, return True, or return False """ -status, ret = commands.getstatusoutput(command) -if not flag and status: -logger.error("executing "+ "\"" + command + "\"" + " failed") -logger.error(ret) -return status, ret - -def check_all_option(conn, logger): -"""check the output of virsh net-list with --all option -""" -all_network = [] -entries = os.listdir(CONFIG_DIR) -logger.debug("%s in %s" % (entries, CONFIG_DIR)) -status, network_names = get_output(logger, VIRSH_QUIET_NETLIST % '--all', 0) -if not status: -all_network = network_names.split('\n') -logger.info("all network is %s" % all_network) -else: -return 1 - -if all_network == ['']: -return 0 -for entry in entries: -if not entry.endswith('.xml'): -continue +(status, output) = utils.exec_cmd(LS_NETWORK_DIR, shell=True) +network_list_dir = [] +if status: +logger.error("Executing " + LS_NETWORK_DIR + " failed") +logg
[libvirt] [test-API][PATCH V2] Modify repos/network/network_list.py and add network_list case to conf
Modify the old network_list.py. The new network_list.py covers all flags of listAllNetworks and the following api. and add network_list to basic_network.conf. virNetwork: name() bridgeName() isActive() isPersistent() virConnect: listAllNetworks() Changes from V2 to V1 as follows 1.Change the flag in conf from digit to string 2.Remove the checking method using the result of virsh with flags 3.Add checking method via checking network autostart dir 4.Modify the basic_network.conf --- cases/basic_network.conf | 35 - repos/network/network_list.py | 277 ++--- 2 files changed, 148 insertions(+), 164 deletions(-) diff --git a/cases/basic_network.conf b/cases/basic_network.conf index 991ad99..91d7f21 100644 --- a/cases/basic_network.conf +++ b/cases/basic_network.conf @@ -14,10 +14,18 @@ network:define netmode nat +network:network_list +flags + inactive + network:start networkname $defaultnetname +network:network_list +flags + active + network:autostart networkname $defaultnetname @@ -28,6 +36,10 @@ network:destroy networkname $defaultnetname +network:network_list +flags + default + network:undefine networkname $defaultnetname @@ -48,6 +60,10 @@ network:create netmode nat +network:network_list +flags +transient + network:destroy networkname $defaultnetname @@ -68,6 +84,10 @@ network:define netmode route +network:network_list +flags + persistent + network:start networkname $defaultnetname @@ -106,7 +126,6 @@ network:destroy networkname $defaultnetname - network:define networkname $defaultnetname @@ -127,12 +146,20 @@ network:start networkname $defaultnetname +network:network_list +flags + noautostart + network:autostart networkname $defaultnetname autostart enable +network:network_list +flags + autostart + network:destroy networkname $defaultnetname @@ -141,7 +168,6 @@ network:undefine networkname $defaultnetname - network:create networkname $defaultnetname @@ -162,8 +188,3 @@ network:destroy networkname $defaultnetname - - - - - diff --git a/repos/network/network_list.py b/repos/network/network_list.py index 7c34f69..175d6fa 100644 --- a/repos/network/network_list.py +++ b/repos/network/network_list.py @@ -1,184 +1,147 @@ #!/usr/bin/env python # To test "virsh net-list" command -import os -import sys -import re -import commands - import libvirt from libvirt import libvirtError from src import sharedmod from utils import utils -required_params = ('netlistopt',) +required_params = ('flags',) optional_params = {} -VIRSH_QUIET_NETLIST = "virsh --quiet net-list %s|awk '{print $1}'" -VIRSH_NETLIST = "virsh net-list %s" -GET_BRIDGE_IP = "/sbin/ifconfig %s | grep 'inet addr:' | cut -d: -f2 | awk '{print $1}'" -CONFIG_DIR = "/etc/libvirt/qemu/networks/" - -def get_option_list(params): -"""return options we need to test -""" -logger = params['logger'] -option_list=[] - -value = params['netlistopt'] - -if value == 'all': -option_list = [' ', '--all', '--inactive'] -elif value == '--all' or value == '--inactive': -option_list.append(value) +VIRSH_NETWORK_LIST = "virsh net-list %s|sed -n '3,$'p|awk '{print $1}'" +GET_BRIDGE_IP = "/sbin/ifconfig %s | grep 'inet addr:' | cut -d: -f2 | awk \ +'{print $1}'" +LS_NETWORK_DIR = "ls /etc/libvirt/qemu/networks/" +LS_AUTOSTART_NET = "ls /etc/libvirt/qemu/networks/autostart/" + +def check_bridge_ip(bridgename): +""" Check if the bridge has ip """ + +(status, output) = utils.exec_cmd(GET_BRIDGE_IP % bridgename,\ + shell=True) +if not status and utils.do_ping(output[0], 50): +logger.info("Bridge %s is active" % bridgename) +logger.info("%s has ip: %s" % (bridgename, output[0])) +return True else: -logger.error("value %s is not supported" % value) -return 1, option_list - -return 0, option_list +logger.error("Bridge %s has no ip or fails to ping" % bridgename) +return False -def get_output(logger, command, flag): -"""execute shell command +def check_persistent_netxml(networkname): """ -status, ret = commands.getstatusoutput(command) -if not flag and status: -logger.error("executing "+ "\"" + command + "\"" + " failed") -logger.error(ret) -return status, ret - -def check_all_option(conn, logger): -"""check the output of virsh net-list with --all option +Check if the network is persistent via checking network xml dir +if the network is persistent, return True, or return False """ -all_network = [] -entries = os.listdir(CONFIG_DIR) -l
[libvirt] [test-API][PATCH] Modify repos/network/network_list.py and add network_list case to conf
Modify the old network_list.py. The new network_list.py covers all flags of listAllNetworks and the following api. and add network_list to basic_network.conf. virNetwork: name() bridgeName() isActive() isPersistent() virConnect: listAllNetworks() --- cases/basic_network.conf | 37 +- repos/network/network_list.py | 279 ++--- 2 files changed, 151 insertions(+), 165 deletions(-) diff --git a/cases/basic_network.conf b/cases/basic_network.conf index 991ad99..805cfd0 100644 --- a/cases/basic_network.conf +++ b/cases/basic_network.conf @@ -14,6 +14,16 @@ network:define netmode nat +#VIR_CONNECT_LIST_NETWORKS_INACTIVE = 1 +#VIR_CONNECT_LIST_NETWORKS_ACTIVE = 2 +#VIR_CONNECT_LIST_NETWORKS_PERSISTENT = 4 +#VIR_CONNECT_LIST_NETWORKS_TRANSIENT = 8 +#VIR_CONNECT_LIST_NETWORKS_AUTOSTART = 16 +#VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART = 32 +network:network_list +flags + 1 + network:start networkname $defaultnetname @@ -24,10 +34,18 @@ network:autostart autostart enable +network:network_list +flags + 3 + network:destroy networkname $defaultnetname +network:network_list +flags + 4 + network:undefine networkname $defaultnetname @@ -48,6 +66,10 @@ network:create netmode nat +network:network_list +flags + 8 + network:destroy networkname $defaultnetname @@ -78,6 +100,10 @@ network:autostart autostart enable +network:network_list +flags + 16 + network:destroy networkname $defaultnetname @@ -102,11 +128,14 @@ network:create netmode route +network:network_list +flags + 32 + network:destroy networkname $defaultnetname - network:define networkname $defaultnetname @@ -141,7 +170,6 @@ network:undefine networkname $defaultnetname - network:create networkname $defaultnetname @@ -162,8 +190,3 @@ network:destroy networkname $defaultnetname - - - - - diff --git a/repos/network/network_list.py b/repos/network/network_list.py index 7c34f69..647da82 100644 --- a/repos/network/network_list.py +++ b/repos/network/network_list.py @@ -1,184 +1,147 @@ #!/usr/bin/env python # To test "virsh net-list" command -import os -import sys -import re -import commands - import libvirt from libvirt import libvirtError from src import sharedmod from utils import utils -required_params = ('netlistopt',) +required_params = ('flags',) optional_params = {} -VIRSH_QUIET_NETLIST = "virsh --quiet net-list %s|awk '{print $1}'" -VIRSH_NETLIST = "virsh net-list %s" -GET_BRIDGE_IP = "/sbin/ifconfig %s | grep 'inet addr:' | cut -d: -f2 | awk '{print $1}'" -CONFIG_DIR = "/etc/libvirt/qemu/networks/" - -def get_option_list(params): -"""return options we need to test -""" -logger = params['logger'] -option_list=[] - -value = params['netlistopt'] - -if value == 'all': -option_list = [' ', '--all', '--inactive'] -elif value == '--all' or value == '--inactive': -option_list.append(value) +VIRSH_NETWORK_LIST = "virsh net-list %s|sed -n '3,$'p|awk '{print $1}'" +GET_BRIDGE_IP = "/sbin/ifconfig %s | grep 'inet addr:' | cut -d: -f2 | awk \ +'{print $1}'" +FLAGDICT = {1:" --inactive", 2:"", 4:" --persistent",\ +8:" --transient", 16:" --autostart", 32:" --no-autostart" } +CONFIG_DIR = "ls /etc/libvirt/qemu/networks/" + +def check_bridge_ip(bridgename): +""" Check if the bridge has ip """ + +(status, output) = utils.exec_cmd(GET_BRIDGE_IP % bridgename,\ + shell=True) +if not status and utils.do_ping(output[0], 50): +logger.info("Bridge %s is active" % bridgename) +logger.info("%s has ip: %s" % (bridgename, output[0])) +return True else: -logger.error("value %s is not supported" % value) -return 1, option_list - -return 0, option_list - -def get_output(logger, command, flag): -"""execute shell command -""" -status, ret = commands.getstatusoutput(command) -if not flag and status: -logger.error("executing "+ "\"" + command + "\"" + " failed") -logger.error(ret) -return status, ret - -def check_all_option(conn, logger): -"""check the output of virsh net-list with --all option -""" -all_network = [] -entries = os.listdir(CONFIG_DIR) -logger.debug("%s in %s" % (entries, CONFIG_DIR)) -status, network_names = get_output(logger, VIRSH_QUIET_NETLIST % '--all', 0) -if not status: -all_network = network_names.split('\n') -logger.info("all network is %s" % all_network) +logger.error("Bridge %s has no ip or fails to ping" % bridgename) +return False + +def check_persistent_netxml(networkname): +""" Check if the network is persistent via checking network xml dir """ + +
Re: [libvirt] [test-API][PATCH] The patch covers all nwfilter api provided by libvirt.py. It includes define/undefine/list nwfilters and check them via checking ebtables rule. The following new files
On 03/18/2013 05:53 PM, Osier Yang wrote: On 2013年03月18日 14:54, hongming wrote: Can you shorten the patch subject? And add the sentences in the commit log instead? Sorry , Please ignore the patch . I made a mistake when generate patch . I send another patch with subject - Add nwfilter test cases and conf --- cases/nwfilter.conf | 59 + repos/nwfilter/nwfilter_check.py| 120 +++ repos/nwfilter/nwfilter_define.py | 54 repos/nwfilter/nwfilter_list.py | 76 ++ repos/nwfilter/nwfilter_undefine.py | 43 + repos/nwfilter/xmls/nwfilter.xml|3 + 6 files changed, 355 insertions(+), 0 deletions(-) create mode 100644 cases/nwfilter.conf create mode 100644 repos/nwfilter/__init__.py create mode 100644 repos/nwfilter/nwfilter_check.py create mode 100644 repos/nwfilter/nwfilter_define.py create mode 100644 repos/nwfilter/nwfilter_list.py create mode 100644 repos/nwfilter/nwfilter_undefine.py create mode 100644 repos/nwfilter/xmls/nwfilter.xml diff --git a/cases/nwfilter.conf b/cases/nwfilter.conf new file mode 100644 index 000..b394ee5 --- /dev/null +++ b/cases/nwfilter.conf @@ -0,0 +1,59 @@ +domain:install_linux_cdrom +guestname +$defaultname +guestos +$defaultos +guestarch +$defaultarch +vcpu +$defaultvcpu +memory +$defaultmem +hddriver +$defaulthd +nicdriver +$defaultnic +imageformat +qcow2 +macaddr +54:52:00:4a:16:30 + +nwfilter:nwfilter_list + +# chain -- ipv4, ipv6, arp .etc +# action -- mandatory; drop, accept, return +# direction -- mandatory; must either be in, out or inout +nwfilter:nwfilter_define +nwfiltername +disallow-arp +chain +arp +action +drop +direction +inout + +nwfilter:nwfilter_list + +nwfilter:nwfilter_check +nwfiltername +disallow-arp +guestname +$defaultname + +nwfilter:nwfilter_define +nwfiltername +disallow-ipv6 +chain +ipv6 +action +drop +direction +in + +nwfilter:nwfilter_undefine +nwfiltername +disallow-ipv6 + +nwfilter:nwfilter_list + diff --git a/repos/nwfilter/__init__.py b/repos/nwfilter/__init__.py new file mode 100644 index 000..e69de29 diff --git a/repos/nwfilter/nwfilter_check.py b/repos/nwfilter/nwfilter_check.py new file mode 100644 index 000..b2c7ece --- /dev/null +++ b/repos/nwfilter/nwfilter_check.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python +import time +import xml.dom.minidom + +from libvirt import libvirtError +from utils import utils +from xml.dom import minidom + +from src import sharedmod + +required_params = ('nwfiltername','guestname',) +optional_params = {} + +EBTABLES = "ebtables -t nat -L" + +def get_ebtables(): +""" Get the output of ebtables """ +(status, output) = utils.exec_cmd(EBTABLES,shell=True) +logger.info("Execute command:" + EBTABLES) +ebtables_list = [] + +if status: +logger.error("Executing " + EBTABLES + " failed") +logger.error(output) +return False +else: +for i in range(len(output)): +ebtables_list.append(output[i]) +logger.info("Get the output of ebtables list: %s" \ +% ebtables_list) + +return ebtables_list + +def check_ebtables(*args): +""" Check the ebtables """ +(nwfiltername,conn)= args +ebtables_list = get_ebtables() + +#Get the filter' attribute value +nwfilter_xml = conn.nwfilterLookupByName(nwfiltername).XMLDesc(0) +nwfilter_parsedxml = minidom.parseString(nwfilter_xml) +chain = nwfilter_parsedxml.getElementsByTagName("filter")[0].\ +getAttribute("chain") +rule = nwfilter_parsedxml.getElementsByTagName("rule")[0] +action = rule.getAttribute("action").upper() +direction = rule.getAttribute("direction") +logger.info("The nwfilter chain:%s ,action:%s ,direction:%s " %\ +(chain,action,direction) ) +in_vnet_chain = "I-vnet0-" + chain +out_vnet_chain = "O-vnet0-" + chain + +if cmp(direction,"inout") == 0 : +if len(ebtables_list) == 21 and in_vnet_chain in ebtables_list[-5]\ +and out_vnet_chain in ebtables_list[-2] \ +and action in ebtables_list[-1] \ +and action in ebtables_list[-4]: +return True +else: +return False +elif cmp(direction,"in") == 0: +if len(ebtables_list) == 14 and out_vnet_chain in ebtables_list[-2]\ +and action in ebtables_list[-1]: +return True +else: +return False + +elif cmp(dire
[libvirt] [test-API][PATCH] Add nwfilter test cases and conf
The patch covers all nwfilter api provided by libvirt.py. It includes define/undefine/list nwfilters and check them via checking ebtables rule. The following new files are added. cases/nwfilter.conf repos/nwfilter/__init__.py repos/nwfilter/nwfilter_check.py * Check the nwfilter via checking ebtales repos/nwfilter/nwfilter_define.py * Define the nwfilter using specified value repos/nwfilter/nwfilter_list.py * List all of the available network filters repos/nwfilter/nwfilter_undefine.py * Undefine the specified nwfilter repos/nwfilter/xmls/nwfilter.xml --- cases/nwfilter.conf | 59 + repos/nwfilter/nwfilter_check.py| 120 +++ repos/nwfilter/nwfilter_define.py | 54 repos/nwfilter/nwfilter_list.py | 76 ++ repos/nwfilter/nwfilter_undefine.py | 43 + repos/nwfilter/xmls/nwfilter.xml|3 + 6 files changed, 355 insertions(+), 0 deletions(-) create mode 100644 cases/nwfilter.conf create mode 100644 repos/nwfilter/__init__.py create mode 100644 repos/nwfilter/nwfilter_check.py create mode 100644 repos/nwfilter/nwfilter_define.py create mode 100644 repos/nwfilter/nwfilter_list.py create mode 100644 repos/nwfilter/nwfilter_undefine.py create mode 100644 repos/nwfilter/xmls/nwfilter.xml diff --git a/cases/nwfilter.conf b/cases/nwfilter.conf new file mode 100644 index 000..b394ee5 --- /dev/null +++ b/cases/nwfilter.conf @@ -0,0 +1,59 @@ +domain:install_linux_cdrom +guestname +$defaultname +guestos +$defaultos +guestarch +$defaultarch +vcpu +$defaultvcpu +memory +$defaultmem +hddriver +$defaulthd +nicdriver +$defaultnic +imageformat +qcow2 +macaddr +54:52:00:4a:16:30 + +nwfilter:nwfilter_list + +# chain -- ipv4, ipv6, arp .etc +# action -- mandatory; drop, accept, return +# direction -- mandatory; must either be in, out or inout +nwfilter:nwfilter_define +nwfiltername + disallow-arp +chain + arp +action + drop +direction + inout + +nwfilter:nwfilter_list + +nwfilter:nwfilter_check +nwfiltername + disallow-arp +guestname + $defaultname + +nwfilter:nwfilter_define +nwfiltername + disallow-ipv6 +chain + ipv6 +action + drop +direction + in + +nwfilter:nwfilter_undefine +nwfiltername + disallow-ipv6 + +nwfilter:nwfilter_list + diff --git a/repos/nwfilter/__init__.py b/repos/nwfilter/__init__.py new file mode 100644 index 000..e69de29 diff --git a/repos/nwfilter/nwfilter_check.py b/repos/nwfilter/nwfilter_check.py new file mode 100644 index 000..b2c7ece --- /dev/null +++ b/repos/nwfilter/nwfilter_check.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python +import time +import xml.dom.minidom + +from libvirt import libvirtError +from utils import utils +from xml.dom import minidom + +from src import sharedmod + +required_params = ('nwfiltername','guestname',) +optional_params = {} + +EBTABLES = "ebtables -t nat -L" + +def get_ebtables(): +""" Get the output of ebtables """ +(status, output) = utils.exec_cmd(EBTABLES,shell=True) +logger.info("Execute command:" + EBTABLES) +ebtables_list = [] + +if status: +logger.error("Executing " + EBTABLES + " failed") +logger.error(output) +return False +else: +for i in range(len(output)): +ebtables_list.append(output[i]) +logger.info("Get the output of ebtables list: %s" \ +% ebtables_list) + +return ebtables_list + +def check_ebtables(*args): +""" Check the ebtables """ +(nwfiltername,conn)= args +ebtables_list = get_ebtables() + +#Get the filter' attribute value +nwfilter_xml = conn.nwfilterLookupByName(nwfiltername).XMLDesc(0) +nwfilter_parsedxml = minidom.parseString(nwfilter_xml) +chain = nwfilter_parsedxml.getElementsByTagName("filter")[0].\ +getAttribute("chain") +rule = nwfilter_parsedxml.getElementsByTagName("rule")[0] +action = rule.getAttribute("action").upper() +direction = rule.getAttribute("direction") +logger.info("The nwfilter chain:%s ,action:%s ,direction:%s " %\ +(chain,action,direction) ) +in_vnet_chain = "I-vnet0-" + chain +out_vnet_chain = "O-vnet0-" + chain + +if cmp(direction,"inout") == 0 : +if len(ebtables_list) == 21 and in_vnet_chain in ebtables_list[-5]\ +and out_vnet_chain in ebtables_list[-2] \ +and action in ebtables_list[-1] \ +and action in ebtables_list[-4]: +return True +else: +return False +elif cmp(direction,"in") == 0: +if len(ebtables_list) == 14 and out_vnet_chain in ebtables_list[-2]\ +and action in ebtables_list[-1]: +return True +else: +return False + +elif cm
[libvirt] [test-API][PATCH] The patch covers all nwfilter api provided by libvirt.py. It includes define/undefine/list nwfilters and check them via checking ebtables rule. The following new files are
--- cases/nwfilter.conf | 59 + repos/nwfilter/nwfilter_check.py| 120 +++ repos/nwfilter/nwfilter_define.py | 54 repos/nwfilter/nwfilter_list.py | 76 ++ repos/nwfilter/nwfilter_undefine.py | 43 + repos/nwfilter/xmls/nwfilter.xml|3 + 6 files changed, 355 insertions(+), 0 deletions(-) create mode 100644 cases/nwfilter.conf create mode 100644 repos/nwfilter/__init__.py create mode 100644 repos/nwfilter/nwfilter_check.py create mode 100644 repos/nwfilter/nwfilter_define.py create mode 100644 repos/nwfilter/nwfilter_list.py create mode 100644 repos/nwfilter/nwfilter_undefine.py create mode 100644 repos/nwfilter/xmls/nwfilter.xml diff --git a/cases/nwfilter.conf b/cases/nwfilter.conf new file mode 100644 index 000..b394ee5 --- /dev/null +++ b/cases/nwfilter.conf @@ -0,0 +1,59 @@ +domain:install_linux_cdrom +guestname +$defaultname +guestos +$defaultos +guestarch +$defaultarch +vcpu +$defaultvcpu +memory +$defaultmem +hddriver +$defaulthd +nicdriver +$defaultnic +imageformat +qcow2 +macaddr +54:52:00:4a:16:30 + +nwfilter:nwfilter_list + +# chain -- ipv4, ipv6, arp .etc +# action -- mandatory; drop, accept, return +# direction -- mandatory; must either be in, out or inout +nwfilter:nwfilter_define +nwfiltername + disallow-arp +chain + arp +action + drop +direction + inout + +nwfilter:nwfilter_list + +nwfilter:nwfilter_check +nwfiltername + disallow-arp +guestname + $defaultname + +nwfilter:nwfilter_define +nwfiltername + disallow-ipv6 +chain + ipv6 +action + drop +direction + in + +nwfilter:nwfilter_undefine +nwfiltername + disallow-ipv6 + +nwfilter:nwfilter_list + diff --git a/repos/nwfilter/__init__.py b/repos/nwfilter/__init__.py new file mode 100644 index 000..e69de29 diff --git a/repos/nwfilter/nwfilter_check.py b/repos/nwfilter/nwfilter_check.py new file mode 100644 index 000..b2c7ece --- /dev/null +++ b/repos/nwfilter/nwfilter_check.py @@ -0,0 +1,120 @@ +#!/usr/bin/env python +import time +import xml.dom.minidom + +from libvirt import libvirtError +from utils import utils +from xml.dom import minidom + +from src import sharedmod + +required_params = ('nwfiltername','guestname',) +optional_params = {} + +EBTABLES = "ebtables -t nat -L" + +def get_ebtables(): +""" Get the output of ebtables """ +(status, output) = utils.exec_cmd(EBTABLES,shell=True) +logger.info("Execute command:" + EBTABLES) +ebtables_list = [] + +if status: +logger.error("Executing " + EBTABLES + " failed") +logger.error(output) +return False +else: +for i in range(len(output)): +ebtables_list.append(output[i]) +logger.info("Get the output of ebtables list: %s" \ +% ebtables_list) + +return ebtables_list + +def check_ebtables(*args): +""" Check the ebtables """ +(nwfiltername,conn)= args +ebtables_list = get_ebtables() + +#Get the filter' attribute value +nwfilter_xml = conn.nwfilterLookupByName(nwfiltername).XMLDesc(0) +nwfilter_parsedxml = minidom.parseString(nwfilter_xml) +chain = nwfilter_parsedxml.getElementsByTagName("filter")[0].\ +getAttribute("chain") +rule = nwfilter_parsedxml.getElementsByTagName("rule")[0] +action = rule.getAttribute("action").upper() +direction = rule.getAttribute("direction") +logger.info("The nwfilter chain:%s ,action:%s ,direction:%s " %\ +(chain,action,direction) ) +in_vnet_chain = "I-vnet0-" + chain +out_vnet_chain = "O-vnet0-" + chain + +if cmp(direction,"inout") == 0 : +if len(ebtables_list) == 21 and in_vnet_chain in ebtables_list[-5]\ +and out_vnet_chain in ebtables_list[-2] \ +and action in ebtables_list[-1] \ +and action in ebtables_list[-4]: +return True +else: +return False +elif cmp(direction,"in") == 0: +if len(ebtables_list) == 14 and out_vnet_chain in ebtables_list[-2]\ +and action in ebtables_list[-1]: +return True +else: +return False + +elif cmp(direction,"out") == 0: +if len(ebtables_list) == 14 and in_vnet_chain in ebtables_list[-2] \ +and action in ebtables_list[-1]: +return True +else: +return False + +def nwfilter_check(params): +"""Check the nwfilter via checking ebtales""" +global logger +logger = params['logger'] +nwfiltername = params['nwfiltername'] +guestname = params['guestname'] +domain_nwfilter_xml = "" + +conn = sharedmod.libvirtobj['conn'] +domobj = conn.lookupByName(guestname) + +try:
[libvirt] [test-API][PATCH V2] managedsave: change the checking method about bypass cache
Check whether the O_DIRECT flag is in use on the managed save file during the duration of the managed save, since that is the real effect of the current implementation of the --bypass-cache flag. Add break condition into the while loop of get_fileflags() method in the PATCH V2 --- repos/managedsave/managedsave.py | 61 -- 1 files changed, 32 insertions(+), 29 deletions(-) diff --git a/repos/managedsave/managedsave.py b/repos/managedsave/managedsave.py index 4a92151..70d4ebc 100644 --- a/repos/managedsave/managedsave.py +++ b/repos/managedsave/managedsave.py @@ -2,6 +2,8 @@ import os import math +import thread +import time import libvirt from libvirt import libvirtError @@ -39,39 +41,43 @@ def check_savefile_create(*args): logger.info("managed save file exists") return True -def compare_cachedfile(cachebefore, cacheafter): -"""Compare cached value before managed save and its value after -managed save """ +def get_fileflags(): +"""Get the file flags of managed save file""" +cmds = "cat /proc/$(lsof -w /var/lib/libvirt/qemu/save/"+guestname+".save"\ +"|awk '/libvirt_i/{print $2}')/fdinfo/1|grep flags|awk '{print $NF}'" +global fileflags +while True: +(status, output) = utils.exec_cmd(cmds, shell=True) +if status == 0: + if len(output) == 1: + logger.info("The flags of saved file %s " % output[0]) +fileflags = output[0][-5] + break +else: +logger.error("Fail to get the flags of saved file") +return 1 + +thread.exit_thread() -diff = cacheafter - cachebefore -logger.info("diff is %s " % diff) -percent = math.fabs(diff)/cachebefore -logger.info("diff percent is %s " % percent) -if percent < 0.05: +def check_fileflag(fileflags): +"""Check the file flags of managed save file if include O_DIRECT""" +if int(fileflags) == 4: +logger.info("file flags include O_DIRECT") return True else: +logger.error("file flags doesn't include O_DIRECT") return False -def get_cachevalue(): -"""Get the file system cached value """ - -cmds = "head -n4 /proc/meminfo|grep Cached|awk '{print $2}'" -(status, output) = utils.exec_cmd(cmds, shell=True) -if status != 0: -logger.error("Fail to run cmd line to get cache") -return 1 -else: -logger.debug(output[0]) -cachevalue= int(output[0]) -return cachevalue - def managedsave(params): """Managed save a running domain""" global logger logger = params['logger'] +global guestname guestname = params['guestname'] flags = params ['flags'] +global fileflags +fileflags = '' #Save given flags to sharedmod.data sharedmod.data['flagsave'] = flags @@ -122,17 +128,14 @@ def managedsave(params): #If given flags include bypass-cache,check if bypass file system cache if flagn % 2 == 1: -logger.info("Given flags include --bypass-cache") -os.system('echo 3 > /proc/sys/vm/drop_caches') -cache_before = get_cachevalue() -logger.info("Cached value before managedsave is %s" % cache_before) +logger.info("Given flags include --bypass-cache") +thread.start_new_thread(get_fileflags,()) + # Guarantee get_fileflags shell has run before managed save +time.sleep(5) domobj.managedSave(flagn) -cache_after = get_cachevalue() -logger.info("Cached value after managedsave is %s" % cache_after) - -if compare_cachedfile(cache_before, cache_after): +if check_fileflag(fileflags): logger.info("Bypass file system cache successfully") else: logger.error("Bypass file system cache failed") -- 1.7.7.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [test-API][PATCH] managedsave: change the checking method about bypass cache
Check whether the O_DIRECT flag is in use on the managed save file during the duration of the managed save, since that is the real effect of the current implementation of the --bypass-cache flag. --- repos/managedsave/managedsave.py | 66 +++-- 1 files changed, 34 insertions(+), 32 deletions(-) diff --git a/repos/managedsave/managedsave.py b/repos/managedsave/managedsave.py index 4a92151..b898876 100644 --- a/repos/managedsave/managedsave.py +++ b/repos/managedsave/managedsave.py @@ -2,6 +2,8 @@ import os import math +import thread +import time import libvirt from libvirt import libvirtError @@ -39,39 +41,42 @@ def check_savefile_create(*args): logger.info("managed save file exists") return True -def compare_cachedfile(cachebefore, cacheafter): -"""Compare cached value before managed save and its value after -managed save """ - -diff = cacheafter - cachebefore -logger.info("diff is %s " % diff) -percent = math.fabs(diff)/cachebefore -logger.info("diff percent is %s " % percent) -if percent < 0.05: -return True -else: -return False - -def get_cachevalue(): -"""Get the file system cached value """ - -cmds = "head -n4 /proc/meminfo|grep Cached|awk '{print $2}'" -(status, output) = utils.exec_cmd(cmds, shell=True) -if status != 0: -logger.error("Fail to run cmd line to get cache") -return 1 +def get_fileflags(): +"""Get the file flags of managed save file""" +cmds = "cat /proc/$(lsof -w /var/lib/libvirt/qemu/save/"+guestname+".save"\ +"|awk '/libvirt_i/{print $2}')/fdinfo/1|grep flags|awk '{print $NF}'" +global fileflags +while True: + (status, output) = utils.exec_cmd(cmds, shell=True) + if status == 0: + for i in range(len(output)): + logger.info("The flags of saved file %s" % output[i]) + fileflags = output[i][-5] + else: + logger.error("Fail to get the flags of saved file") + return 1 + +thread.exit_thread() + +def check_fileflag(fileflags): +"""Check the file flags of managed save file if include O_DIRECT""" +if int(fileflags) == 4: + logger.info("file flags include O_DIRECT") + return True else: -logger.debug(output[0]) -cachevalue= int(output[0]) -return cachevalue + logger.error("file flags doesn't include O_DIRECT") + return False def managedsave(params): """Managed save a running domain""" global logger logger = params['logger'] +global guestname guestname = params['guestname'] flags = params ['flags'] +global fileflags +fileflags = '' #Save given flags to sharedmod.data sharedmod.data['flagsave'] = flags @@ -122,17 +127,14 @@ def managedsave(params): #If given flags include bypass-cache,check if bypass file system cache if flagn % 2 == 1: -logger.info("Given flags include --bypass-cache") -os.system('echo 3 > /proc/sys/vm/drop_caches') -cache_before = get_cachevalue() -logger.info("Cached value before managedsave is %s" % cache_before) +logger.info("Given flags include --bypass-cache") + thread.start_new_thread(get_fileflags,()) + # Guarantee get_fileflags shell has run before managed save + time.sleep(5) domobj.managedSave(flagn) -cache_after = get_cachevalue() -logger.info("Cached value after managedsave is %s" % cache_after) - -if compare_cachedfile(cache_before, cache_after): + if check_fileflag(fileflags): logger.info("Bypass file system cache successfully") else: logger.error("Bypass file system cache failed") -- 1.7.7.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [test-API][PATCH V2] Add managedsave test cases
The patch V2 inclues fixing all spots commented by Gren The managedsave test cases and test suite cover test include verifying virsh commands managedsave(include all flags and their combination)/managedsave-remove and managedSaveRemove/ManagedSave/ hasManagedSaveImage python APIs. The following new files be created. new file: cases/managedsave.conf - Test all test cases new file: repos/managedsave/__init__.py new file: repos/managedsave/managedsave.py - Test mangaedsave command/API and all flags new file: repos/managedsave/managedsave_remove.py - Test managedsave-remove command/API new file: repos/managedsave/managedsave_start.py - Verfiy managedsave'flags and start from managedsave image --- cases/managedsave.conf | 63 repos/managedsave/managedsave.py| 159 +++ repos/managedsave/managedsave_remove.py | 60 repos/managedsave/managedsave_start.py | 150 + 4 files changed, 432 insertions(+), 0 deletions(-) create mode 100644 cases/managedsave.conf create mode 100644 repos/managedsave/__init__.py create mode 100644 repos/managedsave/managedsave.py create mode 100644 repos/managedsave/managedsave_remove.py create mode 100644 repos/managedsave/managedsave_start.py diff --git a/cases/managedsave.conf b/cases/managedsave.conf new file mode 100644 index 000..8dcafe2 --- /dev/null +++ b/cases/managedsave.conf @@ -0,0 +1,63 @@ +domain:install_linux_cdrom +guestname +$defaultname +guestos +$defaultos +guestarch +$defaultarch +vcpu +$defaultvcpu +memory +$defaultmem +hddriver +$defaulthd +nicdriver +$defaultnic +imageformat +qcow2 +macaddr +54:52:00:4a:16:30 + +#VIR_DOMAIN_SAVE_BYPASS_CACHE = 1 +#VIR_DOMAIN_SAVE_RUNNING = 2 +#VIR_DOMAIN_SAVE_PAUSED = 4 +#No_FLAGS = 0 +managedsave:managedsave +guestname +$defaultname +flags +1|2 + +managedsave:managedsave_start +guestname +$defaultname +flags +noping + +managedsave:managedsave +guestname +$defaultname +flags +1|4 + +managedsave:managedsave_start +guestname +$defaultname +flags +noping + +managedsave:managedsave +guestname +$defaultname +flags +0 + +managedsave:managedsave_remove +guestname +$defaultname + +managedsave:managedsave_start +guestname +$defaultname +flags +noping diff --git a/repos/managedsave/__init__.py b/repos/managedsave/__init__.py new file mode 100644 index 000..e69de29 diff --git a/repos/managedsave/managedsave.py b/repos/managedsave/managedsave.py new file mode 100644 index 000..a126cd8 --- /dev/null +++ b/repos/managedsave/managedsave.py @@ -0,0 +1,159 @@ +#!/usr/bin/env python + +import os +import math + +import libvirt +from libvirt import libvirtError + +from src import sharedmod +from utils import utils + +required_params = ('guestname', 'flags',) +optional_params = {} + +def check_guest_status(*args): +"""Check guest current status""" +(domobj, logger) = args +state = domobj.info()[0] +logger.debug("current guest status: %s" % state) + +if state == libvirt.VIR_DOMAIN_SHUTOFF or \ + state == libvirt.VIR_DOMAIN_SHUTDOWN or \ + state == libvirt.VIR_DOMAIN_BLOCKED: +return False +else: +return True + +def check_savefile_create(*args): +"""Check guest's managed save file be created""" + +(guestname) = args +cmds = "ls /var/lib/libvirt/qemu/save/%s" % guestname + ".save -lh" +logger.info("Execute cmd %s" % cmds) +(status, output) = utils.exec_cmd(cmds, shell=True) +if status != 0: +logger.error("No managed save file") +return False +else : +logger.info("managed save file exists") +return True + +def compare_cachedfile(cachebefore, cacheafter): +"""Compare cached value before managed save and its value after +managed save """ + +diff = cacheafter - cachebefore +logger.info("diff is %s " % diff) +percent = math.fabs(diff)/cachebefore +logger.info("diff percent is %s " % percent) +if percent < 0.05: +return True +else: +return False + +def get_cachevalue(): +"""Get the file system cached value """ + +cmds = "head -n4 /proc/meminfo|grep Cached|awk '{print $2}'" +(status, output) = utils.exec_cmd(cmds, shell=True) +if status != 0: +logger.error("Fail to run cmd line to get cache") +return 1 +else: +logger.debug(output[0]) +cachevalue= int(output[0]) +return cachevalue + +def managedsave(params): +"""Managed save a running domain""" + +global logger +logger = params['logger'] +guestname = params['guestname'] +flags = params ['flags'] +#Save given flags to sharedmod.data +sharedmod.data['flagsave'] =
[libvirt] [test-API][PATCH] Add managedsave test cases
The managedsave test cases and test suite cover test include verifying virsh commands managedsave(include all flags and their combination)/managedsave-remove and managedSaveRemove/ManagedSave/ hasManagedSaveImage python APIs. The following new files be created. new file: cases/managedsave.conf - Test all test cases new file: repos/managedsave/__init__.py new file: repos/managedsave/managedsave.py - Test mangaedsave command/API and all flags new file: repos/managedsave/managedsave_remove.py - Test managedsave-remove command/API new file: repos/managedsave/managedsave_start.py - Verfiy managedsave'flags and start from managedsave image --- cases/managedsave.conf | 63 repos/managedsave/managedsave.py| 162 +++ repos/managedsave/managedsave_remove.py | 61 repos/managedsave/managedsave_start.py | 152 + 4 files changed, 438 insertions(+), 0 deletions(-) create mode 100644 cases/managedsave.conf create mode 100644 repos/managedsave/__init__.py create mode 100644 repos/managedsave/managedsave.py create mode 100644 repos/managedsave/managedsave_remove.py create mode 100644 repos/managedsave/managedsave_start.py diff --git a/cases/managedsave.conf b/cases/managedsave.conf new file mode 100644 index 000..8dcafe2 --- /dev/null +++ b/cases/managedsave.conf @@ -0,0 +1,63 @@ +domain:install_linux_cdrom +guestname +$defaultname +guestos +$defaultos +guestarch +$defaultarch +vcpu +$defaultvcpu +memory +$defaultmem +hddriver +$defaulthd +nicdriver +$defaultnic +imageformat +qcow2 +macaddr +54:52:00:4a:16:30 + +#VIR_DOMAIN_SAVE_BYPASS_CACHE = 1 +#VIR_DOMAIN_SAVE_RUNNING = 2 +#VIR_DOMAIN_SAVE_PAUSED = 4 +#No_FLAGS = 0 +managedsave:managedsave +guestname +$defaultname +flags +1|2 + +managedsave:managedsave_start +guestname +$defaultname +flags +noping + +managedsave:managedsave +guestname +$defaultname +flags +1|4 + +managedsave:managedsave_start +guestname +$defaultname +flags +noping + +managedsave:managedsave +guestname +$defaultname +flags +0 + +managedsave:managedsave_remove +guestname +$defaultname + +managedsave:managedsave_start +guestname +$defaultname +flags +noping diff --git a/repos/managedsave/__init__.py b/repos/managedsave/__init__.py new file mode 100644 index 000..e69de29 diff --git a/repos/managedsave/managedsave.py b/repos/managedsave/managedsave.py new file mode 100644 index 000..5e7c105 --- /dev/null +++ b/repos/managedsave/managedsave.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python + +import os +import math + +import libvirt +from libvirt import libvirtError + +from src import sharedmod +from utils import utils + +required_params = ('guestname', 'flags',) +optional_params = {} + +def check_guest_status(*args): +"""Check guest current status""" +(domobj, logger) = args +state = domobj.info()[0] +logger.debug("current guest status: %s" % state) + +if state == libvirt.VIR_DOMAIN_SHUTOFF or \ + state == libvirt.VIR_DOMAIN_SHUTDOWN or \ + state == libvirt.VIR_DOMAIN_BLOCKED: +return False +else: +return True + +def check_savefile_create(*args): +"""Check guest's managed save file be created""" + +(guestname) = args +cmds = "ls /var/lib/libvirt/qemu/save/%s" % guestname + ".save -lh" +logger.info("Execute cmd %s" % cmds) +(status, output) = utils.exec_cmd(cmds, shell=True) +if status != 0: +logger.error("No managed save file") +return False +else : +logger.info("managed save file exists") +return True + +def compare_cachedfile(cachebefore, cacheafter): +"""Compare cached value before managed save and its value after +managed save """ + +diff = cacheafter - cachebefore +logger.info("diff is %s " % diff) +percent = math.fabs(diff)/cachebefore +logger.info("diff percent is %s " % percent) +if math.fabs(diff)/cachebefore < 0.05: +return True +else: +return False + +def get_cachevalue(): +"""Get the file system cached value """ + +cmds = "head -n4 /proc/meminfo|grep Cached|awk '{print $2}'" +(status, output) = utils.exec_cmd(cmds, shell=True) +if status != 0: +logger.error("failed to run cmd line to get cache") +return 1 +else: +logger.debug(output[0]) +cachevalue= int(output[0]) +return cachevalue + +def managedsave(params): +"""Managed save a running domain""" + +global logger +logger = params['logger'] +guestname = params['guestname'] +flags = params ['flags'] +#Save given flags to sharedmod.data +sharedmod.data['flagsave'] = flags + +logger.info("The
[libvirt] [test-API][PATCH] Fix a typo xml_file_path
Change the undefined variable "xml_file_path" to "file_path" --- src/testcasexml.py |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/testcasexml.py b/src/testcasexml.py index 8485d3d..4cbdc03 100644 --- a/src/testcasexml.py +++ b/src/testcasexml.py @@ -31,7 +31,7 @@ def xml_file_to_str(proxy_obj, mod_case, case_params): text = fh.read() fh.close() else: -raise exception.FileDoesNotExist("xml file %s doesn't exist" % xml_file_path) +raise exception.FileDoesNotExist("xml file %s doesn't exist" % file_path) # replace the params that in testcase.conf first for (key, value) in case_params.items(): -- 1.7.7.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] Is virConnectListDefinedDomains broken?
Hi, list, Recently, I upgraded my system to Xen 3.3.1 (from Xen 3.0.3). After this, I found that virConnectListDefinedDomains no longer works. The problem can be reproduced by executing "virsh list -all" - those defined but inactive domains are not be returned. Has libvirt API been tested against Xen 3.3.1? Can this problem be fixed by upgrading libvirt to version 0.6.5? What is the best approach to address this issue? Thanks in advance, Eddy OS: CentOS 5.3 Xen: kernel-xen.x86_64 2.6.18-128.1.14.el5 installed kmod-drbd83-xen.x86_64 8.3.0-3 installed xen.x86_64 3.3.1-0 installed xen-libs.x86_643.3.1-0 installed libvirt: libvirt.x86_64 0.4.4-3 installed libvirt-python.x86_64 0.4.4-3 installed python-virtinst.noarch 0.300.2-12.el5 installed virt-viewer.x86_64 0.0.2-2.el5 installed -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list