[libvirt] [test-API][PATCH V2 0/2] Add case for setSchedulerParametersFlag API

V1->V2: Delete the symbol '\' at the end of lines. Update the domian stats to "libvirt.VIR_DOMAIN_RUNNING" and "libvirt.VIR_DOMAIN_SHUTOFF", instead of the static value. Delete the scenario without flags in file shed_parms.conf V1: Add test case for setSchedulerParametersFlags related API Add conf file of setSchedulerParametersFlags test Xuesong Zhang (2): Add new cases for testing setSchedulerParametersFlags related API Add scenario conf file for testing setSchedulerParametersFlags related API cases/sched_params.conf | 106 ++++++++++++++++++++++++++ repos/domain/sched_params_flag.py | 155 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 261 insertions(+) create mode 100755 cases/sched_params.conf create mode 100755 repos/domain/sched_params_flag.py -- 1.8.3.1

--- repos/domain/sched_params_flag.py | 155 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100755 repos/domain/sched_params_flag.py diff --git a/repos/domain/sched_params_flag.py b/repos/domain/sched_params_flag.py new file mode 100755 index 0000000..f7a5e44 --- /dev/null +++ b/repos/domain/sched_params_flag.py @@ -0,0 +1,155 @@ +#!/usr/bin/evn python +# Set and show scheduler parameters with flag, such as "--current", "--live" +# and "--config" + +import libvirt +from libvirt import libvirtError + +from src import sharedmod +from utils import utils +from xml.dom import minidom +import os + +required_params = ('guestname', 'vcpuquota', 'vcpuperiod', 'emulatorperiod', + 'emulatorquota', 'cpushares', 'flag',) +optional_params = {} + +def check_sched_params_flag(guestname, domobj, sched_params_after, domstate, + flags_value): + """Check scheduler parameters validity after setting + """ + + if (domstate == 1) and ((flags_value == 0) or (flags_value == 1)): + """While the domain is running and the flag is "--live" or "--current", + the value can be checked with the cgroup value + As for the other condition, the value can be checked with the domain + config xml + """ + + if os.path.exists("/cgroup"): + """ Add the judgment method, since the cgroup path is different on + rhel6 and rhel7. + if the folder cgroup is existed, it means the host os is rhel6, + if not existed, it means the the host of is rhel7 + """ + + cgroup_path = "cat /cgroup/cpu/libvirt/qemu/%s/" % guestname + else: + cgroup_path = "cat /sys/fs/cgroup/cpu\,cpuacct/machine.slice/" \ + "machine-qemu\\\\x2d%s.scope/" % guestname + + sched_dicts = {'vcpu_quota': 'vcpu0/cpu.cfs_quota_us', + 'vcpu_period': 'vcpu0/cpu.cfs_period_us', + 'emulator_period': 'emulator/cpu.cfs_period_us', + 'emulator_quota': 'emulator/cpu.cfs_quota_us', + 'cpu_shares': 'cpu.shares'} + + for sched_key in sched_dicts: + cmd = cgroup_path + sched_dicts[sched_key] + status, cmd_value = utils.exec_cmd(cmd, shell=True) + if status: + logger.error("failed to get ***%s*** value" % sched_key) + return 1 + sched_dicts[sched_key] = int(cmd_value[0]) + if sched_dicts[sched_key] != sched_params_after[sched_key]: + logger.error("set scheduler parameters failed") + return 1 + + else: + guestxml = domobj.XMLDesc(libvirt.VIR_DOMAIN_XML_INACTIVE) + logger.debug("domain %s config xml :\n%s" % (domobj.name(), guestxml)) + + xmlrootnode = minidom.parseString(guestxml) + + sched_dicts = {'vcpu_quota': 'quota', 'vcpu_period': 'period', + 'emulator_period': 'emulator_period', + 'emulator_quota': 'emulator_quota', + 'cpu_shares': 'shares'} + + for sched_key in sched_dicts: + node = xmlrootnode.getElementsByTagName(sched_dicts[sched_key])[0] + sched_dicts[sched_key] = int(node.childNodes[0].data) + if sched_dicts[sched_key] != sched_params_after[sched_key]: + logger.error("set scheduler parameters failed") + return 1 + + logger.info("set scheduler parameters success") + return 0 + +def sched_params_flag(params): + """ Change and get the scheduler parameters + """ + + global logger + logger = params['logger'] + guestname = params['guestname'] + dicts = {'vcpu_quota': int(params['vcpuquota']), + 'vcpu_period': int(params['vcpuperiod']), + 'emulator_period': int(params['emulatorperiod']), + 'emulator_quota': int(params['emulatorquota']), + 'cpu_shares': int(params['cpushares'])} + flags = params['flag'] + + try: + conn = sharedmod.libvirtobj['conn'] + domobj = conn.lookupByName(guestname) + + domstate = domobj.state(0)[0] + """virDomainState + VIR_DOMAIN_NOSTATE = 0 + VIR_DOMAIN_RUNNING = 1 + VIR_DOMAIN_BLOCKED = 2 + VIR_DOMAIN_PAUSED = 3 + VIR_DOMAIN_SHUTDOWN = 4 + VIR_DOMAIN_SHUTOFF = 5 + VIR_DOMAIN_CRASHED = 6 + VIR_DOMAIN_PMSUSPENDED = 7 + + please see the following reference link: + http://libvirt.org/html/libvirt-libvirt.html#virDomainState + """ + if domstate == libvirt.VIR_DOMAIN_RUNNING: + logger.info("the state of virtual machine is ***running***") + elif domstate == libvirt.VIR_DOMAIN_SHUTOFF: + logger.info("the state of virtual machine is ***shutoff***") + else: + logger.error("the state of virtual machine is not running or " \ + "shutoff now, it is out of the check range of this " \ + "script. Please check the domain status.") + return 1 + + """virDomainModificationImpact + VIR_DOMAIN_AFFECT_CURRENT = 0 + VIR_DOMAIN_AFFECT_LIVE = 1 + VIR_DOMAIN_AFFECT_CONFIG = 2 + """ + + if flags == "current": + flags_value = libvirt.VIR_DOMAIN_AFFECT_CURRENT + elif flags == "live": + flags_value = libvirt.VIR_DOMAIN_AFFECT_LIVE + elif flags == "config": + flags_value = libvirt.VIR_DOMAIN_AFFECT_CONFIG + else: + logger.error("the value of flags is not correct, please check " \ + "the conf file") + return 1 + + sched_type = str(domobj.schedulerType()[0]) + logger.info("the scheduler type is: %s" % sched_type) + sched_params_original = domobj.schedulerParametersFlags(flags_value) + logger.info("original scheduler parameters with flag ***%s***: %s" % + (flags, sched_params_original)) + logger.info("setting scheduler parameters: %s" % dicts) + domobj.setSchedulerParametersFlags(dicts, flags_value) + sched_params_after = domobj.schedulerParametersFlags(flags_value) + logger.info("current scheduler parameters with flag ***%s***: %s" % + (flags, sched_params_after)) + + ret = check_sched_params_flag(guestname, domobj, sched_params_after, + domstate, flags_value) + + return ret + except libvirtError, e: + logger.error("libvirt call failed: " + str(e)) + return 1 -- 1.8.3.1

--- cases/sched_params.conf | 106 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100755 cases/sched_params.conf diff --git a/cases/sched_params.conf b/cases/sched_params.conf new file mode 100755 index 0000000..21b6c04 --- /dev/null +++ b/cases/sched_params.conf @@ -0,0 +1,106 @@ +domain:install_linux_cdrom + guestname + $defaultname + guestos + $defaultos + guestarch + $defaultarch + vcpu + $defaultvcpu + memory + $defaultmem + hddriver + $defaulthd + nicdriver + $defaultnic + imageformat + qcow2 + +domain:sched_params_flag + guestname + $defaultname + vcpuquota + 1001 + vcpuperiod + 200001 + emulatorperiod + 300001 + emulatorquota + 4001 + cpushares + 5001 + flag + current + +domain:sched_params_flag + guestname + $defaultname + vcpuquota + 1002 + vcpuperiod + 200002 + emulatorperiod + 300002 + emulatorquota + 4002 + cpushares + 5002 + flag + live + +domain:sched_params_flag + guestname + $defaultname + vcpuquota + 1003 + vcpuperiod + 200003 + emulatorperiod + 300003 + emulatorquota + 4003 + cpushares + 5003 + flag + config + +domain:destroy + guestname + $defaultname + +domain:sched_params_flag + guestname + $defaultname + vcpuquota + 1004 + vcpuperiod + 200004 + emulatorperiod + 300004 + emulatorquota + 4004 + cpushares + 5004 + flag + current + +domain:sched_params_flag + guestname + $defaultname + vcpuquota + 1005 + vcpuperiod + 200005 + emulatorperiod + 300005 + emulatorquota + 4005 + cpushares + 5005 + flag + config + +domain:undefine + guestname + $defaultname + -- 1.8.3.1
participants (1)
-
Xuesong Zhang