diff --git a/.gitignore b/.gitignore index 701f02fd5..f9d09bd06 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ *.so .settings shared/data +shared/deps/cpuid_test_kernel/cpuid_dump_kernel.bin qemu/env logs qemu/unittests diff --git a/MAINTAINERS b/MAINTAINERS index 5189fd3f1..8c6acf196 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -26,7 +26,7 @@ Pull request maintenance - Libvirt subtests M: Christopher Evich M: Yu Mingfei - +M: Yang Dongsheng Pull request maintenance - Libguestfs ------------------------------------- diff --git a/README.rst b/README.rst index 88c9e7c50..500ffe707 100644 --- a/README.rst +++ b/README.rst @@ -119,3 +119,30 @@ platform. Autotest is a modular framework, and this suite can be used as a submodule of the client module. If you do not want to use or know about autotest, this is fine too, and we'll provide documentation and tools to perform development style testing with it. + + +Basic Troubleshooting +--------------------- + +If you have problems with the basic usage described here, it's possible +that there's some local change in your working copy of virt-test. These +changes can come in (at least) two different categories: + +- Code changes, which you can check with the git tools (try "git diff" + and "git branch" first) +- Configuration changes that can you reset with "update_config.py" + +If you find that you have local changes in the code, please try to reset +your checked out copy to upstream's master by running:: + +$ git checkout master +$ git pull + + +And then, reset you configuration. If you're going to run qemu tests, run:: + +$ qemu/update_config.py + + +If you're still having problems after these basic troubleshoot steps, +please contact us! diff --git a/libguestfs/tests/cfg/guestfs_add.cfg b/libguestfs/tests/cfg/guestfs_add.cfg new file mode 100644 index 000000000..a76c17934 --- /dev/null +++ b/libguestfs/tests/cfg/guestfs_add.cfg @@ -0,0 +1,25 @@ +- guestfs_add: + type = guestfs_add + start_vm = "no" + # If login to check whether write content successfully. + login_to_check_write = "yes" + variants: + - normal_test: + status_error = "no" + guestfs_add_readonly = "no" + variants: + - add_disk: + guestfs_add_ref = "disk" + - add_domain: + guestfs_add_ref = "domain" + - error_test: + status_error = "yes" + guestfs_add_readonly = "yes" + # normally write content will be failed. + login_to_check_write = "no" + variants: + # Write content to readonly disk or domain + - add_disk_ro: + guestfs_add_ref = "disk" + - add_domain_ro: + guestfs_add_ref = "domain" diff --git a/libguestfs/tests/guestfs_add.py b/libguestfs/tests/guestfs_add.py new file mode 100644 index 000000000..9728e292f --- /dev/null +++ b/libguestfs/tests/guestfs_add.py @@ -0,0 +1,188 @@ +import logging, re, commands +from autotest.client.shared import error +from virttest import utils_libguestfs as lgf +from virttest import aexpect + + +def set_guestfs_args(guestfs, ignore_status=True, debug=False, timeout=60): + """ + Maintain Guestfish class' arguments. + """ + guestfs.set_ignore_status(ignore_status) + guestfs.set_debug(debug) + guestfs.set_timeout(timeout) + + +def add_disk_or_domain(guestfs, disk_or_domain, add_ref="domain", + readonly=False): + """ + Add disk or domain to guestfish + + @param guestfs: a session of guestfish + @param disk_or_domain: a disk or a domain + @param add_ref: domain or disk + @param readonly: is added disk or domain readonly. + """ + if add_ref == "domain": + add_result = guestfs.add_domain(disk_or_domain, readonly=readonly) + elif add_ref == "disk": + add_result = guestfs.add_drive_opts(disk_or_domain, readonly=readonly) + else: + guestfs.close_session() + raise error.TestFail("Added must be a disk or a domain.") + + if add_result.exit_status: + guestfs.close_session() + raise error.TestFail("Add %s failed:%s" % (add_ref, add_result)) + logging.debug("Add %s successfully.", add_ref) + + +def launch_disk(guestfs): + # Launch added disk or domain + launch_result = guestfs.run() + if launch_result.exit_status: + guestfs.close_session() + raise error.TestFail("Launch failed:%s" % launch_result) + logging.debug("Launch successfully.") + + +def get_root(guestfs): + getroot_result = guestfs.inspect_os() + roots_list = getroot_result.stdout.splitlines() + if getroot_result.exit_status or not len(roots_list): + guestfs.close_session() + raise error.TestFail("Get root failed:%s" % getroot_result) + return roots_list[0] + + +def mount_filesystem(guestfs, filesystem, mountpoint): + mount_result = guestfs.mount(filesystem, mountpoint) + if mount_result.exit_status: + guestfs.close_session() + raise error.TestFail("Mount filesystem failed:%s" % mount_result) + logging.debug("Mount filesystem successfully.") + + +def run_guestfs_add(test, params, env): + """ + Test of built-in 'add-xxx' commands in guestfish. + + 1) Get parameters for test + 2) Set options for commands + 3) Run key commands: + a.add disk or domain with readonly or not + b.launch + c.mount root device + 4) Write a file to help result checking + 5) Check result + """ + + vm_name = params.get("main_vm") + vm = env.get_vm(vm_name) + + # Get parameters + add_ref = params.get("guestfs_add_ref", "domain") + add_readonly = "yes" == params.get("guestfs_add_readonly", "no") + status_error = "yes" == params.get("status_error", "no") + login_to_check = "yes" == params.get("login_to_check_write", "no") + # Any failed info will be recorded in this dict + # Result check will rely on it. + fail_flag = 0 + fail_info = {} + + if vm.is_alive(): + # Execute guestfish when vm is alive is dangerous. + # Do not support this test right now. + vm.destroy() + + if add_ref == "domain": + disk_or_domain = vm_name + elif add_ref == "disk": + # Get system disk path of tested domain + disks = vm.get_disk_devices() + if len(disks): + disk = disks.values()[0] + disk_or_domain = disk['source'] + else: + # No need to test since getting vm's disk failed. + raise error.TestFail("Can not get disk of %s" % vm_name) + + guestfs = lgf.GuestfishPersistent() + set_guestfs_args(guestfs) + + # Add tested disk or domain + add_disk_or_domain(guestfs, disk_or_domain, add_ref, add_readonly) + + # Launch added disk or domain + launch_disk(guestfs) + + # Mount root filesystem + root = get_root(guestfs) + mount_filesystem(guestfs, root, '/') + + # Write content to file + status, content = commands.getstatusoutput("uuidgen") + write_result = guestfs.write("/guestfs_temp", content) + if write_result.exit_status: + fail_flag = 1 + fail_info['write_content'] = ("Write content to file failed:" + "%s" % write_result) + else: + logging.debug("Write content to file successfully.") + fail_info['write_content'] = "Write content to file successfully." + + # Check writed file in a new guestfish session + guestfs.new_session() + set_guestfs_args(guestfs) + add_disk_or_domain(guestfs, disk_or_domain, add_ref, add_readonly) + launch_disk(guestfs) + mount_filesystem(guestfs, root, '/') + cat_result = guestfs.cat("/guestfs_temp") + if cat_result.exit_status: + fail_flag = 1 + fail_info['cat_writed'] = ("Cat writed file failed:" + "%s" % cat_result) + else: + guestfs_writed_text = cat_result.stdout + if not re.search(content, guestfs_writed_text): + fail_flag = 1 + fail_info['cat_writed'] = ("Catted text is not match with writed:" + "%s" % cat_result) + logging.debug("Catted text is not match with writed") + else: + logging.debug("Cat content of file successfully.") + fail_info['cat_writed'] = "Cat content of file successfully." + + # Start vm and login to check writed file. + guestfs.close_session() + if login_to_check: + try: + vm.start() + session = vm.wait_for_login() + session.cmd("mount %s /mnt" % root) + try: + login_wrote_text = session.cmd_output("cat /mnt/guestfs_temp", + timeout=5) + except aexpect.ShellTimeoutError, detail: + # writen content with guestfs.write won't contain line break + # Is is a bug of guestfish.write? + login_wrote_text = str(detail) + if not re.search(content, login_wrote_text): + fail_flag = 1 + fail_info['login_to_check'] = ("Login to check failed:" + "%s" % login_wrote_text) + else: + logging.debug("Login to check successfully.") + fail_info['login_to_check'] = "Login to check successfully." + except aexpect.ShellError, detail: + fail_flag = 1 + fail_info['login_to_check'] = detail + vm.destroy() + + if status_error: + if not fail_flag: + raise error.TestFail("Expected error is successful:" + "%s" % fail_info) + else: + if fail_flag: + raise error.TestFail(fail_info) diff --git a/libguestfs/tests/virt_edit.py b/libguestfs/tests/virt_edit.py index 3ab60b58d..aadf4137f 100644 --- a/libguestfs/tests/virt_edit.py +++ b/libguestfs/tests/virt_edit.py @@ -1,6 +1,6 @@ import logging, re from autotest.client.shared import utils, error -from virttest import libvirt_vm +from virttest import libvirt_vm, utils_libvirtd import virttest.utils_libguestfs as lgf @@ -88,7 +88,7 @@ def run_virt_edit(test, params, env): # Stop libvirtd if test need. libvirtd = params.get("libvirtd", "on") if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() # Run test virsh_dargs = {'ignore_status': True, 'debug': True, 'uri': uri} @@ -98,7 +98,7 @@ def run_virt_edit(test, params, env): # Recover libvirtd. if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() utils.run("rm -f %s" % created_img) diff --git a/libvirt/control b/libvirt/control index 1252d064c..1cb082eb5 100644 --- a/libvirt/control +++ b/libvirt/control @@ -22,6 +22,8 @@ from virttest import utils_misc, cartesian_config # set English environment (command output might be localized, need to be safe) os.environ['LANG'] = 'en_US.UTF-8' +# set editor environment (some command will use default editor "vi") +os.environ['EDITOR'] = 'vi' libvirt_test_dir = os.path.join(os.environ['AUTODIR'],'tests/virt/libvirt') diff --git a/libvirt/tests/cfg/virsh_cmd/domain/virsh_change_media.cfg b/libvirt/tests/cfg/virsh_cmd/domain/virsh_change_media.cfg index 9f3c44800..f0dd2b767 100644 --- a/libvirt/tests/cfg/virsh_cmd/domain/virsh_change_media.cfg +++ b/libvirt/tests/cfg/virsh_cmd/domain/virsh_change_media.cfg @@ -1,14 +1,15 @@ - virsh_change_media: + virt_test_type = libvirt type = virsh_change_media - old_iso = "change_media_old.iso" - new_iso = "change_media_new.iso" - update_iso_xml = "update_iso.xml" - disk_device = "hdc" - vm_ref = "name" - init_cdrom = "''" + change_media_update_iso_xml = "update_iso.xml" + change_media_disk_device = "hdc" + change_media_vm_ref = "name" + change_media_init_cdrom = "''" + change_media_old_iso = "change_media_old.iso" + change_media_new_iso = "change_media_new.iso" libvirtd = "on" - init_iso = "change_media_old.iso" change_media_source = + change_media_init_iso = "change_media_old.iso" variants: - positive_test: status_error = "no" @@ -21,52 +22,52 @@ - options: variants: - none: - options = " " + change_media_options = " " - current: - options = "--current" + change_media_options = "--current" - live: no shutoff_guest - options = "--live" + change_media_options = "--live" - force: - options = "--force" + change_media_options = "--force" - config: - options = "--config" + change_media_options = "--config" variants: - eject: - action = "--eject " - check_file = + change_media_action = "--eject " + change_media_check_file = - insert: change_media_source = "change_media_old.iso" - action = "--insert " - check_file = "old" - init_iso = + change_media_action = "--insert " + change_media_check_file = "old" + change_media_init_iso = - update: change_media_source = "change_media_new.iso" - action = "--update " - check_file = "new" + change_media_action = "--update " + change_media_check_file = "new" - negative_test: status_error = "yes" start_vm = "no" - options = "--current" + change_media_options = "--current" variants: - no_option: only insert - options = " " + change_media_options = " " - no_name: - vm_ref = " " + change_media_vm_ref = " " - unexpect_option: - vm_ref = "\#" + change_media_vm_ref = "\#" - invalid_option: - options = "--xyz" + change_media_options = "--xyz" - with_libvirtd_stop: - requires_root = "yes" + change_media_requires_root = "yes" libvirtd = "off" - shutoff_guest_with_live: - options = "--live" + change_media_options = "--live" variants: - eject: - action = "--eject " + change_media_action = "--eject " - insert: - action = "--insert " + change_media_action = "--insert " - update: - action = "--update " + change_media_action = "--update " diff --git a/libvirt/tests/cfg/virsh_cmd/domain/virsh_domif_setlink_getlink.cfg b/libvirt/tests/cfg/virsh_cmd/domain/virsh_domif_setlink_getlink.cfg new file mode 100644 index 000000000..4c687c771 --- /dev/null +++ b/libvirt/tests/cfg/virsh_cmd/domain/virsh_domif_setlink_getlink.cfg @@ -0,0 +1,47 @@ +- virsh_domif_setlink_getlink: + type = virsh_domif_setlink_getlink + if_ifname_re = "\s*\d+:\s+([[a-zA-Z]+\d+):" + variants: + - positive_test: + status_error = "no" + variants: + - domif_setlink: + if_action = "setlink" + variants: + - setlink_up: + if_operation = "up" + - setlink_down: + if_operation = "down" + variants: + - running_guest: + start_vm = "yes" + - shutoff_guest: + start_vm = "no" + no interface_net + variants: + - no_config: + if_options = " " + - with_config: + if_options = "--config" + no interface_net + no shutoff_guest + variants: + - interface_net: + if_device = "net" + if_name = "vnet0" + - interface_mac: + if_device = "mac" + + - negative_test: + status_error = "yes" + if_action = "setlink" + if_operation = "up" + if_device = "mac" + if_options = " " + variants: + - running_guest_invalid_option: + if_options = "--xyz" + start_vm = "yes" + - shutoff_guest_with_vnet: + start_vm = "no" + if_device = "net" diff --git a/libvirt/tests/cfg/virsh_cmd/domain/virsh_domiftune.cfg b/libvirt/tests/cfg/virsh_cmd/domain/virsh_domiftune.cfg new file mode 100644 index 000000000..3bada79f1 --- /dev/null +++ b/libvirt/tests/cfg/virsh_cmd/domain/virsh_domiftune.cfg @@ -0,0 +1,153 @@ +- virsh_domiftune: + type = virsh_domiftune + libvirtd = "on" + variants: + - positive_testing: + status_error = "no" + variants: + - get_domif_parameter: + variants: + - running_guest: + start_vm = "yes" + variants: + - options: + variants: + - none: + options = + - live: + options = "live" + - current: + options = "current" + - set_blkio_parameter: + change_parameters = "yes" + variants: + - running_guest: + start_vm = "yes" + variants: + - change_inbound: + variants: + # the parameters are 32-bit unsigned + # integers and {in,out}bound is in + # range of 1~ 2^32-1 (4294967295) + - minimum_boundary: + inbound = 1 + - inside_boundary: + inbound = 1024 + - maximum_boundary: + inbound = 4294967295 + variants: + - options: + variants: + - live: + options = "live" + - current: + options = "current" + - change_outbound: + variants: + - minimum_boundary: + outbound = 1 + - inside_boundary: + outbound = 65535 + - maximum_boundary: + outbound = 4294967295 + variants: + - options: + variants: + - live: + options = "live" + - current: + options = "current" + + - negative_testing: + status_error = "yes" + variants: + - get_domif_parameter: + variants: + - running_guest: + start_vm = "yes" + variants: + - options: + variants: + - none: + options = "hello" + - shutoff_guest: + start_vm = "no" + variants: + - options: + variants: + - none: + options = "hello" + - live: + options = "live" + - set_domif_parameter: + change_parameters = "yes" + variants: + - running_guest: + start_vm = "yes" + variants: + - change_inbound: + variants: + # inbound average is mandatory + - average: + inbound = 0 + - invalid_format: + inbound = "~@#$%^-=_:,.[]{}" + variants: + - options: + variants: + - live: + options = "live" + - change_outbound: + variants: + - average: + outbound = 0 + - invalid_format: + outbound = "~@#$%^-=_:,.[]{}" + variants: + - options: + variants: + - live: + options = "live" + - config: + options = "config" + - current: + options = "current" + - shutoff_guest: + start_vm = "no" + variants: + - change_inbound: + variants: + - minimum_boundary: + inbound = 1 + - inside_boundary: + inbound = 65535 + - maximum_boundary: + inbound = 4294967295 + variants: + - options: + variants: + - live: + options = "live" + - config: + options = "config" + - current: + options = "current" + + - change_outbound: + variants: + - minimum_boundary: + outbound = 1 + - inside_boundary: + outbound = 65535 + - maximum_boundary: + outbound = 4294967295 + variants: + - options: + variants: + - live: + options = "live" + - config: + options = "config" + - current: + options = "current" + diff --git a/libvirt/tests/cfg/virsh_cmd/domain/virsh_edit.cfg b/libvirt/tests/cfg/virsh_cmd/domain/virsh_edit.cfg index e8a4930df..bf5f2221d 100644 --- a/libvirt/tests/cfg/virsh_cmd/domain/virsh_edit.cfg +++ b/libvirt/tests/cfg/virsh_cmd/domain/virsh_edit.cfg @@ -1,6 +1,6 @@ - virsh_edit: - type = virsh_edit virt_test_type = libvirt + type = virsh_edit take_regular_screendumps = no edit_vm_ref = "name" edit_extra_param = "" diff --git a/libvirt/tests/cfg/virsh_cmd/domain/virsh_managedsave.cfg b/libvirt/tests/cfg/virsh_cmd/domain/virsh_managedsave.cfg index b5a434108..0be8db093 100644 --- a/libvirt/tests/cfg/virsh_cmd/domain/virsh_managedsave.cfg +++ b/libvirt/tests/cfg/virsh_cmd/domain/virsh_managedsave.cfg @@ -40,6 +40,6 @@ variants: - shut_status: start_vm = no - kill_vm = yes + kill_vm_before_test = yes - libvirtd_off: managedsave_libvirtd = "off" diff --git a/libvirt/tests/cfg/virsh_cmd/nodedev/virsh_nodedev_detach_reattach.cfg b/libvirt/tests/cfg/virsh_cmd/nodedev/virsh_nodedev_detach_reattach.cfg new file mode 100644 index 000000000..459675013 --- /dev/null +++ b/libvirt/tests/cfg/virsh_cmd/nodedev/virsh_nodedev_detach_reattach.cfg @@ -0,0 +1,23 @@ +- virsh_nodedev_detach_reattach: + virt_test_type = libvirt + type = virsh_nodedev_detach_reattach + start_vm = "no" + # Name of pci device witch is detachable in host. + # eg. pci_0000_00_1f_5 + nodedev_device_name = 'ENTER.YOUR.PCI.DEVICE.TO.DETACH' + variants: + - positive: + status_error = "no" + variants: + - normal_test: + - negative: + status_error = "yes" + variants: + - no_arg: + nodedev_device_name = '' + - name_unrecognized: + nodedev_device_name = 'unrecognize' + - multi_detach: + nodedev_device_name = "${nodedev_device_name} xyz" + - not_pci_device: + nodedev_device_name = 'computer' diff --git a/libvirt/tests/cfg/virsh_cmd/nodedev/virsh_nodedev_dumpxml.cfg b/libvirt/tests/cfg/virsh_cmd/nodedev/virsh_nodedev_dumpxml.cfg new file mode 100644 index 000000000..7f1891149 --- /dev/null +++ b/libvirt/tests/cfg/virsh_cmd/nodedev/virsh_nodedev_dumpxml.cfg @@ -0,0 +1,24 @@ +- virsh_nodedev_dumpxml: + virt_test_type = libvirt + type = virsh_nodedev_dumpxml + vms = "" + main_vm = "" + start_vm = "no" + #nodedev_device_name need to execute dumpxml command. + nodedev_device_name = "pci_0000_00_00_0" + #nodedev_device_opt: options for nodedev-dumpxml cmd. + nodedev_device_opt = "" + variants: + - positve_test: + status_error = "no" + variants: + - normal_test: + - negative_test: + status_error = "yes" + variants: + - nodedev_notfound: + nodedev_device_name = "not_exists" + - nodedev_spacename: + nodedev_device_name = "" + - nodedev_unknowopt: + nodedev_device_opt = "--xyz" diff --git a/libvirt/tests/cfg/virsh_cmd/pool/virsh_pool_create_as.cfg b/libvirt/tests/cfg/virsh_cmd/pool/virsh_pool_create_as.cfg new file mode 100644 index 000000000..ee2923008 --- /dev/null +++ b/libvirt/tests/cfg/virsh_cmd/pool/virsh_pool_create_as.cfg @@ -0,0 +1,7 @@ +- virsh_pool_create_as: + type = virsh_pool_create_as + vms = "" + # type in [ 'dir', 'fs', 'netfs', 'disk', 'iscsi', 'logical' ] + pool_type = dir + pool_name = custom_pool_name + pool_target = /mnt diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_change_media.py b/libvirt/tests/src/virsh_cmd/domain/virsh_change_media.py index 0164d45e2..9f83cef07 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_change_media.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_change_media.py @@ -1,6 +1,6 @@ -import logging, os, shutil +import logging, os from autotest.client.shared import error, utils -from virttest import libvirt_vm, virsh +from virttest import virsh, utils_libvirtd from virttest.libvirt_xml import vm_xml @@ -20,6 +20,9 @@ def run_virsh_change_media(test, params, env): def env_pre(old_iso, new_iso): """ Prepare ISO image for test + + @param: old_iso: sourse file for insert + @param: new_iso: sourse file for update """ error.context("Preparing ISO images") utils.run("dd if=/dev/urandom of=%s/old bs=10M count=1" % cdrom_dir) @@ -31,9 +34,10 @@ def env_pre(old_iso, new_iso): def check_media(session, target_file, action): """ Check guest cdrom files - 1. guest session - 2. the expected files - 3. test case action + + @param: session: guest session + @param: target_file: the expected files + @action: action: test case action """ if action != "--eject ": error.context("Checking guest cdrom files") @@ -49,26 +53,34 @@ def check_media(session, target_file, action): def add_cdrom_device(vm_name, init_cdrom): """ Add cdrom device for test vm + + @param: vm_name: guest name + @param: init_cdrom: source file """ if vm.is_alive(): virsh.destroy(vm_name) virsh.attach_disk(vm_name, init_cdrom, - " hdc", " --type cdrom --sourcetype file --config", + disk_device, " --type cdrom --sourcetype file --config", debug=True) - def update_cdrom(vm_name, init_iso, options, start_vm ): + def update_cdrom(vm_name, init_iso, options, start_vm): """ Update cdrom iso file for test case + + @param: vm_name: guest name + @param: init_iso: source file + @param: options: update-device option + @param: start_vm: guest start flag """ snippet = """ - + -""" % (init_iso) +""" % (init_iso, disk_device) update_iso_file = open(update_iso_xml, "w") update_iso_file.write(snippet) update_iso_file.close() @@ -84,27 +96,31 @@ def update_cdrom(vm_name, init_iso, options, start_vm ): vm_name = params.get("main_vm") vm = env.get_vm(vm_name) - vm_ref = params.get("vm_ref") - action = params.get("action") + vm_ref = params.get("change_media_vm_ref") + action = params.get("change_media_action") start_vm = params.get("start_vm") - options = params.get("options") + options = params.get("change_media_options") + disk_device = params.get("change_media_disk_device") + libvirtd = params.get("libvirtd", "on") + source_name = params.get("change_media_source") + status_error = params.get("status_error", "no") + check_file = params.get("change_media_check_file") + init_cdrom = params.get("change_media_init_cdrom") + update_iso_xml_name = params.get("change_media_update_iso_xml") + init_iso_name = params.get("change_media_init_iso") + old_iso_name = params.get("change_media_old_iso") + new_iso_name = params.get("change_media_new_iso") cdrom_dir = os.path.join(test.tmpdir, "tmp") + + old_iso = os.path.join(cdrom_dir, old_iso_name) + new_iso = os.path.join(cdrom_dir, new_iso_name) + update_iso_xml = os.path.join(cdrom_dir, update_iso_xml_name) if not os.path.exists(cdrom_dir): os.mkdir(cdrom_dir) - - old_iso_name = params.get("old_iso") - new_iso_name = params.get("new_iso") - old_iso = cdrom_dir + old_iso_name - new_iso = cdrom_dir + new_iso_name - init_cdrom = params.get("init_cdrom") - update_iso_xml_name = params.get("update_iso_xml") - update_iso_xml = cdrom_dir + update_iso_xml_name - init_iso_name = params.get("init_iso") if not init_iso_name : init_iso = "" - else: - init_iso = cdrom_dir + init_iso_name + init_iso = os.path.join(cdrom_dir, init_iso_name) if vm_ref == "name": vm_ref = vm_name @@ -113,7 +129,7 @@ def update_cdrom(vm_name, init_iso, options, start_vm ): # Check domain's disk device disk_blk = vm_xml.VMXML.get_disk_blk(vm_name) logging.info("disk_blk %s" % disk_blk) - if "hdc" not in disk_blk: + if disk_device not in disk_blk: logging.info("Adding cdrom device") add_cdrom_device(vm_name, init_cdrom) @@ -126,43 +142,36 @@ def update_cdrom(vm_name, init_iso, options, start_vm ): vm.start() update_cdrom(vm_name, init_iso, options, start_vm) - disk_device = params.get("disk_device") - libvirtd = params.get("libvirtd", "on") if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() - source_name = params.get("change_media_source") # Libvirt will ignore --source when action is eject if action == "--eject ": source = "" - else: - source = cdrom_dir + source_name + source = os.path.join(cdrom_dir, source_name) all_options = action + options + " " + source result = virsh.change_media(vm_ref, disk_device, all_options, ignore_status=True, debug=True) status = result.exit_status - status_error = params.get("status_error", "no") if status_error == "no": if options == "--config" and vm.is_alive(): vm.destroy() - - vm.start() + if vm.is_dead(): + vm.start() session = vm.wait_for_login() - check_file = params.get("check_file") check_media(session, check_file, action) session.close() # Recover libvirtd service start if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() # Clean the cdrom dir and clean the cdrom device update_cdrom(vm_name, "", options, start_vm) - shutil.rmtree(cdrom_dir) # Check status_error diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_console.py b/libvirt/tests/src/virsh_cmd/domain/virsh_console.py index e520743cd..fd64adf35 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_console.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_console.py @@ -17,12 +17,11 @@ def xml_console_recover(vmxml): """ Recover older xml config with backup vmxml. """ - try: - vmxml.undefine() - vmxml.define() + vmxml.undefine() + if vmxml.define(): return True - except xcepts.LibvirtXMLError, detail: - logging.error("Recover older serial failed:%s.", detail) + else: + logging.error("Recover older serial failed:%s.", vmxml.get('xml')) return False diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_destroy.py b/libvirt/tests/src/virsh_cmd/domain/virsh_destroy.py index 7814edeb6..f316fbec0 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_destroy.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_destroy.py @@ -1,5 +1,5 @@ from autotest.client.shared import error -from virttest import libvirt_vm, remote, virsh +from virttest import libvirt_vm, remote, virsh, utils_libvirtd def run_virsh_destroy(test, params, env): """ @@ -39,7 +39,7 @@ def run_virsh_destroy(test, params, env): vm_ref = domuuid if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() if vm_ref != "remote": status = virsh.destroy(vm_ref, ignore_status=True).exit_status @@ -59,7 +59,7 @@ def run_virsh_destroy(test, params, env): status = 1 if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() #check status_error if status_error == "yes": diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_domid.py b/libvirt/tests/src/virsh_cmd/domain/virsh_domid.py index 04397f628..6e60cd533 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_domid.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_domid.py @@ -1,5 +1,5 @@ from autotest.client.shared import error -from virttest import libvirt_vm, remote, virsh +from virttest import libvirt_vm, remote, virsh, utils_libvirtd def run_virsh_domid(test, params, env): @@ -70,7 +70,7 @@ def remote_test(params, vm_name): vm_ref = domuuid if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() if vm_ref != "remote": result = virsh.domid(vm_ref, ignore_status=True) @@ -82,7 +82,7 @@ def remote_test(params, vm_name): #recover libvirtd service start if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() #check status_error if status_error == "yes": diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_domif_setlink_getlink.py b/libvirt/tests/src/virsh_cmd/domain/virsh_domif_setlink_getlink.py new file mode 100644 index 000000000..b0cc0892d --- /dev/null +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_domif_setlink_getlink.py @@ -0,0 +1,135 @@ +import logging, re +from autotest.client.shared import error +from virttest import libvirt_vm, virsh +from virttest.libvirt_xml import vm_xml + +def run_virsh_domif_setlink_getlink(test, params, env): + """ + Test command: virsh domif-setlink and domif-getlink. + + The command set and get link state of a virtual interface + 1. Prepare test environment. + 2. Perform virsh domif-setlink and domif-getlink operation. + 3. Recover test environment. + 4. Confirm the test result. + """ + + def domif_setlink(vm, device, operation, options): + """ + Set the domain link state + + @param: vm : domain name + @param: device : domain virtual interface + @param: opration : domain virtual interface state + @param: options : some options like --config + + """ + + return virsh.domif_setlink(vm, device, operation, options, debug=True) + + def domif_getlink(vm, device, options): + """ + Get the domain link state + + @param: vm : domain name + @param: device : domain virtual interface + @param: options : some options like --config + + """ + + return virsh.domif_getlink(vm, device, options, + ignore_status=True, debug=True) + + vm_name = params.get("main_vm", "virt-tests-vm1") + vm = env.get_vm(vm_name) + options = params.get("if_options", "--config") + start_vm = params.get("start_vm", "no") + if_device = params.get("if_device", "net") + if_name = params.get("if_name", "vnet0") + if_operation = params.get("if_operation", "up") + if_name_re = params.get("if_ifname_re", + r"\s*\d+:\s+([[a-zA-Z]+\d+):") + status_error = params.get("status_error", "no") + mac_address = vm.get_virsh_mac_address(0) + device = "vnet0" + # Vm status + if start_vm == "yes" and vm.is_dead(): + vm.start() + + elif start_vm == "no" and vm.is_alive(): + vm.destroy() + + # Test device net or mac address + if if_device == "net" and vm.is_alive(): + device = if_name + # Get all vm's interface device + device = vm_xml.VMXML.get_net_dev(vm_name)[0] + + elif if_device == "mac": + device = mac_address + + # Setlink opertation + result = domif_setlink(vm_name, device, if_operation, options) + status = result.exit_status + logging.info("Setlink done") + + # Getlink opertation + get_result = domif_getlink(vm_name, device, options) + getlink_output = get_result.stdout.strip() + + # Check the getlink command output + if not re.search(if_operation, getlink_output) and status_error == "no": + raise error.TestFail("Getlink result should " + "equal with setlink operation ", getlink_output) + + logging.info("Getlink done") + # If --config is given should restart the vm then test link status + if options == "--config" and vm.is_alive(): + vm.destroy() + vm.start() + logging.info("Restart VM") + + elif start_vm == "no": + vm.start() + + if status_error == "no": + # Serial login the vm to check link status + # Start vm check the link statue + session = vm.wait_for_serial_login() + cmd = ("ip add |grep -i '%s' -B1|grep -i 'state %s' " + % (mac_address, if_operation)) + cmd_status, output = session.cmd_status_output(cmd) + logging.info("====%s==%s===", cmd_status, output ) + # Set the link up make host connect with vm + domif_setlink(vm_name, device, "up", "") + # Bring up referenced guest nic + guest_if_name = re.search(if_name_re, output).group(1) + # Ignore status of this one + cmd_status = session.cmd_status('ifdown %s' % guest_if_name) + cmd_status = session.cmd_status('ifup %s' % guest_if_name) + if cmd_status != 0: + raise error.TestFail("Could not bring up interface %s inside guest" + % guest_if_name) + else: # negative test + # stop guest, so state is always consistent on next start + vm.destroy() + + # Check status_error + + if status_error == "yes": + if status: + logging.info("Expected error (negative testing). Output: %s", + result.stderr.strip()) + + else: + raise error.TestFail("Unexpected return code %d " + "(negative testing)" % status) + elif status_error == "no": + status = cmd_status + if status: + raise error.TestFail("Unexpected error (positive testing). " + "Output: %s" % result.stderr.strip()) + + else: + raise error.TestError("Invalid value for status_error '%s' " + "(must be 'yes' or 'no')" % status_error) diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_domiftune.py b/libvirt/tests/src/virsh_cmd/domain/virsh_domiftune.py new file mode 100644 index 000000000..ad92c8813 --- /dev/null +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_domiftune.py @@ -0,0 +1,173 @@ +import logging +from autotest.client.shared import error +from virttest import virsh +from virttest.libvirt_xml import vm_xml + + +def check_domiftune(params): + """ + Compare inbound and outbound value with guest XML configuration + and virsh command output. + @params: the parameter dictionary + """ + vm_name = params.get("vms") + vm = params.get("vm") + interface = params.get("iface_dev") + options = params.get("options") + inbound = params.get("inbound", "") + outbound = params.get("outbound", "") + inbound_from_cmd_output = None + outbound_from_cmd_output = None + domiftune_params = {} + if vm and vm.is_alive(): + result = virsh.domiftune(vm_name, interface, options=options) + dicts = {} + o = result.stdout.strip().split("\n") + for l in o: + if l and l.find(':'): + k, v = l.split(':') + dicts[k.strip()] = v.strip() + + logging.debug(dicts) + inbound_from_cmd_output = dicts['inbound.average'] + outbound_from_cmd_output = dicts['outbound.average'] + + virt_xml_obj = vm_xml.VMXML(virsh_instance=virsh) + + if options == "config" and vm and vm.is_alive(): + domiftune_params = virt_xml_obj.get_iftune_params(vm_name, "--inactive") + elif vm and not vm.is_alive(): + logging.debug("The guest %s isn't running!", vm_name) + return True + else: + domiftune_params = virt_xml_obj.get_iftune_params(vm_name) + + inbound_from_xml = domiftune_params.get("inbound") + outbound_from_xml = domiftune_params.get("outbound") + + if vm and vm.is_alive() and options != "config": + if inbound and inbound != inbound_from_cmd_output: + logging.error("To expect inbound %s: %s", (inbound, + inbound_from_cmd_output)) + return False + if outbound and outbound != outbound_from_cmd_output: + logging.error("To expect inbound %s: %s", (outbound, + outbound_from_cmd_output)) + return False + if inbound and inbound_from_xml and inbound != inbound_from_xml: + logging.error("To expect outbound %s: %s", (inbound, + inbound_from_xml)) + return False + if outbound and outbound_from_xml and outbound != outbound_from_xml: + logging.error("To expect outbound %s: %s", (outbound, + outbound_from_xml)) + return False + + return True + +def get_domiftune_parameter(params): + """ + Get the domiftune parameters + @params: the parameter dictionary + """ + vm_name = params.get("vms") + options = params.get("options") + interface = params.get("iface_dev") + + result = virsh.domiftune(vm_name, interface, options=options) + status = result.exit_status + + # Check status_error + status_error = params.get("status_error", "no") + + if status_error == "yes": + if status: + logging.info("It's an expected error: %s", result.stderr) + else: + raise error.TestFail("%d not a expected command " + "return value", status) + elif status_error == "no": + if status: + raise error.TestFail(result.stderr) + else: + logging.info(result.stdout) + +def set_domiftune_parameter(params): + """ + Set the domiftune parameters + @params: the parameter dictionary + """ + vm_name = params.get("vms") + inbound = params.get("inbound") + outbound = params.get("outbound") + options = params.get("options", None) + interface = params.get("iface_dev") + + result = virsh.domiftune(vm_name, interface, options, inbound, outbound) + status = result.exit_status + + # Check status_error + status_error = params.get("status_error", "no") + + if status_error == "yes": + if status: + logging.info("It's an expected error: %s", result.stderr) + else: + raise error.TestFail("%d not a expected command " + "return value", status) + elif status_error == "no": + if status: + raise error.TestFail(result.stderr) + else: + if check_domiftune(params): + logging.info(result.stdout) + else: + error.TestFail("The 'inbound' or/and 'outbound' are" + " inconsistent with domiftune XML" + " and/or virsh command output") + +def run_virsh_domiftune(test, params, env): + """ + Test domiftune tuning + + 1) Positive testing + 1.1) get the current domiftune parameters for a running guest + 1.2) set the current domiftune parameters for a running guest + 2) Negative testing + 2.1) get domiftune parameters + 2.2) set domiftune parameters + """ + + # Run test case + vm_name = params.get("vms") + vm = env.get_vm(vm_name) + status_error = params.get("status_error", "no") + start_vm = params.get("start_vm", "yes") + change_parameters = params.get("change_parameters", "no") + interface = [] + + if vm and vm.is_alive(): + virt_xml_obj = vm_xml.VMXML(virsh_instance=virsh) + interface = virt_xml_obj.get_iface_dev(vm_name) + + test_dict = dict(params) + test_dict['vm'] = vm + if interface: + test_dict['iface_dev'] = interface[0] + + if start_vm == "no" and vm and vm.is_alive(): + vm.destroy() + + ########## positive and negative testing ######### + + if status_error == "no": + if change_parameters == "no": + get_domiftune_parameter(test_dict) + else: + set_domiftune_parameter(test_dict) + + if status_error == "yes": + if change_parameters == "no": + get_domiftune_parameter(test_dict) + else: + set_domiftune_parameter(test_dict) diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_domjobinfo.py b/libvirt/tests/src/virsh_cmd/domain/virsh_domjobinfo.py index 2f6de1eb5..b92531337 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_domjobinfo.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_domjobinfo.py @@ -1,6 +1,6 @@ import os from autotest.client.shared import error -from virttest import libvirt_vm, virsh +from virttest import virsh, utils_libvirtd def run_virsh_domjobinfo(test, params, env): @@ -50,13 +50,13 @@ def run_virsh_domjobinfo(test, params, env): vm_ref = params.get(vm_ref) if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() status = virsh.domjobinfo(vm_ref, ignore_status=True).exit_status #recover libvirtd service start if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() #check status_error if status_error == "yes": diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_domname.py b/libvirt/tests/src/virsh_cmd/domain/virsh_domname.py index 6b263ef65..c55f9362a 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_domname.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_domname.py @@ -1,6 +1,6 @@ import logging from autotest.client.shared import error -from virttest import libvirt_vm, virsh +from virttest import virsh, utils_libvirtd def run_virsh_domname(test, params, env): @@ -47,14 +47,14 @@ def run_virsh_domname(test, params, env): #Prepare libvirtd status libvirtd = params.get("libvirtd", "on") if libvirtd == "off": - libvirt_vm.service_libvirtd_control("stop") + utils_libvirtd.libvirtd_stop() result = virsh.domname(options, ignore_status=True, debug=True, uri=connect_uri) #Recover libvirtd service to start if libvirtd == "off": - libvirt_vm.service_libvirtd_control("start") + utils_libvirtd.libvirtd_start() addition_status_error = "yes" #check status_error diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_domuuid.py b/libvirt/tests/src/virsh_cmd/domain/virsh_domuuid.py index 941a0e1c7..b42d96176 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_domuuid.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_domuuid.py @@ -1,6 +1,6 @@ import logging from autotest.client.shared import error -from virttest import virsh, libvirt_vm, libvirt_xml +from virttest import virsh, libvirt_xml, utils_libvirtd def run_virsh_domuuid(test, params, env): @@ -40,7 +40,7 @@ def run_virsh_domuuid(test, params, env): # Prepare libvirtd state if libvirtd == "off": - libvirt_vm.service_libvirtd_control("stop") + utils_libvirtd.libvirtd_stop() result = virsh.domuuid(vm_ref) logging.debug(result) @@ -49,7 +49,7 @@ def run_virsh_domuuid(test, params, env): # Recover libvirtd service start if libvirtd == "off": - libvirt_vm.service_libvirtd_control("start") + utils_libvirtd.libvirtd_start() # Check status_error if status_error == "yes": diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_domxml_from_native.py b/libvirt/tests/src/virsh_cmd/domain/virsh_domxml_from_native.py index 257ea59c0..71a502752 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_domxml_from_native.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_domxml_from_native.py @@ -1,7 +1,7 @@ import re, os from autotest.client.shared import error from autotest.client import utils -from virttest import libvirt_vm, virsh +from virttest import virsh, utils_libvirtd def run_virsh_domxml_from_native(test, params, env): @@ -48,7 +48,7 @@ def virsh_convxml(guest_args): #libvirtd off if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() #Ignore exception with ignore_status=True. ret = virsh.domxml_from_native(dfn_format, guest_args, invalid_guest_args, @@ -57,7 +57,7 @@ def virsh_convxml(guest_args): #recover libvirtd service start if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() #clean up if os.path.exists(guest_args): diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_domxml_to_native.py b/libvirt/tests/src/virsh_cmd/domain/virsh_domxml_to_native.py index c6d37e353..a9851bbc2 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_domxml_to_native.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_domxml_to_native.py @@ -1,7 +1,7 @@ import re, os from autotest.client.shared import error from autotest.client import utils -from virttest import libvirt_vm, virsh +from virttest import virsh, utils_libvirtd def run_virsh_domxml_to_native(test, params, env): @@ -68,7 +68,7 @@ def compare(conv_arg): status_error = params.get("status_error") virsh.dumpxml(vm_name, extra="", to_file=file_xml) if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() ret = virsh.domxml_to_native(dtn_format, file_xml, extra_param, ignore_status = True) status = ret.exit_status @@ -76,7 +76,7 @@ def compare(conv_arg): #recover libvirtd service start if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() #clean up if os.path.exists(file_xml): diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_dump.py b/libvirt/tests/src/virsh_cmd/domain/virsh_dump.py index bbd780ae7..dda56640a 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_dump.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_dump.py @@ -1,6 +1,6 @@ import os, logging, commands, thread, time from autotest.client.shared import error -from virttest import libvirt_vm, virsh +from virttest import virsh, utils_libvirtd def check_flag(file_flag): """ @@ -150,7 +150,7 @@ def check_dump_format(dump_image_format, dump_file): if os.system(conf_cmd): logging.error("Config dump_image_format to %s fail", dump_image_format) - libvirt_vm.service_libvirtd_control("restart") + utils_libvirtd.libvirtd_restart() # Deal with bypass-cache option if options.find('bypass-cache') >= 0: @@ -164,7 +164,7 @@ def check_dump_format(dump_image_format, dump_file): status = cmd_result.exit_status # Check libvirtd status - if libvirt_vm.service_libvirtd_control("status"): + if utils_libvirtd.libvirtd_is_running(): if check_domstate(vm.state(), options): if status_error == "yes": if status == 0: diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_edit.py b/libvirt/tests/src/virsh_cmd/domain/virsh_edit.py index 2dc8ca089..82d83566d 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_edit.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_edit.py @@ -1,6 +1,8 @@ -import os, time +import os +import time + from autotest.client.shared import error -from virttest import libvirt_vm, virsh, aexpect +from virttest import virsh, aexpect, utils_libvirtd def run_virsh_edit(test, params, env): @@ -14,12 +16,17 @@ def run_virsh_edit(test, params, env): 4.Recover test environment. 5.Confirm the test result. """ - vm_name = params.get("main_vm") vm = env.get_vm(vm_name) domid = vm.get_id() domuuid = vm.get_uuid() + vcpucount_result = virsh.vcpucount(vm_name, options="--config") + if vcpucount_result.exit_status: + raise error.TestError("Failed to get vcpucount. Detail:\n%s" + % vcpucount_result) + original_vcpu = vcpucount_result.stdout.strip() + expected_vcpu = str(int(original_vcpu)+1) libvirtd = params.get("libvirtd", "on") vm_ref = params.get("edit_vm_ref") @@ -35,7 +42,6 @@ def modify_vcpu(source, edit_cmd): """ session = aexpect.ShellSession("sudo -s") try: - session.sendline("export EDITOR=vi") session.sendline("virsh edit %s" % source) session.sendline(edit_cmd) session.send('\x1b') @@ -55,10 +61,10 @@ def edit_vcpu(source, guest_name): @param: guest_name : vm's name. @return: True if edit successed,False if edit failed. """ - dic_mode = {"edit" : ":%s /1<\/vcpu>/2<\/vcpu>", - "recover" : ":%s /2<\/vcpu>/1<\/vcpu>"} + dic_mode = {"edit": ":%s /[0-9]*<\/vcpu>/"+expected_vcpu+"<\/vcpu>", + "recover": ":%s /[0-9]*<\/vcpu>/"+original_vcpu+"<\/vcpu>"} status = modify_vcpu(source, dic_mode["edit"]) - if not status : + if not status: return status if params.get("paused_after_start_vm") == "yes": virsh.resume(guest_name, ignore_status=True) @@ -68,7 +74,7 @@ def edit_vcpu(source, guest_name): vcpus = vm.dominfo()["CPU(s)"] #Recover cpuinfo status = modify_vcpu(source, dic_mode["recover"]) - if status and vcpus != '2': + if status and vcpus != expected_vcpu: return False return status @@ -77,7 +83,7 @@ def edit_vcpu(source, guest_name): virsh.dumpxml(vm_name, extra="", to_file=xml_file) if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() try: if vm_ref == "id": @@ -100,7 +106,7 @@ def edit_vcpu(source, guest_name): #recover libvirtd service start if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() #Recover VM if vm.is_alive(): diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_managedsave.py b/libvirt/tests/src/virsh_cmd/domain/virsh_managedsave.py index 9c80431eb..a577d55b4 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_managedsave.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_managedsave.py @@ -1,6 +1,6 @@ import re from autotest.client.shared import error -from virttest import libvirt_vm, virsh +from virttest import virsh, utils_libvirtd def run_virsh_managedsave(test, params, env): @@ -55,7 +55,7 @@ def vm_recover_check(guest_name): #stop the libvirtd service if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() #Ignore exception with "ignore_status=True" ret = virsh.managedsave(vm_ref, ignore_status=True) @@ -63,7 +63,7 @@ def vm_recover_check(guest_name): #recover libvirtd service start if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() #check status_error status_error = params.get("status_error") diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_memtune.py b/libvirt/tests/src/virsh_cmd/domain/virsh_memtune.py index 6e285b387..67bbb1bc8 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_memtune.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_memtune.py @@ -1,7 +1,14 @@ import logging, re, os, commands, string, math from autotest.client.shared import error from virttest import virsh, libvirt_vm -from autotest.client import utils, cgroup_utils + +try: + from autotest.client.shared import utils_memory + from autotest.client.shared import utils_cgroup +except ImportError: + from virttest.staging import utils_memory + from virttest.staging import utils_cgroup + def run_virsh_memtune(test, params, env): """ @@ -145,13 +152,13 @@ def check_hardswaplimit(path, expected_value): logging.info("Verify valid cgroup path for VM pid: %s", pid) # Resolve the memory cgroup path for a domain - path = cgroup_utils.resolve_task_cgroup_path(int(pid), "memory") + path = utils_cgroup.resolve_task_cgroup_path(int(pid), "memory") # Set the initial memory starting value for test case # By default set 1GB less than the total memory # In case of total memory is less than 1GB set to 256MB # visit subtests.cfg to change these default values - Memtotal = utils.read_from_meminfo('MemTotal') + Memtotal = utils_memory.read_from_meminfo('MemTotal') base_mem = params.get("memtune_base_mem") if int(Memtotal) < int(base_mem): diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_migrate.py b/libvirt/tests/src/virsh_cmd/domain/virsh_migrate.py index 7eb721c15..7bab0a1c9 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_migrate.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_migrate.py @@ -1,6 +1,6 @@ import logging, os, re, time, codecs from autotest.client.shared import error -from virttest import libvirt_vm, utils_test, virsh +from virttest import utils_test, virsh, utils_libvirtd def run_virsh_migrate(test, params, env): @@ -142,7 +142,7 @@ def do_migration(delay, vm, dest_uri, options, extra): # Turn libvirtd into certain state. logging.debug("Turning libvirtd into certain status.") if libvirtd_state == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() # Test uni-direction migration. logging.debug("Doing migration test.") @@ -155,7 +155,7 @@ def do_migration(delay, vm, dest_uri, options, extra): # Recover libvirtd state. logging.debug("Recovering libvirtd status.") if libvirtd_state == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() # Check vm state on destination. logging.debug("Checking %s state on %s." % (vm.name, vm.connect_uri)) diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_numatune.py b/libvirt/tests/src/virsh_cmd/domain/virsh_numatune.py index ca2bb6150..097b33084 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_numatune.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_numatune.py @@ -1,7 +1,11 @@ import re, logging from autotest.client.shared import error, utils -from virttest import libvirt_vm, libvirt_xml, virsh -from virttest import utils_cgroup +from virttest import libvirt_xml, virsh, utils_libvirtd +try: + from autotest.client.shared import utils_cgroup +except ImportError: + # TODO: Obsoleted path used prior autotest-0.15.2/virttest-2013.06.24 + from virttest.staging import utils_cgroup def num_numa_nodes(): @@ -234,11 +238,11 @@ def run_virsh_numatune(test, params, env): # and will start the guest after restarting libvirtd service if vm.is_alive(): vm.destroy() - if utils_cgroup.service_cgconfig_control("status"): - utils_cgroup.service_cgconfig_control("stop") + if utils_cgroup.cgconfig_is_running(): + utils_cgroup.cgconfig_stop() # Refresh libvirtd service to get latest cgconfig service change if libvirtd == "restart": - libvirt_vm.service_libvirtd_control("restart") + utils_libvirtd.libvirtd_restart() # Recover previous running guest if cgconfig == "off" and libvirtd == "restart" \ and not vm.is_alive() and start_vm == "yes": @@ -249,9 +253,9 @@ def run_virsh_numatune(test, params, env): else: set_numa_parameter(params) # Recover cgconfig and libvirtd service - if not utils_cgroup.service_cgconfig_control("status"): - utils_cgroup.service_cgconfig_control("start") - libvirt_vm.service_libvirtd_control("restart") + if not utils_cgroup.cgconfig_is_running(): + utils_cgroup.cgconfig_start() + utils_libvirtd.libvirtd_restart() finally: vm.destroy() # Restore guest, first remove existing diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_reboot.py b/libvirt/tests/src/virsh_cmd/domain/virsh_reboot.py index bdd7bea58..8fa21a893 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_reboot.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_reboot.py @@ -1,6 +1,6 @@ import re, logging from autotest.client.shared import error -from virttest import libvirt_vm, virsh, remote +from virttest import libvirt_vm, virsh, remote, utils_libvirtd def run_virsh_reboot(test, params, env): """ @@ -28,7 +28,7 @@ def run_virsh_reboot(test, params, env): domid = vm.get_id() domuuid = vm.get_uuid() if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() if vm_ref == "id": vm_ref = domid @@ -70,7 +70,7 @@ def run_virsh_reboot(test, params, env): #recover libvirtd service start if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() #check status_error if status_error == "yes": diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_restore.py b/libvirt/tests/src/virsh_cmd/domain/virsh_restore.py index 99d48c87c..bcbc77382 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_restore.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_restore.py @@ -1,6 +1,6 @@ import re, os from autotest.client.shared import error -from virttest import libvirt_vm, virsh +from virttest import virsh, utils_libvirtd def run_virsh_restore(test, params, env): @@ -50,7 +50,7 @@ def run_virsh_restore(test, params, env): if pre_status == "start": virsh.start(vm_name) if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() status = virsh.restore(vm_ref, ignore_status=True).exit_status if os.path.exists(tmp_file): os.unlink(tmp_file) @@ -61,7 +61,7 @@ def run_virsh_restore(test, params, env): #recover libvirtd service start if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() if vm.is_alive(): vm.destroy() diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_save.py b/libvirt/tests/src/virsh_cmd/domain/virsh_save.py index 1475be688..3408ff5c9 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_save.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_save.py @@ -1,6 +1,6 @@ import os from autotest.client.shared import error -from virttest import libvirt_vm, virsh +from virttest import virsh, utils_libvirtd def run_virsh_save(test, params, env): @@ -54,12 +54,12 @@ def run_virsh_save(test, params, env): vm_ref = vm_name if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() status = virsh.save(vm_ref, savefile, ignore_status=True).exit_status # recover libvirtd service start if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() # cleanup if os.path.exists(savefile): diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_schedinfo_qemu_posix.py b/libvirt/tests/src/virsh_cmd/domain/virsh_schedinfo_qemu_posix.py index 152407e82..2ccd55896 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_schedinfo_qemu_posix.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_schedinfo_qemu_posix.py @@ -1,8 +1,12 @@ -import re, logging -from autotest.client import cgroup_utils +import re, logging, os from autotest.client.shared import utils, error from virttest import virsh +try: + from autotest.client.shared import utils_cgroup +except ImportError: + from virttest.staging import utils_cgroup + def run_virsh_schedinfo_qemu_posix(test, params, env): """ @@ -33,12 +37,18 @@ def get_parameter_in_cgroup(domname, controller="cpu", else return value's result object. """ try: - ctl_mount = cgroup_utils.get_cgroup_mountpoint(controller) + ctl_mount = utils_cgroup.get_cgroup_mountpoint(controller) except IndexError: return None if ctl_mount is not False: - get_value_cmd = "cat %s/%s/%s/%s" % (ctl_mount, - libvirt_cgroup_path, domname, parameter) + cgroup_path = os.path.join(ctl_mount, libvirt_cgroup_path, + domname, parameter) + if not os.path.exists(cgroup_path): + cgroup_path = os.path.join(ctl_mount, "machine", domname + + ".libvirt-qemu", parameter) + if not os.path.exists(cgroup_path): + raise error.TestNAError("Unknown path to cgroups") + get_value_cmd = "cat %s" % cgroup_path result = utils.run(get_value_cmd, ignore_status=True) return result.stdout.strip() else: diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_setmem.py b/libvirt/tests/src/virsh_cmd/domain/virsh_setmem.py index 3c1b602f8..b2b196355 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_setmem.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_setmem.py @@ -1,6 +1,6 @@ import re, logging, time from autotest.client.shared import error -from virttest import libvirt_vm, virsh +from virttest import virsh, utils_libvirtd def run_virsh_setmem(test, params, env): @@ -164,9 +164,9 @@ def print_debug_stats(original_inside_mem, original_outside_mem, # Prepare libvirtd status if libvirt == "off": - libvirt_vm.service_libvirtd_control("stop") + utils_libvirtd.libvirtd_stop() else: # make sure it's running - libvirt_vm.service_libvirtd_control("restart") + utils_libvirtd.libvirtd_restart() if status_error == "yes" or old_libvirt_fail == "yes": logging.info("Error Test: Expecting an error to occur!") @@ -176,7 +176,7 @@ def print_debug_stats(original_inside_mem, original_outside_mem, # Recover libvirtd status if libvirt == "off": - libvirt_vm.service_libvirtd_control("start") + utils_libvirtd.libvirtd_start() if status is 0: logging.info("Waiting %d seconds for VM memory to settle", quiesce_delay) diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_setvcpus.py b/libvirt/tests/src/virsh_cmd/domain/virsh_setvcpus.py index 205a99650..adc575108 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_setvcpus.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_setvcpus.py @@ -1,6 +1,6 @@ import re, os, logging, commands from autotest.client.shared import error -from virttest import remote, libvirt_vm, virsh, libvirt_xml +from virttest import remote, virsh, libvirt_xml from xml.dom.minidom import parse def run_virsh_setvcpus(test, params, env): diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_shutdown.py b/libvirt/tests/src/virsh_cmd/domain/virsh_shutdown.py index 7ca6b0814..64f282a44 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_shutdown.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_shutdown.py @@ -1,5 +1,5 @@ from autotest.client.shared import error -from virttest import remote, libvirt_vm, virsh +from virttest import remote, libvirt_vm, virsh, utils_libvirtd def run_virsh_shutdown(test, params, env): @@ -37,7 +37,7 @@ def run_virsh_shutdown(test, params, env): vm_ref = domuuid if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() if vm_ref != "remote": status = virsh.shutdown(vm_ref, ignore_status = True).exit_status @@ -59,7 +59,7 @@ def run_virsh_shutdown(test, params, env): #recover libvirtd service start if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() #check status_error status_error = params.get("status_error") diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_start.py b/libvirt/tests/src/virsh_cmd/domain/virsh_start.py index 57ee9f498..29bbc472a 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_start.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_start.py @@ -1,5 +1,5 @@ from autotest.client.shared import error -from virttest import remote, libvirt_vm, virsh, libvirt_xml +from virttest import remote, libvirt_vm, virsh, libvirt_xml, utils_libvirtd class StartError(Exception): @@ -63,9 +63,9 @@ def run_virsh_start(test, params, env): try: #prepare before start vm if libvirtd_state == "on": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() elif libvirtd_state == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() if pre_operation == "rename": new_vm_name = params.get("vs_new_vm_name", "virsh_start_vm1") @@ -103,9 +103,10 @@ def run_virsh_start(test, params, env): finally: #clean up if libvirtd_state == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() if (pre_operation == "undefine") and (not vmxml.xml == None): - vmxml.define() + if not vmxml.define(): + raise error.TestError("Restore vm failed.") elif pre_operation == "rename": libvirt_xml.VMXML.vm_rename(vm, backup_name) diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_ttyconsole.py b/libvirt/tests/src/virsh_cmd/domain/virsh_ttyconsole.py index 008bbaa17..8ac17f7b4 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_ttyconsole.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_ttyconsole.py @@ -17,12 +17,11 @@ def xml_console_recover(vmxml): """ Recover older xml config with backup vmxml. """ - try: - vmxml.undefine() - vmxml.define() + vmxml.undefine() + if vmxml.define(): return True - except xcepts.LibvirtXMLError, detail: - logging.error("Recover older serial failed:%s.", detail) + else: + logging.error("Recover older serial failed:%s.", vmxml.get('xml')) return False diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_undefine.py b/libvirt/tests/src/virsh_cmd/domain/virsh_undefine.py index 9dd57ffc1..8d6334383 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_undefine.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_undefine.py @@ -1,6 +1,6 @@ import os, logging from autotest.client.shared import error -from virttest import libvirt_vm, virsh, remote +from virttest import libvirt_vm, virsh, remote, utils_libvirtd def run_virsh_undefine(test, params, env): """ @@ -49,7 +49,7 @@ def run_virsh_undefine(test, params, env): # Turn libvirtd into certain state. if libvirtd_state == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() # Test virsh undefine command. status = 0 @@ -80,7 +80,7 @@ def run_virsh_undefine(test, params, env): # Recover libvirtd state. if libvirtd_state == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() # Shutdown VM. if virsh.domain_exists(vm.name, uri=uri): diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_vcpuinfo.py b/libvirt/tests/src/virsh_cmd/domain/virsh_vcpuinfo.py index 0484bcac9..f88bbca6c 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_vcpuinfo.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_vcpuinfo.py @@ -1,5 +1,5 @@ from autotest.client.shared import error -from virttest import virsh, libvirt_vm +from virttest import virsh, utils_libvirtd def run_virsh_vcpuinfo(test, params, env): """ @@ -18,7 +18,7 @@ def run_virsh_vcpuinfo(test, params, env): status_error = params.get("status_error", "no") libvirtd = params.get("libvirtd", "on") if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() #run test case vm_ref = params.get("vcpuinfo_vm_ref") @@ -85,7 +85,7 @@ def remote_case(params, vm_name): #recover libvirtd service start if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() #check status_error if status_error == "yes": diff --git a/libvirt/tests/src/virsh_cmd/domain/virsh_vncdisplay.py b/libvirt/tests/src/virsh_cmd/domain/virsh_vncdisplay.py index 2141f327f..461a56ae7 100644 --- a/libvirt/tests/src/virsh_cmd/domain/virsh_vncdisplay.py +++ b/libvirt/tests/src/virsh_cmd/domain/virsh_vncdisplay.py @@ -1,6 +1,5 @@ -import logging from autotest.client.shared import error -from virttest import libvirt_vm, virsh, remote +from virttest import libvirt_vm, virsh, remote, utils_libvirtd def run_virsh_vncdisplay(test, params, env): """ @@ -65,7 +64,7 @@ def remote_case(params, vm_name): vm_ref = domuuid if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() if vm_ref == "remote": status, output = remote_case(params, vm_name) @@ -75,7 +74,7 @@ def remote_case(params, vm_name): output = result.stdout.strip() if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() #check status_error if status_error == "yes": diff --git a/libvirt/tests/src/virsh_cmd/host/virsh_capabilities.py b/libvirt/tests/src/virsh_cmd/host/virsh_capabilities.py index cc7235a31..37afb39c8 100644 --- a/libvirt/tests/src/virsh_cmd/host/virsh_capabilities.py +++ b/libvirt/tests/src/virsh_cmd/host/virsh_capabilities.py @@ -1,7 +1,7 @@ import logging, re from xml.dom.minidom import parseString from autotest.client.shared import utils, error -from virttest import libvirt_vm, virsh +from virttest import libvirt_vm, virsh, utils_libvirtd def run_virsh_capabilities(test, params, env): """ @@ -72,7 +72,7 @@ def compare_capabilities_xml(source): if params.has_key("libvirtd"): libvirtd = params.get("libvirtd") if libvirtd == "off": - libvirt_vm.service_libvirtd_control("stop") + utils_libvirtd.libvirtd_stop() # Run test case option = params.get("virsh_cap_options") @@ -86,7 +86,7 @@ def compare_capabilities_xml(source): # Recover libvirtd service start if libvirtd == "off": - libvirt_vm.service_libvirtd_control("start") + utils_libvirtd.libvirtd_start() # Check status_error status_error = params.get("status_error") diff --git a/libvirt/tests/src/virsh_cmd/host/virsh_freecell.py b/libvirt/tests/src/virsh_cmd/host/virsh_freecell.py index fc0b00c3a..33937c86e 100644 --- a/libvirt/tests/src/virsh_cmd/host/virsh_freecell.py +++ b/libvirt/tests/src/virsh_cmd/host/virsh_freecell.py @@ -1,6 +1,6 @@ import re from autotest.client.shared import error -from virttest import libvirt_vm, virsh +from virttest import libvirt_vm, virsh, utils_libvirtd def run_virsh_freecell(test, params, env): """ @@ -22,7 +22,7 @@ def run_virsh_freecell(test, params, env): if check_libvirtd: libvirtd = params.get("libvirtd") if libvirtd == "off": - libvirt_vm.service_libvirtd_control("stop") + utils_libvirtd.libvirtd_stop() # Run test case cmd_result = virsh.freecell(ignore_status=True, extra=option, @@ -32,7 +32,7 @@ def run_virsh_freecell(test, params, env): # Recover libvirtd service start if libvirtd == "off": - libvirt_vm.service_libvirtd_control("start") + utils_libvirtd.libvirtd_start() # Check the output if virsh.has_help_command('numatune'): diff --git a/libvirt/tests/src/virsh_cmd/host/virsh_hostname.py b/libvirt/tests/src/virsh_cmd/host/virsh_hostname.py index 983a7f683..58f43d469 100644 --- a/libvirt/tests/src/virsh_cmd/host/virsh_hostname.py +++ b/libvirt/tests/src/virsh_cmd/host/virsh_hostname.py @@ -1,5 +1,5 @@ from autotest.client.shared import utils, error -from virttest import libvirt_vm, virsh +from virttest import virsh, utils_libvirtd def run_virsh_hostname(test, params, env): @@ -19,7 +19,7 @@ def run_virsh_hostname(test, params, env): if check_libvirtd: libvirtd = params.get("libvirtd") if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() # Run test case option = params.get("virsh_hostname_options") @@ -34,7 +34,7 @@ def run_virsh_hostname(test, params, env): # Recover libvirtd service start if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() # Check status_error status_error = params.get("status_error") diff --git a/libvirt/tests/src/virsh_cmd/host/virsh_nodecpustats.py b/libvirt/tests/src/virsh_cmd/host/virsh_nodecpustats.py index 038b09839..9542ae100 100644 --- a/libvirt/tests/src/virsh_cmd/host/virsh_nodecpustats.py +++ b/libvirt/tests/src/virsh_cmd/host/virsh_nodecpustats.py @@ -1,7 +1,7 @@ import re from autotest.client.shared import error from autotest.client import utils -from virttest import libvirt_vm, virsh +from virttest import virsh, utils_libvirtd def run_virsh_nodecpustats(test, params, env): """ @@ -133,7 +133,7 @@ def parse_percentage_output(output): # Prepare libvirtd service if libvirtd == "off": - libvirt_vm.service_libvirtd_control("stop") + utils_libvirtd.libvirtd_stop() # Get the host cpu count host_cpu_count = utils.count_cpus() @@ -147,7 +147,7 @@ def parse_percentage_output(output): if status == 0: if libvirtd == "off": - libvirt_vm.service_libvirtd_control("start") + utils_libvirtd.libvirtd_start() raise error.TestFail("Command 'virsh nodecpustats' " "succeeded with libvirtd service " "stopped, incorrect") @@ -209,4 +209,4 @@ def parse_percentage_output(output): # Recover libvirtd service start if libvirtd == "off": - libvirt_vm.service_libvirtd_control("start") + utils_libvirtd.libvirtd_start() diff --git a/libvirt/tests/src/virsh_cmd/host/virsh_nodeinfo.py b/libvirt/tests/src/virsh_cmd/host/virsh_nodeinfo.py index 8b126b57c..e25f1eaa3 100644 --- a/libvirt/tests/src/virsh_cmd/host/virsh_nodeinfo.py +++ b/libvirt/tests/src/virsh_cmd/host/virsh_nodeinfo.py @@ -1,7 +1,12 @@ import re, logging from autotest.client import utils from autotest.client.shared import error -from virttest import libvirt_vm, virsh +from virttest import virsh, utils_libvirtd + +try: + from autotest.client.shared import utils_memory +except ImportError: + from virttest.staging import utils_memory def run_virsh_nodeinfo(test, params, env): @@ -66,7 +71,7 @@ def output_check(nodeinfo_output): # Check Memory size memory_size_nodeinfo = int(_check_nodeinfo(nodeinfo_output, 'Memory size', 3)) - memory_size_os = utils.memtotal() + memory_size_os = utils_memory.memtotal() if memory_size_nodeinfo != memory_size_os: raise error.TestFail("Virsh nodeinfo output didn't match " "Memory size") @@ -77,7 +82,7 @@ def output_check(nodeinfo_output): if check_libvirtd: libvirtd = params.get("libvirtd") if libvirtd == "off": - libvirt_vm.service_libvirtd_control("stop") + utils_libvirtd.libvirtd_stop() # Run test case option = params.get("virsh_node_options") @@ -91,7 +96,7 @@ def output_check(nodeinfo_output): # Recover libvirtd service start if libvirtd == "off": - libvirt_vm.service_libvirtd_control("start") + utils_libvirtd.libvirtd_start() # Check status_error status_error = params.get("status_error") diff --git a/libvirt/tests/src/virsh_cmd/host/virsh_nodememstats.py b/libvirt/tests/src/virsh_cmd/host/virsh_nodememstats.py index b6129827b..8db325ac3 100644 --- a/libvirt/tests/src/virsh_cmd/host/virsh_nodememstats.py +++ b/libvirt/tests/src/virsh_cmd/host/virsh_nodememstats.py @@ -1,7 +1,13 @@ import logging, re from autotest.client.shared import error -from autotest.client import utils -from virttest import libvirt_vm, virsh +from virttest import virsh, utils_libvirtd + + +try: + from autotest.client.shared import utils_memory +except ImportError: + from virttest.staging import utils_memory + def run_virsh_nodememstats(test, params, env): """ @@ -50,7 +56,7 @@ def virsh_check_nodememtats(actual_stats, expected_stats, delta): if check_libvirtd: libvirtd = params.get("libvirtd") if libvirtd == "off": - libvirt_vm.service_libvirtd_control("stop") + utils_libvirtd.libvirtd_stop() # Get the option for the test case option = params.get("virsh_nodememstats_options") @@ -69,7 +75,7 @@ def virsh_check_nodememtats(actual_stats, expected_stats, delta): if status_error == "yes": if status == 0: if libvirtd == "off": - libvirt_vm.service_libvirtd_control("start") + utils_libvirtd.libvirtd_start() raise error.TestFail("Command 'virsh nodememstats' " "succeeded with libvirtd service" " stopped, incorrect") @@ -102,10 +108,10 @@ def virsh_check_nodememtats(actual_stats, expected_stats, delta): expected[name] = int(value) / 1024 # Get the actual value from /proc/meminfo and normalise to MBs - actual['total'] = int(utils.memtotal()) / 1024 - actual['free'] = int(utils.freememtotal()) / 1024 - actual['buffers'] = int(utils.read_from_meminfo('Buffers'))/1024 - actual['cached'] = int(utils.read_from_meminfo('Cached')) / 1024 + actual['total'] = int(utils_memory.memtotal()) / 1024 + actual['free'] = int(utils_memory.freememtotal()) / 1024 + actual['buffers'] = int(utils_memory.read_from_meminfo('Buffers'))/1024 + actual['cached'] = int(utils_memory.read_from_meminfo('Cached')) / 1024 # Currently the delta value is kept at 200 MB this can be # tuned based on the accuracy @@ -120,7 +126,7 @@ def virsh_check_nodememtats(actual_stats, expected_stats, delta): # Recover libvirtd service start if libvirtd == "off": - libvirt_vm.service_libvirtd_control("start") + utils_libvirtd.libvirtd_start() # Print the deviated values for all iterations if status_error == "no": diff --git a/libvirt/tests/src/virsh_cmd/host/virsh_uri.py b/libvirt/tests/src/virsh_cmd/host/virsh_uri.py index 5c58df54e..80155af15 100644 --- a/libvirt/tests/src/virsh_cmd/host/virsh_uri.py +++ b/libvirt/tests/src/virsh_cmd/host/virsh_uri.py @@ -1,6 +1,6 @@ import logging from autotest.client.shared import error -from virttest import libvirt_vm, virsh +from virttest import libvirt_vm, virsh, utils_libvirtd def run_virsh_uri(test, params, env): """ @@ -31,7 +31,7 @@ def run_virsh_uri(test, params, env): if check_libvirtd: libvirtd = params.get("libvirtd") if libvirtd == "off": - libvirt_vm.service_libvirtd_control("stop") + utils_libvirtd.libvirtd_stop() # Run test case logging.info("The command: %s", cmd) @@ -48,7 +48,7 @@ def run_virsh_uri(test, params, env): # Recover libvirtd service start if libvirtd == "off": - libvirt_vm.service_libvirtd_control("start") + utils_libvirtd.libvirtd_start() # Check status_error status_error = params.get("status_error") diff --git a/libvirt/tests/src/virsh_cmd/host/virsh_version.py b/libvirt/tests/src/virsh_cmd/host/virsh_version.py index e155b08eb..396b15b31 100644 --- a/libvirt/tests/src/virsh_cmd/host/virsh_version.py +++ b/libvirt/tests/src/virsh_cmd/host/virsh_version.py @@ -1,5 +1,5 @@ from autotest.client.shared import error -from virttest import libvirt_vm, virsh +from virttest import libvirt_vm, virsh, utils_libvirtd def run_virsh_version(test, params, env): @@ -19,7 +19,7 @@ def run_virsh_version(test, params, env): if check_libvirtd: libvirtd = params.get("libvirtd") if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() # Run test case option = params.get("virsh_version_options") @@ -32,7 +32,7 @@ def run_virsh_version(test, params, env): # Recover libvirtd service start if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() # Check status_error status_error = params.get("status_error") diff --git a/libvirt/tests/src/virsh_cmd/monitor/virsh_domblkstat.py b/libvirt/tests/src/virsh_cmd/monitor/virsh_domblkstat.py index bbc397380..a7f3878a9 100644 --- a/libvirt/tests/src/virsh_cmd/monitor/virsh_domblkstat.py +++ b/libvirt/tests/src/virsh_cmd/monitor/virsh_domblkstat.py @@ -1,5 +1,5 @@ from autotest.client.shared import error -from virttest import libvirt_vm, virsh, libvirt_xml +from virttest import virsh, libvirt_xml, utils_libvirtd def run_virsh_domblkstat(test, params, env): """ @@ -46,7 +46,7 @@ def run_virsh_domblkstat(test, params, env): status_error = "yes" break if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() result = virsh.domblkstat(vm_ref, blk, options, ignore_status=True) status = result.exit_status @@ -55,7 +55,7 @@ def run_virsh_domblkstat(test, params, env): #recover libvirtd service start if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() #check status_error if status_error == "yes": if status == 0 or err == "": diff --git a/libvirt/tests/src/virsh_cmd/monitor/virsh_domifstat.py b/libvirt/tests/src/virsh_cmd/monitor/virsh_domifstat.py index 74ec923d2..e7bae1bb1 100644 --- a/libvirt/tests/src/virsh_cmd/monitor/virsh_domifstat.py +++ b/libvirt/tests/src/virsh_cmd/monitor/virsh_domifstat.py @@ -1,5 +1,5 @@ from autotest.client.shared import error, utils -from virttest import libvirt_vm, virsh +from virttest import virsh, utils_libvirtd from xml.dom.minidom import parseString @@ -68,13 +68,13 @@ def get_interface(guest_name): interface = "%s %s" % (interface, params.get("domifstat_extra")) if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() status = virsh.domifstat(vm_ref, interface, ignore_status=True).exit_status #recover libvirtd service start if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() #check status_error if status_error == "yes": diff --git a/libvirt/tests/src/virsh_cmd/monitor/virsh_dominfo.py b/libvirt/tests/src/virsh_cmd/monitor/virsh_dominfo.py index f16fb0846..50cf99e12 100644 --- a/libvirt/tests/src/virsh_cmd/monitor/virsh_dominfo.py +++ b/libvirt/tests/src/virsh_cmd/monitor/virsh_dominfo.py @@ -1,5 +1,5 @@ from autotest.client.shared import error -from virttest import libvirt_vm, remote, virsh +from virttest import libvirt_vm, remote, virsh, utils_libvirtd def run_virsh_dominfo(test, params, env): """ @@ -71,7 +71,7 @@ def remote_test(params, vm_name): vm_ref = domuuid if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() if vm_ref != "remote": result = virsh.dominfo(vm_ref, ignore_status=True) @@ -83,7 +83,7 @@ def remote_test(params, vm_name): #recover libvirtd service start if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() #check status_error if status_error == "yes": diff --git a/libvirt/tests/src/virsh_cmd/monitor/virsh_dommemstat.py b/libvirt/tests/src/virsh_cmd/monitor/virsh_dommemstat.py index 1a3681255..d10ea582c 100644 --- a/libvirt/tests/src/virsh_cmd/monitor/virsh_dommemstat.py +++ b/libvirt/tests/src/virsh_cmd/monitor/virsh_dommemstat.py @@ -1,5 +1,5 @@ from autotest.client.shared import error -from virttest import libvirt_vm, virsh, remote +from virttest import libvirt_vm, virsh, remote, utils_libvirtd def run_virsh_dommemstat(test, params, env): """ @@ -23,7 +23,7 @@ def run_virsh_dommemstat(test, params, env): libvirtd = params.get("libvirtd", "on") extra = params.get("dommemstat_extra", "") if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() #run test case if vm_ref == "id": @@ -39,7 +39,7 @@ def run_virsh_dommemstat(test, params, env): vm_ref = "%s" % vm_name if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() if vm_ref != "remote": status = virsh.dommemstat(vm_ref, extra, ignore_status=True, @@ -65,7 +65,7 @@ def run_virsh_dommemstat(test, params, env): #recover libvirtd service start if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() #check status_error if status_error == "yes": diff --git a/libvirt/tests/src/virsh_cmd/monitor/virsh_domstate.py b/libvirt/tests/src/virsh_cmd/monitor/virsh_domstate.py index 14dc10625..21e34ca42 100644 --- a/libvirt/tests/src/virsh_cmd/monitor/virsh_domstate.py +++ b/libvirt/tests/src/virsh_cmd/monitor/virsh_domstate.py @@ -1,6 +1,6 @@ import re from autotest.client.shared import error -from virttest import libvirt_vm, remote, virsh +from virttest import libvirt_vm, remote, virsh, utils_libvirtd def run_virsh_domstate(test, params, env): """ @@ -34,7 +34,7 @@ def run_virsh_domstate(test, params, env): vm_ref = domuuid if libvirtd == "off": - libvirt_vm.libvirtd_stop() + utils_libvirtd.libvirtd_stop() if vm_ref == "remote": remote_ip = params.get("remote_ip", "REMOTE.EXAMPLE.COM") @@ -61,7 +61,7 @@ def run_virsh_domstate(test, params, env): #recover libvirtd service start if libvirtd == "off": - libvirt_vm.libvirtd_start() + utils_libvirtd.libvirtd_start() #check status_error if status_error == "yes": diff --git a/libvirt/tests/src/virsh_cmd/monitor/virsh_list.py b/libvirt/tests/src/virsh_cmd/monitor/virsh_list.py index 63bab1a17..943ebbb3f 100644 --- a/libvirt/tests/src/virsh_cmd/monitor/virsh_list.py +++ b/libvirt/tests/src/virsh_cmd/monitor/virsh_list.py @@ -1,6 +1,6 @@ import re, logging, time from autotest.client.shared import error -from virttest import virsh, libvirt_vm, remote +from virttest import virsh, libvirt_vm, remote, utils_libvirtd def run_virsh_list(test, params, env): @@ -67,7 +67,7 @@ def list_local_domains_on_remote(options_ref, remote_ip, remote_passwd, local_ip #Prepare libvirtd status libvirtd = params.get("libvirtd", "on") if libvirtd == "off": - libvirt_vm.service_libvirtd_control("stop") + utils_libvirtd.libvirtd_stop() #run test case if list_ref == "--uuid": @@ -112,7 +112,7 @@ def list_local_domains_on_remote(options_ref, remote_ip, remote_passwd, local_ip #Recover libvirtd service status if libvirtd == "off": - libvirt_vm.service_libvirtd_control("start") + utils_libvirtd.libvirtd_start() #Recover of domain if vm_ref == "transient": diff --git a/libvirt/tests/src/virsh_cmd/network/virsh_net_autostart.py b/libvirt/tests/src/virsh_cmd/network/virsh_net_autostart.py index f6c2e7a43..985086245 100644 --- a/libvirt/tests/src/virsh_cmd/network/virsh_net_autostart.py +++ b/libvirt/tests/src/virsh_cmd/network/virsh_net_autostart.py @@ -1,6 +1,6 @@ import logging from autotest.client.shared import error -from virttest import virsh, libvirt_vm +from virttest import virsh, libvirt_vm, utils_libvirtd from virttest.libvirt_xml import network_xml, xcepts @@ -77,7 +77,7 @@ def run_virsh_net_autostart(test, params, env): # Check if autostart or disable is successful with libvirtd restart. # TODO: Since autostart is designed for host reboot, # we'd better check it with host reboot. - libvirt_vm.libvirtd_restart() + utils_libvirtd.libvirtd_restart() # Reopen default_xml virsh_instance = virsh.VirshPersistent(**virsh_dargs) diff --git a/libvirt/tests/src/virsh_cmd/network/virsh_net_list.py b/libvirt/tests/src/virsh_cmd/network/virsh_net_list.py index 130822654..e246d899f 100644 --- a/libvirt/tests/src/virsh_cmd/network/virsh_net_list.py +++ b/libvirt/tests/src/virsh_cmd/network/virsh_net_list.py @@ -1,5 +1,5 @@ import re, os -from autotest.client.shared import utils, error +from autotest.client.shared import error from virttest import virsh def run_virsh_net_list(test, params, env): diff --git a/libvirt/tests/src/virsh_cmd/nodedev/virsh_nodedev_detach_reattach.py b/libvirt/tests/src/virsh_cmd/nodedev/virsh_nodedev_detach_reattach.py new file mode 100644 index 000000000..1a70ea836 --- /dev/null +++ b/libvirt/tests/src/virsh_cmd/nodedev/virsh_nodedev_detach_reattach.py @@ -0,0 +1,87 @@ +import os, logging +from autotest.client.shared import error +from virttest import virsh +from virttest.libvirt_xml import nodedev_xml + + +def driver_readlink(device_name): + """ + readlink the driver of device. + """ + nodedevxml = nodedev_xml.NodedevXML.new_from_dumpxml(device_name) + driver_path = ('%s/driver') % (nodedevxml.get_sysfs_path()) + try: + driver = os.readlink(driver_path) + except (OSError, UnicodeError): + return None + return driver + +def do_nodedev_detach_reattach(device_name): + """ + do the detach and reattach. + + (1).do detach. + (2).check the result of detach. + (3).do reattach. + (4).check the result of reattach + """ + #do the detach + logging.debug('Node device name is %s.' % device_name) + CmdResult = virsh.nodedev_detach(device_name) + #check the exit_status. + if CmdResult.exit_status: + raise error.TestFail("Failed to detach %s.\n" + "Detail: %s." + % (device_name, CmdResult.stderr)) + #check the driver. + driver = driver_readlink(device_name) + logging.debug('Driver after detach is %s.' % driver) + if (driver is None) or (not driver.endswith('pci-stub')): + raise error.TestFail("Driver for %s is not pci-stub " + "after nodedev-detach" % (device_name)) + else: + pass + logging.debug('Nodedev-detach %s successed.' % device_name) + #do the reattach. + CmdResult = virsh.nodedev_reattach(device_name) + #check the exit_status. + if CmdResult.exit_status: + raise error.TestFail("Failed to reattach %s.\n" + "Detail: %s." + % (device_name, CmdResult.stderr)) + #check the driver. + driver = driver_readlink(device_name) + if (driver is None) or (not driver.endswith('pci-stub')): + pass + else: + raise error.TestFail("Driver for %s is not be reset after " + "nodedev-reattach" % (device_name)) + logging.debug('Nodedev-reattach %s successed.' % device_name) + +def run_virsh_nodedev_detach_reattach(test, params, env): + """ + Test virsh nodedev-detach and virsh nodedev-reattach + + (1).Init variables for test. + (2).Check variables. + (3).do nodedev_detach_reattach. + """ + #Init variables + device_name = params.get('nodedev_device_name', 'ENTER.YOUR.PCI.DEVICE') + status_error = ('yes' == params.get('status_error', 'no')) + #check variables. + if device_name.count('ENTER'): + raise error.TestNAError('Param device_name is not configured.') + #do nodedev_detach_reattach + try: + do_nodedev_detach_reattach(device_name) + except error.TestFail, e: + #Do nodedev detach and reattach failed. + if status_error: + return + else: + raise error.TestFail("Test failed in positive case." + "error: %s" % e) + #Do nodedev detach and reattach success. + if status_error: + raise error.TestFail('Test successed in negative case.') diff --git a/libvirt/tests/src/virsh_cmd/nodedev/virsh_nodedev_dumpxml.py b/libvirt/tests/src/virsh_cmd/nodedev/virsh_nodedev_dumpxml.py new file mode 100644 index 000000000..af3e99779 --- /dev/null +++ b/libvirt/tests/src/virsh_cmd/nodedev/virsh_nodedev_dumpxml.py @@ -0,0 +1,82 @@ +import logging +from autotest.client import utils +from autotest.client.shared import error +from virttest import virsh +from virttest.libvirt_xml import nodedev_xml + + +def do_nodedev_dumpxml(dev_name, dev_opt=""): + """ + Do dumpxml and check the result. + + (1).execute nodedev-dumpxml command. + (2).compare info in xml with info in sysfs. + + @param dev_name: name of device. + @raise TestFail: if execute command failed + or check result failed. + """ + result = virsh.nodedev_dumpxml(dev_name, options=dev_opt) + if result.exit_status: + raise error.TestError("Dumpxml node device %s failed.\n" + "Detail:%s." % (dev_name, result.stderr)) + logging.debug('Executing "virsh nodedev-dumpxml %s" finished.', dev_name) + #compare info in xml with info in sysfs. + nodedevxml = nodedev_xml.NodedevXML.new_from_dumpxml(dev_name) + if not nodedevxml.validates: + raise error.TestError("nodedvxml of %s is not validated." % (dev_name)) + #Get the dict of key to value in xml. + #key2value_dict_xml contain the all keys and values in xml need checking. + key2value_dict_xml = nodedevxml.get_key2value_dict() + #Get the dict of key to path in sysfs. + #key2syspath_dict contain the all keys and the path of file which contain + # infomation for each key. + key2syspath_dict = nodedevxml.get_key2syspath_dict() + #Get the values contained in files. + #key2value_dict_sys contain the all keys and values in sysfs. + key2value_dict_sys = {} + for key, filepath in key2syspath_dict.items(): + value = utils.read_one_line(filepath) + key2value_dict_sys[key] = value + + #Compare the value in xml and in syspath. + for key in key2value_dict_xml: + value_xml = key2value_dict_xml.get(key) + value_sys = key2value_dict_sys.get(key) + if not value_xml == value_sys: + raise error.TestError("key: %s in xml is %s," + "but in sysfs is %s." % + (key, value_xml, value_sys)) + else: + continue + + logging.debug("Compare info in xml and info in sysfs finished" + "for device %s.", dev_name) + + +def run_virsh_nodedev_dumpxml(test, params, env): + """ + Test command virsh nodedev-dumpxml. + + (1).get param from params. + (2).do nodedev dumpxml. + (3).clean up. + """ + #Init variables. + status_error = ('yes' == params.get('status_error', 'no')) + device_name = params.get('nodedev_device_name', None) + device_opt = params.get('nodedev_device_opt', "") + + #do nodedev dumpxml. + try: + do_nodedev_dumpxml(dev_name=device_name, dev_opt=device_opt) + if status_error: + raise error.TestFail('Nodedev dumpxml successed in negitive test.') + else: + pass + except error.TestError, e: + if status_error: + pass + else: + raise error.TestFail('Nodedev dumpxml failed in positive test.' + 'Error: %s' % e) diff --git a/libvirt/tests/src/virsh_cmd/pool/virsh_pool.py b/libvirt/tests/src/virsh_cmd/pool/virsh_pool.py index d34c6a145..3221184fa 100644 --- a/libvirt/tests/src/virsh_cmd/pool/virsh_pool.py +++ b/libvirt/tests/src/virsh_cmd/pool/virsh_pool.py @@ -1,6 +1,6 @@ import logging, re, os, shutil from autotest.client.shared import error -from virttest import libvirt_vm, virsh +from virttest import virsh, utils_libvirtd def run_virsh_pool(test, params, env): @@ -191,9 +191,9 @@ def define_pool(pool_name, pool_type, pool_target): "instead of yes" % pool_name) # Step (7.a) - libvirt_vm.service_libvirtd_control("stop") + utils_libvirtd.libvirtd_stop() # TODO: Add more negative cases after libvirtd stopped - libvirt_vm.service_libvirtd_control("start") + utils_libvirtd.libvirtd_start() # Step (7.b) if not check_list_state(pool_name, "active"): diff --git a/libvirt/tests/src/virsh_cmd/pool/virsh_pool_create_as.py b/libvirt/tests/src/virsh_cmd/pool/virsh_pool_create_as.py index 29db5b495..b0dd33e00 100644 --- a/libvirt/tests/src/virsh_cmd/pool/virsh_pool_create_as.py +++ b/libvirt/tests/src/virsh_cmd/pool/virsh_pool_create_as.py @@ -28,7 +28,7 @@ def run_virsh_pool_create_as(test, params, env): else: os.makedirs(pool_target) - logging.info('Creating a %s type pool %s' % (pool_type, pool_name)) + logging.info('Creating a %s type pool %s', pool_type, pool_name) status = virsh.pool_create_as(pool_name, pool_type, pool_target, extra=pool_options, uri=virsh.canonical_uri()) @@ -36,15 +36,18 @@ def run_virsh_pool_create_as(test, params, env): status_error = params.get('status_error') if status_error == 'yes': if status: - raise error.TestFail("%d not a expected command return value" % status) + raise error.TestFail("%d not a expected command return value" + % status) else: logging.info("It's an expected error") elif status_error == 'no': - if not virsh.pool_info(pool_name, uri=virsh.canonical_uri()): + result = virsh.pool_info(pool_name, uri=virsh.canonical_uri()) + if result.exit_status: raise error.TestFail('Failed to check pool information') else: - logging.info('Pool %s is running' % pool_name) + logging.info('Pool %s is running', pool_name) if not status: - raise error.TestFail('%d not a expected command return value' % status) + raise error.TestFail('%d not a expected command return value' + % status) else: - logging.info('Succeed to create pool %s' % pool_name) + logging.info('Succeed to create pool %s', pool_name) diff --git a/openvswitch/tests/ovs_basic.py b/openvswitch/tests/ovs_basic.py index 522b62211..0048b327b 100644 --- a/openvswitch/tests/ovs_basic.py +++ b/openvswitch/tests/ovs_basic.py @@ -1,5 +1,6 @@ import logging, time, os from virttest import utils_misc, aexpect, utils_net, openvswitch, ovs_utils +from virttest import versionable_class from autotest.client.shared import error @@ -40,7 +41,7 @@ def setup(self, test, params, env): vm.verify_alive() error.context("Start OpenVSwitch.") - self.ovs = openvswitch.OpenVSwitchSystem() + self.ovs = versionable_class.factory(openvswitch.OpenVSwitchSystem)() self.ovs.init_system() self.ovs.check() error.context("Add new bridge %s." % (self.br0_name)) diff --git a/qemu/cfg/build.cfg b/qemu/cfg/build.cfg index 5fbd1afb9..8bf534bfe 100644 --- a/qemu/cfg/build.cfg +++ b/qemu/cfg/build.cfg @@ -49,12 +49,13 @@ variants: #git_repo_qemu_tag = for_anthony # If tag_signed is provided, then we will be strict and verify the # tag. If the tag verification fails, the entire build test will fail. - #git_repo_qemu_tag_signed = pgp.mit.edu:AFBE8E67 + # A file with the trusted GPG keys should be put at shared/gpg. The + # build test will look for it. If not found, the test will fail. + #git_repo_qemu_tag_signed = mst.keys # SPICE installation from a GIT repo - git_repo_spice_uri = git://anongit.freedesktop.org/spice/spice - git_repo_spice_common_uri = git://anongit.freedesktop.org/spice/spice-common - git_repo_spice_protocol_uri = git://anongit.freedesktop.org/spice/spice-protocol + git_repo_spice_uri = git://cgit.freedesktop.org/spice/spice + git_repo_spice_protocol_uri = git://git.freedesktop.org/git/spice/spice-protocol # QEMU (KVM) installation from a YUM repo # yum_qemu_kvm_pkgs = ['qemu-kvm', 'qemu-kvm-tools', 'qemu-system-x86', 'qemu-common', 'qemu-img'] @@ -81,7 +82,7 @@ variants: # INSTALLERS SELECTION # Choose here what components you want to install ###################################################################### - installers = git_repo_spice_protocol git_repo_spice_common git_repo_spice git_repo_qemu + installers = git_repo_spice_protocol git_repo_spice git_repo_qemu # Choose wether you want to include debug information/symbols install_debug_info = yes diff --git a/qemu/cfg/host-kernel.cfg b/qemu/cfg/host-kernel.cfg index e28146f48..f00aa68e9 100644 --- a/qemu/cfg/host-kernel.cfg +++ b/qemu/cfg/host-kernel.cfg @@ -27,6 +27,7 @@ variants: host_kernel_ver_str = Host_RHEL variants: - 5: + no qcow2v3 host_kernel_ver_str += ".5" monitor_type = human monitors = hmp1 @@ -61,7 +62,7 @@ variants: status_query_cmd = "ksmctl info" setup_cmd = "ksmctl start 5000 50" query_cmd = "top -p QEMU_PID -n 1" - query_regex = "(\d+.\d+\w)\s+.\s+\d+\.\d+\s+\d+\.\d+\s+\d+:\d+\.\d+\s+qemu" + query_regex = "([\d\.]+\w)\s+.\s+\d+\.\d+\s+\d+\.\d+\s+\d+:\d+\.\d+\s+qemu" ksm_module = "ksm" cpuinfo_query.qmachine_type: cpu_info = "pc,rhel5.4.0,rhel5.4.4,rhel5.5.0,rhel5.6.0" @@ -84,6 +85,7 @@ variants: host_kernel_ver_str += ".9" requires_kernel = [">= 2.6.18-348", "< 2.6.19"] - 6: + no qcow2v3 # RHEL-6 pointer host_kernel_ver_str += ".6" netdev_peer_re = "\s{2,}(.*?):.*?peer=(.*?)\s" @@ -91,6 +93,8 @@ variants: query_cmd = "cat /sys/kernel/mm/ksm/pages_sharing" virtio_net: vhost = "vhost=on" + # enable_vhostfd only works with vhost=on + enable_vhostfd = yes Win2008, Win2008r2, Win7: cpu_model_flags += ",hv_relaxed" block_stream, drive_mirror, live_snapshot, live_snapshot_chain: @@ -135,6 +139,8 @@ variants: cpu_model_flags += ",hv_relaxed" virtio_net: vhost = "vhost=on" + # enable_vhostfd only works with vhost=on + enable_vhostfd = yes monitor_cmds_check.qmp: black_cmds = "block-stream block-job-cancel block-job-set-speed drive-mirror block-job-complete block-job-pause block-job-resume" monitor_cmds_check.human: diff --git a/qemu/cfg/multi-host-tests.cfg b/qemu/cfg/multi-host-tests.cfg index b61be3d23..25af363ae 100644 --- a/qemu/cfg/multi-host-tests.cfg +++ b/qemu/cfg/multi-host-tests.cfg @@ -24,7 +24,7 @@ variants: only pc only Fedora.17.x86_64 cpu_model = "core2duo" - cpu_model_flags = "+sse3" + cpu_model_flags = ",+sse3" only migrate_multi_host # Runs qemu, f16 64 bit guest OS, install, boot, shutdown diff --git a/qemu/cfg/tests-spice.cfg b/qemu/cfg/tests-spice.cfg index 88030eefb..f3cfb3dd5 100644 --- a/qemu/cfg/tests-spice.cfg +++ b/qemu/cfg/tests-spice.cfg @@ -11,16 +11,20 @@ password=123456 # Use static MAC addresses for spice tests to have # the same IP in all test. -nics = nic1 nic2 -nics_vm1 = nic1 -nics_vm2 = nic2 -mac_nic1 = 9a:96:97:98:99:9a -mac_nic2 = 9a:9b:9c:9d:9e:9f +#nics = nic1 nic2 +#nics_vm1 = nic1 +#nics_vm2 = nic2 +#mac_nic1 = 9a:9a:97:98:99:9a +#mac_nic2 = 9a:9a:9c:9d:9e:9f qemu_binary = /usr/libexec/qemu-kvm qemu_img_binary = /usr/bin/qemu-img qemu_io_binary = /usr/bin/qemu-io rv_binary = /usr/bin/remote-viewer +spice_info = None +listening_addr = None +certdb=None +gencerts=None # Only qcow2 file format only qcow2 @@ -36,6 +40,10 @@ only no_9p_export only no_pci_assignable # No large memory pages only smallpages +# No gluster fs support +only no_glusterfs_support +# Only i440fx pc type +only i440fx variants: - qxl: @@ -56,6 +64,18 @@ variants: vga = qxl display = spice + variants: + - @default_sc: + smartcard = no + - smartcard: + smartcard = yes + smartcard_chardev = "spicevmc" + smartcard_id = "ccid" + usb_type_usb = piix3-usb-uhci + usbs_vm1 = usb + - no_smartcard: + smartcard = no + variants: - 1monitor: qxl_dev_nr = 1 @@ -76,6 +96,7 @@ variants: variants: - @no_password: + spice_password = - password: spice_password = 12456 variants: @@ -97,7 +118,7 @@ variants: spice_x509_cert_file = server-cert.pem spice_x509_key_password = testPassPhrase spice_x509_cacert_subj = /C=CZ/L=BRNO/O=SPICE/CN=my CA - spice_x509_server_subj = /C=CZ/L=BRNO/O=SPICE/CN=my Server + spice_x509_server_subj = /C=CZ/L=BRNO/O=SPICE/CN= spice_secure_channels = main, inputs spice_client_host_subject = yes variants: @@ -185,41 +206,41 @@ variants: - qemu_kvm_rhel6devel_install_client: image_name += "_client" only os.RHEL - only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.default_sc only unattended_install.cdrom.extra_cdrom_ks # Runs qemu-kvm Windows guest install - @qemu_kvm_windows_install_guest: only os.Windows # Subtest choice. You can modify that line to add more subtests - only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.default_sc only unattended_install.cdrom - qemu_kvm_rhel6devel_install_guest: only os.RHEL - only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.default_sc only unattended_install.cdrom.extra_cdrom_ks - @remote_viewer_rhel6develssl: only os.RHEL - only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.ssl.key_password.password.dcp_off.1monitor - only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.client_guest_shutdown.RHEL.6.devel.x86_64 + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.ssl.key_password.password.dcp_off.1monitor.default_sc + only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_clearx.RHEL.6.devel.x86_64 - @remote_viewer_rhel6devel_quick: only os.RHEL - only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor - only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.client_guest_shutdown.RHEL.6.devel.x86_64 + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.default_sc + only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_clearx.RHEL.6.devel.x86_64 - @remote_viewer_rhel6devel_password: only os.RHEL - only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.password.dcp_off.1monitor.default_sc only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.client_guest_shutdown.RHEL.6.devel.x86_64 - @remote_viewer_win_guest_quick: only os.Windows - only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.default_sc #rv_connect_win is specifically a test meant for a windows guest and a rhel client, rv_connect cannot be used. - only rv.rw.rv_connect.RHEL.6.devel.x86_64, rv.rr.client_guest_shutdown.RHEL.6.devel.x86_64 + only rv.rw.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_clearx.RHEL.6.devel.x86_64 - @spice_negative_rhel6devel: only os.RHEL @@ -227,38 +248,85 @@ variants: - @rv_disconnect_rhel6devel: only os.RHEL - only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor - only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_disconnect.RHEL.6.devel.x86_64, rv.rr.client_guest_shutdown.RHEL.6.devel.x86_64 + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.default_sc + only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_disconnect.RHEL.6.devel.x86_64, rv.rr.rv_clearx.RHEL.6.devel.x86_64 + + - @spice_migrate_rhel6devel: + kill_on_vms = "client_vm" + kill_app_name = "remote-viewer" + only os.RHEL + variants: + - no_ssl: + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.default_sc + only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_migrate.default.RHEL.6.devel.x86_64, rv.rr.rv_disconnect.RHEL.6.devel.x86_64, rv.rr.rv_clearx.RHEL.6.devel.x86_64 + - ssl: + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.ssl.key_password.password.dcp_off.1monitor.default_sc + only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_migrate.default.RHEL.6.devel.x86_64, rv.rr.rv_disconnect.RHEL.6.devel.x86_64, rv.rr.rv_clearx.RHEL.6.devel.x86_64 + - ssl_reboot: + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.ssl.key_password.password.dcp_off.1monitor.default_sc + only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_migrate.with_reboot.RHEL.6.devel.x86_64, rv.rr.rv_disconnect.RHEL.6.devel.x86_64, rv.rr.rv_clearx.RHEL.6.devel.x86_64 + - ssl_video: + kill_app_name = "totem" + kill_on_vms = "guest_vm" + iterations = 1 + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.ssl.key_password.password.dcp_off.1monitor.default_sc + only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_video.RHEL.6.devel.x86_64, rv.rr.rv_migrate.default.RHEL.6.devel.x86_64, rv.rr.rv_disconnect.RHEL.6.devel.x86_64, rv.rr.rv_clearx.RHEL.6.devel.x86_64 + - ssl_vdagent: + config_test = "positive_client_to_guest" + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.ssl.key_password.password.dcp_off.1monitor.default_sc + only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_migrate.default.RHEL.6.devel.x86_64, rv.rr.rv_copyandpaste.RHEL.6.devel.x86_64, rv.rr.rv_disconnect.RHEL.6.devel.x86_64, rv.rr.rv_clearx.RHEL.6.devel.x86_64 - @rv_fullscreen_rhel6devel: spice_port=3000 only os.RHEL - only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor - only rv.rr.fullscreen_setup.RHEL.6.devel.x86_64, rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_fullscreen.RHEL.6.devel.x86_64, rv.rr.client_guest_shutdown.RHEL.6.devel.x86_64 + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.default_sc + only rv.rr.fullscreen_setup.RHEL.6.devel.x86_64, rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_fullscreen.RHEL.6.devel.x86_64, rv.rr.rv_clearx.RHEL.6.devel.x86_64 + + - @rv_smartcard_rhel6devel: + spice_port=3000 + only os.RHEL + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.smartcard + only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.smartcard_setup.RHEL.6.devel.x86_64, rv.rr.rv_smartcard.RHEL.6.devel.x86_64, rv.rr.rv_clearx.RHEL.6.devel.x86_64 - @rv_logging_rhel6devel: only os.RHEL - only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor - only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_logging.RHEL.6.devel.x86_64, rv.rr.client_guest_shutdown.RHEL.6.devel.x86_64 + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.default_sc + only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_logging.RHEL.6.devel.x86_64, rv.rr.rv_clearx.RHEL.6.devel.x86_64 + + - @rv_vdagent_rhel6devel: + only os.RHEL + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.default_sc + only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_vdagent.RHEL.6.devel.x86_64, rv.rr.rv_clearx.RHEL.6.devel.x86_64 - @rv_copyandpaste_rhel6devel: only os.RHEL - only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor - only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_copyandpaste.RHEL.6.devel.x86_64, rv.rr.client_guest_shutdown.RHEL.6.devel.x86_64 + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.default_sc + only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_copyandpaste.RHEL.6.devel.x86_64, rv.rr.rv_clearx.RHEL.6.devel.x86_64 - @rv_copyandpaste_dcp_rhel6devel: only os.RHEL - only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_on.1monitor - only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_copyandpaste.RHEL.6.devel.x86_64, rv.rr.client_guest_shutdown.RHEL.6.devel.x86_64 + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_on.1monitor.default_sc + only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_copyandpaste.RHEL.6.devel.x86_64, rv.rr.rv_clearx.RHEL.6.devel.x86_64 - @rv_input_rhel6devel: only os.RHEL - only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor - only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_input.RHEL.6.devel.x86_64, rv.rr.client_guest_shutdown.RHEL.6.devel.x86_64 + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.default_sc + only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_input.RHEL.6.devel.x86_64, rv.rr.rv_clearx.RHEL.6.devel.x86_64 + + - @rv_audio_rhel6devel: + only os.RHEL + soundcards_vm1 = hda + variants: + - pc: + only spice.default_ipv.pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.default_sc + only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_audio.RHEL.6.devel.x86_64, rv.rr.rv_clearx.RHEL.6.devel.x86_64 + - no_pc: + only spice.default_ipv.no_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.default_sc + only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_audio.RHEL.6.devel.x86_64, rv.rr.rv_clearx.RHEL.6.devel.x86_64 - @rv_vmshutdown_rhel6devel: only os.RHEL - only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.default_sc only rv.rr.rv_connect.RHEL.6.devel.x86_64, rv.rr.rv_vmshutdown.RHEL.6.devel.x86_64, rv.rr.client_guest_shutdown.RHEL.6.devel.x86_64 variants: @@ -268,27 +336,41 @@ variants: - install_win_guest: only qemu_kvm_windows_install_guest - negative_qemu_spice_launch_badport: - only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.bad_port.no_password.dcp_off.1monitor + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.bad_port.no_password.dcp_off.1monitor.default_sc only spice_negative_rhel6devel - negative_qemu_spice_launch_badic: - only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.bad_ic.no_ssl.no_password.dcp_off.1monitor + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.default_jpeg_wc.bad_ic.no_ssl.no_password.dcp_off.1monitor.default_sc only spice_negative_rhel6devel - negative_qemu_spice_launch_badjpegwc: - only spice.default_ipv.default_pc.default_sv.default_zlib_wc.bad_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor + only spice.default_ipv.default_pc.default_sv.default_zlib_wc.bad_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.default_sc only spice_negative_rhel6devel - negative_qemu_spice_launch_badzlib: - only spice.default_ipv.default_pc.default_sv.bad_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor + only spice.default_ipv.default_pc.default_sv.bad_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.default_sc only spice_negative_rhel6devel - negative_qemu_spice_launch_badsv: - only spice.default_ipv.default_pc.bad_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor + only spice.default_ipv.default_pc.bad_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.default_sc only spice_negative_rhel6devel - negative_qemu_spice_launch_badpc: - only spice.default_ipv.bad_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor + only spice.default_ipv.bad_pc.default_sv.default_zlib_wc.default_jpeg_wc.default_ic.no_ssl.no_password.dcp_off.1monitor.default_sc only spice_negative_rhel6devel - remote_viewer_test: only remote_viewer_rhel6devel_quick + #The following ipv6 test is not a true test of ipv6, it is converting an + #ipv4 address to ipv6, and verify the ipv6 format can be accepted. The pure + #ipv6 address cannot be tested because the network is not setup to support + #ipv6 + - remote_viewer_ipv6_addr: + listening_addr = ipv6 + only remote_viewer_rhel6devel_quick + - rv_qemu_report_ipv6: + listening_addr = ipv6 + spice_info = ipv6 + only remote_viewer_rhel6devel_quick - rv_connect_passwd: only remote_viewer_rhel6devel_password + - rv_connect_menu: + rv_menu=yes + only remote_viewer_rhel6devel_quick - rv_connect_wrong_passwd: test_type = negative spice_password_send = incorrectpass @@ -314,9 +396,51 @@ variants: - remote_viewer_winguest_test: only remote_viewer_win_guest_quick - remote_viewer_disconnect_test: + kill_app_name = "remote-viewer" + kill_on_vms = "client_vm" only rv_disconnect_rhel6devel - remote_viewer_ssl_test: + kill_app_name = "remote-viewer" + kill_on_vms = "client_vm" + only remote_viewer_rhel6develssl + - rv_ssl_explicit_hs: + ssltype = "explicit_hs" + only remote_viewer_rhel6develssl + - rv_ssl_implicit_hs: + ssltype = "implicit_hs" + spice_client_host_subject = no + only remote_viewer_rhel6develssl + - rv_ssl_invalid_explicit_hs: + test_type = negative + ssltype = "invalid_explicit_hs" + only remote_viewer_rhel6develssl + - rv_ssl_invalid_implicit_hs: + test_type = negative + spice_client_host_subject = no + ssltype = "invalid_implicit_hs" only remote_viewer_rhel6develssl + - spice_migrate_simple: + only spice_migrate_rhel6devel.no_ssl + - spice_migrate_ssl: + only spice_migrate_rhel6devel.ssl + - spice_migrate_reboot: + only spice_migrate_rhel6devel.ssl_reboot + - spice_migrate_video: + only spice_migrate_rhel6devel.ssl_video + - spice_migrate_vdagent: + only spice_migrate_rhel6devel.ssl_vdagent + - start_vdagent_test: + vdagent_test = start + only rv_vdagent_rhel6devel + - stop_vdagent_test: + vdagent_test = stop + only rv_vdagent_rhel6devel + - restart_start_vdagent_test: + vdagent_test = restart_start + only rv_vdagent_rhel6devel + - restart_stop_vdagent_test: + vdagent_test = restart_stop + only rv_vdagent_rhel6devel - copy_client_to_guest_pos: config_test = "positive_client_to_guest" only rv_copyandpaste_rhel6devel @@ -450,6 +574,47 @@ variants: full_screen = yes config_test = "leds_migration" only rv_input_rhel6devel + - audio_compression: + audio_tgt = "~/tone.wav" + audio_rec = "~/rec.wav" + audio_src = #path to your audio file (recommend generating a square/sine wave) + only rv_audio_rhel6devel.pc + - audio_no_compression: + audio_tgt = "~/tone.wav" + audio_rec = "~/rec.wav" + audio_src = #path to your audio file (recommend generating a square/sine wave) + only rv_audio_rhel6devel.no_pc + - disable_audio: + audio_tgt = "~/tone.wav" + audio_rec = "~/rec.wav" + audio_src = #path to your audio file (recommend generating a square/sine wave) + disable_audio = "yes" + only rv_audio_rhel6devel.pc + - migrate_audio: + audio_tgt = "~/tone.wav" + audio_rec = "~/rec.wav" + audio_src = #path to your audio file (recommend generating a square/sine wave) + config_test = migration + rv_audio_treshold = 529200 + only rv_audio_rhel6devel.pc + - remote_viewer_smartcard_certinfo: + smartcard_testtype = "pkcs11_listcerts" + gencerts = "cert1,cert2,cert3" + certdb = "/etc/pki/nssdb/" + self_sign = True + trustargs = "CT,CT,CT" + only rv_smartcard_rhel6devel + - remote_viewer_smartcard_certdetail: + smartcard_testtype = "pklogin_finder" + gencerts = "cert1,cert2,cert3" + certdb = "/etc/pki/nssdb/" + self_sign = True + trustargs = "CT,CT,CT" + certcheckstr = "Found '3' certificate(s)" + certcheckstr2 = "verifing the certificate #" + certcheck3 = "Couldn't verify Cert: Issuer certificate is invalid." + certcheck4 = "verify_certificate() failed:" + only rv_smartcard_rhel6devel - qxl_logging: only rv_logging_rhel6devel - spice_vdagent_logging: @@ -457,7 +622,7 @@ variants: only rv_logging_rhel6devel #Running all RHEL Client, RHEL Guest Spice Tests -only create_vms, negative_qemu_spice_launch_badport, negative_qemu_spice_launch_badic, negative_qemu_spice_launch_badjpegwc, negative_qemu_spice_launch_badzlib, negative_qemu_spice_launch_badsv, negative_qemu_spice_launch_badpc, remote_viewer_test, remote_viewer_ssl_test, remote_viewer_disconnect_test, guestvmshutdown_cmd, guestvmshutdown_qemu, copy_client_to_guest_largetext_pos, copy_guest_to_client_largetext_pos, copy_client_to_guest_pos, copy_guest_to_client_pos, copy_guest_to_client_neg, copy_client_to_guest_neg, copyimg_client_to_guest_pos, copyimg_client_to_guest_neg, copyimg_guest_to_client_pos, copyimg_guest_to_client_neg, copyimg_client_to_guest_dcp_neg, copyimg_guest_to_client_dcp_neg, copy_guest_to_client_dcp_neg, copy_client_to_guest_dcp_neg, copybmpimg_client_to_guest_pos, copybmpimg_guest_to_client_pos, copy_guest_to_client_largetext_10mb_pos, copy_client_to_guest_largetext_10mb_pos, copyimg_medium_client_to_guest_pos, copyimg_medium_guest_to_client_pos, copyimg_large_client_to_guest_pos, copyimg_large_guest_to_client_pos, restart_vdagent_copy_client_to_guest_pos, restart_vdagent_copy_guest_to_client_pos, restart_vdagent_copyimg_client_to_guest_pos, restart_vdagent_copyimg_guest_to_client_pos, restart_vdagent_copybmpimg_client_to_guest_pos, restart_vdagent_copybmpimg_guest_to_client_pos, restart_vdagent_copy_client_to_guest_largetext_pos, restart_vdagent_copy_guest_to_client_largetext_pos, remote_viewer_fullscreen_test, remote_viewer_fullscreen_test_neg, spice_vdagent_logging, qxl_logging, keyboard_input_leds_and_esc_keys, keyboard_input_non-us_layout, keyboard_input_type_and_func_keys, keyboard_input_leds_migration, rv_connect_passwd, rv_connect_wrong_passwd, rv_qemu_password, rv_qemu_password_overwrite +only create_vms, negative_qemu_spice_launch_badport, negative_qemu_spice_launch_badic, negative_qemu_spice_launch_badjpegwc, negative_qemu_spice_launch_badzlib, negative_qemu_spice_launch_badsv, negative_qemu_spice_launch_badpc, remote_viewer_test, remote_viewer_ssl_test, remote_viewer_disconnect_test, guestvmshutdown_cmd, guestvmshutdown_qemu, copy_client_to_guest_largetext_pos, copy_guest_to_client_largetext_pos, copy_client_to_guest_pos, copy_guest_to_client_pos, copy_guest_to_client_neg, copy_client_to_guest_neg, copyimg_client_to_guest_pos, copyimg_client_to_guest_neg, copyimg_guest_to_client_pos, copyimg_guest_to_client_neg, copyimg_client_to_guest_dcp_neg, copyimg_guest_to_client_dcp_neg, copy_guest_to_client_dcp_neg, copy_client_to_guest_dcp_neg, copybmpimg_client_to_guest_pos, copybmpimg_guest_to_client_pos, copy_guest_to_client_largetext_10mb_pos, copy_client_to_guest_largetext_10mb_pos, copyimg_medium_client_to_guest_pos, copyimg_medium_guest_to_client_pos, copyimg_large_client_to_guest_pos, copyimg_large_guest_to_client_pos, restart_vdagent_copy_client_to_guest_pos, restart_vdagent_copy_guest_to_client_pos, restart_vdagent_copyimg_client_to_guest_pos, restart_vdagent_copyimg_guest_to_client_pos, restart_vdagent_copybmpimg_client_to_guest_pos, restart_vdagent_copybmpimg_guest_to_client_pos, restart_vdagent_copy_client_to_guest_largetext_pos, restart_vdagent_copy_guest_to_client_largetext_pos, remote_viewer_fullscreen_test, remote_viewer_fullscreen_test_neg, spice_vdagent_logging, qxl_logging, keyboard_input_leds_and_esc_keys, keyboard_input_non-us_layout, keyboard_input_type_and_func_keys, keyboard_input_leds_migration, rv_connect_passwd, rv_connect_wrong_passwd, rv_qemu_password, rv_qemu_password_overwrite, spice_migrate_simple, spice_migrate_ssl, spice_migrate_reboot, spice_migrate_video, spice_migrate_vdagent, rv_ssl_invalid_explicit_hs, rv_ssl_invalid_implicit_hs, rv_ssl_implicit_hs, rv_ssl_explicit_hs, rv_connect_menu, audio_compression, audio_no_compression, disable_audio, migrate_audio, remote_viewer_ipv6_addr, rv_qemu_report_ipv6, start_vdagent_test, stop_vdagent_test, restart_start_vdagent_test, restart_stop_vdagent_test, remote_viewer_smartcard_certdetail, remote_viewer_smartcard_certinfo #Running all RHEL Client, Windows Guest Spice Tests #only install_win_guest, remote_viewer_winguest_test diff --git a/qemu/control.kernel-version b/qemu/control.kernel-version index 5c99c3b22..13f2491f0 100644 --- a/qemu/control.kernel-version +++ b/qemu/control.kernel-version @@ -95,6 +95,8 @@ parser.parse_file(os.path.join(qemu_test_dir, "cfg", "tests-example.cfg")) host_kernel_ver_str = "" host_kernel_ver_file = "/tmp/host_kernel_version" +if os.path.isfile(host_kernel_ver_file): + os.remove(host_kernel_ver_file) filter_str = "" for dict_test in parser.get_dicts(): diff --git a/qemu/tests/balloon_check.py b/qemu/tests/balloon_check.py index 084640d37..f83faa5bd 100644 --- a/qemu/tests/balloon_check.py +++ b/qemu/tests/balloon_check.py @@ -219,4 +219,14 @@ def balloon_memory(new_mem): ballooned_mem = 0 memory_check("after subtest when enlarging memory", ballooned_mem, monitor_boot_mem , guest_boot_mem, ratio) + + # we should reset the memory to the origin value, so that next + # iterations can pass when check memory before test + error.context("Reset the memory to monitor boot memory", logging.info) + + balloon_memory(monitor_boot_mem) + ballooned_mem = vm_assigned_mem - monitor_boot_mem + memory_check("after reset memory", ballooned_mem, + monitor_boot_mem, guest_boot_mem, ratio) + session.close() diff --git a/qemu/tests/blk_stream.py b/qemu/tests/blk_stream.py index 21873c357..1222a1bed 100644 --- a/qemu/tests/blk_stream.py +++ b/qemu/tests/blk_stream.py @@ -1,5 +1,5 @@ import logging, time -from virttest import utils_misc +from virttest import utils_misc, data_dir from autotest.client.shared import error from qemu.tests import block_copy @@ -52,7 +52,8 @@ def create_snapshots(self): format = params.get("snapshot_format", "qcow2") error.context("create live snapshots", logging.info) for sn in snapshots: - image_file = self.get_block_file() + sn = utils_misc.get_path(data_dir.get_data_dir(), sn) + image_file = self.get_image_file() device = self.vm.live_snapshot(image_file, sn, format) if device != self.device: image_file = self.get_image_file() @@ -85,6 +86,7 @@ def wait_for_finished(self): text="wait job finshed in %ss"% timeout) if not finished: raise error.TestFail("Wait job finished timeout in %s" % timeout) + logging.info("Block stream job done.") def action_before_start(self): diff --git a/qemu/tests/block_copy.py b/qemu/tests/block_copy.py index cd4a9215c..d5de8dcc1 100644 --- a/qemu/tests/block_copy.py +++ b/qemu/tests/block_copy.py @@ -20,13 +20,16 @@ class BlockCopy(object): sessions = [] trash = [] + def __init__(self, test, params, env, tag): self.test = test self.env = env self.params = params self.tag = tag self.vm = self.get_vm() + self.data_dir = data_dir.get_data_dir() self.device = self.get_device() + self.image_file = self.get_image_file() def parser_test_args(self): @@ -57,35 +60,13 @@ def get_device(self): """ according configuration get target device ID; """ - root_dir = data_dir.get_data_dir() + root_dir = self.data_dir params = self.parser_test_args() image_file = storage.get_image_filename(params, root_dir) device = self.vm.get_block({"file": image_file}) return device - def get_image_file(self): - """ - return file associated with $device device - """ - blocks = self.vm.monitor.info("block") - image_file = None - if isinstance(blocks, str): - image_file = re.findall('%s: .*file=(\S*) ' % self.device, blocks) - if not image_file: - return None - else: - image_file = image_file[0] - else: - for block in blocks: - if block['device'] == self.device: - try: - image_file = block['inserted']['file'] - except KeyError: - continue - return image_file - - def get_session(self): """ get a session object; @@ -130,14 +111,15 @@ def is_cancelled(): error.context("cancel block copy job", logging.info) params = self.parser_test_args() timeout = params.get("cancel_timeout") - if self.vm.monitor.protocol == "qmp": - self.vm.monitor.clear_events() + self.vm.monitor.clear_event("BLOCK_JOB_CANCELLED") self.vm.cancel_block_job(self.device) cancelled = utils_misc.wait_for(is_cancelled, timeout=timeout) if not cancelled: msg = "Cancel block job timeout in %ss" % timeout raise error.TestFail(msg) + if self.vm.monitor.protocol == "qmp": + self.vm.monitor.clear_event("BLOCK_JOB_CANCELLED") @error.context_aware @@ -178,37 +160,27 @@ def reboot(self, method="shell", boot_check=True): """ reboot VM, alias of vm.reboot(); """ - def reseted(): - """ - check reset event recived after system_reset execute, only for qmp - monitor; - """ - return self.vm.monitor.get_event("RESET") - params = self.parser_test_args() timeout = params["login_timeout"] if boot_check: session = self.get_session() - return self.vm.reboot(session=session, timeout=timeout, method=method) - if method == "system_reset": + return self.vm.reboot(session=session, + timeout=timeout, method=method) + if self.vm.monitor.protocol == "qmp": error.context("reset guest via system_reset", logging.info) - event_check = False - if self.vm.monitor.protocol == "qmp": - event_check = True - self.vm.monitor.clear_events() + self.vm.monitor.clear_event("RESET") self.vm.monitor.cmd("system_reset") - if event_check: - reseted = utils_misc.wait_for(reseted, timeout=timeout) - if not reseted: - raise error.TestFail("No RESET event recived after" - "execute system_reset %ss" % timeout) - elif method == "shell": - reboot_cmd = params.get("reboot_command") - session = self.get_session() - session.sendline(reboot_cmd) + reseted = utils_misc.wait_for(lambda: + self.vm.monitor.get_event("RESET"), + timeout=timeout) + if not reseted: + raise error.TestFail("No RESET event recived after" + "execute system_reset %ss" % timeout) + self.vm.monitor.clear_event("RESET") else: - raise error.TestError("Unsupport reboot method '%s'" % method) + self.vm.monitor.cmd("system_reset") + return None @error.context_aware @@ -243,17 +215,16 @@ def verify_alive(self): return session.cmd(cmd, timeout=120) - def get_block_file(self): + def get_image_file(self): """ return file associated with $device device """ blocks = self.vm.monitor.info("block") + image_file = None if isinstance(blocks, str): - image_file = re.findall('%s: .*file=(\S*) ' % self.device, blocks) - if not image_file: - return None - else: - image_file = image_file[0] + image_file = re.findall('%s.*\s+file=(\S*)' % self.device, blocks) + if image_file: + return image_file[0] else: for block in blocks: if block['device'] == self.device: diff --git a/qemu/tests/block_mirror.py b/qemu/tests/block_mirror.py deleted file mode 100644 index ac4fb6158..000000000 --- a/qemu/tests/block_mirror.py +++ /dev/null @@ -1,138 +0,0 @@ -import os, logging, time -from autotest.client.shared import utils, error -from virttest import qemu_monitor, qemu_storage, storage, env_process, data_dir -from virttest import utils_misc - - -@error.context_aware -def run_block_mirror(test, params, env): - """ - Test block mirroring functionality - - Test consists of two subtests: - - 1) Mirror the guest and switch to the mirrored one - 2) Synchronize disk and then do continuous backup - - "qemu-img compare" is used to verify disk is mirrored successfully. - """ - image_name = params.get("image_name", "image") - image_format = params.get("image_format", "qcow2") - image_mirror = utils_misc.get_path(data_dir.get_data_dir(), - "%s-mirror.%s" % (image_name, - image_format)) - block_mirror_cmd = params.get("block_mirror_cmd", "drive-mirror") - qemu_img = qemu_storage.QemuImg(params, data_dir.get_data_dir(), - "block-mirror") - source_images = params.get("source_images", "image1").split() - source_image = source_images[0] - _params = params.object_params(source_image) - speed = int(_params.get("default_speed", 0)) - sync = _params.get("full_copy").lower() - if block_mirror_cmd.startswith("__"): - sync = (sync == "full") - mode = _params.get("create_mode", "absolute-paths") - format = _params.get("target_format", "qcow2") - check_event = _params.get("check_event") - - - def check_block_jobs_info(device_id): - """ - Verify block-jobs status reported by monitor command info block-jobs. - - @return: parsed output of info block-jobs - """ - fail = 0 - status = dict() - try: - status = vm.get_job_status(device_id) - except qemu_monitor.MonitorError, e: - logging.error(e) - fail += 1 - return status - return status - - - def run_mirroring(vm, device, dest, sync, speed=0, foramt="qcow2", - mode="absolute-paths", complete = True): - """ - Run block mirroring. - - @param vm: Virtual machine object - @param device: Guest device that has to be mirrored - @param dest: Location image has to be mirrored into - @param speed: limited speed - @param format: target image format - @param mode: image create mode - @param complete: If True, mirroring will complete (switch to mirror), - If False, finish image synchronization and keep - mirroring running (any changes will be mirrored) - """ - vm.block_mirror(device, dest, speed, sync, format, mode) - while True: - status = check_block_jobs_info(device) - if 'mirror' in status.get("type", ""): - logging.info("[(Completed bytes): %s (Total bytes): %s " - "(Speed limit in bytes/s): %s]", status["offset"], - status["len"], status["speed"]) - if status["offset"] != int(status["len"]): - time.sleep(10) - continue - elif vm.monitor.protocol == "qmp" and check_event == "yes": - if vm.monitor.get_event("BLOCK_JOB_READY") is None: - continue - else: - logging.info("Target synchronized with source") - if complete: - logging.info("Start mirroring completing") - vm.pause() - vm.block_reopen(device, dest, format) - time.sleep(5) - else: - break - elif not status: - logging.info("Block job completed") - break - - try: - # Setup phase - vm_name = params['main_vm'] - env_process.preprocess_vm(test, params, env, vm_name) - vm = env.get_vm(vm_name) - vm.create() - - timeout = int(params.get("login_timeout", 360)) - session = vm.wait_for_login(timeout=timeout) - img_path = storage.get_image_filename(params, data_dir.get_data_dir()) - device_id = vm.get_block({"file": img_path}) - - - # Subtest 1 - Complete mirroring - error.context("Testing complete mirroring") - run_mirroring(vm, device_id, image_mirror, sync, speed, format, mode) - _device_id = vm.get_block({"file": image_mirror}) - if device_id != _device_id: - raise error.TestError("Mirrored image not being used by guest") - error.context("Compare fully mirrored images") - qemu_img.compare_images(img_path, image_mirror) - vm.destroy() - - # Subtest 2 - Continuous backup - error.context("Testing continuous backup") - vm.create() - session = vm.wait_for_login(timeout=timeout) - run_mirroring(vm, device_id, image_mirror, sync, - speed, format, mode, False) - for fn in range(0,128): - session.cmd("dd bs=1024 count=1024 if=/dev/urandom of=tmp%d.file" - % fn) - time.sleep(10) - vm.pause() - time.sleep(5) - error.context("Compare original and backup images") - qemu_img.compare_images(img_path, image_mirror) - vm.destroy() - - finally: - if os.path.isfile(image_mirror): - os.remove(image_mirror) diff --git a/qemu/tests/block_stream.py b/qemu/tests/block_stream.py index 7d48a7068..39d74e46c 100644 --- a/qemu/tests/block_stream.py +++ b/qemu/tests/block_stream.py @@ -1,6 +1,18 @@ -import re, os, logging, time -from autotest.client.shared import utils, error -from virttest import qemu_monitor, env_process, data_dir +import re, logging +from autotest.client.shared import error, utils +from virttest import env_process, utils_misc +from qemu.tests import blk_stream + +class BlockStreamTest(blk_stream.BlockStream): + + def get_image_size(self, image_file): + qemu_img = utils_misc.get_qemu_img_binary(self.params) + cmd = "%s info %s" % (qemu_img, image_file) + info = utils.system_output(cmd) + size = re.findall("(\d+) bytes", info) + if size: + return int(size[0]) + return 0 @error.context_aware @@ -8,135 +20,43 @@ def run_block_stream(test, params, env): """ Test block streaming functionality. - 1) Create a image_bak.img with the backing file image.img - 2) Start the image_bak.img in qemu command line. - 3) Request for block-stream ide0-hd0/virtio0 + 1) create live snapshot image sn1 + 3) Request for block-stream 4) Wait till the block job finishs - 5) Check for backing file in image_bak.img - 6) TODO: Check for the size of the image_bak.img should not exceeds the image.img - 7) TODO(extra): Block job completion can be check in QMP + 5) Check for backing file in sn1 + 6) Check for the size of the sn1 should not exceeds image.img """ - image_format = params["image_format"] - image_name = params.get("image_name", "image") - if not os.path.isabs(image_name): - image_name = os.path.join(data_dir.get_data_dir(), image_name) - drive_format = params["drive_format"] - backing_file_name = "%s_bak" % (image_name) - qemu_img = params["qemu_img_binary"] - block_stream_cmd = "block-stream" - - - def check_block_jobs_info(): - """ - Verify the status of block-jobs reported by monitor command info block-jobs. - @return: parsed output of info block-jobs - """ - fail = 0 - - try: - output = vm.monitor.info("block-jobs") - except qemu_monitor.MonitorError, e: - logging.error(e) - fail += 1 - return None, None - return (re.match("\w+", str(output)), re.findall("\d+", str(output))) - + tag = params.get("source_images", "image1") + stream_test = BlockStreamTest(test, params, env, tag) try: - # Remove the existing backing file - backing_file = "%s.%s" % (backing_file_name, image_format) - if os.path.isfile(backing_file): - os.remove(backing_file) - - # Create the new backing file - create_cmd = "%s create -b %s.%s -f %s %s.%s" % (qemu_img, - image_name, - image_format, - image_format, - backing_file_name, - image_format) - error.context("Creating backing file") - utils.system(create_cmd) - - info_cmd = "%s info %s.%s" % (qemu_img,image_name,image_format) - error.context("Image file can not be find") - results = utils.system_output(info_cmd) - logging.info("Infocmd output of basefile: %s" ,results) - - # Set the qemu harddisk to the backing file - logging.info("Original image_name is: %s", params['image_name']) - params['image_name'] = backing_file_name - logging.info("Param image_name changed to: %s", params['image_name']) - - # Start virtual machine, using backing file as its harddisk - vm_name = params['main_vm'] - env_process.preprocess_vm(test, params, env, vm_name) - vm = env.get_vm(vm_name) - vm.create() - timeout = int(params.get("login_timeout", 360)) - session = vm.wait_for_login(timeout=timeout) - - info_cmd = "%s info %s.%s" % (qemu_img, backing_file_name, image_format) - error.context("Image file can not be find") - results = utils.system_output(info_cmd) - logging.info("Infocmd output of backing file before block streaming: " - "%s", results) - - if not re.search("backing file:", str(results)): + image_file = stream_test.get_image_file() + image_size = stream_test.get_image_size(image_file) + stream_test.create_snapshots() + backingfile = stream_test.get_backingfile() + if not backingfile: raise error.TestFail("Backing file is not available in the " "backdrive image") - - if vm.monitor.protocol == "human": - block_stream_cmd = "block_stream" - - # Start streaming in qemu-cmd line - if 'ide' in drive_format: - error.context("Block streaming on qemu monitor (ide drive)") - vm.monitor.cmd("%s ide0-hd0" % block_stream_cmd) - elif 'virtio' in drive_format: - error.context("Block streaming on qemu monitor (virtio drive)") - vm.monitor.cmd("%s virtio0" % block_stream_cmd) - else: - raise error.TestError("The drive format is not supported") - - while True: - blkjobout, blkjobstatus = check_block_jobs_info() - if 'Streaming' in blkjobout.group(0): - logging.info("[(Completed bytes): %s (Total bytes): %s " - "(Speed in bytes/s): %s]", blkjobstatus[-3], - blkjobstatus[-2], blkjobstatus[-1]) - time.sleep(10) - continue - if 'No' in blkjobout.group(0): - logging.info("Block job completed") - break - - info_cmd = "%s info %s.%s" % (qemu_img,backing_file_name,image_format) - error.context("Image file can not be find") - results = utils.system_output(info_cmd) - logging.info("Infocmd output of backing file after block streaming: %s", - results) - - if re.search("backing file:", str(results)): - raise error.TestFail(" Backing file is still available in the " + logging.info("Image file: %s" % stream_test.get_image_file()) + logging.info("Backing file: %s" % backingfile) + stream_test.start() + stream_test.wait_for_finished() + backingfile = stream_test.get_backingfile() + if backingfile: + raise error.TestFail("Backing file is still available in the " "backdrive image") - # TODO - # The file size should be more/less equal to the "backing file" size - - # Shutdown the virtual machine - vm.destroy() - - # Relogin with the backup-harddrive - vm.create() - timeout = int(params.get("login_timeout", 360)) - session = vm.wait_for_login(timeout=timeout) - logging.info("Checking whether the guest with backup-harddrive boot " - "and respond after block stream completion") - error.context("checking responsiveness of guest") - session.cmd(params["alive_check_cmd"]) - - # Finally shutdown the virtual machine - vm.destroy() + target_file = stream_test.get_image_file() + target_size = stream_test.get_image_size(target_file) + error.context("Compare image size", logging.info) + if image_size < target_size: + raise error.TestFail("Compare %s image, size of %s increased" + "(%s -> %s)" % (image_file, target_file, + image_size, target_size)) + stream_test.verify_alive() + stream_test.vm.destroy() + vm_name = params["main_vm"] + env_process.preprocess_vm(test, params, env, vm_name) + vm = env.get_vm(vm_name) + stream_test.vm = vm + stream_test.verify_alive() finally: - # Remove the backing file - if os.path.isfile(backing_file): - os.remove(backing_file) + stream_test.clean() diff --git a/qemu/tests/block_stream_check_backingfile.py b/qemu/tests/block_stream_check_backingfile.py index 974d2e564..845773a0d 100644 --- a/qemu/tests/block_stream_check_backingfile.py +++ b/qemu/tests/block_stream_check_backingfile.py @@ -1,5 +1,6 @@ import logging from autotest.client.shared import error +from virttest import utils_misc from qemu.tests import blk_stream class BlockStreamCheckBackingfile(blk_stream.BlockStream): @@ -40,6 +41,7 @@ def check_imagefile(self): """ params = self.parser_test_args() exp_img_file = params["expected_image_file"] + exp_img_file = utils_misc.get_path(self.data_dir, exp_img_file) error.context("Check image file is '%s'" % exp_img_file, logging.info) img_file = self.get_image_file() if exp_img_file != img_file: diff --git a/qemu/tests/block_stream_stress.py b/qemu/tests/block_stream_stress.py index 1b2a96e19..23968efa4 100644 --- a/qemu/tests/block_stream_stress.py +++ b/qemu/tests/block_stream_stress.py @@ -1,5 +1,6 @@ import time, logging from autotest.client.shared import error +from autotest.client import utils from virttest import utils_misc from qemu.tests import blk_stream @@ -19,12 +20,37 @@ def parser_test_args(self): "configuration at first") return params + @error.context_aware + def install_stress_app(self): + params = self.parser_test_args() + session = self.get_session() + if session.cmd_status(params.get("app_check_cmd","true")) == 0: + return True + error.context("install stress app in guest", logging.info) + link = params.get("download_link") + md5sum = params.get("md5sum") + tmp_dir = params.get("tmp_dir") + install_cmd = params.get("install_cmd") + config_cmd = params.get("config_cmd") + logging.info("Fetch package: %s" % link) + pkg = utils.unmap_url_cache(self.test.tmpdir, link, md5sum) + self.vm.copy_files_to(pkg, tmp_dir) + logging.info("Install app: %s" % install_cmd) + s, o = session.cmd_status_output(install_cmd, timeout=300) + if s != 0: + raise error.TestError("Fail to install stress app(%s)" % o) + logging.info("Configure app: %s" % config_cmd) + s, o = session.cmd_status_output(config_cmd, timeout=300) + if s != 0: + raise error.TestError("Fail to conifg stress app(%s)" % o) + @error.context_aware def load_stress(self): """ load IO/CPU/Memoery stress in guest; """ params = self.parser_test_args() + self.install_stress_app() cmd = params.get("start_cmd") session = self.get_session() error.context("Load stress in guest(%s)" % cmd, logging.info) diff --git a/qemu/tests/boot_time.py b/qemu/tests/boot_time.py index 525203a6f..416dd1f5c 100644 --- a/qemu/tests/boot_time.py +++ b/qemu/tests/boot_time.py @@ -1,8 +1,12 @@ import logging, time, re, os from autotest.client.shared import error -from autotest.client import utils from virttest import utils_misc, utils_test, env_process, storage, data_dir +try: + from autotest.client.shared import utils_memory +except ImportError: + from virttest.staging import utils_memory + @error.context_aware def run_boot_time(test, params, env): @@ -34,7 +38,7 @@ def run_boot_time(test, params, env): vm.destroy() error.context("Boot up guest and measure the boot time", logging.info) - utils.drop_caches() + utils_memory.drop_caches() vm.create() vm.verify_alive() session = vm.wait_for_serial_login(timeout=timeout) diff --git a/qemu/tests/cfg/block_stream.cfg b/qemu/tests/cfg/block_stream.cfg index 679be22a9..90ed2891f 100644 --- a/qemu/tests/cfg/block_stream.cfg +++ b/qemu/tests/cfg/block_stream.cfg @@ -1,11 +1,16 @@ +# Below case works stablly on QMP monitor, but have no more test with Human +# monitor, so suggest to use QMP monitor as default qemu monitor run below test +# - block_stream: + no raw qed vmdk backup_image_before_testing = yes restore_image_after_testing = yes wait_finished = yes source_image = image1 default_speed_image1 = 0 - snapshot_chain = "/tmp/sn1 /tmp/sn2" + snapshot_chain = "images/sn1" wait_timeout = 1800 + snapshot_format = qcow2 kill_vm = yes alive_check_cmd = dir variants: @@ -35,26 +40,27 @@ default_speed_image1 = 8M - when_reboot: type = block_stream_reboot - reboot_method = "shell" + reboot_method = "system_reset" before_start = "reboot" after_finished = "reboot verify_alive" - - when_boot: - type = block_stream_reboot - reboot_method = "shell" - before_start = "bootup" - after_finished = "reboot verify_alive" - drop_backingfile: + snapshot_chain += " images/sn2" type = block_stream_drop_backingfile # set limited_speed to 10MB/s eq 10485760B/s limited_speed = 10485760 snapshot_check_cmd = "lsof -p %s|awk '{print $9}'|grep ^/" - check_backingfile: type = block_stream_check_backingfile - snapshot_chain = "/tmp/sn1" - expected_image_file = "/tmp/sn1" + snapshot_chain = "images/sn1" + expected_image_file = "images/sn1" after_finished = "check_backingfile check_imagefile verify_alive" - with_stress: type = block_stream_stress + download_link = http://weather.ou.edu/~apw/projects/stress/stress-1.0.4.tar.gz + md5sum = a607afa695a511765b40993a64c6e2f4 + install_cmd = "tar -xzvf ${tmp_dir}/stress-1.0.4.tar.gz -C ./ && cd stress-1.0.4 && ./configure --prefix=/usr && make && make install " + config_cmd = "" + app_check_cmd = "stress --help" wait_timeout = 3600 before_start = "load_stress" start_cmd = "stress --cpu 4 --io 4 --vm 2 --vm-bytes 256M --quiet &" diff --git a/qemu/tests/cfg/cpu_hotplug.cfg b/qemu/tests/cfg/cpu_hotplug.cfg index a8f445756..e12740022 100644 --- a/qemu/tests/cfg/cpu_hotplug.cfg +++ b/qemu/tests/cfg/cpu_hotplug.cfg @@ -10,6 +10,7 @@ kill_vm = yes smp = 1 vcpu_maxcpus = 160 + cpu_hotplug_cmd = 'cpu_set cpu=%s,state=online' # this at least need a RHEL.6.3 host # the smp can be overrided (tests.cfg is a good place) # if you want to test with a guest booted with diff SMP, pls modify it. diff --git a/qemu/tests/cfg/drive_mirror.cfg b/qemu/tests/cfg/drive_mirror.cfg index 79b312254..7910a54a4 100644 --- a/qemu/tests/cfg/drive_mirror.cfg +++ b/qemu/tests/cfg/drive_mirror.cfg @@ -2,7 +2,7 @@ no Host_RHEL.5 no Host_RHEL.6.1 no Host_RHEL.6.2 - only qcow2 + no raw qed vmdk type = drive_mirror monitor_type = qmp monitors = qmp1 @@ -27,13 +27,14 @@ # default speed unit is B/s, for 10MB/s please set speed to '10M' target_format_image1 = "qcow2" create_mode_image1 = "absolute-paths" - target_image_image1 = "/tmp/target1" + target_image_image1 = "images/target1" check_event = no + tmp_dir = "/tmp" variants: - - simple: + - simple_test: type = drive_mirror_simple repeat_times = 3 - cancel_timeout = 3 + cancel_timeout = 5 variants: - cancel: before_steady = "cancel" @@ -50,16 +51,21 @@ default_speed_image1 = 3M max_speed_image1 = 10M - mirroring: - type = block_mirror + variants: + - block_job_complete: + type = drive_mirror_complete + - continuous_backup: + type = drive_mirror_continuous_backup + clean_cmd = "rm -f tmp*.file" + dd_cmd = "dd if=/dev/zero bs=1024 count=1024 of=tmp%s.file" - with_stress: type = drive_mirror_stress - reopen_timeout = 360 + reopen_timeout = 600 variants: - heavyload: - tmp_dir = "/tmp" download_link = http://weather.ou.edu/~apw/projects/stress/stress-1.0.4.tar.gz md5sum = a607afa695a511765b40993a64c6e2f4 - install_cmd = "tar -xzvf %s/stress-1.0.4.tar.gz -C ./ && cd stress-1.0.4 && ./configure --prefix=/usr && make && make install " + install_cmd = "tar -xzvf ${tmp_dir}/stress-1.0.4.tar.gz -C ./ && cd stress-1.0.4 && ./configure --prefix=/usr && make && make install " config_cmd = "" app_check_cmd = "stress --help" start_cmd = "stress --cpu 4 --io 4 --vm 2 --vm-bytes 256M --quiet &" @@ -83,23 +89,26 @@ after_reopen = "reboot verify_alive" - dd: app_check_cmd = "dd --help" - start_cmd = "(dd if=/dev/urandom of=/tmp/tmp.img bs=4k count=500000 oflag=direct &)" + start_cmd = "dd if=/dev/urandom of=/tmp/dd.img bs=4k count=500000" check_cmd = "pidof dd" - stop_cmd = "killall -g dd;rm -f /tmp/tmp.img" + stop_cmd = "pkill -g dd && rm -rf /tmp/dd*" before_start = "load_stress" when_steady = "reopen" after_reopen = "reboot verify_alive" - with_reboot: type = drive_mirror_reboot - when_steady = "reopen stop_reset" + when_steady = "reopen" after_reopen = "reboot verify_alive" - with_powerdown: type = drive_mirror_powerdown - app_check_cmd = "uname" - start_cmd = 'sh -c "wget -c https://www.kernel.org/pub/linux/kernel/v2.6/longterm/v2.6.35/linux-2.6.35.14.tar.gz -O /mnt/Linux.tgz && ' - start_cmd += 'tar -xzvf /mnt/Linux.tgz -C /mnt && cd /mnt/linux-2.6.35.14 && make defconfig && make && make modules"' - check_cmd = 'pidof -s make' - stop_cmd = 'pkill sh;rm -rf /mnt/linux-2.6.35.14' + app_check_cmd = "test -d ${tmp_dir}/linux-2.6.35.14" + download_link = "https://www.kernel.org/pub/linux/kernel/v2.6/longterm/v2.6.35/linux-2.6.35.14.tar.gz" + md5sum = "15e4021ffcb47b93c218083e1f2734a7" + install_cmd = "tar xzvf ${tmp_dir}/linux-2.6.35.14.tar.gz -C ${tmp_dir}/" + config_cmd = "cd ${tmp_dir}/linux-2.6.35.14 && make defconfig" + start_cmd = "cd ${tmp_dir}/linux-2.6.35.14 && make clean && make -j `grep processor /proc/cpuinfo|wc -l` && make modules" + check_cmd = "pidof make" + stop_cmd = "pkill -g make && rm -rf ${tmp_dir}/linux*" before_start = "load_stress" when_steady = "powerdown" after_reopen ="verify_alive" diff --git a/qemu/tests/cfg/hdparm.cfg b/qemu/tests/cfg/hdparm.cfg index 713ee2462..0c2b97061 100644 --- a/qemu/tests/cfg/hdparm.cfg +++ b/qemu/tests/cfg/hdparm.cfg @@ -1,6 +1,7 @@ - hdparm: install setup image_copy unattended_install.cdrom only Linux no sd + no virtio_scsi type = hdparm get_disk_cmd = \ls /dev/[vhs]da low_status_cmd = hdparm -a64 -d0 -u0 %s diff --git a/qemu/tests/cfg/live_snapshot.cfg b/qemu/tests/cfg/live_snapshot.cfg index 0b7634d92..4cd3298ac 100644 --- a/qemu/tests/cfg/live_snapshot.cfg +++ b/qemu/tests/cfg/live_snapshot.cfg @@ -1,6 +1,7 @@ - live_snapshot: virt_test_type = qemu type = live_snapshot + no raw vmdk qed kill_vm = yes create_sn_cmd = snapshot_blkdev create_cmd = "dd if=/dev/urandom of=%s bs=1M count=1024" diff --git a/qemu/tests/cfg/live_snapshot_chain.cfg b/qemu/tests/cfg/live_snapshot_chain.cfg index 3405f9737..ef4b00bbb 100644 --- a/qemu/tests/cfg/live_snapshot_chain.cfg +++ b/qemu/tests/cfg/live_snapshot_chain.cfg @@ -1,5 +1,5 @@ - live_snapshot_chain: - only qcow2 + no qed vmdk raw virt_test_type = qemu type = live_snapshot_chain snapshot_chain = "image1 sn1" diff --git a/qemu/tests/cfg/multi_disk.cfg b/qemu/tests/cfg/multi_disk.cfg index fc373b65f..21bd1e153 100644 --- a/qemu/tests/cfg/multi_disk.cfg +++ b/qemu/tests/cfg/multi_disk.cfg @@ -23,6 +23,7 @@ cdroms = "" ide: # 3 + boot disk = 4 disks + image_extra_params = "" stg_image_num = 3 stg_params = "image_size:1G,10G,5G " stg_params += "image_format:qcow2,qcow2,raw " diff --git a/qemu/tests/cfg/qemu_cpu.cfg b/qemu/tests/cfg/qemu_cpu.cfg index 64e9c4982..2c4689c5b 100644 --- a/qemu/tests/cfg/qemu_cpu.cfg +++ b/qemu/tests/cfg/qemu_cpu.cfg @@ -3,21 +3,36 @@ virt_test_type = qemu type = cpuid start_vm = "no" + kill_vm = yes + kill_vm_gracefully = no smp = 1 # ask autotest to not mess with the cpu_model settings auto_cpu_model = no # QEMU versions: - variants: - - unknown_qemu: - - rhel64: - - qemu13: + variants qemu_flavor: + - @unknown: + - rhel: + variants rhel_version: + - 6_0: + - 6_1: + - 6_2: + - 6_3: + - 6_4: + - upstream: + variants qemu_version: + - 1_0: + - 1_1: + - 1_2: + - 1_3: + - 1_4: + - 1_5: # uncomment the line corresponding to the QEMU version, if you know it: - only unknown_qemu - #only rhel64 - #only qemu13 + only (qemu_flavor = unknown) + #only (qemu_flavor = rhel).(rhel_version = 6_4) + #only (qemu_flavor = upstream).(qemu_version = 1_5) # CPU model lists: variants: @@ -76,10 +91,10 @@ - Opteron_G5: cpu_model = "Opteron_G5" - cpu64_rhel6: - only rhel64 + only (qemu_flavor = rhel) cpu_model = "cpu64-rhel6" - cpu64_rhel4: - only rhel64 + only (qemu_flavor = rhel) cpu_model = "cpu64-rhel5" variants: @@ -96,7 +111,7 @@ only nokvm # we don't know if all models will be available if QEMU # version is unknown: - no unknown_qemu + no (qemu_flavor = unknown) # CPUID data tests: - cpuid: # 486 is excluded due to not supporting cpuid @@ -116,7 +131,7 @@ nokvm: # we don't know if all models will be available if QEMU # version is unknown: - no unknown_qemu + no (qemu_flavor = unknown) only cpu.intel cpu.amd cpu.intel: vendor = "GenuineIntel" diff --git a/qemu/tests/cfg/qemu_disk_img.cfg b/qemu/tests/cfg/qemu_disk_img.cfg index 9d5b5202f..d21fbe5a9 100644 --- a/qemu/tests/cfg/qemu_disk_img.cfg +++ b/qemu/tests/cfg/qemu_disk_img.cfg @@ -2,7 +2,7 @@ # For windows guest, you can download md5sum.exe from http://www.brothersoft.com/md5sum-81781.html, # then add parents dir to $PATH or config md5sum in share/cfg/guest-os/Windows.cfg; - qemu_disk_img: - only qcow2 + no qed raw vmdk virt_test_type = qemu type = qemu_disk_img image_chain= "image1" diff --git a/qemu/tests/cfg/qemu_guest_agent.cfg b/qemu/tests/cfg/qemu_guest_agent.cfg index 4b571e549..77128b9c2 100644 --- a/qemu/tests/cfg/qemu_guest_agent.cfg +++ b/qemu/tests/cfg/qemu_guest_agent.cfg @@ -1,5 +1,6 @@ - qemu_guest_agent: install setup image_copy unattended_install.cdrom - only Fedora.16, Fedora.17, Fedora.18, Fedora.test, Windows + only Fedora, RHEL, Windows + no 8, 9, 10, 11, 12, 13, 14, 15 type = qemu_guest_agent gagent_name = "org.qemu.guest_agent.0" gagent_install_cmd = "rpm -q qemu-guest-agent || yum install -y qemu-guest-agent" diff --git a/qemu/tests/cfg/qemu_img.cfg b/qemu/tests/cfg/qemu_img.cfg index 4170f45f0..1d7ffd8ae 100644 --- a/qemu/tests/cfg/qemu_img.cfg +++ b/qemu/tests/cfg/qemu_img.cfg @@ -57,6 +57,7 @@ - to_raw: dest_image_format = raw - to_qed: + no Host_RHEL dest_image_format = qed - snapshot: @@ -65,10 +66,12 @@ - info: subcommand = info - rebase: + no raw vmdk qed subcommand = rebase rebase_mode = unsafe image_name_snapshot1 = images/sn1 image_name_snapshot2 = images/sn2 # Commit is the only subtest that does need an installed guest - commit: install setup image_copy unattended_install.cdrom + no vmdk raw qed subcommand = commit diff --git a/qemu/tests/cfg/qemu_iotests.cfg b/qemu/tests/cfg/qemu_iotests.cfg index 4de3f2fad..ef27d3238 100644 --- a/qemu/tests/cfg/qemu_iotests.cfg +++ b/qemu/tests/cfg/qemu_iotests.cfg @@ -13,14 +13,19 @@ - raw_format: qemu_io_image_format = raw - qcow_format: + no Host_RHEL qemu_io_image_format = qcow - qcow2_format: qemu_io_image_format = qcow2 - qed_format: + no Host_RHEL qemu_io_image_format = qed - vdi_format: + no Host_RHEL qemu_io_image_format = vdi - vpc_format: + no Host_RHEL qemu_io_image_format = vpc - vmdk_format: + no Host_RHEL qemu_io_image_format = vmdk diff --git a/qemu/tests/cfg/spice.cfg b/qemu/tests/cfg/spice.cfg index 96edbb117..67ee0857b 100644 --- a/qemu/tests/cfg/spice.cfg +++ b/qemu/tests/cfg/spice.cfg @@ -21,15 +21,42 @@ -RHEL.6.devel.i386: image_name_vm2 = images/rhel6devel-32_client variants: - -fullscreen_setup: + - fullscreen_setup: type = fullscreen_setup - -rv_connect: + - smartcard_setup: + type = smartcard_setup + - rv_connect: type = rv_connect - -rv_disconnect: rv_connect - type = rv_disconnect - -rv_fullscreen: fullscreen_setup, rv_connect + - rv_video: + type = rv_video + video_binary = totem + repeat_video = "yes" + source_video_file = video_sample_test.ogv + destination_video_file_path = /tmp/test.ogv + - rv_migrate: + type = migration + main_vm = vm1 + migrate_background = yes + migration_test_command = help + #migration_bg_command = "cd /tmp; nohup tcpdump -q -i any -t ip host localhost" + #migration_bg_check_command = pgrep tcpdump + #migration_bg_kill_command = pkill tcpdump + kill_vm_on_error = yes + iterations = 2 + used_mem = 1024 + mig_timeout = 3600 + migration_protocol = "tcp" + variants: + - @default: + - with_set_speed: + mig_speed = 1G + pre_migrate = "mig_set_speed" + - with_reboot: + iterations = 1 + type = migration_with_reboot + - rv_fullscreen: fullscreen_setup, rv_connect type = rv_fullscreen - -rv_copyandpaste: rv_connect + - rv_copyandpaste: rv_connect type = rv_copyandpaste interpreter = python dst_dir = /tmp @@ -50,6 +77,8 @@ - rv_input: rv_connect type = rv_input guest_script = key_event_form.py + - rv_audio: rv_connect + type = rv_audio - rv_logging: rv_connect type = rv_logging logtest = qxl @@ -60,10 +89,20 @@ guest_script = cb.py script_params = --set text_to_test = Testing_this_text_was_copied + - rv_vdagent: rv_connect + type = rv_vdagent + vdagent_test = start + - rv_smartcard: rv_connect + type = rv_smartcard + - rv_disconnect: rv_connect + type = kill_app - rv_vmshutdown: rv_connect type = rv_vmshutdown cmd_cli_shutdown = "shutdown -h now" cmd_qemu_shutdown = "system_powerdown" + - rv_clearx: + type = rv_clearx + kill_vm = no - client_guest_shutdown: type = client_guest_shutdown shutdown_method = shell diff --git a/qemu/tests/cfg/systemtap_tracing.cfg b/qemu/tests/cfg/systemtap_tracing.cfg index c6eff2139..9b564177a 100644 --- a/qemu/tests/cfg/systemtap_tracing.cfg +++ b/qemu/tests/cfg/systemtap_tracing.cfg @@ -100,7 +100,7 @@ usb_type_hub = usb-hub usb_max_port_usb2 = 6 images += " stg" - image_name_stg = "usbdevice" + image_name_stg = "images/usbdevice" image_format_stg = "qcow2" create_image_stg = yes index_enable = yes diff --git a/qemu/tests/cfg/timerdevice.cfg b/qemu/tests/cfg/timerdevice.cfg new file mode 100644 index 000000000..8ba889f48 --- /dev/null +++ b/qemu/tests/cfg/timerdevice.cfg @@ -0,0 +1,28 @@ +- timerdevice: + only Fedora.19, RHEL.7 + no Host_RHEL.5, Host_RHEL.6 + restart_vm = yes + variants: + - tscwrite: + type = timerdevice_tscwrite + msr_tools_install_cmd = "yum install -y msr-tools" + msr_tools_cmd = "a=$(rdmsr -d 0x00000010); echo -e ibase=16\\n $a | tail -n 1 | while read n; do wrmsr 0x00000010 $(($n+100000000000)); echo $n; done" + - clock_drift_with_ntp: + type = timerdevice_clock_drift_with_ntp + host_cpu_cnt_cmd = "cat /proc/cpuinfo | grep "physical id" | wc -l" + test_run_timeout = 7200 + - tscsync: + variants: + - change_host_clksource: + type = timerdevice_tscsync_change_host_clksource + test_run_timeout = 10 + - longtime: + type = timerdevice_tscsync_longtime + host_socket_cnt_cmd = "cat /proc/cpuinfo | grep "physical id" | uniq | wc -l" + test_timeout = 36000 + test_run_timeout = 14400 + variants: + - one_socket: + vcpu_socket = 1 + - two_sockets: + vcpu_socket = 2 diff --git a/qemu/tests/cfg/usb.cfg b/qemu/tests/cfg/usb.cfg index 218a943d3..440676ec5 100644 --- a/qemu/tests/cfg/usb.cfg +++ b/qemu/tests/cfg/usb.cfg @@ -20,14 +20,19 @@ usb_max_port_usbtest = 6 drive_format_stg = "usb2" - xhci: + no RHEL.3 + no RHEL.4 + no RHEL.5 usb_type_usbtest = nec-usb-xhci usb_controller = xhci usb_max_port_usbtest = 4 drive_format_stg = "usb3" + Host_RHEL: + no Win2000, WinXP, Win2003, WinVista, Win7, Win2008 # usb toplogy variants: - - usb_default: + - without_usb_hub: - with_usb_hub: no usb_nodev usb_devices += " hub1" @@ -50,8 +55,6 @@ # usb devices variants: - @usb_nodev: - # Not used in RHEL testing. - no Host_RHEL only usb_storage, usb_host, usb_multi_disk - usb_kbd: only usb_boot, usb_reboot, usb_hotplug @@ -87,6 +90,7 @@ product = "QEMU USB CCID" - usb_audio: no Host_RHEL.6 + no Host_RHEL.7 only usb_boot, usb_reboot, usb_hotplug usb_type = usb-audio info_usb_name = "QEMU USB Audio" @@ -110,22 +114,12 @@ usb_devices += " testdev" deviceid_str = "%s:%s" chk_usb_info_cmd = "lsusb -v" - Windows: - deviceid_str = "VID_%s&PID_%s" - chk_usb_info_cmd = 'wmic path Win32_USBControllerDevice get Dependent | find "USB"' - vendor_equal = "" - product_equal = "" - usb_reboot: type = usb_basic_check reboot_method = shell usb_devices += " testdev" deviceid_str = "%s:%s" chk_usb_info_cmd = "lsusb -v" - Windows: - deviceid_str = "VID_%s&PID_%s" - chk_usb_info_cmd = 'wmic path Win32_USBControllerDevice get Dependent | find "USB"' - vendor_equal = "" - product_equal = "" - usb_hotplug: #XXX: usb_hotplug uses some linux-only cmds. # And the pattern to verify device is pluged can't @@ -158,11 +152,16 @@ usb_type_usbtest = usb-ehci usb_negative_test = "yes" usb_reply_msg = "Warning: speed mismatch trying to attach usb device" + variants: + - usb_one_time: + usb_repeat_times = 1 + - usb_multi_times: + usb_repeat_times = 5000 - usb_storage: type = usb_storage images += " stg" image_boot_image1 = yes - image_name_stg = "usbdevice" + image_name_stg = "images/usbdevice" image_format_stg = "qcow2" image_boot_stg = no drive_index_stg = 1 @@ -204,6 +203,24 @@ # must configure which device should be used #usb_host_device = ":" type = usb_host + #XXX: Now usb_host doesn't support QMP monitor. + # Limit it to human monitor only. + monitor_type = human + monitors = hmp1 + main_monitor = hmp1 + variants: + - usb_normal_test: + - usb_negative_test: + usb_negative_test = "yes" + usb_reply_msg = "Property 'usb-host.productid' doesn't take value" + usb_host_device_list = "aaa:aaa,aaa:111,21231:11231333,21231:1123132233,2123133:1123132233111" + - usb_check_isobufs: + usb_check_isobufs = "yes" + variants: + - usb_one_time: + usb_repeat_times = 1 + - usb_multi_times: + usb_repeat_times = 5000 - usb_multi_disk: only ehci type = multi_disk @@ -222,7 +239,7 @@ - one_disk_repeat: images += " stg" image_format_stg = qcow2 - image_name_stg = storage + image_name_stg = images/storage image_size_stg = 1G drive_format_stg = usb2 drive_index_stg = 1 diff --git a/qemu/tests/cgroup.py b/qemu/tests/cgroup.py index a27bb2b41..16c950bcf 100644 --- a/qemu/tests/cgroup.py +++ b/qemu/tests/cgroup.py @@ -6,14 +6,25 @@ import logging, os, re, time from autotest.client.shared import error from autotest.client import utils -from virttest.utils_cgroup import Cgroup -from virttest.utils_cgroup import CgroupModules -from virttest.utils_cgroup import get_load_per_cpu from virttest.env_process import preprocess from virttest import qemu_monitor from virttest.aexpect import ExpectTimeoutError from virttest.aexpect import ExpectProcessTerminatedError from virttest.aexpect import ShellTimeoutError +try: + from autotest.client.shared.utils_cgroup import Cgroup + from autotest.client.shared.utils_cgroup import CgroupModules + from autotest.client.shared.utils_cgroup import get_load_per_cpu +except ImportError: + # TODO: Obsoleted path used prior autotest-0.15.2/virttest-2013.06.24 + from virttest.staging.utils_cgroup import Cgroup + from virttest.staging.utils_cgroup import CgroupModules + from virttest.staging.utils_cgroup import get_load_per_cpu + +try: + from autotest.client.shared import utils_memory +except ImportError: + from virttest.staging import utils_memory @error.context_aware @@ -601,7 +612,10 @@ def cpu_cfs_util(): timeout = 1.5 * int(params.get("login_timeout", 360)) # First one vms.append(env.get_all_vms()[0]) - cpu_pids = vms[0].get_vcpu_pids(params) + vcpu_thread_pattern = params.get("vcpu_thread_pattern", + r"thread_id.?[:|=]\s*(\d+)") + cpu_pids = vms[0].get_vcpu_pids(vcpu_thread_pattern) + smp = len(cpu_pids) cgroup.mk_cgroup() cgroup.set_property("cpu.cfs_period_us", 100000, 0) @@ -632,7 +646,10 @@ def cpu_cfs_util(): # Total quota is for ALL vCPUs cgroup.set_property("cpu.cfs_quota_us", 50000 * smp, -1) assign_vm_into_cgroup(vms[-1], cgroup, -1) - cpu_pids = vms[-1].get_vcpu_pids(params) + vcpu_thread_pattern = params.get("vcpu_thread_pattern", + r"thread_id.?[:|=]\s*(\d+)") + cpu_pids = vms[-1].get_vcpu_pids(vcpu_thread_pattern) + for j in range(smp): cgroup.mk_cgroup(pwd) cgroup.set_property("cpu.cfs_period_us", 100000, -1) @@ -1076,7 +1093,10 @@ def _generate_verification(cpusets, no_cpus): params['smp'] = vm_cpus vm.create(params=params) # Verify vcpus matches prescription - vcpus = vm.get_vcpu_pids(params) + vcpu_thread_pattern = params.get("vcpu_thread_pattern", + r"thread_id.?[:|=]\s*(\d+)") + vcpus = vm.get_vcpu_pids(vcpu_thread_pattern) + if len(vcpus) != vm_cpus: raise error.TestFail("Incorrect number of vcpu PIDs; smp=%s vcpus=" "%s" % (vm_cpus, vcpus)) @@ -1754,7 +1774,7 @@ def memory_limit(memsw=False): err = "Hugepages can't be used in this test." logging.error(err) raise error.TestNAError(err) - if utils.read_from_meminfo('SwapFree') < (mem * 0.1): + if utils_memory.read_from_meminfo('SwapFree') < (mem * 0.1): err = "Not enough free swap space" logging.error(err) raise error.TestNAError(err) diff --git a/qemu/tests/cpu_hotplug.py b/qemu/tests/cpu_hotplug.py index 831cd6bf7..7089d48b3 100644 --- a/qemu/tests/cpu_hotplug.py +++ b/qemu/tests/cpu_hotplug.py @@ -35,6 +35,7 @@ def run_cpu_hotplug(test, params, env): maxcpus = int(params.get("maxcpus", 160)) current_cpus = int(params.get("smp", 1)) onoff_iterations = int(params.get("onoff_iterations", 20)) + cpu_hotplug_cmd = params['cpu_hotplug_cmd'] if n_cpus_add + current_cpus > maxcpus: logging.warn("CPU quantity more than maxcpus, set it to %s", maxcpus) @@ -49,7 +50,7 @@ def run_cpu_hotplug(test, params, env): for i in range(current_cpus, total_cpus): error.context("hot-pluging vCPU %s" % i, logging.info) - vm.monitor.send_args_cmd("cpu_set %s online" % i) + vm.monitor.send_args_cmd(cpu_hotplug_cmd % i) output = vm.monitor.send_args_cmd("info cpus") logging.debug("Output of info CPUs:\n%s", output) diff --git a/qemu/tests/cpuid.py b/qemu/tests/cpuid.py index ce869f3cc..d0b4ac914 100644 --- a/qemu/tests/cpuid.py +++ b/qemu/tests/cpuid.py @@ -1,11 +1,15 @@ """ Group of cpuid tests for X86 CPU """ -import logging, re, sys, traceback, os, string +import re, sys, os, string from autotest.client.shared import error, utils from autotest.client.shared import test as test_module from virttest import utils_misc, env_process +import logging +logger = logging.getLogger(__name__) +dbg = logger.debug +info = logger.info def run_cpuid(test, params, env): """ @@ -23,51 +27,6 @@ def run_cpuid(test, params, env): if (params.get("xfail") is not None) and (params.get("xfail") == "yes"): xfail = True - class MiniSubtest(test_module.Subtest): - """ - subtest base class for actual tests - """ - def __new__(cls, *args, **kargs): - self = test.__new__(cls) - ret = None - if args is None: - args = [] - try: - ret = self.test(*args, **kargs) - finally: - if hasattr(self, "clean"): - self.clean() - return ret - - def clean(self): - """ - cleans up running VM instance - """ - if (hasattr(self, "vm")): - vm = getattr(self, "vm") - if vm.is_alive(): - vm.pause() - vm.destroy(gracefully=False) - - def test(self): - """ - stub for actual test code - """ - raise error.TestFail("test() must be redifined in subtest") - - def print_exception(called_object): - """ - print error including stack trace - """ - exc_type, exc_value, exc_traceback = sys.exc_info() - logging.error("In function (" + called_object.__name__ + "):") - logging.error("Call from:\n" + - traceback.format_stack()[-2][:-1]) - logging.error("Exception from:\n" + - "".join(traceback.format_exception( - exc_type, exc_value, - exc_traceback.tb_next))) - def cpu_models_to_test(): """Return the list of CPU models to be tested, based on the cpu_models and cpu_model config options. @@ -96,24 +55,63 @@ def cpu_models_to_test(): return cpu_models - class test_qemu_cpu_models_list(MiniSubtest): + def test_qemu_cpu_models_list(self): """ check CPU models returned by -cpu '?' are what is expected """ - def test(self): - """ - test method - """ - cpu_models = cpu_models_to_test() - qemu_models = utils_misc.get_qemu_cpu_models(qemu_binary) - missing = set(cpu_models) - set(qemu_models) - if missing: - raise error.TestFail("Some CPU models not in QEMU CPU model list: %s") - added = set(qemu_models) - set(cpu_models) - if added: - logging.info("Extra CPU models in QEMU CPU listing: %s", added) - - def get_guest_cpuid(self, cpu_model, feature=None): + """ + test method + """ + cpu_models = cpu_models_to_test() + qemu_models = utils_misc.get_qemu_cpu_models(qemu_binary) + missing = set(cpu_models) - set(qemu_models) + if missing: + raise error.TestFail("Some CPU models not in QEMU CPU model list: %s") + added = set(qemu_models) - set(cpu_models) + if added: + logging.info("Extra CPU models in QEMU CPU listing: %s", added) + + def compare_cpuid_output(a, b): + """ + Generates a list of (register, bit, va, vb) tuples for + each bit that is different between a and b. + """ + for reg in ('eax', 'ebx', 'ecx', 'edx'): + for bit in range(32): + ba = (a[reg] & (1 << bit)) >> bit + bb = (b[reg] & (1 << bit)) >> bit + if ba <> bb: + yield (reg, bit, ba, bb) + + def parse_cpuid_dump(output): + dbg("parsing cpuid dump: %r", output) + cpuid_re = re.compile("^ *(0x[0-9a-f]+) +0x([0-9a-f]+): +eax=0x([0-9a-f]+) ebx=0x([0-9a-f]+) ecx=0x([0-9a-f]+) edx=0x([0-9a-f]+)$") + out_lines = output.splitlines() + if out_lines[0] <> '==START TEST==' or out_lines[-1] <> '==END TEST==': + dbg("cpuid dump doesn't have expected delimiters") + return None + if out_lines[1] <> 'CPU:': + dbg("cpuid dump doesn't start with 'CPU:' line") + return None + result = {} + for l in out_lines[2:-1]: + m = cpuid_re.match(l) + if m is None: + dbg("invalid cpuid dump line: %r", l) + return None + in_eax = int(m.group(1), 16) + in_ecx = int(m.group(2), 16) + out = { + 'eax':int(m.group(3), 16), + 'ebx':int(m.group(4), 16), + 'ecx':int(m.group(5), 16), + 'edx':int(m.group(6), 16), + } + result[(in_eax, in_ecx)] = out + return result + + + def get_guest_cpuid(self, cpu_model, feature=None, extra_params=None): test_kernel_dir = os.path.join(test.virtdir, "deps", "cpuid_test_kernel") os.chdir(test_kernel_dir) @@ -126,8 +124,11 @@ def get_guest_cpuid(self, cpu_model, feature=None): params_b["cpu_model_flags"] = feature del params_b["images"] del params_b["nics"] + if extra_params: + params_b.update(extra_params) env_process.preprocess_vm(self, params_b, env, vm_name) vm = env.get_vm(vm_name) + dbg('is dead: %r', vm.is_dead()) vm.create() self.vm = vm vm.resume() @@ -137,39 +138,15 @@ def get_guest_cpuid(self, cpu_model, feature=None): if not utils_misc.wait_for(f, timeout, 1): raise error.TestFail("Could not get test complete message.") - test_sig = re.compile("==START TEST==\n((?:.*\n)*)\n*==END TEST==") - test_output = test_sig.search(vm.serial_console.get_output()) - if test_output == None: + test_output = parse_cpuid_dump(vm.serial_console.get_output()) + if test_output is None: raise error.TestFail("Test output signature not found in " "output:\n %s", vm.serial_console.get_output()) - self.clean() - return test_output.group(1) - - def cpuid_regs_to_dic(level_count, cpuid_dump): - """ - @param level_count: is CPUID level and count string in format - 'LEVEL COUNT', where: - LEVEL - CPUID level in hex format - 8 chracters width - COUNT - input ECX value of cpuid in - hex format 2 charaters width - example: '0x00000001 0x00' - @cpuid_dump: string: output of 'cpuid' utility or provided with - this test simple kernel that dumps cpuid - in a similar format. - @return: dictionary of register values indexed by register name - """ - grp = '\w*=(\w*)\s*' - regs = re.search('\s+%s:.*%s%s%s%s' % (level_count, grp, grp, grp, grp), - cpuid_dump) - if regs == None: - raise error.TestFail("Could not find %s in cpuid output:\n%s", - level_count, cpuid_dump) - return {'eax': int(regs.group(1), 16), 'ebx': int(regs.group(2), 16), - 'ecx': int(regs.group(3), 16), 'edx': int(regs.group(4), 16) } + vm.destroy(gracefully=False) + return test_output def cpuid_to_vendor(cpuid_dump, idx): - r = cpuid_regs_to_dic(idx + ' 0x00', cpuid_dump) + r = cpuid_dump[idx, 0] dst = [] map(lambda i: dst.append((chr(r['ebx'] >> (8 * i) & 0xff))), range(0, 4)) @@ -179,211 +156,204 @@ def cpuid_to_vendor(cpuid_dump, idx): dst.append((chr(r['ecx'] >> (8 * i) & 0xff))), range(0, 4)) return ''.join(dst) - class default_vendor(MiniSubtest): + def default_vendor(self): """ Boot qemu with specified cpu models and verify that CPU vendor matches requested """ - def test(self): - cpu_models = cpu_models_to_test() - - vendor = params.get("vendor") - if vendor is None or vendor == "host": - cmd = "grep 'vendor_id' /proc/cpuinfo | head -n1 | awk '{print $3}'" - cmd_result = utils.run(cmd, ignore_status=True) - vendor = cmd_result.stdout.strip() - - ignore_cpus = set(params.get("ignore_cpu_models","").split(' ')) - cpu_models = cpu_models - ignore_cpus - - for cpu_model in cpu_models: - out = get_guest_cpuid(self, cpu_model) - guest_vendor = cpuid_to_vendor(out, '0x00000000') - logging.debug("Guest's vendor: " + guest_vendor) - if guest_vendor != vendor: - raise error.TestFail("Guest vendor [%s], doesn't match " - "required vendor [%s] for CPU [%s]" % - (guest_vendor, vendor, cpu_model)) - - class custom_vendor(MiniSubtest): + cpu_models = cpu_models_to_test() + + vendor = params.get("vendor") + if vendor is None or vendor == "host": + cmd = "grep 'vendor_id' /proc/cpuinfo | head -n1 | awk '{print $3}'" + cmd_result = utils.run(cmd, ignore_status=True) + vendor = cmd_result.stdout.strip() + + ignore_cpus = set(params.get("ignore_cpu_models","").split(' ')) + cpu_models = cpu_models - ignore_cpus + + for cpu_model in cpu_models: + out = get_guest_cpuid(self, cpu_model) + guest_vendor = cpuid_to_vendor(out, 0x00000000) + logging.debug("Guest's vendor: " + guest_vendor) + if guest_vendor != vendor: + raise error.TestFail("Guest vendor [%s], doesn't match " + "required vendor [%s] for CPU [%s]" % + (guest_vendor, vendor, cpu_model)) + + def custom_vendor(self): """ Boot qemu with specified vendor """ - def test(self): - has_error = False - vendor = params["vendor"] - - try: - out = get_guest_cpuid(self, cpu_model, "vendor=" + vendor) - guest_vendor0 = cpuid_to_vendor(out, '0x00000000') - guest_vendor80000000 = cpuid_to_vendor(out, '0x80000000') - logging.debug("Guest's vendor[0]: " + guest_vendor0) - logging.debug("Guest's vendor[0x80000000]: " + - guest_vendor80000000) - if guest_vendor0 != vendor: - raise error.TestFail("Guest vendor[0] [%s], doesn't match " - "required vendor [%s] for CPU [%s]" % - (guest_vendor0, vendor, cpu_model)) - if guest_vendor80000000 != vendor: - raise error.TestFail("Guest vendor[0x80000000] [%s], " - "doesn't match required vendor " - "[%s] for CPU [%s]" % - (guest_vendor80000000, vendor, - cpu_model)) - except: - has_error = True - if xfail is False: - raise - if (has_error is False) and (xfail is True): - raise error.TestFail("Test was expected to fail, but it didn't") + has_error = False + vendor = params["vendor"] + + try: + out = get_guest_cpuid(self, cpu_model, "vendor=" + vendor) + guest_vendor0 = cpuid_to_vendor(out, 0x00000000) + guest_vendor80000000 = cpuid_to_vendor(out, 0x80000000) + logging.debug("Guest's vendor[0]: " + guest_vendor0) + logging.debug("Guest's vendor[0x80000000]: " + + guest_vendor80000000) + if guest_vendor0 != vendor: + raise error.TestFail("Guest vendor[0] [%s], doesn't match " + "required vendor [%s] for CPU [%s]" % + (guest_vendor0, vendor, cpu_model)) + if guest_vendor80000000 != vendor: + raise error.TestFail("Guest vendor[0x80000000] [%s], " + "doesn't match required vendor " + "[%s] for CPU [%s]" % + (guest_vendor80000000, vendor, + cpu_model)) + except: + has_error = True + if xfail is False: + raise + if (has_error is False) and (xfail is True): + raise error.TestFail("Test was expected to fail, but it didn't") def cpuid_to_level(cpuid_dump): - r = cpuid_regs_to_dic('0x00000000 0x00', cpuid_dump) + r = cpuid_dump[0, 0] return r['eax'] - class custom_level(MiniSubtest): + def custom_level(self): """ Boot qemu with specified level """ - def test(self): - has_error = False - level = params["level"] - try: - out = get_guest_cpuid(self, cpu_model, "level=" + level) - guest_level = str(cpuid_to_level(out)) - if guest_level != level: - raise error.TestFail("Guest's level [%s], doesn't match " - "required level [%s]" % - (guest_level, level)) - except: - has_error = True - if xfail is False: - raise - if (has_error is False) and (xfail is True): - raise error.TestFail("Test was expected to fail, but it didn't") + has_error = False + level = params["level"] + try: + out = get_guest_cpuid(self, cpu_model, "level=" + level) + guest_level = str(cpuid_to_level(out)) + if guest_level != level: + raise error.TestFail("Guest's level [%s], doesn't match " + "required level [%s]" % + (guest_level, level)) + except: + has_error = True + if xfail is False: + raise + if (has_error is False) and (xfail is True): + raise error.TestFail("Test was expected to fail, but it didn't") def cpuid_to_family(cpuid_dump): # Intel Processor Identification and the CPUID Instruction # http://www.intel.com/Assets/PDF/appnote/241618.pdf # 5.1.2 Feature Information (Function 01h) - eax = cpuid_regs_to_dic('0x00000001 0x00', cpuid_dump)['eax'] + eax = cpuid_dump[1, 0]['eax'] family = (eax >> 8) & 0xf if family == 0xf: # extract extendend family return family + ((eax >> 20) & 0xff) return family - class custom_family(MiniSubtest): + def custom_family(self): """ Boot qemu with specified family """ - def test(self): - has_error = False - family = params["family"] - try: - out = get_guest_cpuid(self, cpu_model, "family=" + family) - guest_family = str(cpuid_to_family(out)) - if guest_family != family: - raise error.TestFail("Guest's family [%s], doesn't match " - "required family [%s]" % - (guest_family, family)) - except: - has_error = True - if xfail is False: - raise - if (has_error is False) and (xfail is True): - raise error.TestFail("Test was expected to fail, but it didn't") + has_error = False + family = params["family"] + try: + out = get_guest_cpuid(self, cpu_model, "family=" + family) + guest_family = str(cpuid_to_family(out)) + if guest_family != family: + raise error.TestFail("Guest's family [%s], doesn't match " + "required family [%s]" % + (guest_family, family)) + except: + has_error = True + if xfail is False: + raise + if (has_error is False) and (xfail is True): + raise error.TestFail("Test was expected to fail, but it didn't") def cpuid_to_model(cpuid_dump): # Intel Processor Identification and the CPUID Instruction # http://www.intel.com/Assets/PDF/appnote/241618.pdf # 5.1.2 Feature Information (Function 01h) - eax = cpuid_regs_to_dic('0x00000001 0x00', cpuid_dump)['eax'] + eax = cpuid_dump[1, 0]['eax'] model = (eax >> 4) & 0xf # extended model model |= (eax >> 12) & 0xf0 return model - class custom_model(MiniSubtest): + def custom_model(self): """ Boot qemu with specified model """ - def test(self): - has_error = False - model = params["model"] - try: - out = get_guest_cpuid(self, cpu_model, "model=" + model) - guest_model = str(cpuid_to_model(out)) - if guest_model != model: - raise error.TestFail("Guest's model [%s], doesn't match " - "required model [%s]" % - (guest_model, model)) - except: - has_error = True - if xfail is False: - raise - if (has_error is False) and (xfail is True): - raise error.TestFail("Test was expected to fail, but it didn't") + has_error = False + model = params["model"] + try: + out = get_guest_cpuid(self, cpu_model, "model=" + model) + guest_model = str(cpuid_to_model(out)) + if guest_model != model: + raise error.TestFail("Guest's model [%s], doesn't match " + "required model [%s]" % + (guest_model, model)) + except: + has_error = True + if xfail is False: + raise + if (has_error is False) and (xfail is True): + raise error.TestFail("Test was expected to fail, but it didn't") def cpuid_to_stepping(cpuid_dump): # Intel Processor Identification and the CPUID Instruction # http://www.intel.com/Assets/PDF/appnote/241618.pdf # 5.1.2 Feature Information (Function 01h) - eax = cpuid_regs_to_dic('0x00000001 0x00', cpuid_dump)['eax'] + eax = cpuid_dump[1, 0]['eax'] stepping = eax & 0xf return stepping - class custom_stepping(MiniSubtest): + def custom_stepping(self): """ Boot qemu with specified stepping """ - def test(self): - has_error = False - stepping = params["stepping"] - try: - out = get_guest_cpuid(self, cpu_model, "stepping=" + stepping) - guest_stepping = str(cpuid_to_stepping(out)) - if guest_stepping != stepping: - raise error.TestFail("Guest's stepping [%s], doesn't match " - "required stepping [%s]" % - (guest_stepping, stepping)) - except: - has_error = True - if xfail is False: - raise - if (has_error is False) and (xfail is True): - raise error.TestFail("Test was expected to fail, but it didn't") + has_error = False + stepping = params["stepping"] + try: + out = get_guest_cpuid(self, cpu_model, "stepping=" + stepping) + guest_stepping = str(cpuid_to_stepping(out)) + if guest_stepping != stepping: + raise error.TestFail("Guest's stepping [%s], doesn't match " + "required stepping [%s]" % + (guest_stepping, stepping)) + except: + has_error = True + if xfail is False: + raise + if (has_error is False) and (xfail is True): + raise error.TestFail("Test was expected to fail, but it didn't") def cpuid_to_xlevel(cpuid_dump): # Intel Processor Identification and the CPUID Instruction # http://www.intel.com/Assets/PDF/appnote/241618.pdf # 5.2.1 Largest Extendend Function # (Function 80000000h) - return cpuid_regs_to_dic('0x80000000 0x00', cpuid_dump)['eax'] + return cpuid_dump[0x80000000, 0x00]['eax'] - class custom_xlevel(MiniSubtest): + def custom_xlevel(self): """ Boot qemu with specified xlevel """ - def test(self): - has_error = False - xlevel = params["xlevel"] - if params.get("expect_xlevel") is not None: - xlevel = params.get("expect_xlevel") - - try: - out = get_guest_cpuid(self, cpu_model, "xlevel=" + - params.get("xlevel")) - guest_xlevel = str(cpuid_to_xlevel(out)) - if guest_xlevel != xlevel: - raise error.TestFail("Guest's xlevel [%s], doesn't match " - "required xlevel [%s]" % - (guest_xlevel, xlevel)) - except: - has_error = True - if xfail is False: - raise - if (has_error is False) and (xfail is True): - raise error.TestFail("Test was expected to fail, but it didn't") + has_error = False + xlevel = params["xlevel"] + if params.get("expect_xlevel") is not None: + xlevel = params.get("expect_xlevel") + + try: + out = get_guest_cpuid(self, cpu_model, "xlevel=" + + params.get("xlevel")) + guest_xlevel = str(cpuid_to_xlevel(out)) + if guest_xlevel != xlevel: + raise error.TestFail("Guest's xlevel [%s], doesn't match " + "required xlevel [%s]" % + (guest_xlevel, xlevel)) + except: + has_error = True + if xfail is False: + raise + if (has_error is False) and (xfail is True): + raise error.TestFail("Test was expected to fail, but it didn't") def cpuid_to_model_id(cpuid_dump): # Intel Processor Identification and the CPUID Instruction @@ -391,8 +361,8 @@ def cpuid_to_model_id(cpuid_dump): # 5.2.3 Processor Brand String (Functions 80000002h, 80000003h, # 80000004h) m_id = "" - for idx in ('0x80000002', '0x80000003', '0x80000004'): - regs = cpuid_regs_to_dic('%s 0x00' % idx, cpuid_dump) + for idx in (0x80000002, 0x80000003, 0x80000004): + regs = cpuid_dump[idx, 0] for name in ('eax', 'ebx', 'ecx', 'edx'): for shift in range(4): c = ((regs[name] >> (shift * 8)) & 0xff) @@ -401,31 +371,30 @@ def cpuid_to_model_id(cpuid_dump): m_id += chr(c) return m_id - class custom_model_id(MiniSubtest): + def custom_model_id(self): """ Boot qemu with specified model_id """ - def test(self): - has_error = False - model_id = params["model_id"] - - try: - out = get_guest_cpuid(self, cpu_model, "model_id='%s'" % - model_id) - guest_model_id = cpuid_to_model_id(out) - if guest_model_id != model_id: - raise error.TestFail("Guest's model_id [%s], doesn't match " - "required model_id [%s]" % - (guest_model_id, model_id)) - except: - has_error = True - if xfail is False: - raise - if (has_error is False) and (xfail is True): - raise error.TestFail("Test was expected to fail, but it didn't") + has_error = False + model_id = params["model_id"] + + try: + out = get_guest_cpuid(self, cpu_model, "model_id='%s'" % + model_id) + guest_model_id = cpuid_to_model_id(out) + if guest_model_id != model_id: + raise error.TestFail("Guest's model_id [%s], doesn't match " + "required model_id [%s]" % + (guest_model_id, model_id)) + except: + has_error = True + if xfail is False: + raise + if (has_error is False) and (xfail is True): + raise error.TestFail("Test was expected to fail, but it didn't") def cpuid_regs_to_string(cpuid_dump, leaf, idx, regs): - r = cpuid_regs_to_dic('%s %s' % (leaf, idx), cpuid_dump) + r = cpuid_dump[leaf, idx] signature = "" for i in regs: for shift in range(0, 4): @@ -438,97 +407,85 @@ def cpuid_regs_to_string(cpuid_dump, leaf, idx, regs): signature)) return signature - class cpuid_signature(MiniSubtest): + def cpuid_signature(self): """ test signature in specified leaf:index:regs """ - def test(self): - has_error = False - flags = params.get("flags","") - leaf = params.get("leaf","0x40000000") - idx = params.get("index","0x00") - regs = params.get("regs","ebx ecx edx").split() - signature = params["signature"] - try: - out = get_guest_cpuid(self, cpu_model, flags) - _signature = cpuid_regs_to_string(out, leaf, idx, regs) - if _signature != signature: - raise error.TestFail("Guest's signature [%s], doesn't" - "match required signature [%s]" % - (_signature, signature)) - except: - has_error = True - if xfail is False: - raise - if (has_error is False) and (xfail is True): - raise error.TestFail("Test was expected to fail, but it didn't") - - class cpuid_bit_test(MiniSubtest): + has_error = False + flags = params.get("flags","") + leaf = int(params.get("leaf","0x40000000"), 0) + idx = int(params.get("index","0x00"), 0) + regs = params.get("regs","ebx ecx edx").split() + signature = params["signature"] + try: + out = get_guest_cpuid(self, cpu_model, flags) + _signature = cpuid_regs_to_string(out, leaf, idx, regs) + if _signature != signature: + raise error.TestFail("Guest's signature [%s], doesn't" + "match required signature [%s]" % + (_signature, signature)) + except: + has_error = True + if xfail is False: + raise + if (has_error is False) and (xfail is True): + raise error.TestFail("Test was expected to fail, but it didn't") + + def cpuid_bit_test(self): """ test bits in specified leaf:func:reg """ - def test(self): - has_error = False - flags = params.get("flags","") - leaf = params.get("leaf","0x40000000") - idx = params.get("index","0x00") - reg = params.get("reg","eax") - bits = params["bits"].split() - try: - out = get_guest_cpuid(self, cpu_model, flags) - r = cpuid_regs_to_dic('%s %s' % (leaf, idx), out)[reg] - logging.debug("CPUID(%s.%s).%s=0x%08x" % (leaf, idx, reg, r)) - for i in bits: - if (r & (1 << int(i))) == 0: - raise error.TestFail("CPUID(%s.%s).%s[%s] is not set" % - (leaf, idx, reg, i)) - except: - has_error = True - if xfail is False: - raise - if (has_error is False) and (xfail is True): - raise error.TestFail("Test was expected to fail, but it didn't") - - class cpuid_reg_test(MiniSubtest): + has_error = False + flags = params.get("flags","") + leaf = int(params.get("leaf","0x40000000"), 0) + idx = int(params.get("index","0x00"), 0) + reg = params.get("reg","eax") + bits = params["bits"].split() + try: + out = get_guest_cpuid(self, cpu_model, flags) + r = out[leaf, idx][reg] + logging.debug("CPUID(%s.%s).%s=0x%08x" % (leaf, idx, reg, r)) + for i in bits: + if (r & (1 << int(i))) == 0: + raise error.TestFail("CPUID(%s.%s).%s[%s] is not set" % + (leaf, idx, reg, i)) + except: + has_error = True + if xfail is False: + raise + if (has_error is False) and (xfail is True): + raise error.TestFail("Test was expected to fail, but it didn't") + + def cpuid_reg_test(self): """ test register value in specified leaf:index:reg """ - def test(self): - has_error = False - flags = params.get("flags","") - leaf = params.get("leaf") - idx = params.get("index","0x00") - reg = params.get("reg","eax") - val = int(params["value"]) - try: - out = get_guest_cpuid(self, cpu_model, flags) - r = cpuid_regs_to_dic('%s %s' % (leaf, idx), out)[reg] - logging.debug("CPUID(%s.%s).%s=0x%08x" % (leaf, idx, reg, r)) - if r != val: - raise error.TestFail("CPUID(%s.%s).%s is not 0x%08x" % - (leaf, idx, reg, val)) - except: - has_error = True - if xfail is False: - raise - if (has_error is False) and (xfail is True): - raise error.TestFail("Test was expected to fail, but it didn't") + has_error = False + flags = params.get("flags","") + leaf = int(params.get("leaf", "0x00"), 0) + idx = int(params.get("index","0x00"), 0) + reg = params.get("reg","eax") + val = int(params["value"], 0) + try: + out = get_guest_cpuid(self, cpu_model, flags) + r = out[leaf, idx][reg] + logging.debug("CPUID(%s.%s).%s=0x%08x" % (leaf, idx, reg, r)) + if r != val: + raise error.TestFail("CPUID(%s.%s).%s is not 0x%08x" % + (leaf, idx, reg, val)) + except: + has_error = True + if xfail is False: + raise + if (has_error is False) and (xfail is True): + raise error.TestFail("Test was expected to fail, but it didn't") # subtests runner test_type = params["test_type"] - failed = [] - if test_type in locals(): - tests_group = locals()[test_type] - try: - tests_group() - except: - print_exception(tests_group) - failed.append(test_type) - else: - raise error.TestError("Test group '%s' is not defined in" + if test_type not in locals(): + raise error.TestError("Test function '%s' is not defined in" " test" % test_type) - if failed != []: - raise error.TestFail("Test of cpu models %s failed." % - (str(failed))) + test_func = locals()[test_type] + return test_func(test) diff --git a/qemu/tests/drive_mirror.py b/qemu/tests/drive_mirror.py index 90416353c..c7efd0e01 100644 --- a/qemu/tests/drive_mirror.py +++ b/qemu/tests/drive_mirror.py @@ -1,6 +1,6 @@ import logging, time from autotest.client.shared import error -from virttest import utils_misc +from virttest import utils_misc, storage from qemu.tests import block_copy class DriveMirror(block_copy.BlockCopy): @@ -10,6 +10,7 @@ class DriveMirror(block_copy.BlockCopy): def __init__(self, test, params, env, tag): super(DriveMirror, self).__init__(test, params, env, tag) + self.target_image = self.get_target_image() def parser_test_args(self): """ @@ -21,30 +22,38 @@ def parser_test_args(self): params["reopen_timeout"] = int(params.get("reopen_timeout", 60)) params["full_copy"] = params.get("full_copy", "").lower() params["check_event"] = params.get("check_event", "no").lower() - cmd = params.get("block_mirror_cmd", "__com.redhat.drive-mirror") - if cmd.startswith("__com.redhat"): + if params["block_mirror_cmd"].startswith("__"): params["full_copy"] = (params["full_copy"] == "full") return params + def get_target_image(self): + params = self.parser_test_args() + t_params = {} + t_params["image_name"] = params["target_image"] + t_params["image_format"] = params["target_format"] + target_image = storage.get_image_filename(t_params, self.data_dir) + return target_image + @error.context_aware def start(self): """ start block device mirroring job; """ params = self.parser_test_args() - target_image = params.get("target_image") - default_speed = params.get("default_speed") - full_copy = params.get("full_copy") - create_mode = params.get("create_mode") - target_format = params.get("target_format") - - error.context("start to mirror block device", logging.info) - self.vm.block_mirror(self.device, target_image, default_speed, + target_image = self.target_image + device = self.device + default_speed = params["default_speed"] + target_format = params["target_format"] + create_mode = params["create_mode"] + full_copy = params["full_copy"] + + error.context("Start to mirror block device", logging.info) + self.vm.block_mirror(device, target_image, default_speed, full_copy, target_format, create_mode) time.sleep(0.5) started = self.get_status() if not started: - raise error.TestFail("No active mirror job found") + raise error.TestFail("No active mirroring job found") self.trash.append(target_image) @error.context_aware @@ -53,14 +62,12 @@ def reopen(self): reopen target image, then check if image file of the device is target images; """ - params = self.parser_test_args() - target_image = params.get("target_image") - target_format = params.get("target_format") - reopen_timeout = params.get("reopen_timeout") + target_format = params["target_format"] + timeout = params["reopen_timeout"] def is_opened(): - device = self.vm.get_block({"file": target_image}) + device = self.vm.get_block({"file": self.target_image}) ret = (device == self.device) if self.vm.monitor.protocol == "qmp": ret &= bool(self.vm.monitor.get_event("BLOCK_JOB_COMPLETED")) @@ -68,11 +75,11 @@ def is_opened(): error.context("reopen new target image", logging.info) if self.vm.monitor.protocol == "qmp": - self.vm.monitor.clear_events() - self.vm.block_reopen(self.device, target_image, target_format) - opened = utils_misc.wait_for(is_opened, timeout=reopen_timeout) + self.vm.monitor.clear_event("BLOCK_JOB_COMPLETED") + self.vm.block_reopen(self.device, self.target_image, target_format) + opened = utils_misc.wait_for(is_opened, first=3.0, timeout=timeout) if not opened: - msg = "Wait open new image timeout(%ss)" % reopen_timeout + msg = "Target image not used,wait timeout in %ss" % timeout raise error.TestFail(msg) def is_steady(self): @@ -95,10 +102,12 @@ def wait_for_steady(self): """ params = self.parser_test_args() timeout = params.get("wait_timeout") - steady =utils_misc.wait_for(self.is_steady, - step=2.0, timeout=timeout) + if self.vm.monitor.protocol == "qmp": + self.vm.monitor.clear_event("BLOCK_JOB_READY") + steady = utils_misc.wait_for(self.is_steady, step=2.0, + timeout=timeout) if not steady: - raise error.TestFail("wait job goin ready status" + raise error.TestFail("Wait mirroring job ready " "timeout in %ss" % timeout) def action_before_start(self): diff --git a/qemu/tests/drive_mirror_complete.py b/qemu/tests/drive_mirror_complete.py new file mode 100644 index 000000000..9fa9fe8b8 --- /dev/null +++ b/qemu/tests/drive_mirror_complete.py @@ -0,0 +1,33 @@ +import logging, time +from autotest.client.shared import error +from virttest import qemu_storage, data_dir +from qemu.tests import drive_mirror + +@error.context_aware +def run_drive_mirror_complete(test, params, env): + """ + Test block mirroring functionality + + 1) Mirror the guest and switch to the mirrored one + + "qemu-img compare" is used to verify disk is mirrored successfully. + """ + tag = params.get("source_images", "image1") + qemu_img = qemu_storage.QemuImg(params, data_dir.get_data_dir(), tag) + mirror_test = drive_mirror.DriveMirror(test, params, env, tag) + try: + source_image = mirror_test.get_image_file() + target_image = mirror_test.get_target_image() + mirror_test.start() + mirror_test.wait_for_steady() + mirror_test.vm.pause() + mirror_test.reopen() + device_id = mirror_test.vm.get_block({"file": target_image}) + if device_id != mirror_test.device: + raise error.TestError("Mirrored image not being used by guest") + time.sleep(5) + error.context("Compare fully mirrored images", logging.info) + qemu_img.compare_images(source_image, target_image) + mirror_test.vm.destroy() + finally: + mirror_test.clean() diff --git a/qemu/tests/drive_mirror_continuous_backup.py b/qemu/tests/drive_mirror_continuous_backup.py new file mode 100644 index 000000000..f710b1323 --- /dev/null +++ b/qemu/tests/drive_mirror_continuous_backup.py @@ -0,0 +1,41 @@ +import logging, time +from autotest.client.shared import error +from virttest import qemu_storage, data_dir +from qemu.tests import drive_mirror + +@error.context_aware +def run_drive_mirror_continuous_backup(test, params, env): + """ + 1) Synchronize disk and then do continuous backup + + "qemu-img compare" is used to verify disk is mirrored successfully. + """ + tag = params.get("source_images", "image1") + qemu_img = qemu_storage.QemuImg(params, data_dir.get_data_dir(), tag) + mirror_test = drive_mirror.DriveMirror(test, params, env, tag) + tmp_dir = params.get("tmp_dir", "c:\\") + clean_cmd = params.get("clean_cmd", "del /f /s /q tmp*.file") + dd_cmd = "dd if=/dev/zero bs=1024 count=1024 of=tmp%s.file" + dd_cmd = params.get("dd_cmd", dd_cmd) + try: + source_image = mirror_test.get_image_file() + target_image = mirror_test.get_target_image() + mirror_test.start() + mirror_test.wait_for_steady() + error.context("Testing continuous backup") + session = mirror_test.get_session() + session.cmd("cd %s" % tmp_dir) + for fn in range(0, 128): + session.cmd(dd_cmd % fn) + time.sleep(10) + mirror_test.vm.pause() + time.sleep(5) + error.context("Compare original and backup images", logging.info) + mirror_test.vm.resume() + session = mirror_test.get_session() + session.cmd(clean_cmd) + session.cmd("cd %s" % tmp_dir) + qemu_img.compare_images(source_image, target_image) + mirror_test.vm.destroy() + finally: + mirror_test.clean() diff --git a/qemu/tests/drive_mirror_powerdown.py b/qemu/tests/drive_mirror_powerdown.py index 473bb84be..b53ad85a1 100644 --- a/qemu/tests/drive_mirror_powerdown.py +++ b/qemu/tests/drive_mirror_powerdown.py @@ -1,61 +1,43 @@ import logging -from virttest import storage, data_dir -from autotest.client.shared import error, utils +from virttest import env_process +from autotest.client.shared import error from qemu.tests import drive_mirror_stress class DriveMirrorPowerdown(drive_mirror_stress.DriveMirrorStress): def __init__(self, test, params, env, tag): super(DriveMirrorPowerdown, self).__init__(test, params, env, tag) - params = self.params.object_params(self.tag) - image_file = storage.get_image_filename(params, - data_dir.get_data_dir()) - self.params["image_file"] = image_file @error.context_aware def powerdown(self): """ power down guest via quit qemu; """ - params = self.parser_test_args() error.context("powerdown vm", logging.info) - self.vm.destroy() - error.context("backup base image", logging.info) - image_file = params.get("image_file") - cmd = "mv %s %s-bak" % (image_file, image_file) - utils.system(cmd) - return + return self.vm.destroy() @error.context_aware def powerup(self): """ - bootup guest with target image, same as reopen new image; - steps are: - 1). backup base image, move target image as base image - 2). bootup guest with target image; + bootup guest with target image; """ params = self.parser_test_args() - image_file = params.get("image_file") - target_image = params.get("target_image") - cmd = "mv -f %s %s" % (target_image, image_file) - error.context("copy target image") - utils.system(cmd) + vm_name = params['main_vm'] + self.params["image_name"] = params["target_image"] + self.params["image_format"] = params["target_format"] + logging.info("Target image: %s" % self.target_image) error.context("powerup vm with target image", logging.info) - self.vm.create() - - def clean(self): - params = self.parser_test_args() - image_file = params.get("image_file") - super(DriveMirrorPowerdown, self).clean() - cmd = "mv -f %s-bak %s" % (image_file, image_file) - utils.system(cmd) + env_process.preprocess_vm(self.test, self.params, self.env, vm_name) + vm = self.env.get_vm(vm_name) + vm.verify_alive() + self.vm = vm def run_drive_mirror_powerdown(test, params, env): """ drive_mirror_powerdown test: 1). boot guest, do kernel build - 3). mirror disk to target image - 4). wait go into steady status, then quit qemu + 3). mirror boot disk to target image + 4). wait mirroring go into ready status then quit qemu 5). bootup guest with target image 6). check guest can response correctly diff --git a/qemu/tests/drive_mirror_reboot.py b/qemu/tests/drive_mirror_reboot.py index 7120a6082..315002b1b 100644 --- a/qemu/tests/drive_mirror_reboot.py +++ b/qemu/tests/drive_mirror_reboot.py @@ -1,42 +1,11 @@ -import time, random, logging -from autotest.client.shared import error, utils from qemu.tests import drive_mirror -class DriveMirrorReboot(drive_mirror.DriveMirror): - - STOP = False - - def __init__(self, test, params, env, tag): - super(DriveMirrorReboot, self).__init__(test, params, env, tag) - - @error.context_aware - def start_reset(self): - """ - Reset guest with system_reset in loop; - """ - reboot_method = self.params.get("reboot_method", "system_reset") - error.context("reset/restart guest in loop", logging.info) - while not self.STOP: - self.reboot(method=reboot_method) - random_sleep =random.randint(3, 20) - time.sleep(random_sleep) - return None - - @error.context_aware - def stop_reset(self): - """ - stop reset guest loop; - """ - error.context("stop reset/restart guest loop", logging.info) - self.STOP = True - - def run_drive_mirror_reboot(test, params, env): """ drive_mirror_reboot test: - 1). boot guest, do system_reset in loop + 1). boot guest, do system_reset 2). start mirroring, wait go into steady status - 3). reopen new image and stop system_reset, then reboot guest + 3). reopen new image then reboot guest 4). check guest alive @param test: QEMU test object @@ -44,13 +13,11 @@ def run_drive_mirror_reboot(test, params, env): @param env: Dictionary with test environment. """ tag = params.get("source_images", "image1") - reboot_test = DriveMirrorReboot(test, params, env, tag) + reboot_test = drive_mirror.DriveMirror(test, params, env, tag) try: - bg = utils.InterruptedThread(reboot_test.start_reset) - bg.start() + reboot_test.reboot("system_reset", False) reboot_test.start() reboot_test.action_when_steady() - bg.join() reboot_test.action_after_reopen() finally: reboot_test.clean() diff --git a/qemu/tests/drive_mirror_stress.py b/qemu/tests/drive_mirror_stress.py index 3177efdef..24dbd8205 100644 --- a/qemu/tests/drive_mirror_stress.py +++ b/qemu/tests/drive_mirror_stress.py @@ -11,22 +11,24 @@ def __init__(self, test, params, env, tag): @error.context_aware def install_stress_app(self): - error.context("install stress app in guest") params = self.parser_test_args() session = self.get_session() - installed = session.cmd_status(params.get("app_check_cmd")) == 0 - if installed: - return + if session.cmd_status(params.get("app_check_cmd","true")) == 0: + return True + error.context("install stress app in guest", logging.info) link = params.get("download_link") md5sum = params.get("md5sum") tmp_dir = params.get("tmp_dir") - install_cmd = params.get("install_cmd") % tmp_dir + install_cmd = params.get("install_cmd") config_cmd = params.get("config_cmd") + logging.info("Fetch package: %s" % link) pkg = utils.unmap_url_cache(self.test.tmpdir, link, md5sum) self.vm.copy_files_to(pkg, tmp_dir) + logging.info("Install app: %s" % install_cmd) s, o = session.cmd_status_output(install_cmd, timeout=300) if s != 0: raise error.TestError("Fail to install stress app(%s)" % o) + logging.info("Configure app: %s" % config_cmd) s, o = session.cmd_status_output(config_cmd, timeout=300) if s != 0: raise error.TestError("Fail to conifg stress app(%s)" % o) @@ -43,8 +45,8 @@ def load_stress(self): session = self.get_session() error.context("launch stress app in guest", logging.info) session.sendline(cmd) - logging.info("Command: %s" % cmd) - runing = utils_misc.wait_for(self.app_runing, first=0.5, timeout=300) + logging.info("Start command: %s" % cmd) + runing = utils_misc.wait_for(self.app_runing, timeout=150, step=5) if not runing: raise error.TestFail("stress app isn't running") return None diff --git a/qemu/tests/hdparm.py b/qemu/tests/hdparm.py index 268ee1a7f..893e8331a 100644 --- a/qemu/tests/hdparm.py +++ b/qemu/tests/hdparm.py @@ -61,7 +61,7 @@ def perform_read_timing(disk, timeout, num=5): ignore_string = params.get("ignore_string") vm = env.get_vm(params["main_vm"]) - vm.create() + vm.verify_alive() session = vm.wait_for_login(timeout=int(params.get("login_timeout", 360))) try: timeout = float(params.get("cmd_timeout", 60)) diff --git a/qemu/tests/ksm_overcommit.py b/qemu/tests/ksm_overcommit.py index 2933aea1f..030d6603f 100644 --- a/qemu/tests/ksm_overcommit.py +++ b/qemu/tests/ksm_overcommit.py @@ -1,8 +1,14 @@ import logging, time, random, math, os from autotest.client.shared import error -from autotest.client import utils from virttest import utils_misc, utils_test, aexpect, env_process, data_dir +from autotest.client.shared import utils + +try: + from autotest.client.shared import utils_memory +except ImportError: + from virttest.staging import utils_memory + def run_ksm_overcommit(test, params, env): """ @@ -215,10 +221,10 @@ def split_guest(): e_msg = ("VM %d died while executing " "static_random_fill on allocator loop" % i) raise error.TestFail(e_msg) - free_mem = int(utils.read_from_meminfo("MemFree")) + free_mem = int(utils_memory.read_from_meminfo("MemFree")) if (ksm_swap): free_mem = (free_mem + - int(utils.read_from_meminfo("SwapFree"))) + int(utils_memory.read_from_meminfo("SwapFree"))) logging.debug("Free memory on host: %d", free_mem) # We need to keep some memory for python to run. @@ -232,7 +238,6 @@ def split_guest(): logging.debug("Only %s free memory, killing %d guests", free_mem, (i - 1)) last_vm = i - break out = session.read_nonblocking(0.1, 1) time.sleep(2) except OSError: @@ -267,7 +272,7 @@ def split_guest(): (mem / 200 * 50 * perf_ratio)) logging.debug(utils_test.get_memory_info([lvms[last_vm]])) - lsessions[i].cmd_output("die()", 20) + lsessions[last_vm].cmd_output("die()", 20) lvms[last_vm].destroy(gracefully=False) logging.info("Phase 3b: PASS") @@ -423,7 +428,8 @@ def split_parallel(): if (host_reserve == -1): # default host_reserve = MemAvailable + one_minimal_guest(128MB) # later we add 64MB per additional guest - host_reserve = ((utils.memtotal() - utils.read_from_meminfo("MemFree")) + host_reserve = ((utils_memory.memtotal() + - utils_memory.read_from_meminfo("MemFree")) / 1024 + 128) # using default reserve _host_reserve = True @@ -456,7 +462,7 @@ def split_parallel(): host_reserve += vmsc * 64 _host_reserve = vmsc - host_mem = (int(utils.memtotal()) / 1024 - host_reserve) + host_mem = (int(utils_memory.memtotal()) / 1024 - host_reserve) ksm_swap = False if params.get("ksm_swap") == "yes": @@ -524,7 +530,7 @@ def split_parallel(): if _guest_reserve: guest_reserve += math.ceil(mem * 0.055) - swap = int(utils.read_from_meminfo("SwapTotal")) / 1024 + swap = int(utils_memory.read_from_meminfo("SwapTotal")) / 1024 logging.debug("Overcommit = %f", overcommit) logging.debug("True overcommit = %f ", (float(vmsc * mem) / diff --git a/qemu/tests/pci_hotplug.py b/qemu/tests/pci_hotplug.py index aac322941..37b7a4c46 100644 --- a/qemu/tests/pci_hotplug.py +++ b/qemu/tests/pci_hotplug.py @@ -77,7 +77,7 @@ def verify_supported_device(dev): (cmd_type, dev)) - def device_add_nic(pci_num): + def device_add_nic(pci_num, queues=1): device_id = pci_type + "-" + utils_misc.generate_random_id() pci_info.append([device_id, device_id]) @@ -87,6 +87,8 @@ def device_add_nic(pci_num): verify_supported_device(pci_model) pci_add_cmd = "device_add id=%s,driver=%s" % (pci_info[pci_num][1], pci_model) + if queues > 1 and "virtio" in pci_model: + pci_add_cmd += ",mq=on" return device_add(pci_num, pci_add_cmd) @@ -151,7 +153,7 @@ def device_add(pci_num, pci_add_cmd): # Hot add a pci device - def add_device(pci_num): + def add_device(pci_num, queues=1): info_pci_ref = vm.monitor.info("pci") reference = session.cmd_output(reference_cmd) @@ -164,7 +166,7 @@ def add_device(pci_num): after_add = None if add_fuction: # Do add pci device. - after_add = add_fuction(pci_num) + after_add = add_fuction(pci_num, queues) try: # Define a helper function to compare the output @@ -278,6 +280,7 @@ def _device_removed(): local_functions = locals() pci_num_range = int(params.get("pci_num")) + queues = int(params.get("queues")) rp_times = int(params.get("repeat_times")) img_list = params.get("images").split() context_msg = "Running sub test '%s' %s" @@ -297,7 +300,7 @@ def _device_removed(): utils_test.run_virt_sub_test(test, params, env, sub_type) error.context("Start hot-adding pci device, repeat %d" % j) - add_device(pci_num) + add_device(pci_num, queues) sub_type = params.get("sub_type_after_plug") if sub_type: diff --git a/qemu/tests/physical_resources_check.py b/qemu/tests/physical_resources_check.py index 7237a2663..20527d1f8 100644 --- a/qemu/tests/physical_resources_check.py +++ b/qemu/tests/physical_resources_check.py @@ -23,7 +23,7 @@ def check_num(devices, info_cmd, check_str): expected_num = params.objects(devices).__len__() o = "" try: - o = vm.monitor.info(info_cmd) + o = vm.monitor.human_monitor_cmd("info %s " % info_cmd) except qemu_monitor.MonitorError, e: fail_log = e + "\n" fail_log += "info/query monitor command failed (%s)" % info_cmd @@ -49,7 +49,7 @@ def chk_fmt_model(device, fmt_model, info_cmd, regexp): expected = "rtl8139" o = "" try: - o = vm.monitor.info(info_cmd) + o = vm.monitor.human_monitor_cmd("info %s" % info_cmd) except qemu_monitor.MonitorError, e: fail_log = e + "\n" fail_log += "info/query monitor command failed (%s)" % info_cmd @@ -257,7 +257,7 @@ def verify_machine_type(): logging.info("Network card MAC check") o = "" try: - o = vm.monitor.info("network") + o = vm.monitor.human_monitor_cmd("info network") except qemu_monitor.MonitorError, e: fail_log = e + "\n" fail_log += "info/query monitor command failed (network)" diff --git a/qemu/tests/qemu_img.py b/qemu/tests/qemu_img.py index 1568f9900..490adf1d1 100644 --- a/qemu/tests/qemu_img.py +++ b/qemu/tests/qemu_img.py @@ -464,14 +464,13 @@ def rebase_test(cmd): os.remove(sn1) _rebase(cmd, sn2, base_img, image_format, mode=rebase_mode) - # Boot base image after rebase - img_suffix = ".%s" % image_format - img_name = base_img.split(img_suffix)[0] - _boot(img_name, image_format) + # Boot snapshot image after rebase + img_name, img_format = sn2.split('.') + _boot(img_name, img_format) # Check sn2's format and backing_file actual_base_img = _info(cmd, sn2, "backing file") - base_img_name = os.path.basename(params.get("image_name")) + base_img_name = os.path.basename(base_img) if not base_img_name in actual_base_img: raise error.TestFail("After rebase the backing_file of 'sn2' is " "'%s' which is not expected as '%s'" diff --git a/qemu/tests/stress_kernel_compile.py b/qemu/tests/stress_kernel_compile.py index dde2436f7..c17f631ae 100644 --- a/qemu/tests/stress_kernel_compile.py +++ b/qemu/tests/stress_kernel_compile.py @@ -1,8 +1,12 @@ import logging, os from autotest.client.shared import error -from autotest.client import utils from virttest import utils_test, utils_misc, env_process +try: + from autotest.client.shared import utils_memory +except ImportError: + from virttest.staging import utils_memory + def run_stress_kernel_compile(tests, params, env): """ @@ -54,7 +58,7 @@ def kernelcompile(session, vm_name): for tag in range(1, guest_number): params["vms"] += " stress_guest_%s" % tag - mem_host = utils.memtotal() / 1024 + mem_host = utils_memory.memtotal() / 1024 vmem = int(mem_host * over_c / guest_number) if vmem < 256: diff --git a/qemu/tests/timerdevice_clock_drift_with_ntp.py b/qemu/tests/timerdevice_clock_drift_with_ntp.py new file mode 100644 index 000000000..c626c1995 --- /dev/null +++ b/qemu/tests/timerdevice_clock_drift_with_ntp.py @@ -0,0 +1,100 @@ +import logging, os +from autotest.client.shared import error +from autotest.client import utils +from virttest import data_dir, utils_misc, aexpect + +@error.context_aware +def run_timerdevice_clock_drift_with_ntp(test, params, env): + """ + Timer device check clock frequency offset using NTP on CPU starved guest: + + 1) Check for an appropriate clocksource on host. + 2) Boot the guest. + 3) Copy time-warp-test.c to guest. + 4) Compile the time-warp-test.c. + 5) Stop ntpd and apply load on guest. + 6) Pin every vcpu to a physical cpu. + 7) Verify each vcpu is pinned on host. + 8) Run time-warp-test on guest. + 9) Start ntpd on guest. + 10) Check the drift in /var/lib/ntp/drift file on guest after hours + of running. + + @param test: QEMU test object. + @param params: Dictionary with test parameters. + @param env: Dictionary with the test environment. + """ + def _drift_file_exist(): + try: + session.cmd("test -f /var/lib/ntp/drift") + return True + except Exception: + return False + + error.context("Check for an appropriate clocksource on host", logging.info) + host_cmd = "cat /sys/devices/system/clocksource/" + host_cmd += "clocksource0/current_clocksource" + if not "tsc" in utils.system_output(host_cmd): + raise error.TestNAError("Host must use 'tsc' clocksource") + + error.context("Boot the guest", logging.info) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() + + timeout = int(params.get("login_timeout", 360)) + sess_guest_load = vm.wait_for_login(timeout=timeout) + + error.context("Copy time-warp-test.c to guest", logging.info) + src_file_name = os.path.join(data_dir.get_root_dir(), "shared", "deps", + "time-warp-test.c") + vm.copy_files_to(src_file_name, "/tmp") + + error.context("Compile the time-warp-test.c", logging.info) + cmd = "cd /tmp/;" + cmd += " yum install -y popt-devel;" + cmd += " rm -f time-warp-test;" + cmd += " gcc -Wall -o time-warp-test time-warp-test.c -lrt" + sess_guest_load.cmd(cmd) + + error.context("Stop ntpd and apply load on guest", logging.info) + sess_guest_load.cmd("yum install -y ntp; service ntpd stop") + load_cmd = "for ((I=0; I<`grep 'processor id' /proc/cpuinfo| wc -l`; I++));" + load_cmd += " do taskset -c $I /bin/bash -c 'for ((;;)); do X=1; done &';" + load_cmd += " done" + sess_guest_load.sendline(load_cmd) + + error.context("Pin every vcpu to a physical cpu", logging.info) + host_cpu_cnt_cmd = params["host_cpu_cnt_cmd"] + host_cpu_num = utils.system_output(host_cpu_cnt_cmd).strip() + host_cpu_list = (_ for _ in range(int(host_cpu_num))) + cpu_pin_list = zip(vm.vcpu_threads, host_cpu_list) + if len(cpu_pin_list) < len(vm.vcpu_threads): + raise error.TestNAError("There isn't enough physical cpu to" + " pin all the vcpus") + for vcpu, pcpu in cpu_pin_list: + utils.system("taskset -p -c %s %s" % (pcpu, vcpu)) + + error.context("Verify each vcpu is pinned on host", logging.info) + + error.context("Run time-warp-test", logging.info) + session = vm.wait_for_login(timeout=timeout) + cmd = "/tmp/time-warp-test > /dev/null &" + session.sendline(cmd) + + error.context("Start ntpd on guest", logging.info) + cmd = "service ntpd start; sleep 1; echo" + session.cmd(cmd) + + error.context("Check if the drift file exists on guest", logging.info) + test_run_timeout = float(params["test_run_timeout"]) + try: + utils_misc.wait_for(_drift_file_exist, test_run_timeout, step=5) + except aexpect.ShellCmdError, detail: + raise error.TestError("Failed to wait for the creation of" + " /var/lib/ntp/drift file. Detail: '%s'" % detail) + + error.context("Verify the drift file content on guest", logging.info) + output = session.cmd("cat /var/lib/ntp/drift") + if int(output) > 20: + raise error.TestFail("Failed to check the ntp drift." + " Output: '%s'" % output) diff --git a/qemu/tests/timerdevice_tscsync_change_host_clksource.py b/qemu/tests/timerdevice_tscsync_change_host_clksource.py new file mode 100644 index 000000000..230e97cc7 --- /dev/null +++ b/qemu/tests/timerdevice_tscsync_change_host_clksource.py @@ -0,0 +1,110 @@ +import logging, os, re +from autotest.client.shared import error +from autotest.client import utils +from virttest import data_dir + +@error.context_aware +def run_timerdevice_tscsync_change_host_clksource(test, params, env): + """ + Timer device check TSC synchronity after change host clocksource: + + 1) Check for an appropriate clocksource on host. + 2) Boot the guest. + 3) Check the guest is using vsyscall. + 4) Copy time-warp-test.c to guest. + 5) Compile the time-warp-test.c. + 6) Switch host to hpet clocksource. + 6) Run time-warp-test. + 7) Check the guest is using vsyscall. + + @param test: QEMU test object. + @param params: Dictionary with test parameters. + @param env: Dictionary with the test environment. + """ + error.context("Check for an appropriate clocksource on host", logging.info) + host_cmd = "cat /sys/devices/system/clocksource/" + host_cmd += "clocksource0/current_clocksource" + if not "tsc" in utils.system_output(host_cmd): + raise error.TestNAError("Host must use 'tsc' clocksource") + + error.context("Boot the guest with one cpu socket", logging.info) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() + + timeout = int(params.get("login_timeout", 360)) + session = vm.wait_for_login(timeout=timeout) + + error.context("Check the guest is using vsyscall", logging.info) + date_cmd = "strace date 2>&1|egrep 'clock_gettime|gettimeofday'|wc -l" + output = session.cmd(date_cmd) + if not '0' in output: + raise error.TestFail("Failed to check vsyscall. Output: '%s'" % output) + + error.context("Copy time-warp-test.c to guest", logging.info) + src_file_name = os.path.join(data_dir.get_root_dir(), "shared", "deps", + "time-warp-test.c") + vm.copy_files_to(src_file_name, "/tmp") + + error.context("Compile the time-warp-test.c", logging.info) + cmd = "cd /tmp/;" + cmd += " yum install -y popt-devel;" + cmd += " rm -f time-warp-test;" + cmd += " gcc -Wall -o time-warp-test time-warp-test.c -lrt" + session.cmd(cmd) + + error.context("Run time-warp-test", logging.info) + test_run_timeout = int(params.get("test_run_timeout", 10)) + session.sendline("$(sleep %d; pkill time-warp-test) &" % test_run_timeout) + cmd = "/tmp/time-warp-test" + _, output = session.cmd_status_output(cmd, timeout=(test_run_timeout + 60)) + + re_str = "fail:(\d+).*?fail:(\d+).*fail:(\d+)" + fail_cnt = re.findall(re_str, output) + if not fail_cnt: + raise error.TestError("Could not get correct test output." + " Output: '%s'" % output) + + tsc_cnt, tod_cnt, clk_cnt = [int(_) for _ in fail_cnt[-1]] + if tsc_cnt or tod_cnt or clk_cnt: + msg = output.splitlines()[-5:] + raise error.TestFail("Get error when running time-warp-test." + " Output (last 5 lines): '%s'" % msg) + + try: + error.context("Switch host to hpet clocksource", logging.info) + cmd = "echo hpet > /sys/devices/system/clocksource/" + cmd += "clocksource0/current_clocksource" + utils.system(cmd) + + error.context("Run time-warp-test after change the host clock source", + logging.info) + cmd = "$(sleep %d; pkill time-warp-test) &" + session.sendline(cmd % test_run_timeout) + cmd = "/tmp/time-warp-test" + _, output = session.cmd_status_output(cmd, + timeout=(test_run_timeout + 60)) + + fail_cnt = re.findall(re_str, output) + if not fail_cnt: + raise error.TestError("Could not get correct test output." + " Output: '%s'" % output) + + tsc_cnt, tod_cnt, clk_cnt = [int(_) for _ in fail_cnt[-1]] + if tsc_cnt or tod_cnt or clk_cnt: + msg = output.splitlines()[-5:] + raise error.TestFail("Get error when running time-warp-test." + " Output (last 5 lines): '%s'" % msg) + + output = session.cmd(date_cmd) + if not "1" in output: + raise error.TestFail("Failed to check vsyscall." + " Output: '%s'" % output) + finally: + error.context("Restore host to tsc clocksource", logging.info) + cmd = "echo tsc > /sys/devices/system/clocksource/" + cmd += "clocksource0/current_clocksource" + try: + utils.system(cmd) + except Exception, detail: + logging.error("Failed to restore host clocksource." + "Detail: %s" % detail) diff --git a/qemu/tests/timerdevice_tscsync_longtime.py b/qemu/tests/timerdevice_tscsync_longtime.py new file mode 100644 index 000000000..11cc93a2d --- /dev/null +++ b/qemu/tests/timerdevice_tscsync_longtime.py @@ -0,0 +1,68 @@ +import logging, os, re +from autotest.client.shared import error +from autotest.client import utils +from virttest import data_dir + +@error.context_aware +def run_timerdevice_tscsync_longtime(test, params, env): + """ + Timer device check TSC synchronity for long time test: + + 1) Check for an appropriate clocksource on host. + 2) Check host has more than one cpu socket. + 3) Boot the guest with specified cpu socket. + 4) Copy time-warp-test.c to guest. + 5) Compile the time-warp-test.c. + 6) Run time-warp-test for minimum 4 hours. + + @param test: QEMU test object. + @param params: Dictionary with test parameters. + @param env: Dictionary with the test environment. + """ + error.context("Check for an appropriate clocksource on host", logging.info) + host_cmd = "cat /sys/devices/system/clocksource/" + host_cmd += "clocksource0/current_clocksource" + if not "tsc" in utils.system_output(host_cmd): + raise error.TestNAError("Host must use 'tsc' clocksource") + + error.context("Check host has more than one cpu socket", logging.info) + host_socket_cnt_cmd = params["host_socket_cnt_cmd"] + if utils.system_output(host_socket_cnt_cmd).strip() == "1": + raise error.TestNAError("Host must have more than 1 socket") + + error.context("Boot the guest with one cpu socket", logging.info) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() + + timeout = int(params.get("login_timeout", 360)) + session = vm.wait_for_login(timeout=timeout) + + error.context("Copy time-warp-test.c to guest", logging.info) + src_file_name = os.path.join(data_dir.get_root_dir(), "shared", "deps", + "time-warp-test.c") + vm.copy_files_to(src_file_name, "/tmp") + + error.context("Compile the time-warp-test.c", logging.info) + cmd = "cd /tmp/;" + cmd += " yum install -y popt-devel;" + cmd += " rm -f time-warp-test;" + cmd += " gcc -Wall -o time-warp-test time-warp-test.c -lrt" + session.cmd(cmd) + + error.context("Run time-warp-test for minimum 4 hours", logging.info) + test_run_timeout = int(params.get("test_run_timeout", 14400)) + session.sendline("$(sleep %d; pkill time-warp-test) &" % test_run_timeout) + cmd = "/tmp/time-warp-test" + _, output = session.cmd_status_output(cmd, timeout=(test_run_timeout + 60)) + + re_str = "fail:(\d+).*?fail:(\d+).*fail:(\d+)" + fail_cnt = re.findall(re_str, output) + if not fail_cnt: + raise error.TestError("Could not get correct test output." + " Output: '%s'" % output) + + tsc_cnt, tod_cnt, clk_cnt = [int(_) for _ in fail_cnt[-1]] + if tsc_cnt or tod_cnt or clk_cnt: + msg = output.splitlines()[-5:] + raise error.TestFail("Get error when running time-warp-test." + " Output (last 5 lines): '%s'" % msg) diff --git a/qemu/tests/timerdevice_tscwrite.py b/qemu/tests/timerdevice_tscwrite.py new file mode 100644 index 000000000..6d34ea99e --- /dev/null +++ b/qemu/tests/timerdevice_tscwrite.py @@ -0,0 +1,56 @@ +import logging +from autotest.client.shared import error +from autotest.client import utils + + +@error.context_aware +def run_timerdevice_tscwrite(test, params, env): + """ + Timer device tscwrite test: + + 1) Check for an appropriate clocksource on host. + 2) Boot the guest. + 3) Download and compile the newest msr-tools. + 4) Execute cmd in guest. + + @param test: QEMU test object. + @param params: Dictionary with test parameters. + @param env: Dictionary with the test environment. + """ + error.context("Check for an appropriate clocksource on host", logging.info) + host_cmd = "cat /sys/devices/system/clocksource/" + host_cmd += "clocksource0/current_clocksource" + if not "tsc" in utils.system_output(host_cmd): + raise error.TestNAError("Host must use 'tsc' clocksource") + + error.context("Boot the guest", logging.info) + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() + + timeout = int(params.get("login_timeout", 360)) + session = vm.wait_for_login(timeout=timeout) + + error.context("Download and compile the newest msr-tools", logging.info) + msr_tools_install_cmd = params["msr_tools_install_cmd"] + session.cmd(msr_tools_install_cmd) + + error.context("Execute cmd in guest", logging.info) + cmd = "dmesg -c > /dev/null" + session.cmd(cmd) + + date_cmd = "strace date 2>&1 | egrep 'clock_gettime|gettimeofday' | wc -l" + output = session.cmd(date_cmd) + if not '0' in output: + raise error.TestFail("Test failed before run msr tools." + " Output: '%s'" % output) + + msr_tools_cmd = params["msr_tools_cmd"] + session.cmd(msr_tools_cmd) + + cmd = "dmesg" + session.cmd(cmd) + + output = session.cmd(date_cmd) + if not "1" in output: + raise error.TestFail("Test failed after run msr tools." + " Output: '%s'" % output) diff --git a/qemu/tests/usb_host.py b/qemu/tests/usb_host.py index 8793b9dee..53f6b3e0c 100644 --- a/qemu/tests/usb_host.py +++ b/qemu/tests/usb_host.py @@ -1,4 +1,4 @@ -import logging, re, uuid +import logging from autotest.client.shared import error from autotest.client import utils @@ -11,6 +11,56 @@ def run_usb_host(test, params, env): @param params: Dictionary with the test parameters @param env: Dictionary with test environment. """ + @error.context_aware + def usb_dev_hotplug(): + error.context("Plugin usb device", logging.info) + session.cmd_status("dmesg -c") + vm.monitor.cmd(monitor_add) + session.cmd_status("sleep 1") + session.cmd_status("udevadm settle") + messages_add = session.cmd("dmesg -c") + for line in messages_add.splitlines(): + logging.debug("[dmesg add] %s" % line) + if messages_add.find(match_add) == -1: + raise error.TestFail("kernel didn't detect plugin") + + + @error.context_aware + def usb_dev_verify(): + error.context("Check usb device %s in guest" % device, logging.info) + session.cmd(lsusb_cmd) + + + @error.context_aware + def usb_dev_unplug(): + error.context("Unplug usb device", logging.info) + vm.monitor.cmd(monitor_del) + session.cmd_status("sleep 1") + messages_del = session.cmd("dmesg -c") + for line in messages_del.splitlines(): + logging.debug("[dmesg del] %s" % line) + if messages_del.find(match_del) == -1: + raise error.TestFail("kernel didn't detect unplug") + + + if params.get("usb_negative_test", "no") != "no": + # Negative test. + vm = env.get_vm(params["main_vm"]) + vm.verify_alive() + session = vm.wait_for_login() + usb_host_device_list = params["usb_host_device_list"].split(",") + for dev in usb_host_device_list: + vid, pid = dev.split(":") + monitor_add = "device_add usb-host,bus=usbtest.0,id=usbhostdev" + monitor_add += ",vendorid=%s" % vid + monitor_add += ",productid=%s" % pid + reply = vm.monitor.cmd(monitor_add) + if params["usb_reply_msg"] not in reply: + raise error.TestFail("Could not get expected warning" + " msg in negative test, monitor" + " returns: '%s'" % reply) + vm.reboot() + return device = params["usb_host_device"] (vendorid,productid) = device.split(":") @@ -35,28 +85,22 @@ def run_usb_host(test, params, env): vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login() - session.cmd_status("dmesg -c") - - error.context("Plugin usb device", logging.info) - vm.monitor.cmd(monitor_add) - session.cmd_status("sleep 1") - session.cmd_status("udevadm settle") - messages_add = session.cmd("dmesg -c") - for line in messages_add.splitlines(): - logging.debug("[dmesg add] %s" % line) - if messages_add.find(match_add) == -1: - raise error.TestFail("kernel didn't detect plugin") - - error.context("Check usb device %s in guest" % device, logging.info) - session.cmd(lsusb_cmd) - - error.context("Unplug usb device", logging.info) - vm.monitor.cmd(monitor_del) - session.cmd_status("sleep 1") - messages_del = session.cmd("dmesg -c") - for line in messages_del.splitlines(): - logging.debug("[dmesg del] %s" % line) - if messages_del.find(match_del) == -1: - raise error.TestFail("kernel didn't detect unplug") + + repeat_times = int(params.get("usb_repeat_times", "1")) + for i in range(repeat_times): + if params.get("usb_check_isobufs", "no") == "no": + error.context("Hotplug (iteration %i)" % (i + 1), logging.info) + else: + # The value of isobufs could only be in '4, 8, 16' + isobufs = (2 << (i % 3 + 1)) + monitor_add = "device_add usb-host,bus=usbtest.0,id=usbhostdev" + monitor_add += ",vendorid=%s" % vendorid + monitor_add += ",productid=%s" % productid + monitor_add += ",isobufs=%d" % isobufs + error.context("Hotplug (iteration %i), with 'isobufs' option" + " set to %d" % ((i + 1), isobufs), logging.info) + usb_dev_hotplug() + usb_dev_verify() + usb_dev_unplug() session.close() diff --git a/qemu/tests/usb_hotplug.py b/qemu/tests/usb_hotplug.py index 12b370fa3..ad02590d7 100644 --- a/qemu/tests/usb_hotplug.py +++ b/qemu/tests/usb_hotplug.py @@ -10,6 +10,46 @@ def run_usb_hotplug(test, params, env): @param params: Dictionary with the test parameters @param env: Dictionary with test environment. """ + @error.context_aware + def usb_dev_hotplug(): + error.context("Plugin usb device", logging.info) + session.cmd(clear_guest_log_cmd) + reply = vm.monitor.cmd(monitor_add) + if params.get("usb_negative_test") == "yes": + if params["usb_reply_msg"] not in reply: + raise error.TestFail("Could not get expected warning" + " msg in negative test, monitor" + " returns: '%s'" % reply) + return + + monitor_pattern = "Parameter 'driver' expects a driver name" + if reply.find(monitor_pattern) != -1: + raise error.TestNAError("usb device %s not available" % device) + + + @error.context_aware + def usb_dev_verify(): + error.context("Verify usb device is pluged on guest", logging.info) + time.sleep(sleep_time) + session.cmd(udev_refresh_cmd) + messages_add = session.cmd(query_syslog_cmd) + for line in messages_add.splitlines(): + logging.debug("[Guest add] %s" % line) + if not re.search(match_add, messages_add, re.I): + raise error.TestFail("Guest didn't detect plugin") + + + @error.context_aware + def usb_dev_unplug(): + error.context("Unplug usb device", logging.info) + vm.monitor.cmd(monitor_del) + time.sleep(sleep_time) + messages_del = session.cmd(query_syslog_cmd) + for line in messages_del.splitlines(): + logging.debug("[Guest del] %s" % line) + if messages_del.find(match_del) == -1: + raise error.TestFail("Guest didn't detect unplug") + device = params.object_params("testdev")["usb_type"] vendor_id = params["vendor_id"] @@ -31,34 +71,12 @@ def run_usb_hotplug(test, params, env): vm = env.get_vm(params["main_vm"]) vm.verify_alive() session = vm.wait_for_login() - session.cmd(clear_guest_log_cmd) - - error.context("Plugin usb device", logging.info) - reply = vm.monitor.cmd(monitor_add) - if params.get("usb_negative_test") == "yes": - if params["usb_reply_msg"] not in reply: - raise error.TestFail("Could not get expected warning msg in" - " negative test, monitor returns: '%s'" % reply) - return - - if reply.find("Parameter 'driver' expects a driver name") != -1: - raise error.TestNAError("usb device %s not available" % device) - - time.sleep(sleep_time) - session.cmd(udev_refresh_cmd) - messages_add = session.cmd(query_syslog_cmd) - for line in messages_add.splitlines(): - logging.debug("[Guest add] %s" % line) - if not re.search(match_add, messages_add, re.I): - raise error.TestFail("Guest didn't detect plugin") - error.context("Unplug usb device", logging.info) - vm.monitor.cmd(monitor_del) - time.sleep(sleep_time) - messages_del = session.cmd(query_syslog_cmd) - for line in messages_del.splitlines(): - logging.debug("[Guest del] %s" % line) - if messages_del.find(match_del) == -1: - raise error.TestFail("Guest didn't detect unplug") + repeat_times = int(params["usb_repeat_times"]) + for i in range(repeat_times): + error.context("Hotplug (iteration %i)" % (i + 1), logging.info) + usb_dev_hotplug() + usb_dev_verify() + usb_dev_unplug() session.close() diff --git a/qemu/tests/vhost_with_cgroup.py b/qemu/tests/vhost_with_cgroup.py index fcb143460..afa5d2aa9 100644 --- a/qemu/tests/vhost_with_cgroup.py +++ b/qemu/tests/vhost_with_cgroup.py @@ -1,9 +1,14 @@ import logging from autotest.client.shared import error from autotest.client import utils -from virttest.utils_cgroup import Cgroup, CgroupModules from virttest.env_process import preprocess +try: + from autotest.client.shared.utils_cgroup import Cgroup, CgroupModules +except ImportError: + # TODO: Obsoleted path used prior autotest-0.15.2/virttest-2013.06.24 + from virttest.staging.utils_cgroup import Cgroup, CgroupModules + @error.context_aware def run_vhost_with_cgroup(test, params, env): diff --git a/qemu/tests/virtio_console.py b/qemu/tests/virtio_console.py index cb2caa830..0ab0d6902 100644 --- a/qemu/tests/virtio_console.py +++ b/qemu/tests/virtio_console.py @@ -1907,4 +1907,9 @@ def test_delete_guest_script(): "".join(traceback.format_exception( exc_type, exc_value, exc_traceback.tb_next))) - raise error.TestFail('%s failed: %s' % (_fce, details)) + if isinstance(details, error.TestError): + raise error.TestError('%s error: %s' % (_fce, details)) + elif isinstance(details, error.TestNAError): + raise error.TestNAError('%s skipped: %s' % (_fce, details)) + else: + raise error.TestFail('%s failed: %s' % (_fce, details)) diff --git a/run b/run index d20668fd9..35b47d6ce 100755 --- a/run +++ b/run @@ -291,8 +291,10 @@ class VirtTestRunParser(optparse.OptionParser): DEFAULT_MACHINE_TYPE = "i440fx" DEFAULT_GUEST_OS = "JeOS" QEMU_DEFAULT_SET = "migrate..tcp, migrate..unix, migrate..exec, migrate..fd" -LIBVIRT_DEFAULT_SET = ("unattended_install.import.import, virsh_domname, " - "remove_guest.without_disk") +LIBVIRT_DEFAULT_SET = ( + "unattended_install.import.import.default_install.aio_native, " + "virsh_domname, " + "remove_guest.without_disk") class VirtTestApp(object): """ diff --git a/shared/cfg/base.cfg b/shared/cfg/base.cfg index 6b7778468..eff740bc5 100644 --- a/shared/cfg/base.cfg +++ b/shared/cfg/base.cfg @@ -24,6 +24,9 @@ main_vm = virt-tests-vm1 # Always set optional parameters (addr, bus, ...) strict_mode = no +# Uncomment this to always wait 1s before executing QMP command +# (due of bug immediate use of QMP monitor after qemu start causes qemu crash) +# workaround_qemu_qmp_crash = always # List of default network device object names (whitespace seperated) # All VMs get these by default, unless specific vm name references @@ -187,10 +190,8 @@ monitors = hmp1 #monitor_type_hmp1 = human # Default monitor type (protocol), if multiple types to be used monitor_type = human -# Pattern to get vcpu threads from monitor. -# human monitor: thread_id=(\d+) -# qmp monitor: u'thread_id':\s+(\d+) -vcpu_thread_pattern = "thread_id=(\d+)" +# Pattern to get vcpu threads from monitor.both support +vcpu_thread_pattern = "thread_id.?[:|=]\s*(\d+)" # Guest Display type (vnc, sdl, spice, or nographic) display = vnc @@ -316,9 +317,14 @@ restore_image = no # after the test runs (corruption checking, etc.) skip_image_processing = no -# Some preprocessor/postprocessor params +# Some preprocessor params +# If there is any conflict between 'start_vm' and 'kill_vm_before_test', +# the final desicion is made by start_vm. start_vm = yes +kill_vm_before_test = no paused_after_start_vm = no + +# Some postprocessor params kill_vm = no kill_vm_gracefully = yes kill_unresponsive_vms = yes diff --git a/shared/cfg/guest-hw.cfg b/shared/cfg/guest-hw.cfg index ca78e53c7..306101511 100644 --- a/shared/cfg/guest-hw.cfg +++ b/shared/cfg/guest-hw.cfg @@ -8,6 +8,8 @@ variants: nic_model = e1000 - virtio_net: nic_model = virtio + # Assign the queue number of nic device + #queues = 4 # You can add advanced attributes on nic_extra_params such as mrg_rxbuf #nic_extra_params = # You can add advanced attributes through netdev_extra_params @@ -54,6 +56,7 @@ variants: # then kvm_vm will ignore this option. image_boot=yes - virtio_scsi: + no WinXP # supported formats are: scsi-hd, scsi-cd, scsi-disk, scsi-block, # scsi-generic # Use drive_format_$DISKNAME = "scsi-generic" to force disk driver @@ -68,6 +71,7 @@ variants: scsi_hba=spapr-vscsi only pseries - lsi_scsi: + no Host_RHEL drive_format=scsi-hd cd_format=scsi-cd scsi_hba=lsi53c895a @@ -83,8 +87,8 @@ variants: # placeholder variants: - - qcow3: - image_format = qcow2 + - qcow2v3: + image_format = qcow2v3 image_extra_params = "compat=1.1" - qcow2: image_format = qcow2 diff --git a/shared/cfg/guest-os/Linux.cfg b/shared/cfg/guest-os/Linux.cfg index 40e994d85..6df38ea09 100644 --- a/shared/cfg/guest-os/Linux.cfg +++ b/shared/cfg/guest-os/Linux.cfg @@ -46,7 +46,7 @@ readlink_command = readlink -e sys_path = "/sys/class/net/%s/device/driver" mac_change: - change_cmd = ifconfig %s down && ifconfig %s hw ether %s && ifconfig %s up + change_cmd = ifconfig %s hw ether %s multi_disk: show_mount_cmd = mount|gawk '/mnt/{print $1}' clean_cmd = "\rm -rf /mnt/*" diff --git a/shared/cfg/guest-os/Linux/Fedora.cfg b/shared/cfg/guest-os/Linux/Fedora.cfg index 91a93f3a5..68297c767 100644 --- a/shared/cfg/guest-os/Linux/Fedora.cfg +++ b/shared/cfg/guest-os/Linux/Fedora.cfg @@ -5,11 +5,29 @@ boot_path = "images/pxeboot" kernel_params = "ks=cdrom nicdelay=60 console=ttyS0,115200 console=tty0" anaconda_log = "yes" + guest_s3: + global_enable_s3: + s3_support_chk_cmd = "yum install -y iasl" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + s3_support_chk_cmd += " && dmesg -c > /dev/null && grep -q mem /sys/power/state" + global_disable_s3: + s3_support_chk_cmd = "yum install -y iasl" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" guest_s4: 17, 18: s4_log_chk_cmd = 'dmesg | grep -E "PM: Image restored successfully."' + global_enable_s4: + s4_support_chk_cmd = "yum install -y iasl" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" + s4_support_chk_cmd += " && dmesg -c > /dev/null && grep -q disk /sys/power/state" global_disable_s4: s4_support_chk_cmd = "yum install -y iasl" - s4_support_chk_cmd += " && cat cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" s4_support_chk_cmd += " && iasl -d /tmp/ssdt" s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/Fedora/16.ppc64.cfg b/shared/cfg/guest-os/Linux/Fedora/16.ppc64.cfg index 88526e292..ba0943e9e 100644 --- a/shared/cfg/guest-os/Linux/Fedora/16.ppc64.cfg +++ b/shared/cfg/guest-os/Linux/Fedora/16.ppc64.cfg @@ -2,6 +2,7 @@ image_name = images/f16-ppc64 only pseries no unattended_install..floppy_ks + no guest_s3, guest_s4 unattended_install: kernel_params = "root=live:CDLABEL=Fedora-16-ppc64 ks=cdrom:/ks.cfg console=hvc0 serial rd_NO_PLYMOUTH" unattended_file = unattended/Fedora-16.ks diff --git a/shared/cfg/guest-os/Linux/Fedora/17.ppc64.cfg b/shared/cfg/guest-os/Linux/Fedora/17.ppc64.cfg index 2dacc89f7..af11526a1 100644 --- a/shared/cfg/guest-os/Linux/Fedora/17.ppc64.cfg +++ b/shared/cfg/guest-os/Linux/Fedora/17.ppc64.cfg @@ -2,6 +2,7 @@ image_name = images/f17-ppc64 only pseries no unattended_install..floppy_ks + no guest_s3, guest_s4 mem_chk_cmd = numactl --hardware | awk -F: '/size/ {print $2}' netdev_peer_re = "(.*?): .*?\\\s(.*?):" unattended_install: diff --git a/shared/cfg/guest-os/Linux/Fedora/18.ppc64.cfg b/shared/cfg/guest-os/Linux/Fedora/18.ppc64.cfg index 3ff948b3f..c61bcb51d 100644 --- a/shared/cfg/guest-os/Linux/Fedora/18.ppc64.cfg +++ b/shared/cfg/guest-os/Linux/Fedora/18.ppc64.cfg @@ -2,6 +2,7 @@ image_name = images/f18-ppc64 only pseries no unattended_install..floppy_ks + no guest_s3, guest_s4 mem_chk_cmd = numactl --hardware | awk -F: '/size/ {print $2}' netdev_peer_re = "(.*?): .*?\\\s(.*?):" unattended_install: diff --git a/shared/cfg/guest-os/Linux/Fedora/19.i386.cfg b/shared/cfg/guest-os/Linux/Fedora/19.i386.cfg new file mode 100644 index 000000000..7edf3b024 --- /dev/null +++ b/shared/cfg/guest-os/Linux/Fedora/19.i386.cfg @@ -0,0 +1,17 @@ +- 19.i386: + image_name = images/f19-32 + vm_arch_name = i386 + no unattended_install..floppy_ks + unattended_install: + kernel_params = "repo=cdrom:/dev/sr0 ks=cdrom:/dev/sr1 nicdelay=60 console=ttyS0,115200 console=tty0" + unattended_file = unattended/Fedora-19.ks + cdrom_unattended = images/f19-32/ks.iso + kernel = images/f19-32/vmlinuz + initrd = images/f19-32/initrd.img + syslog_server_proto = tcp + unattended_install.cdrom: + cdrom_cd1 = isos/linux/Fedora-19-i386-DVD.iso + md5sum_cd1 = d3b02fda3010220a26d7fa41c929509c + md5sum_1m_cd1 = 31fcaf802010041f06928fa51fd3e452 + unattended_install.url: + url = http://dl.fedoraproject.org/pub/fedora/linux/releases/19/Fedora/i386/os diff --git a/shared/cfg/guest-os/Linux/Fedora/19.ppc64.cfg b/shared/cfg/guest-os/Linux/Fedora/19.ppc64.cfg new file mode 100644 index 000000000..ef938eead --- /dev/null +++ b/shared/cfg/guest-os/Linux/Fedora/19.ppc64.cfg @@ -0,0 +1,20 @@ +- 19.ppc64: + image_name = images/f19-ppc64 + only pseries + no unattended_install..floppy_ks + mem_chk_cmd = numactl --hardware | awk -F: '/size/ {print $2}' + netdev_peer_re = "(.*?): .*?\\\s(.*?):" + unattended_install: + kernel_params = "root=live:CDLABEL=Fedora-19-ppc64 ks=cdrom:/ks.cfg console=hvc0 serial rd_NO_PLYMOUTH" + unattended_file = unattended/Fedora-19.ks + cdrom_unattended = images/f19-ppc64/ks.iso + kernel = images/f19-ppc64/vmlinuz + initrd = images/f19-ppc64/initrd.img + syslog_server_proto = tcp + unattended_install.cdrom: + boot_path = ppc/ppc64 + cdrom_cd1 = isos/linux/Fedora-19-ppc64-DVD.iso + md5sum_cd1 = 26b6e0068a2c76742c0f097a0c9e1eb9 + md5sum_1m_cd1 = 10043a86d6e8929f80cad16c5ff5eccb + unattended_install.url: + url = http://dl.fedoraproject.org/pub/fedora-secondary/releases/19/Everything/ppc64/os diff --git a/shared/cfg/guest-os/Linux/Fedora/19.x86_64.cfg b/shared/cfg/guest-os/Linux/Fedora/19.x86_64.cfg new file mode 100644 index 000000000..a9016491b --- /dev/null +++ b/shared/cfg/guest-os/Linux/Fedora/19.x86_64.cfg @@ -0,0 +1,17 @@ +- 19.x86_64: + image_name = images/f19-64 + vm_arch_name = x86_64 + no unattended_install..floppy_ks + unattended_install: + kernel_params = "repo=cdrom:/dev/sr0 ks=cdrom:/dev/sr1 nicdelay=60 console=ttyS0,115200 console=tty0" + unattended_file = unattended/Fedora-19.ks + cdrom_unattended = images/f19-64/ks.iso + kernel = images/f19-64/vmlinuz + initrd = images/f19-64/initrd.img + syslog_server_proto = tcp + unattended_install.cdrom: + cdrom_cd1 = isos/linux/Fedora-19-x86_64-DVD.iso + md5sum_cd1 = 638d69c23621d5befc714bcd66b0611e + md5sum_1m_cd1 = 21204a7d8e018064dd85ca1ecbc5f1c4 + unattended_install.url: + url = http://dl.fedoraproject.org/pub/fedora/linux/releases/19/Fedora/x86_64/os diff --git a/shared/cfg/guest-os/Linux/RHEL/3.9.cfg b/shared/cfg/guest-os/Linux/RHEL/3.9.cfg index 60d0218b0..235cb7949 100644 --- a/shared/cfg/guest-os/Linux/RHEL/3.9.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/3.9.cfg @@ -1,6 +1,6 @@ - 3.9: no virtio_net, virtio_blk, e1000 - no setup autotest linux_s3 guest_s4 shutdown multi_disk + no setup autotest linux_s3 guest_s4 shutdown multi_disk xfstests no usb_multi_disk, balloon_check mem_chk_cmd = dmidecode | awk -F: '/Maximum Capacity/ {print $2}' image_name = images/rhel39 diff --git a/shared/cfg/guest-os/Linux/RHEL/4.7.cfg b/shared/cfg/guest-os/Linux/RHEL/4.7.cfg index 73e14dbb9..aa3781790 100644 --- a/shared/cfg/guest-os/Linux/RHEL/4.7.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/4.7.cfg @@ -1,5 +1,5 @@ - 4.7: - no setup autotest + no setup autotest xfstests image_name = images/rhel47 unattended_install, check_block_size.4096_512, check_block_size.512_512: unattended_file = unattended/RHEL-4-series.ks diff --git a/shared/cfg/guest-os/Linux/RHEL/4.8.cfg b/shared/cfg/guest-os/Linux/RHEL/4.8.cfg index a75e92c89..abd43649b 100644 --- a/shared/cfg/guest-os/Linux/RHEL/4.8.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/4.8.cfg @@ -1,5 +1,5 @@ - 4.8: - no setup autotest + no setup autotest xfstests image_name = images/rhel48 unattended_install, check_block_size.4096_512, check_block_size.512_512: unattended_file = unattended/RHEL-4-series.ks diff --git a/shared/cfg/guest-os/Linux/RHEL/5.3.cfg b/shared/cfg/guest-os/Linux/RHEL/5.3.cfg index dfc6474f2..9f04e9ecd 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.3.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.3.cfg @@ -1,5 +1,5 @@ - 5.3: - no setup + no setup xfstests image_name = images/rhel53 unattended_install, check_block_size.4096_512, check_block_size.512_512: unattended_file = unattended/RHEL-5-series.ks diff --git a/shared/cfg/guest-os/Linux/RHEL/5.3/i386.cfg b/shared/cfg/guest-os/Linux/RHEL/5.3/i386.cfg index 221b70d20..29a821d13 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.3/i386.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.3/i386.cfg @@ -1,4 +1,5 @@ - i386: + grub_file = /boot/grub/grub.conf vm_arch_name = i686 image_name += -32 install: diff --git a/shared/cfg/guest-os/Linux/RHEL/5.3/x86_64.cfg b/shared/cfg/guest-os/Linux/RHEL/5.3/x86_64.cfg index 33596a566..5deaa42d6 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.3/x86_64.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.3/x86_64.cfg @@ -1,4 +1,5 @@ - x86_64: + grub_file = /boot/grub/grub.conf vm_arch_name = x86_64 image_name += -64 install: diff --git a/shared/cfg/guest-os/Linux/RHEL/5.4.cfg b/shared/cfg/guest-os/Linux/RHEL/5.4.cfg index 0975b89e2..cbe7ef54d 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.4.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.4.cfg @@ -1,5 +1,5 @@ - 5.4: - no setup + no setup xfstests image_name = images/rhel54 unattended_install, check_block_size.4096_512, check_block_size.512_512: unattended_file = unattended/RHEL-5-series.ks diff --git a/shared/cfg/guest-os/Linux/RHEL/5.4/i386.cfg b/shared/cfg/guest-os/Linux/RHEL/5.4/i386.cfg index 6f928fa57..99990bc2c 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.4/i386.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.4/i386.cfg @@ -1,4 +1,5 @@ - i386: + grub_file = /boot/grub/grub.conf vm_arch_name = i686 image_name += -32 unattended_install, check_block_size.4096_512, check_block_size.512_512: diff --git a/shared/cfg/guest-os/Linux/RHEL/5.4/x86_64.cfg b/shared/cfg/guest-os/Linux/RHEL/5.4/x86_64.cfg index 77756ec62..dc950dc6c 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.4/x86_64.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.4/x86_64.cfg @@ -1,4 +1,5 @@ - x86_64: + grub_file = /boot/grub/grub.conf vm_arch_name = x86_64 image_name += -64 unattended_install, check_block_size.4096_512, check_block_size.512_512: @@ -12,8 +13,27 @@ unattended_install..floppy_ks: floppies = "fl" floppy_name = images/rhel54-64/ks.vfd - guest_s4..global_disable_s4: - s4_support_chk_cmd = "rpm --force --nodeps http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" - s4_support_chk_cmd += " && cat cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" - s4_support_chk_cmd += " && iasl -d /tmp/ssdt" - s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" + guest_s3: + global_enable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + s3_support_chk_cmd += " && dmesg -c > /dev/null && grep -q mem /sys/power/state" + global_disable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + guest_s4: + global_enable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" + s4_support_chk_cmd += " && dmesg -c > /dev/null && grep -q disk /sys/power/state" + global_disable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/5.5.cfg b/shared/cfg/guest-os/Linux/RHEL/5.5.cfg index e2c877939..85e30f87b 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.5.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.5.cfg @@ -1,5 +1,5 @@ - 5.5: - no setup + no setup xfstests image_name = images/rhel55 unattended_install, check_block_size.4096_512, check_block_size.512_512: unattended_file = unattended/RHEL-5-series.ks diff --git a/shared/cfg/guest-os/Linux/RHEL/5.5/i386.cfg b/shared/cfg/guest-os/Linux/RHEL/5.5/i386.cfg index 65244fb07..f426bf124 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.5/i386.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.5/i386.cfg @@ -1,4 +1,5 @@ - i386: + grub_file = /boot/grub/grub.conf vm_arch_name = i686 image_name += -32 unattended_install, check_block_size.4096_512, check_block_size.512_512: diff --git a/shared/cfg/guest-os/Linux/RHEL/5.5/x86_64.cfg b/shared/cfg/guest-os/Linux/RHEL/5.5/x86_64.cfg index 5392a2540..9291bcc2e 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.5/x86_64.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.5/x86_64.cfg @@ -1,4 +1,5 @@ - x86_64: + grub_file = /boot/grub/grub.conf vm_arch_name = x86_64 image_name += -64 unattended_install, check_block_size.4096_512, check_block_size.512_512: @@ -12,8 +13,27 @@ unattended_install..floppy_ks: floppies = "fl" floppy_name = images/rhel55-64/ks.vfd - guest_s4..global_disable_s4: - s4_support_chk_cmd = "rpm --force --nodeps http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" - s4_support_chk_cmd += " && cat cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" - s4_support_chk_cmd += " && iasl -d /tmp/ssdt" - s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" + guest_s3: + global_enable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + s3_support_chk_cmd += " && dmesg -c > /dev/null && grep -q mem /sys/power/state" + global_disable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + guest_s4: + global_enable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" + s4_support_chk_cmd += " && dmesg -c > /dev/null && grep -q disk /sys/power/state" + global_disable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/5.6.cfg b/shared/cfg/guest-os/Linux/RHEL/5.6.cfg index a5063efd6..bac247a58 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.6.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.6.cfg @@ -1,5 +1,5 @@ - 5.6: - no setup + no setup xfstests image_name = images/rhel56 unattended_install, check_block_size.4096_512, check_block_size.512_512: unattended_file = unattended/RHEL-5-series.ks diff --git a/shared/cfg/guest-os/Linux/RHEL/5.6/i386.cfg b/shared/cfg/guest-os/Linux/RHEL/5.6/i386.cfg index e61ed2c22..2270a2d82 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.6/i386.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.6/i386.cfg @@ -1,4 +1,5 @@ - i386: + grub_file = /boot/grub/grub.conf vm_arch_name = i686 image_name += -32 unattended_install, check_block_size.4096_512, check_block_size.512_512: diff --git a/shared/cfg/guest-os/Linux/RHEL/5.6/x86_64.cfg b/shared/cfg/guest-os/Linux/RHEL/5.6/x86_64.cfg index 42e4df0a5..c73b99045 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.6/x86_64.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.6/x86_64.cfg @@ -1,4 +1,5 @@ - x86_64: + grub_file = /boot/grub/grub.conf vm_arch_name = x86_64 image_name += -64 unattended_install, check_block_size.4096_512, check_block_size.512_512: @@ -12,8 +13,27 @@ unattended_install..floppy_ks: floppies = "fl" floppy_name = images/rhel56-64/ks.vfd - guest_s4..global_disable_s4: - s4_support_chk_cmd = "rpm --force --nodeps http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" - s4_support_chk_cmd += " && cat cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" - s4_support_chk_cmd += " && iasl -d /tmp/ssdt" - s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" + guest_s3: + global_enable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + s3_support_chk_cmd += " && dmesg -c > /dev/null && grep -q mem /sys/power/state" + global_disable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + guest_s4: + global_enable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" + s4_support_chk_cmd += " && dmesg -c > /dev/null && grep -q disk /sys/power/state" + global_disable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/5.7.cfg b/shared/cfg/guest-os/Linux/RHEL/5.7.cfg index 42b3556cb..1214941ee 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.7.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.7.cfg @@ -1,5 +1,5 @@ - 5.7: - no setup + no setup xfstests image_name = images/rhel57 unattended_install, check_block_size.4096_512, check_block_size.512_512: unattended_file = unattended/RHEL-5-series.ks diff --git a/shared/cfg/guest-os/Linux/RHEL/5.7/i386.cfg b/shared/cfg/guest-os/Linux/RHEL/5.7/i386.cfg index de3e032b6..95435996b 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.7/i386.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.7/i386.cfg @@ -1,4 +1,5 @@ - i386: + grub_file = /boot/grub/grub.conf vm_arch_name = i686 image_name += -32 unattended_install, check_block_size.4096_512, check_block_size.512_512: diff --git a/shared/cfg/guest-os/Linux/RHEL/5.7/x86_64.cfg b/shared/cfg/guest-os/Linux/RHEL/5.7/x86_64.cfg index 868180457..a05028b3a 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.7/x86_64.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.7/x86_64.cfg @@ -1,4 +1,5 @@ - x86_64: + grub_file = /boot/grub/grub.conf vm_arch_name = x86_64 image_name += -64 unattended_install, check_block_size.4096_512, check_block_size.512_512: @@ -12,8 +13,27 @@ unattended_install..floppy_ks: floppies = "fl" floppy_name = images/rhel56-64/ks.vfd - guest_s4..global_disable_s4: - s4_support_chk_cmd = "rpm --force --nodeps http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" - s4_support_chk_cmd += " && cat cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" - s4_support_chk_cmd += " && iasl -d /tmp/ssdt" - s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" + guest_s3: + global_enable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + s3_support_chk_cmd += " && dmesg -c > /dev/null && grep -q mem /sys/power/state" + global_disable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + guest_s4: + global_enable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" + s4_support_chk_cmd += " && dmesg -c > /dev/null && grep -q disk /sys/power/state" + global_disable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/5.8.cfg b/shared/cfg/guest-os/Linux/RHEL/5.8.cfg index 196030d0a..c67491ccf 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.8.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.8.cfg @@ -1,5 +1,5 @@ - 5.8: - no setup + no setup xfstests image_name = images/rhel58 unattended_install, check_block_size.4096_512, check_block_size.512_512: unattended_file = unattended/RHEL-5-series.ks diff --git a/shared/cfg/guest-os/Linux/RHEL/5.8/i386.cfg b/shared/cfg/guest-os/Linux/RHEL/5.8/i386.cfg index e1709b6f3..cec9b4f57 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.8/i386.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.8/i386.cfg @@ -1,4 +1,5 @@ - i386: + grub_file = /boot/grub/grub.conf vm_arch_name = i686 image_name += -32 unattended_install, check_block_size.4096_512, check_block_size.512_512: diff --git a/shared/cfg/guest-os/Linux/RHEL/5.8/x86_64.cfg b/shared/cfg/guest-os/Linux/RHEL/5.8/x86_64.cfg index 5b9a568b3..cc2fcce62 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.8/x86_64.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.8/x86_64.cfg @@ -1,4 +1,5 @@ - x86_64: + grub_file = /boot/grub/grub.conf vm_arch_name = x86_64 image_name += -64 unattended_install, check_block_size.4096_512, check_block_size.512_512: @@ -12,8 +13,27 @@ unattended_install..floppy_ks: floppies = "fl" floppy_name = images/rhel58-64/ks.vfd - guest_s4..global_disable_s4: - s4_support_chk_cmd = "rpm --force --nodeps http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" - s4_support_chk_cmd += " && cat cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" - s4_support_chk_cmd += " && iasl -d /tmp/ssdt" - s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" + guest_s3: + global_enable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + s3_support_chk_cmd += " && dmesg -c > /dev/null && grep -q mem /sys/power/state" + global_disable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + guest_s4: + global_enable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" + s4_support_chk_cmd += " && dmesg -c > /dev/null && grep -q disk /sys/power/state" + global_disable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/5.9.cfg b/shared/cfg/guest-os/Linux/RHEL/5.9.cfg index 43f7964fe..0a4d01949 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.9.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.9.cfg @@ -1,5 +1,5 @@ - 5.9: - no setup + no setup xfstests image_name = images/rhel59 unattended_install, check_block_size.4096_512, check_block_size.512_512: unattended_file = unattended/RHEL-5-series.ks diff --git a/shared/cfg/guest-os/Linux/RHEL/5.9/i386.cfg b/shared/cfg/guest-os/Linux/RHEL/5.9/i386.cfg index 17f1dfad6..afe304554 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.9/i386.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.9/i386.cfg @@ -1,4 +1,5 @@ - i386: + grub_file = /boot/grub/grub.conf vm_arch_name = i686 image_name += -32 unattended_install, check_block_size.4096_512, check_block_size.512_512: diff --git a/shared/cfg/guest-os/Linux/RHEL/5.9/x86_64.cfg b/shared/cfg/guest-os/Linux/RHEL/5.9/x86_64.cfg index 38c1f3d26..92a78859a 100644 --- a/shared/cfg/guest-os/Linux/RHEL/5.9/x86_64.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/5.9/x86_64.cfg @@ -1,4 +1,5 @@ - x86_64: + grub_file = /boot/grub/grub.conf vm_arch_name = x86_64 image_name += -64 unattended_install, check_block_size.4096_512, check_block_size.512_512: @@ -12,8 +13,27 @@ unattended_install..floppy_ks: floppies = "fl" floppy_name = images/rhel59-64/ks.vfd - guest_s4..global_disable_s4: - s4_support_chk_cmd = "rpm --force --nodeps http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" - s4_support_chk_cmd += " && cat cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" - s4_support_chk_cmd += " && iasl -d /tmp/ssdt" - s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" + guest_s3: + global_enable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + s3_support_chk_cmd += " && dmesg -c > /dev/null && grep -q mem /sys/power/state" + global_disable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + guest_s4: + global_enable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" + s4_support_chk_cmd += " && dmesg -c > /dev/null && grep -q disk /sys/power/state" + global_disable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/5/os/x86_64/CentOS/iasl-20090123-1.el5.x86_64.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/6.0.cfg b/shared/cfg/guest-os/Linux/RHEL/6.0.cfg index b4df9fb5f..540b31065 100644 --- a/shared/cfg/guest-os/Linux/RHEL/6.0.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/6.0.cfg @@ -8,3 +8,27 @@ modprobe_module = block_hotplug: modprobe_module = + guest_s3: + global_enable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + s3_support_chk_cmd += " && dmesg -c > /dev/null && grep -q mem /sys/power/state" + global_disable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + guest_s4: + global_enable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" + s4_support_chk_cmd += " && dmesg -c > /dev/null && grep -q disk /sys/power/state" + global_disable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/6.0/i386.cfg b/shared/cfg/guest-os/Linux/RHEL/6.0/i386.cfg index b074d13e2..a8de5acc6 100644 --- a/shared/cfg/guest-os/Linux/RHEL/6.0/i386.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/6.0/i386.cfg @@ -1,4 +1,5 @@ - i386: + grub_file = /boot/grub/grub.conf vm_arch_name = i686 image_name += -32 unattended_install, check_block_size.4096_512, check_block_size.512_512: @@ -12,8 +13,3 @@ unattended_install..floppy_ks: floppies = "fl" floppy_name = images/rhel60-32/ks.vfd - guest_s4..global_disable_s4: - s4_support_chk_cmd = "rpm --force --nodeps http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" - s4_support_chk_cmd += " && cat cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" - s4_support_chk_cmd += " && iasl -d /tmp/ssdt" - s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/6.0/x86_64.cfg b/shared/cfg/guest-os/Linux/RHEL/6.0/x86_64.cfg index 21deab392..83e240cbb 100644 --- a/shared/cfg/guest-os/Linux/RHEL/6.0/x86_64.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/6.0/x86_64.cfg @@ -1,4 +1,5 @@ - x86_64: + grub_file = /boot/grub/grub.conf vm_arch_name = x86_64 image_name += -64 unattended_install, check_block_size.4096_512, check_block_size.512_512: @@ -12,8 +13,3 @@ unattended_install..floppy_ks: floppies = "fl" floppy_name = images/rhel60-64/ks.vfd - guest_s4..global_disable_s4: - s4_support_chk_cmd = "rpm --force --nodeps http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" - s4_support_chk_cmd += " && cat cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" - s4_support_chk_cmd += " && iasl -d /tmp/ssdt" - s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/6.1.cfg b/shared/cfg/guest-os/Linux/RHEL/6.1.cfg index d2fcfc2ba..c18f1b395 100644 --- a/shared/cfg/guest-os/Linux/RHEL/6.1.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/6.1.cfg @@ -8,3 +8,27 @@ modprobe_module = block_hotplug: modprobe_module = + guest_s3: + global_enable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + s3_support_chk_cmd += " && dmesg -c > /dev/null && grep -q mem /sys/power/state" + global_disable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + guest_s4: + global_enable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" + s4_support_chk_cmd += " && dmesg -c > /dev/null && grep -q disk /sys/power/state" + global_disable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/6.1/i386.cfg b/shared/cfg/guest-os/Linux/RHEL/6.1/i386.cfg index 7d1eba4cd..29967c17e 100644 --- a/shared/cfg/guest-os/Linux/RHEL/6.1/i386.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/6.1/i386.cfg @@ -1,4 +1,5 @@ - i386: + grub_file = /boot/grub/grub.conf vm_arch_name = i686 image_name += -32 unattended_install, check_block_size.4096_512, check_block_size.512_512: @@ -12,8 +13,3 @@ unattended_install..floppy_ks: floppies = "fl" floppy_name = images/rhel61-32/ks.vfd - guest_s4..global_disable_s4: - s4_support_chk_cmd = "rpm --force --nodeps http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" - s4_support_chk_cmd += " && cat cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" - s4_support_chk_cmd += " && iasl -d /tmp/ssdt" - s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/6.1/x86_64.cfg b/shared/cfg/guest-os/Linux/RHEL/6.1/x86_64.cfg index 03bec2dc7..db845083f 100644 --- a/shared/cfg/guest-os/Linux/RHEL/6.1/x86_64.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/6.1/x86_64.cfg @@ -1,4 +1,5 @@ - x86_64: + grub_file = /boot/grub/grub.conf vm_arch_name = x86_64 image_name += -64 unattended_install, check_block_size.4096_512, check_block_size.512_512: diff --git a/shared/cfg/guest-os/Linux/RHEL/6.2.cfg b/shared/cfg/guest-os/Linux/RHEL/6.2.cfg index 6c775b431..1689a66e2 100644 --- a/shared/cfg/guest-os/Linux/RHEL/6.2.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/6.2.cfg @@ -8,3 +8,27 @@ modprobe_module = block_hotplug: modprobe_module = + guest_s3: + global_enable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + s3_support_chk_cmd += " && dmesg -c > /dev/null && grep -q mem /sys/power/state" + global_disable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + guest_s4: + global_enable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" + s4_support_chk_cmd += " && dmesg -c > /dev/null && grep -q disk /sys/power/state" + global_disable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/6.2/i386.cfg b/shared/cfg/guest-os/Linux/RHEL/6.2/i386.cfg index 82408d451..6989ea40a 100644 --- a/shared/cfg/guest-os/Linux/RHEL/6.2/i386.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/6.2/i386.cfg @@ -1,4 +1,5 @@ - i386: + grub_file = /boot/grub/grub.conf vm_arch_name = i686 image_name += -32 unattended_install, check_block_size.4096_512, check_block_size.512_512: @@ -12,8 +13,3 @@ unattended_install..floppy_ks: floppies = "fl" floppy_name = images/rhel62-32/ks.vfd - guest_s4..global_disable_s4: - s4_support_chk_cmd = "rpm --force --nodeps http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" - s4_support_chk_cmd += " && cat cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" - s4_support_chk_cmd += " && iasl -d /tmp/ssdt" - s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/6.2/x86_64.cfg b/shared/cfg/guest-os/Linux/RHEL/6.2/x86_64.cfg index 5259403f0..f1b3c940d 100644 --- a/shared/cfg/guest-os/Linux/RHEL/6.2/x86_64.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/6.2/x86_64.cfg @@ -1,4 +1,5 @@ - x86_64: + grub_file = /boot/grub/grub.conf vm_arch_name = x86_64 image_name += -64 unattended_install, check_block_size.4096_512, check_block_size.512_512: @@ -12,8 +13,3 @@ unattended_install..floppy_ks: floppies = "fl" floppy_name = images/rhel62-64/ks.vfd - guest_s4..global_disable_s4: - s4_support_chk_cmd = "rpm --force --nodeps http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" - s4_support_chk_cmd += " && cat cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" - s4_support_chk_cmd += " && iasl -d /tmp/ssdt" - s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/6.3.cfg b/shared/cfg/guest-os/Linux/RHEL/6.3.cfg index dee5be5cf..92ac83862 100644 --- a/shared/cfg/guest-os/Linux/RHEL/6.3.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/6.3.cfg @@ -8,3 +8,27 @@ modprobe_module = block_hotplug: modprobe_module = + guest_s3: + global_enable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + s3_support_chk_cmd += " && dmesg -c > /dev/null && grep -q mem /sys/power/state" + global_disable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + guest_s4: + global_enable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" + s4_support_chk_cmd += " && dmesg -c > /dev/null && grep -q disk /sys/power/state" + global_disable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/6.3/i386.cfg b/shared/cfg/guest-os/Linux/RHEL/6.3/i386.cfg index 835582034..53615b402 100644 --- a/shared/cfg/guest-os/Linux/RHEL/6.3/i386.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/6.3/i386.cfg @@ -1,4 +1,5 @@ - i386: + grub_file = /boot/grub/grub.conf vm_arch_name = i686 image_name += -32 unattended_install, check_block_size.4096_512, check_block_size.512_512: @@ -12,8 +13,3 @@ unattended_install..floppy_ks: floppies = "fl" floppy_name = images/rhel63-32/ks.vfd - guest_s4..global_disable_s4: - s4_support_chk_cmd = "rpm --force --nodeps http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" - s4_support_chk_cmd += " && cat cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" - s4_support_chk_cmd += " && iasl -d /tmp/ssdt" - s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/6.3/x86_64.cfg b/shared/cfg/guest-os/Linux/RHEL/6.3/x86_64.cfg index 6acc93a90..76345f83c 100644 --- a/shared/cfg/guest-os/Linux/RHEL/6.3/x86_64.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/6.3/x86_64.cfg @@ -1,4 +1,5 @@ - x86_64: + grub_file = /boot/grub/grub.conf vm_arch_name = x86_64 image_name += -64 unattended_install, check_block_size.4096_512, check_block_size.512_512: @@ -12,8 +13,3 @@ unattended_install..floppy_ks: floppies = "fl" floppy_name = images/rhel63-64/ks.vfd - guest_s4..global_disable_s4: - s4_support_chk_cmd = "rpm --force --nodeps http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" - s4_support_chk_cmd += " && cat cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" - s4_support_chk_cmd += " && iasl -d /tmp/ssdt" - s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/6.4.cfg b/shared/cfg/guest-os/Linux/RHEL/6.4.cfg index 21dd053b3..610e88153 100644 --- a/shared/cfg/guest-os/Linux/RHEL/6.4.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/6.4.cfg @@ -8,3 +8,27 @@ modprobe_module = block_hotplug: modprobe_module = + guest_s3: + global_enable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + s3_support_chk_cmd += " && dmesg -c > /dev/null && grep -q mem /sys/power/state" + global_disable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + guest_s4: + global_enable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" + s4_support_chk_cmd += " && dmesg -c > /dev/null && grep -q disk /sys/power/state" + global_disable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/6.4/i386.cfg b/shared/cfg/guest-os/Linux/RHEL/6.4/i386.cfg index 72b02bcdd..1680f80d4 100644 --- a/shared/cfg/guest-os/Linux/RHEL/6.4/i386.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/6.4/i386.cfg @@ -1,4 +1,5 @@ - i386: + grub_file = /boot/grub/grub.conf vm_arch_name = i686 image_name += -32 unattended_install, check_block_size.4096_512, check_block_size.512_512: @@ -12,8 +13,3 @@ unattended_install..floppy_ks: floppies = "fl" floppy_name = images/rhel64-32/ks.vfd - guest_s4..global_disable_s4: - s4_support_chk_cmd = "rpm --force --nodeps http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" - s4_support_chk_cmd += " && cat cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" - s4_support_chk_cmd += " && iasl -d /tmp/ssdt" - s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/6.4/x86_64.cfg b/shared/cfg/guest-os/Linux/RHEL/6.4/x86_64.cfg index c37453486..258639b9f 100644 --- a/shared/cfg/guest-os/Linux/RHEL/6.4/x86_64.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/6.4/x86_64.cfg @@ -1,4 +1,5 @@ - x86_64: + grub_file = /boot/grub/grub.conf vm_arch_name = x86_64 image_name += -64 unattended_install, check_block_size.4096_512, check_block_size.512_512: @@ -12,8 +13,3 @@ unattended_install..floppy_ks: floppies = "fl" floppy_name = images/rhel64-64/ks.vfd - guest_s4..global_disable_s4: - s4_support_chk_cmd = "rpm --force --nodeps http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" - s4_support_chk_cmd += " && cat cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" - s4_support_chk_cmd += " && iasl -d /tmp/ssdt" - s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/6.devel.cfg b/shared/cfg/guest-os/Linux/RHEL/6.devel.cfg index 74c6d54ac..042031e3c 100644 --- a/shared/cfg/guest-os/Linux/RHEL/6.devel.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/6.devel.cfg @@ -8,3 +8,27 @@ modprobe_module = block_hotplug: modprobe_module = + guest_s3: + global_enable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + s3_support_chk_cmd += " && dmesg -c > /dev/null && grep -q mem /sys/power/state" + global_disable_s3: + s3_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s3_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s3_support_chk_cmd += " && iasl -d /tmp/ssdt" + s3_support_chk_cmd += " && grep "_S3" /tmp/ssdt.dsl" + guest_s4: + global_enable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" + s4_support_chk_cmd += " && dmesg -c > /dev/null && grep -q disk /sys/power/state" + global_disable_s4: + s4_support_chk_cmd = "rpm --force --nodeps -ivh http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" + s4_support_chk_cmd += " && cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" + s4_support_chk_cmd += " && iasl -d /tmp/ssdt" + s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/6.devel/i386.cfg b/shared/cfg/guest-os/Linux/RHEL/6.devel/i386.cfg index 3a4a37c82..638d77f60 100644 --- a/shared/cfg/guest-os/Linux/RHEL/6.devel/i386.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/6.devel/i386.cfg @@ -1,4 +1,5 @@ - i386: + grub_file = /boot/grub/grub.conf vm_arch_name = i386 image_name += -32 unattended_install, check_block_size.4096_512, check_block_size.512_512: @@ -10,8 +11,3 @@ unattended_install..floppy_ks: floppies = "fl" floppy_name = images/rhel63-64/ks.vfd - guest_s4..global_disable_s4: - s4_support_chk_cmd = "rpm --force --nodeps http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" - s4_support_chk_cmd += " && cat cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" - s4_support_chk_cmd += " && iasl -d /tmp/ssdt" - s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Linux/RHEL/6.devel/x86_64.cfg b/shared/cfg/guest-os/Linux/RHEL/6.devel/x86_64.cfg index 798d395a6..5572861d3 100644 --- a/shared/cfg/guest-os/Linux/RHEL/6.devel/x86_64.cfg +++ b/shared/cfg/guest-os/Linux/RHEL/6.devel/x86_64.cfg @@ -1,4 +1,5 @@ - x86_64: + grub_file = /boot/grub/grub.conf vm_arch_name = x86_64 image_name += -64 unattended_install, check_block_size.4096_512, check_block_size.512_512: @@ -11,8 +12,3 @@ floppies = "fl" floppy_name = images/rhel6-64/ks.vfd cdrom_cd1 = isos/linux/RHEL6-devel-x86_64.iso - guest_s4..global_disable_s4: - s4_support_chk_cmd = "rpm --force --nodeps http://mirrors.sonic.net/centos/6/os/`uname -m`/Packages/iasl-20090123-3.1.el6.`uname -m`.rpm" - s4_support_chk_cmd += " && cat cat /sys/firmware/acpi/tables/SSDT > /tmp/ssdt" - s4_support_chk_cmd += " && iasl -d /tmp/ssdt" - s4_support_chk_cmd += " && grep "_S4" /tmp/ssdt.dsl" diff --git a/shared/cfg/guest-os/Windows.cfg b/shared/cfg/guest-os/Windows.cfg index c3fc7db82..d2dfcbc58 100644 --- a/shared/cfg/guest-os/Windows.cfg +++ b/shared/cfg/guest-os/Windows.cfg @@ -1,6 +1,7 @@ - @Windows: vfd_size = 2880k os_type = windows + image_size = 30G use_libvirt_cdrom_switch = yes shutdown_command = shutdown /s /f /t 0 reboot_command = shutdown /r /f /t 0 @@ -53,8 +54,6 @@ guest_path = C:\tmpfile stress_boot: alive_test_cmd = systeminfo - block_stream: - alive_test_cmd = systeminfo timedrift: # Timedrift compensation on Windows with hpet does not happen disable_hpet = yes @@ -160,7 +159,7 @@ umount_cmd = "" physical_resources_check: catch_uuid_cmd = - catch_serial_cmd = + catch_serial_cmd = "wmic diskdrive get serialnumber | more +1" cpu_vendor_id_chk_cmd = "wmic cpu get Manufacturer | more +1" #XXX: Since I don't find a reliable way to check the cpu socket # numbers for windows, disable this kind of checking temporarily. @@ -183,7 +182,7 @@ black_list += " E:" shell_port = 23 shell_client = telnet - post_cmd = del c:\cmd.exe + post_cmd = del c:\cmd.exe; true file_system = "ntfs fat32" cmd_list = "copy_to_command copy_from_command" list_volume_command = wmic volume get driveletter @@ -224,7 +223,7 @@ black_list += " E:" shell_port = 23 shell_client = telnet - post_cmd = del c:\cmd.exe + post_cmd = del c:\cmd.exe; true file_system = "ntfs fat32" cmd_list = "copy_to_command copy_from_command" list_volume_command = wmic volume get driveletter @@ -286,17 +285,7 @@ start_cmd = "dd if=/dev/random of=c:\test.img bs=4k count=25000" stop_cmd = 'taskkill /F /T /IM dd.exe & del /f /s /q "c:\test.img"' check_cmd = 'tasklist | findstr /I "dd.exe"' - drive_mirror.with_stress.heavyload: - tmp_dir = "C:\" - download_link = "http://www.jam-software.com/heavyload/HeavyLoadSetup.exe" - md5sum = 5bf187bd914ac8ce7f79361d7b56bc15 - install_cmd = 'start /wait %s\HeavyLoadSetup.exe /verysilent' - config_cmd = 'setx path "%path%;C:\Program Files\JAM Software\HeavyLoad" -m' - app_check_cmd = "heavyload" - start_cmd = "heavyload /CPU /MEMORY /START" - check_cmd = 'tasklist | findstr /I "heavyload.exe"' - stop_cmd = "taskkill /T /F /IM heavyload.exe" - drive_mirror.powerdown: + drive_mirror.with_stress.heavyload, drive_mirror.with_powerdown, block_stream.with_stress: tmp_dir = "C:\" download_link = "http://www.jam-software.com/heavyload/HeavyLoadSetup.exe" md5sum = 5bf187bd914ac8ce7f79361d7b56bc15 @@ -326,4 +315,8 @@ bg_cmd = copy C:\1.txt C:\2.txt /y check_op = echo cd C:\ > C:\tmp.bat&& echo for /F "tokens=1,*" %%i in ('D:\coreutils\md5sum.exe C:\1.txt') do D:\coreutils\md5sum.exe C:\2.txt ^| find "%%i" >> C:\tmp.bat && C:\tmp.bat clean_op = dir C:\ && del C:\1.txt C:\2.txt C:\tmp.bat && dir C:\ - + usb..usb_boot, usb..usb_reboot: + deviceid_str = "VID_%s&PID_%s" + chk_usb_info_cmd = 'wmic path Win32_USBControllerDevice get Dependent | find "USB"' + vendor = "" + product = "" diff --git a/shared/cfg/guest-os/Windows/Win2003.cfg b/shared/cfg/guest-os/Windows/Win2003.cfg index 7aec7d683..b4253b7f6 100644 --- a/shared/cfg/guest-os/Windows/Win2003.cfg +++ b/shared/cfg/guest-os/Windows/Win2003.cfg @@ -1,7 +1,6 @@ - Win2003: os_variant = win2k3 image_name = images/win2003 - image_size = 20G netperf_win.netperf_exe.best_registry_setting: shell_port = 23 shell_client = telnet diff --git a/shared/cfg/guest-os/Windows/Win2008.cfg b/shared/cfg/guest-os/Windows/Win2008.cfg index 0e823b327..ab55d5b72 100644 --- a/shared/cfg/guest-os/Windows/Win2008.cfg +++ b/shared/cfg/guest-os/Windows/Win2008.cfg @@ -1,7 +1,6 @@ - Win2008: os_variant = win2k8 image_name = images/win2008 - image_size = 20G netperf_win.netperf_exe.best_registry_setting: shell_port = 23 shell_client = telnet diff --git a/shared/cfg/guest-os/Windows/Win2012.cfg b/shared/cfg/guest-os/Windows/Win2012.cfg index 584b5ade2..c141d856e 100644 --- a/shared/cfg/guest-os/Windows/Win2012.cfg +++ b/shared/cfg/guest-os/Windows/Win2012.cfg @@ -1,7 +1,6 @@ - Win2012: image_name = images/win2012 guest_name = Win2012 - image_size = 30G shutdown_command = shutdown /s /f /t 0 reboot_command = shutdown /r /f /t 0 format_disk: diff --git a/shared/cfg/guest-os/Windows/Win7.cfg b/shared/cfg/guest-os/Windows/Win7.cfg index 79672b5d2..e4252c97d 100644 --- a/shared/cfg/guest-os/Windows/Win7.cfg +++ b/shared/cfg/guest-os/Windows/Win7.cfg @@ -1,7 +1,6 @@ - Win7: os_variant = win7 image_name = images/win7 - image_size = 20G whql.submission: desc_path_desc1 = $\WDK\Logo Type\Device Logo\Windows 7 Client\Logo desc_path_desc2 = $\WDK\Logo Type\Device Logo\Windows 7 Client diff --git a/shared/cfg/guest-os/Windows/Win8.cfg b/shared/cfg/guest-os/Windows/Win8.cfg index 431b3ce5c..85a3c6a96 100644 --- a/shared/cfg/guest-os/Windows/Win8.cfg +++ b/shared/cfg/guest-os/Windows/Win8.cfg @@ -1,7 +1,6 @@ - Win8: os_variant = win8 image_name = images/win8 - image_size = 30G shutdown_command = shutdown /s /f /t 0 reboot_command = shutdown /r /f /t 0 # it can be removed while bug 821741 is fixed diff --git a/shared/cfg/guest-os/Windows/WinVista.cfg b/shared/cfg/guest-os/Windows/WinVista.cfg index 5cc2e719c..8c0401aa1 100644 --- a/shared/cfg/guest-os/Windows/WinVista.cfg +++ b/shared/cfg/guest-os/Windows/WinVista.cfg @@ -1,7 +1,6 @@ - WinVista: os_variant = vista image_name = images/winvista - image_size = 20G whql.submission: desc_path_desc1 = $\WDK\Logo Type\Device Logo\Vista Client\Device Premium desc_path_desc2 = $\WDK\Logo Type\Device Logo\Vista Client\Device Standard diff --git a/shared/control/aiostress.control b/shared/control/aiostress.control new file mode 100644 index 000000000..16e059fa4 --- /dev/null +++ b/shared/control/aiostress.control @@ -0,0 +1,24 @@ +AUTHOR = "Masoud S " +NAME = "aio stress" +TEST_CATEGORY = "Stress" +TEST_CLASS = "Kernel" +TIME = "SHORT" +TEST_TYPE = "client" +DOC = """\ +aio-stress + +will open or create each file on the command line, and start a series +of aio to it. + +aio is done in a rotating loop. first file1 gets 8 requests, then +file2, then file3 etc. As each file finishes writing, it is switched +to reads + +io buffers are aligned in case you want to do raw io + +This test takes less than a minute. It ends up writing and reading less +than a few Megs. It is a sequential workload. This test stresses the aio +interface not the disk, or kernel. +""" + +job.run_test('aiostress') diff --git a/shared/control/bonnie.control b/shared/control/bonnie.control index 2717a8040..878f559ba 100644 --- a/shared/control/bonnie.control +++ b/shared/control/bonnie.control @@ -18,4 +18,4 @@ throughput, %CPU rand seeks per second. Not sure if the the CPU numbers are trustworthy. """ -job.run_test('bonnie') +job.run_test('bonnie', extra_args="-n 500 -s 2048M -r 1024M") diff --git a/shared/control/compilebench.control b/shared/control/compilebench.control new file mode 100644 index 000000000..813c3b451 --- /dev/null +++ b/shared/control/compilebench.control @@ -0,0 +1,13 @@ +AUTHOR = "Curt Wohlgemuth " +NAME = "compilebench" +TEST_CATEGORY = "Functional" +TEST_CLASS = "General" +TEST_TYPE = "client" +TIME = "SHORT" +DOC=""" +Compilebench is a filesystem performance test. It simulates some of the disk +IO common in creating, compiling, patching, stating and reading kernel trees. +It indirectly measures how well filesystems can maintain directory locality as +the disk fills up and directories age. +""" +job.run_test("compilebench") diff --git a/shared/control/fio.control b/shared/control/fio.control new file mode 100644 index 000000000..2b5e75f68 --- /dev/null +++ b/shared/control/fio.control @@ -0,0 +1,13 @@ +AUTHOR = "Randy.Dunlap " +NAME = "fio" +TEST_CATEGORY = "Stress" +TEST_CLASS = "General" +TEST_TYPE = "client" +TIME = 'MEDIUM' +EXPERIMENTAL = "True" +DOC=''' +fio is an I/O tool meant to be used both for benchmark and stress/hardware +verification. This test runs the fio tool. Details can be found at : +http://freecode.com/projects/fio +''' +job.run_test('fio', args="-rw=randread -bs=8k -size 1G -numjobs=8 -runtime=600 -iodepth=32 -iodepth_batch=16") diff --git a/shared/control/fsstress.control b/shared/control/fsstress.control new file mode 100644 index 000000000..20b9dad5d --- /dev/null +++ b/shared/control/fsstress.control @@ -0,0 +1,16 @@ +AUTHOR = "Ricardo Salveti de Araujo must already exist on + # the machine. To avoid device initialization + # set to None. +remove_previous=False # Boolean. +sparse_file=os.path.join( # Absolute path to the sparse file. + job.tmpdir, + 'sparse_file') +old_cleanup=False # Remove a previously created mount_point if it + # exits and not mounted. + +# Beginning execution of the xfstests: +# ------------------------------------ +job.run_test('wb_kupdate', + mount_point=mount_point, + file_count=int(file_count), + write_size=int(write_size), + max_flush_time=int(max_flush_time), + file_system=file_system, + remove_previous=remove_previous, + sparse_file=sparse_file, + old_cleanup=old_cleanup, + tag='wb_kupdate_execution') diff --git a/shared/control/xfstests.control b/shared/control/xfstests.control index 9ab1f69df..61bb11156 100644 --- a/shared/control/xfstests.control +++ b/shared/control/xfstests.control @@ -60,15 +60,34 @@ Make sure you have them or a real spare device to test things. """ # Define the partitions you want to use. # -# Here, by default we use the concept of virtual partition (a partition of 1GB -# of size), to avoid setup by the user. However, you'll most likely use a real -# block device for your tests. from autotest.client import partition -file_img = os.path.join(job.tmpdir, 'xfstests.img') -vp = partition.virtual_partition(file_img=file_img, file_size=1024*1024) -device = vp.device -# You can use a real block device, such as /dev/sdc1 -#device=/dev/sdc1 +import re + +disks=[] +boot_disk = [] +for line in open("/proc/partitions").readlines(): + try: + major,minor, blocks, name = line.split() + except: + continue + if re.match("[shv]d.*", name): + if name[-1].isdigit(): + boot_disk.append(name[:-1]) + else: + disks.append(name) + +device = set(disks) - set(boot_disk) +try: + device = device.pop() +except KeyError: + raise error.TestError("No realy partation found") + +device = os.path.join("/dev", device) +cmd = "parted -s %s mklabel gpt && " % device +cmd += "parted -s %s mkpart primary 1 1G" % device +utils.run(cmd) +# Make test run on first partition of the disc +device += "1" # By default, we create a directory under autotest mountpoint = os.path.join(job.tmpdir, 'xfstests') @@ -140,4 +159,5 @@ for fs_type in FS_TYPES: # It is good practice to unmount the partition created p.unmount() # If you are using the virtual partition, you may destroy it here -vp.destroy() +cmd = "parted -s %s rm 1 && partprobe %s" % (device, device) +utils.run(cmd) diff --git a/shared/deps/finish.bat b/shared/deps/finish.bat index 41f2beb4e..7015ea582 100644 --- a/shared/deps/finish.bat +++ b/shared/deps/finish.bat @@ -26,5 +26,6 @@ reg add "HKLM\System\CurrentControlSet\Control\CrashControl" /v DumpFile /d %Sys reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Run" /v bsod /d "D:\autoit3.exe D:\dump_control.au3" /t REG_SZ /f reg add "HKLM\System\CurrentControlSet\Control\CrashControl" /v AlwaysKeepMemoryDump /d 1 /t REG_DWORD /f reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\Windows Error Reporting" /v Disabled /d 1 /t REG_DWORD /f +reg add "HKLM\SYSTEM\CurrentControlSet\Services\vds" /v Start /t REG_DWORD /d 3 /f echo Post set up finished> COM1 diff --git a/shared/deps/time-warp-test.c b/shared/deps/time-warp-test.c new file mode 100644 index 000000000..7fceeda93 --- /dev/null +++ b/shared/deps/time-warp-test.c @@ -0,0 +1,368 @@ +/* +* Copyright (C) 2005, Ingo Molnar +* +* time-warp-test.c: check TSC synchronity on x86 CPUs. Also detects +* gettimeofday()-level time warps. +* +* Compile with: gcc -Wall -O2 -o time-warp-test time-warp-test.c -lrt +*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TEST_TSC 1 +#define TEST_TOD 1 +#define TEST_CLOCK 1 + +#if !TEST_TSC && !TEST_TOD && !TEST_CLOCK +# error this setting makes no sense ... +#endif + +#if DEBUG +# define Printf(x...) printf(x) +#else +# define Printf(x...) do { } while (0) +#endif + +/* + * Shared locks and variables between the test tasks: + */ +enum { + SHARED_LOCK = 0, + SHARED_TSC = 2, + SHARED_TOD = 4, + SHARED_CLOCK = 6, + SHARED_WORST_TSC = 8, + SHARED_WORST_TOD = 10, + SHARED_WORST_CLOCK = 12, + SHARED_NR_TSC_LOOPS = 14, + SHARED_NR_TSC_WARPS = 16, + SHARED_NR_TOD_LOOPS = 18, + SHARED_NR_TOD_WARPS = 20, + SHARED_NR_CLOCK_LOOPS = 22, + SHARED_NR_CLOCK_WARPS = 24, + SHARED_END = 26, +}; + +#define SHARED(x) (*(shared + SHARED_##x)) +#define SHARED_LL(x) (*(long long *)(shared + SHARED_##x)) + +#define BUG_ON(c) assert(!(c)) + +typedef unsigned long long cycles_t; +typedef unsigned long long usecs_t; +typedef unsigned long long u64; + +#ifdef __x86_64__ +#define DECLARE_ARGS(val, low, high) unsigned low, high +#define EAX_EDX_VAL(val, low, high) ((low) | ((u64)(high) << 32)) +#define EAX_EDX_ARGS(val, low, high) "a" (low), "d" (high) +#define EAX_EDX_RET(val, low, high) "=a" (low), "=d" (high) +#else +#define DECLARE_ARGS(val, low, high) unsigned long long val +#define EAX_EDX_VAL(val, low, high) (val) +#define EAX_EDX_ARGS(val, low, high) "A" (val) +#define EAX_EDX_RET(val, low, high) "=A" (val) +#endif + +static inline unsigned long long __rdtscll(void) +{ + DECLARE_ARGS(val, low, high); + + asm volatile("cpuid; rdtsc" : EAX_EDX_RET(val, low, high)); + + return EAX_EDX_VAL(val, low, high); +} + +#define rdtscll(val) do { (val) = __rdtscll(); } while (0) + +#define rdtod(val) \ + do { \ + struct timeval tv; \ + \ + gettimeofday(&tv, NULL); \ + (val) = tv.tv_sec * 1000000ULL + tv.tv_usec; \ + } while (0) + +#define rdclock(val) \ + do { \ + struct timespec ts; \ + \ + clock_gettime(CLOCK_MONOTONIC, &ts); \ + (val) = ts.tv_sec * 1000000000ULL + ts.tv_nsec; \ + } while (0) + +static unsigned long *setup_shared_var(void) +{ + char zerobuff [4096] = { 0, }; + int ret, fd; + unsigned long *buf; + + fd = creat(".tmp_mmap", 0700); + BUG_ON(fd == -1); + close(fd); + + fd = open(".tmp_mmap", O_RDWR|O_CREAT|O_TRUNC); + BUG_ON(fd == -1); + ret = write(fd, zerobuff, 4096); + BUG_ON(ret != 4096); + + buf = (void *)mmap(0, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + BUG_ON(buf == (void *)-1); + + close(fd); + unlink(".tmp_mmap"); + + return buf; +} + +static inline void lock(unsigned long *flag) +{ +#if 0 + __asm__ __volatile__( + "1: lock; btsl $0,%0\n" + "jc 1b\n" + : "=g"(*flag) : : "memory"); +#else + __asm__ __volatile__( + "1: lock; btsl $0,%0\n\t" + "jnc 3f\n" + "2: testl $1,%0\n\t" + "je 1b\n\t" + "rep ; nop\n\t" + "jmp 2b\n" + "3:" + : "+m"(*flag) : : "memory"); +#endif +} + +static inline void unlock(unsigned long *flag) +{ +#if 0 + __asm__ __volatile__( + "lock; btrl $0,%0\n" + : "=g"(*flag) :: "memory"); + __asm__ __volatile__("rep; nop"); +#else + __asm__ __volatile__("mov $0,%0; rep; nop" : "=g"(*flag) :: "memory"); +#endif +} + +static void print_status(unsigned long *shared) +{ + const char progress[] = "\\|/-"; + + static unsigned long long sum_tsc_loops, sum_tod_loops, sum_clock_loops, + sum_tod; + static unsigned int count1, count2; + static usecs_t prev_tod; + + usecs_t tod; + + if (!prev_tod) + rdtod(prev_tod); + + count1++; + if (count1 < 1000) + return; + count1 = 0; + + rdtod(tod); + if (abs(tod - prev_tod) < 100000ULL) + return; + + sum_tod += tod - prev_tod; + sum_tsc_loops += SHARED_LL(NR_TSC_LOOPS); + sum_tod_loops += SHARED_LL(NR_TOD_LOOPS); + sum_clock_loops += SHARED_LL(NR_CLOCK_LOOPS); + SHARED_LL(NR_TSC_LOOPS) = 0; + SHARED_LL(NR_TOD_LOOPS) = 0; + SHARED_LL(NR_CLOCK_LOOPS) = 0; + + if (TEST_TSC) + printf(" | TSC: %.2fus, fail:%ld", + (double)sum_tod/(double)sum_tsc_loops, + SHARED(NR_TSC_WARPS)); + + if (TEST_TOD) + printf(" | TOD: %.2fus, fail:%ld", + (double)sum_tod/(double)sum_tod_loops, + SHARED(NR_TOD_WARPS)); + + if (TEST_CLOCK) + printf(" | CLK: %.2fus, fail:%ld", + (double)sum_tod/(double)sum_clock_loops, + SHARED(NR_CLOCK_WARPS)); + + prev_tod = tod; + count2++; + printf(" %c\r", progress[count2 & 3]); + fflush(stdout); +} + +static inline void test_TSC(unsigned long *shared) +{ +#if TEST_TSC + cycles_t t0, t1; + long long delta; + + lock(&SHARED(LOCK)); + rdtscll(t1); + t0 = SHARED_LL(TSC); + SHARED_LL(TSC) = t1; + SHARED_LL(NR_TSC_LOOPS)++; + unlock(&SHARED(LOCK)); + + delta = t1-t0; + if (delta < 0) { + lock(&SHARED(LOCK)); + SHARED(NR_TSC_WARPS)++; + if (delta < SHARED_LL(WORST_TSC)) { + SHARED_LL(WORST_TSC) = delta; + fprintf(stderr, "\rnew TSC-warp maximum: %9Ld cycles, %016Lx -> %016Lx\n", + delta, t0, t1); + } + unlock(&SHARED(LOCK)); + } + if (!((unsigned long)t0 & 31)) + asm volatile ("rep; nop"); +#endif +} + +static inline void test_TOD(unsigned long *shared) +{ +#if TEST_TOD + usecs_t T0, T1; + long long delta; + + lock(&SHARED(LOCK)); + rdtod(T1); + T0 = SHARED_LL(TOD); + SHARED_LL(TOD) = T1; + SHARED_LL(NR_TOD_LOOPS)++; + unlock(&SHARED(LOCK)); + + delta = T1-T0; + if (delta < 0) { + lock(&SHARED(LOCK)); + SHARED(NR_TOD_WARPS)++; + if (delta < SHARED_LL(WORST_TOD)) { + SHARED_LL(WORST_TOD) = delta; + fprintf(stderr, "\rnew TOD-warp maximum: %9Ld usecs, %016Lx -> %016Lx\n", + delta, T0, T1); + } + unlock(&SHARED(LOCK)); + } +#endif +} + +static inline void test_CLOCK(unsigned long *shared) +{ +#if TEST_CLOCK + usecs_t T0, T1; + long long delta; + + lock(&SHARED(LOCK)); + rdclock(T1); + T0 = SHARED_LL(CLOCK); + SHARED_LL(CLOCK) = T1; + SHARED_LL(NR_CLOCK_LOOPS)++; + unlock(&SHARED(LOCK)); + + delta = T1-T0; + if (delta < 0) { + lock(&SHARED(LOCK)); + SHARED(NR_CLOCK_WARPS)++; + if (delta < SHARED_LL(WORST_CLOCK)) { + SHARED_LL(WORST_CLOCK) = delta; + fprintf(stderr, "\rnew CLOCK-warp maximum: %9Ld nsecs, %016Lx -> %016Lx\n", + delta, T0, T1); + } + unlock(&SHARED(LOCK)); + } +#endif +} + +int main(int argc, char **argv) +{ + int i, parent, me; + unsigned long *shared; + unsigned long cpus, tasks; + + cpus = system("exit `grep ^processor /proc/cpuinfo | wc -l`"); + cpus = WEXITSTATUS(cpus); + + if (argc > 2) { +usage: + fprintf(stderr, + "usage: tsc-sync-test \n"); + exit(-1); + } + if (argc == 2) { + tasks = atol(argv[1]); + if (!tasks) + goto usage; + } else + tasks = cpus; + + printf("%ld CPUs, running %ld parallel test-tasks.\n", cpus, tasks); + printf("checking for time-warps via:\n" +#if TEST_TSC + "- read time stamp counter (RDTSC) instruction (cycle resolution)\n" +#endif +#if TEST_TOD + "- gettimeofday (TOD) syscall (usec resolution)\n" +#endif +#if TEST_CLOCK + "- clock_gettime(CLOCK_MONOTONIC) syscall (nsec resolution)\n" +#endif + "\n" + ); + shared = setup_shared_var(); + + parent = getpid(); + + for (i = 1; i < tasks; i++) { + if (!fork()) + break; + } + me = getpid(); + + while (1) { + int i; + + for (i = 0; i < 10; i++) + test_TSC(shared); + for (i = 0; i < 10; i++) + test_TOD(shared); + for (i = 0; i < 10; i++) + test_CLOCK(shared); + + if (me == parent) + print_status(shared); + } + + return 0; +} diff --git a/shared/downloads/fedora-19-x86_64.ini b/shared/downloads/fedora-19-x86_64.ini new file mode 100644 index 000000000..21ca3576e --- /dev/null +++ b/shared/downloads/fedora-19-x86_64.ini @@ -0,0 +1,4 @@ +[fedora-19-x86_64] +title = Fedora 19 x86_64 DVD +url = http://download.fedoraproject.org/pub/fedora/linux/releases/19/Fedora/x86_64/iso/Fedora-19-x86_64-DVD.iso +destination = isos/linux/Fedora-19-x86_64-DVD.iso diff --git a/shared/downloads/video-sample.ini b/shared/downloads/video-sample.ini new file mode 100644 index 000000000..5ee913331 --- /dev/null +++ b/shared/downloads/video-sample.ini @@ -0,0 +1,5 @@ +[video-sample] +title = Video sample for Spice tests +url = http://lmr.fedorapeople.org/video_sample/video_sample_test.ogv +sha1_url = http://lmr.fedorapeople.org/video_sample/SHA1SUM +destination = shared/deps/video_sample_test.ogv diff --git a/shared/gpg/README b/shared/gpg/README new file mode 100644 index 000000000..9e2945f10 --- /dev/null +++ b/shared/gpg/README @@ -0,0 +1 @@ +You may add a file with your trusted GPG keys in this dir. diff --git a/shared/unattended/Debian-6.0.7.preseed b/shared/unattended/Debian-6.0.7.preseed index bfd483e96..1da1b1545 100644 --- a/shared/unattended/Debian-6.0.7.preseed +++ b/shared/unattended/Debian-6.0.7.preseed @@ -32,7 +32,7 @@ d-i mirror/http/proxy string tasksel tasksel/first multiselect standard -d-i pkgsel/include string openssh-server build-essential +d-i pkgsel/include string openssh-server build-essential lvm2 ethtool sg3-utils lsscsi libaio-dev libtime-hires-perl d-i grub-installer/only_debian boolean true d-i grub-installer/with_other_os boolean true diff --git a/shared/unattended/Fedora-10.ks b/shared/unattended/Fedora-10.ks index 2cabb9445..5a5ae0640 100644 --- a/shared/unattended/Fedora-10.ks +++ b/shared/unattended/Fedora-10.ks @@ -24,12 +24,13 @@ poweroff @development-tools ntpdate -%post --interpreter /usr/bin/python -import os -os.system('grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel)') -os.system('dhclient') -os.system('chkconfig sshd on') -os.system('iptables -F') -os.system('echo 0 > /selinux/enforce') -os.system('echo Post set up finished > /dev/ttyS0') -os.system('echo Post set up finished > /dev/hvc0') +%post +echo "OS install is completed" > /dev/ttyS0 +grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel) +dhclient +chkconfig sshd on +iptables -F +echo 0 > /selinux/enforce +sed -i "/^HWADDR/d" /etc/sysconfig/network-scripts/ifcfg-eth0 +echo 'Post set up finished' > /dev/ttyS0 +echo Post set up finished > /dev/hvc0 diff --git a/shared/unattended/Fedora-11.ks b/shared/unattended/Fedora-11.ks index d5a1523c7..5a90ae65a 100644 --- a/shared/unattended/Fedora-11.ks +++ b/shared/unattended/Fedora-11.ks @@ -24,13 +24,14 @@ autopart ntpdate %end -%post --interpreter /usr/bin/python -import os -os.system('grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel)') -os.system('dhclient') -os.system('chkconfig sshd on') -os.system('iptables -F') -os.system('echo 0 > /selinux/enforce') -os.system('echo Post set up finished > /dev/ttyS0') -os.system('echo Post set up finished > /dev/hvc0') +%post +echo "OS install is completed" > /dev/ttyS0 +grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel) +dhclient +chkconfig sshd on +iptables -F +echo 0 > /selinux/enforce +sed -i "/^HWADDR/d" /etc/sysconfig/network-scripts/ifcfg-eth0 +echo 'Post set up finished' > /dev/ttyS0 +echo Post set up finished > /dev/hvc0 %end diff --git a/shared/unattended/Fedora-12.ks b/shared/unattended/Fedora-12.ks index d5a1523c7..5a90ae65a 100644 --- a/shared/unattended/Fedora-12.ks +++ b/shared/unattended/Fedora-12.ks @@ -24,13 +24,14 @@ autopart ntpdate %end -%post --interpreter /usr/bin/python -import os -os.system('grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel)') -os.system('dhclient') -os.system('chkconfig sshd on') -os.system('iptables -F') -os.system('echo 0 > /selinux/enforce') -os.system('echo Post set up finished > /dev/ttyS0') -os.system('echo Post set up finished > /dev/hvc0') +%post +echo "OS install is completed" > /dev/ttyS0 +grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel) +dhclient +chkconfig sshd on +iptables -F +echo 0 > /selinux/enforce +sed -i "/^HWADDR/d" /etc/sysconfig/network-scripts/ifcfg-eth0 +echo 'Post set up finished' > /dev/ttyS0 +echo Post set up finished > /dev/hvc0 %end diff --git a/shared/unattended/Fedora-13.ks b/shared/unattended/Fedora-13.ks index d5a1523c7..5a90ae65a 100644 --- a/shared/unattended/Fedora-13.ks +++ b/shared/unattended/Fedora-13.ks @@ -24,13 +24,14 @@ autopart ntpdate %end -%post --interpreter /usr/bin/python -import os -os.system('grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel)') -os.system('dhclient') -os.system('chkconfig sshd on') -os.system('iptables -F') -os.system('echo 0 > /selinux/enforce') -os.system('echo Post set up finished > /dev/ttyS0') -os.system('echo Post set up finished > /dev/hvc0') +%post +echo "OS install is completed" > /dev/ttyS0 +grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel) +dhclient +chkconfig sshd on +iptables -F +echo 0 > /selinux/enforce +sed -i "/^HWADDR/d" /etc/sysconfig/network-scripts/ifcfg-eth0 +echo 'Post set up finished' > /dev/ttyS0 +echo Post set up finished > /dev/hvc0 %end diff --git a/shared/unattended/Fedora-14.ks b/shared/unattended/Fedora-14.ks index f684d7ab5..9afbdf55f 100644 --- a/shared/unattended/Fedora-14.ks +++ b/shared/unattended/Fedora-14.ks @@ -25,13 +25,14 @@ ntpdate dmidecode %end -%post --interpreter /usr/bin/python -import os -os.system('grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel)') -os.system('dhclient') -os.system('chkconfig sshd on') -os.system('iptables -F') -os.system('echo 0 > /selinux/enforce') -os.system('echo Post set up finished > /dev/ttyS0') -os.system('echo Post set up finished > /dev/hvc0') +%post +echo "OS install is completed" > /dev/ttyS0 +grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel) +dhclient +chkconfig sshd on +iptables -F +echo 0 > /selinux/enforce +sed -i "/^HWADDR/d" /etc/sysconfig/network-scripts/ifcfg-eth0 +echo 'Post set up finished' > /dev/ttyS0 +echo Post set up finished > /dev/hvc0 %end diff --git a/shared/unattended/Fedora-15.ks b/shared/unattended/Fedora-15.ks index f8ff7f475..4ea002dcb 100644 --- a/shared/unattended/Fedora-15.ks +++ b/shared/unattended/Fedora-15.ks @@ -26,13 +26,14 @@ ntpdate dmidecode %end -%post --interpreter /usr/bin/python -import os -os.system('grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel)') -os.system('dhclient') -os.system('chkconfig sshd on') -os.system('iptables -F') -os.system('echo 0 > /selinux/enforce') -os.system('echo Post set up finished > /dev/ttyS0') -os.system('echo Post set up finished > /dev/hvc0') +%post +echo "OS install is completed" > /dev/ttyS0 +grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel) +dhclient +chkconfig sshd on +iptables -F +echo 0 > /selinux/enforce +sed -i "/^HWADDR/d" /etc/sysconfig/network-scripts/ifcfg-eth0 +echo 'Post set up finished' > /dev/ttyS0 +echo Post set up finished > /dev/hvc0 %end diff --git a/shared/unattended/Fedora-16.ks b/shared/unattended/Fedora-16.ks index 8b9ca73bc..9f7ba0ca7 100644 --- a/shared/unattended/Fedora-16.ks +++ b/shared/unattended/Fedora-16.ks @@ -24,13 +24,14 @@ autopart @development-tools %end -%post --interpreter /usr/bin/python -import os -os.system('grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel)') -os.system('dhclient') -os.system('chkconfig sshd on') -os.system('iptables -F') -os.system('echo 0 > /selinux/enforce') -os.system('echo Post set up finished > /dev/ttyS0') -os.system('echo Post set up finished > /dev/hvc0') +%post +echo "OS install is completed" > /dev/ttyS0 +grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel) +dhclient +chkconfig sshd on +iptables -F +echo 0 > /selinux/enforce +sed -i "/^HWADDR/d" /etc/sysconfig/network-scripts/ifcfg-eth0 +echo 'Post set up finished' > /dev/ttyS0 +echo Post set up finished > /dev/hvc0 %end diff --git a/shared/unattended/Fedora-17.ks b/shared/unattended/Fedora-17.ks index f98a3a7f7..c0a612cc3 100644 --- a/shared/unattended/Fedora-17.ks +++ b/shared/unattended/Fedora-17.ks @@ -25,13 +25,14 @@ autopart dmidecode %end -%post --interpreter /usr/bin/python -import os -os.system('grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel)') -os.system('dhclient') -os.system('chkconfig sshd on') -os.system('iptables -F') -os.system('echo 0 > /selinux/enforce') -os.system('echo Post set up finished > /dev/ttyS0') -os.system('echo Post set up finished > /dev/hvc0') +%post +echo "OS install is completed" > /dev/ttyS0 +grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel) +dhclient +chkconfig sshd on +iptables -F +echo 0 > /selinux/enforce +sed -i "/^HWADDR/d" /etc/sysconfig/network-scripts/ifcfg-eth0 +echo 'Post set up finished' > /dev/ttyS0 +echo Post set up finished > /dev/hvc0 %end diff --git a/shared/unattended/Fedora-18.ks b/shared/unattended/Fedora-18.ks index 4d1f93b06..093f278b6 100644 --- a/shared/unattended/Fedora-18.ks +++ b/shared/unattended/Fedora-18.ks @@ -25,15 +25,15 @@ autopart dmidecode %end -%post --interpreter /usr/bin/python -import os -os.system('grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel)') -os.system('dhclient') -os.system('chkconfig sshd on') -os.system('iptables -F') -os.system('systemctl mask tmp.mount') - -os.system('echo 0 > /selinux/enforce') -os.system('echo Post set up finished > /dev/ttyS0') -os.system('echo Post set up finished > /dev/hvc0') +%post +echo "OS install is completed" > /dev/ttyS0 +grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel) +dhclient +chkconfig sshd on +iptables -F +systemctl mask tmp.mount +echo 0 > /selinux/enforce +sed -i "/^HWADDR/d" /etc/sysconfig/network-scripts/ifcfg-eth0 +echo 'Post set up finished' > /dev/ttyS0 +echo Post set up finished > /dev/hvc0 %end diff --git a/shared/unattended/Fedora-19.ks b/shared/unattended/Fedora-19.ks new file mode 100644 index 000000000..56f00e733 --- /dev/null +++ b/shared/unattended/Fedora-19.ks @@ -0,0 +1,38 @@ +install +KVM_TEST_MEDIUM +text +reboot +lang en_US +keyboard us +network --bootproto dhcp --hostname atest-guest +rootpw 123456 +firewall --enabled --ssh +selinux --enforcing +timezone --utc America/New_York +firstboot --disable +bootloader --location=mbr --append="console=tty0 console=ttyS0,115200" +zerombr +poweroff +KVM_TEST_LOGGING + +clearpart --all --initlabel +autopart + +%packages +@standard +@development-tools +dmidecode +%end + +%post +echo "OS install is completed" > /dev/ttyS0 +grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel) +dhclient +chkconfig sshd on +iptables -F +systemctl mask tmp.mount +echo 0 > /selinux/enforce +sed -i "/^HWADDR/d" /etc/sysconfig/network-scripts/ifcfg-eth0 +echo 'Post set up finished' > /dev/ttyS0 +echo Post set up finished > /dev/hvc0 +%end diff --git a/shared/unattended/Fedora-8.ks b/shared/unattended/Fedora-8.ks index 0ed5fc53e..09d82b2b8 100644 --- a/shared/unattended/Fedora-8.ks +++ b/shared/unattended/Fedora-8.ks @@ -23,12 +23,13 @@ reboot @development-tools ntpdate -%post --interpreter /usr/bin/python -import os -os.system('grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel)') -os.system('dhclient') -os.system('chkconfig sshd on') -os.system('iptables -F') -os.system('echo 0 > /selinux/enforce') -os.system('echo Post set up finished > /dev/ttyS0') -os.system('echo Post set up finished > /dev/hvc0') +%post +echo "OS install is completed" > /dev/ttyS0 +grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel) +dhclient +chkconfig sshd on +iptables -F +echo 0 > /selinux/enforce +sed -i "/^HWADDR/d" /etc/sysconfig/network-scripts/ifcfg-eth0 +echo 'Post set up finished' > /dev/ttyS0 +echo Post set up finished > /dev/hvc0 diff --git a/shared/unattended/Fedora-9.ks b/shared/unattended/Fedora-9.ks index 2cabb9445..5a5ae0640 100644 --- a/shared/unattended/Fedora-9.ks +++ b/shared/unattended/Fedora-9.ks @@ -24,12 +24,13 @@ poweroff @development-tools ntpdate -%post --interpreter /usr/bin/python -import os -os.system('grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel)') -os.system('dhclient') -os.system('chkconfig sshd on') -os.system('iptables -F') -os.system('echo 0 > /selinux/enforce') -os.system('echo Post set up finished > /dev/ttyS0') -os.system('echo Post set up finished > /dev/hvc0') +%post +echo "OS install is completed" > /dev/ttyS0 +grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel) +dhclient +chkconfig sshd on +iptables -F +echo 0 > /selinux/enforce +sed -i "/^HWADDR/d" /etc/sysconfig/network-scripts/ifcfg-eth0 +echo 'Post set up finished' > /dev/ttyS0 +echo Post set up finished > /dev/hvc0 diff --git a/shared/unattended/Fedora-test.ks b/shared/unattended/Fedora-test.ks index 8bf1426fa..aca885c70 100644 --- a/shared/unattended/Fedora-test.ks +++ b/shared/unattended/Fedora-test.ks @@ -23,15 +23,17 @@ autopart @development-libs @development-tools dmidecode +sg3_utils %end -%post --interpreter /usr/bin/python -import os -os.system('grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel)') -os.system('dhclient') -os.system('chkconfig sshd on') -os.system('iptables -F') -os.system('echo 0 > /selinux/enforce') -os.system('echo Post set up finished > /dev/ttyS0') -os.system('echo Post set up finished > /dev/hvc0') +%post +echo "OS install is completed" > /dev/ttyS0 +grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel) +dhclient +chkconfig sshd on +iptables -F +echo 0 > /selinux/enforce +sed -i "/^HWADDR/d" /etc/sysconfig/network-scripts/ifcfg-eth0 +echo 'Post set up finished' > /dev/ttyS0 +echo Post set up finished > /dev/hvc0 %end diff --git a/shared/unattended/JeOS-17.ks b/shared/unattended/JeOS-17.ks index 6c257766d..27aad8340 100644 --- a/shared/unattended/JeOS-17.ks +++ b/shared/unattended/JeOS-17.ks @@ -168,37 +168,38 @@ usbutils -rsyslog %end -%post --interpreter /usr/bin/python -import os -os.system('grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel)') -os.system('echo 0 > /selinux/enforce') -os.system('systemctl enable sshd.service') -os.system('systemctl mask fedora-wait-storage.service') -os.system('systemctl mask fedora-storage-init-late.service') -os.system('systemctl mask fedora-storage-init.service') -os.system('systemctl mask fedora-autoswap.service') -os.system('systemctl mask fedora-configure.service') -os.system('systemctl mask fedora-loadmodules.service') -os.system('systemctl mask fedora-readonly.service') -os.system('systemctl mask systemd-readahead-collect.service') -os.system('systemctl mask plymouth-start.service') -os.system('systemctl mask network.service') -os.system('systemctl mask remote-fs.target') -os.system('systemctl mask cryptsetup.target') -os.system('systemctl mask sys-devices-virtual-tty-tty2.device') -os.system('systemctl mask sys-devices-virtual-tty-tty3.device') -os.system('systemctl mask sys-devices-virtual-tty-tty4.device') -os.system('systemctl mask sys-devices-virtual-tty-tty5.device') -os.system('systemctl mask sys-devices-virtual-tty-tty6.device') -os.system('systemctl mask sys-devices-virtual-tty-tty7.device') -os.system('systemctl mask sys-devices-virtual-tty-tty8.device') -os.system('systemctl mask sys-devices-virtual-tty-tty9.device') -os.system('systemctl mask sys-devices-virtual-tty-tty10.device') -os.system('systemctl mask sys-devices-virtual-tty-tty11.device') -os.system('systemctl mask sys-devices-virtual-tty-tty12.device') -os.system('yum install -y hdparm ntpdate') -os.system('yum clean all') -os.system('mkdir -p /var/log/journal') -os.system('echo Post set up finished > /dev/ttyS0') -os.system('echo Post set up finished > /dev/hvc0') +%post +echo "OS install is completed" > /dev/ttyS0 +grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel) +echo 0 > /selinux/enforce +sed -i "/^HWADDR/d" /etc/sysconfig/network-scripts/ifcfg-eth0 +systemctl enable sshd.service +systemctl mask fedora-wait-storage.service +systemctl mask fedora-storage-init-late.service +systemctl mask fedora-storage-init.service +systemctl mask fedora-autoswap.service +systemctl mask fedora-configure.service +systemctl mask fedora-loadmodules.service +systemctl mask fedora-readonly.service +systemctl mask systemd-readahead-collect.service +systemctl mask plymouth-start.service +systemctl mask network.service +systemctl mask remote-fs.target +systemctl mask cryptsetup.target +systemctl mask sys-devices-virtual-tty-tty2.device +systemctl mask sys-devices-virtual-tty-tty3.device +systemctl mask sys-devices-virtual-tty-tty4.device +systemctl mask sys-devices-virtual-tty-tty5.device +systemctl mask sys-devices-virtual-tty-tty6.device +systemctl mask sys-devices-virtual-tty-tty7.device +systemctl mask sys-devices-virtual-tty-tty8.device +systemctl mask sys-devices-virtual-tty-tty9.device +systemctl mask sys-devices-virtual-tty-tty10.device +systemctl mask sys-devices-virtual-tty-tty11.device +systemctl mask sys-devices-virtual-tty-tty12.device +yum install -y hdparm ntpdate +yum clean all +mkdir -p /var/log/journal +echo 'Post set up finished' > /dev/ttyS0 +echo Post set up finished > /dev/hvc0 %end diff --git a/shared/unattended/OpenSUSE-11.xml b/shared/unattended/OpenSUSE-11.xml index 0f11ac9ce..a67aed6bd 100644 --- a/shared/unattended/OpenSUSE-11.xml +++ b/shared/unattended/OpenSUSE-11.xml @@ -181,6 +181,7 @@ service sshd restart autoyast2-installation dhcp-client dhcp-tools + sg3_utils autoyast2-installation autoyast2-installation autoyast2-installation diff --git a/shared/unattended/OpenSUSE-12.xml b/shared/unattended/OpenSUSE-12.xml index 089c70b21..12721e76b 100644 --- a/shared/unattended/OpenSUSE-12.xml +++ b/shared/unattended/OpenSUSE-12.xml @@ -189,6 +189,7 @@ service sshd restart autoyast2-installation dhcp-client dhcp-tools + sg3_utils autoyast2-installation autoyast2-installation autoyast2-installation diff --git a/shared/unattended/RHEL-3-series.ks b/shared/unattended/RHEL-3-series.ks index 89903b57c..bc7721aa7 100644 --- a/shared/unattended/RHEL-3-series.ks +++ b/shared/unattended/RHEL-3-series.ks @@ -1,7 +1,6 @@ install KVM_TEST_MEDIUM text -reboot lang en_US.UTF-8 langsupport --default=en_US.UTF-8 en_US.UTF-9 keyboard us @@ -21,12 +20,21 @@ skipx @ base @ development-libs @ development-tools +gcc +patch +make +nc ntp +redhat-lsb -%post --interpreter /usr/bin/python -import os -os.system('/sbin/ifconfig eth0 10.0.2.15 netmask 255.255.255.0 up') -os.system('/sbin/route add default gw 10.0.2.2') -os.system('chkconfig sshd on') -os.system('echo Post set up finished > /dev/ttyS0') -os.system('echo Post set up finished > /dev/hvc0') +%post +echo "OS install is completed" > /dev/ttyS0 +cd home +echo "s0:2345:respawn:/sbin/agetty -L -f /etc/issue 115200 ttyS0 vt100" >> /etc/inittab +echo "ttyS0" >> /etc/securetty +dhclient +chkconfig sshd on +sed -i "/^HWADDR/d" /etc/sysconfig/network-scripts/ifcfg-eth0 +echo 'Post set up finished' > /dev/ttyS0 +echo Post set up finished > /dev/hvc0 +%end diff --git a/shared/unattended/RHEL-4-series.ks b/shared/unattended/RHEL-4-series.ks index 03890ea23..e3e69c05a 100644 --- a/shared/unattended/RHEL-4-series.ks +++ b/shared/unattended/RHEL-4-series.ks @@ -1,7 +1,6 @@ install KVM_TEST_MEDIUM text -reboot lang en_US.UTF-8 langsupport --default=en_US.UTF-8 en_US.UTF-9 keyboard us @@ -19,15 +18,36 @@ poweroff %packages @ base -@ development-libs -@ development-tools +@development-libs +@development-tools +gcc4 +gcc4-gfortran +patch +make +nc ntp +redhat-lsb -%post --interpreter /usr/bin/python -import os -os.system('dhclient') -os.system('chkconfig sshd on') -os.system('iptables -F') -os.system('echo 0 > /selinux/enforce') -os.system('echo Post set up finished > /dev/ttyS0') -os.system('echo Post set up finished > /dev/hvc0') +%post +echo "OS install is completed" > /dev/ttyS0 +grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel) +grubby --args="divider=10" --update-kernel=$(grubby --default-kernel) +cd home +dhclient +chkconfig sshd on +iptables -F +echo 0 > selinux/enforce +sed -i '/^HWADDR/d' /etc/sysconfig/network-scripts/ifcfg-eth0 +echo "s0:2345:respawn:/sbin/agetty -L -f /etc/issue 115200 ttyS0 vt100" >> /etc/inittab +echo "ttyS0" >> /etc/securetty +wget http://www.python.org/ftp/python/2.6.6/Python-2.6.6.tar.bz2 +tar xjf Python-2.6.6.tar.bz2 +cd Python-2.6.6 +./configure --prefix=/usr/local --exec-prefix=/usr/local +make +make install +ln -sf /usr/local/bin/python /usr/bin/python +sleep 10 +echo 'Post set up finished' > /dev/ttyS0 +echo Post set up finished > /dev/hvc0 +%end diff --git a/shared/unattended/RHEL-5-series.ks b/shared/unattended/RHEL-5-series.ks index 8edb03990..0ff6613cc 100644 --- a/shared/unattended/RHEL-5-series.ks +++ b/shared/unattended/RHEL-5-series.ks @@ -13,8 +13,14 @@ timezone --utc America/New_York firstboot --disable bootloader --location=mbr --append="console=tty0 console=ttyS0,115200" zerombr +xconfig --startxonboot +#partitioning clearpart --all --initlabel -autopart +part /boot --fstype=ext3 --size=500 +part pv.01 --grow --size=1 +volgroup VolGroup --pesize=131072 pv.01 +logvol swap --name=LogVol_swap --vgname=VolGroup --size=4096 +logvol / --fstype=ext4 --name=LogVol_root --vgname=VolGroup --size=1 --grow poweroff KVM_TEST_LOGGING @@ -22,15 +28,33 @@ KVM_TEST_LOGGING @base @development-libs @development-tools +@gnome-desktop +@base-x +@core +xorg-x11-utils +xorg-x11-server-Xnest kexec-tools watchdog +gcc +patch +make +nc ntp +redhat-lsb +sg3_utils +lsscsi +libaio-devel +perl-Time-HiRes -%post --interpreter /usr/bin/python -import os -os.system('dhclient') -os.system('chkconfig sshd on') -os.system('iptables -F') -os.system('echo 0 > /selinux/enforce') -os.system('echo Post set up finished > /dev/ttyS0') -os.system('echo Post set up finished > /dev/hvc0') +%post +echo "OS install is completed" > /dev/ttyS0 +grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel) +grubby --args="divider=10 crashkernel=128M@16M" --update-kernel=$(grubby --default-kernel) +dhclient +chkconfig sshd on +iptables -F +echo 0 > /selinux/enforce +sed -i "/^HWADDR/d" /etc/sysconfig/network-scripts/ifcfg-eth0 +echo 'Post set up finished' > /dev/ttyS0 +echo Post set up finished > /dev/hvc0 +%end diff --git a/shared/unattended/RHEL-6-series.ks b/shared/unattended/RHEL-6-series.ks index 9d7fe5bef..19bd48b13 100644 --- a/shared/unattended/RHEL-6-series.ks +++ b/shared/unattended/RHEL-6-series.ks @@ -1,7 +1,6 @@ install KVM_TEST_MEDIUM text -reboot lang en_US.UTF-8 keyboard us key --skip @@ -13,30 +12,59 @@ timezone --utc America/New_York firstboot --disable bootloader --location=mbr --append="console=tty0 console=ttyS0,115200" zerombr +xconfig --startxonboot +#partitioning clearpart --all --initlabel -autopart +part /boot --fstype=ext4 --size=500 +part pv.01 --grow --size=1 +volgroup VolGroup --pesize=131072 pv.01 +logvol swap --name=LogVol_swap --vgname=VolGroup --size=4096 +logvol / --fstype=ext4 --name=LogVol_root --vgname=VolGroup --size=1 --grow poweroff KVM_TEST_LOGGING -%packages +%packages --ignoremissing @base @core @development @additional-devel @debugging-tools @network-tools +@basic-desktop +@desktop-platform +@fonts +@general-desktop +@graphical-admin-tools +@x11 +lftp +gcc +gcc-c++ +patch +make +git +nc NetworkManager ntpdate +redhat-lsb watchdog coreutils usbutils +qemu-guest-agent +sg3_utils +xfsprogs +lsscsi +libaio-devel +perl-Time-HiRes -%post --interpreter /usr/bin/python -import os -os.system('grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel)') -os.system('dhclient') -os.system('chkconfig sshd on') -os.system('iptables -F') -os.system('echo 0 > /selinux/enforce') -os.system('echo Post set up finished > /dev/ttyS0') -os.system('echo Post set up finished > /dev/hvc0') +%post +echo "OS install is completed" > /dev/ttyS0 +grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel) +dhclient +chkconfig sshd on +iptables -F +echo 0 > /selinux/enforce +chkconfig NetworkManager on +sed -i "/^HWADDR/d" /etc/sysconfig/network-scripts/ifcfg-eth0 +echo 'Post set up finished' > /dev/ttyS0 +echo Post set up finished > /dev/hvc0 +%end diff --git a/shared/unattended/RHEL-6.3.ks b/shared/unattended/RHEL-6.3.ks index 576f27cf9..649250fa0 100644 --- a/shared/unattended/RHEL-6.3.ks +++ b/shared/unattended/RHEL-6.3.ks @@ -29,6 +29,8 @@ KVM_TEST_LOGGING @network-tools @x11 @basic-desktop +@fonts +@Smart Card Support NetworkManager ntpdate watchdog @@ -39,19 +41,36 @@ virt-viewer spice-vdagent usbredir SDL +totem %end -%post --nochroot --interpreter /usr/bin/python -import os -os.system('grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel)') -os.system('dhclient') -os.system('chkconfig sshd on') -os.system('iptables -F') -os.system('echo 0 > /selinux/enforce') -os.system('echo Post set up finished > /dev/ttyS0') -os.system('echo Post set up finished > /dev/hvc0') -f = open('/mnt/sysimage/etc/gdm/custom.conf','w') -f.write('[daemon]\n' - 'AutomaticLogin=test\n' - 'AutomaticLoginEnable=True\n') +%post +echo "OS install is completed" > /dev/ttyS0 +grubby --remove-args="rhgb quiet" --update-kernel=$(grubby --default-kernel) +dhclient +chkconfig sshd on +iptables -F +echo 0 > /selinux/enforce +chkconfig NetworkManager on +sed -i "/^HWADDR/d" /etc/sysconfig/network-scripts/ifcfg-eth0 +echo 'Post set up finished' > /dev/ttyS0 +echo Post set up finished > /dev/hvc0 +cat > '/etc/gdm/custom.conf' << EOF +[daemon] +AutomaticLogin=test +AutomaticLoginEnable=True +EOF +cat >> '/etc/sudoers' << EOF +test ALL = NOPASSWD: /sbin/shutdown -r now,/sbin/shutdown -h now +EOF +cat >> '/home/test/.bashrc' << EOF +alias shutdown='sudo shutdown' +EOF +cat >> '/etc/rc.modules' << EOF +modprobe snd-aloop +modprobe snd-pcm-oss +modprobe snd-mixer-oss +modprobe snd-seq-oss +EOF +chmod +x /etc/rc.modules %end diff --git a/shared/unattended/SLES-10.xml b/shared/unattended/SLES-10.xml index cb334b476..8a704c62e 100644 --- a/shared/unattended/SLES-10.xml +++ b/shared/unattended/SLES-10.xml @@ -552,6 +552,10 @@ service network restart dhcp-client + sg3_utils + lsscsi + libaio-devel + perl-Time-HiRes Basis-Devel diff --git a/shared/unattended/SLES-11-SP2.xml b/shared/unattended/SLES-11-SP2.xml index dbd4fc4ab..ffbaae6fc 100644 --- a/shared/unattended/SLES-11-SP2.xml +++ b/shared/unattended/SLES-11-SP2.xml @@ -552,6 +552,10 @@ service sshd restart dhcp-client open-iscsi + sg3_utils + lsscsi + libaio-devel + perl-Time-HiRes Basis-Devel diff --git a/shared/unattended/SLES-11.xml b/shared/unattended/SLES-11.xml index 1af65864d..0f4dbb739 100644 --- a/shared/unattended/SLES-11.xml +++ b/shared/unattended/SLES-11.xml @@ -581,6 +581,10 @@ ycpc -c Packages.ycp dhcp-client patch + sg3_utils + lsscsi + libaio-devel + perl-Time-HiRes Basis-Devel diff --git a/shared/unattended/Ubuntu-11-04.preseed b/shared/unattended/Ubuntu-11-04.preseed index c7ececca4..7b153f7fb 100644 --- a/shared/unattended/Ubuntu-11-04.preseed +++ b/shared/unattended/Ubuntu-11-04.preseed @@ -30,7 +30,7 @@ d-i mirror/udeb/components multiselect main, restricted, universe, multiverse tasksel tasksel/first multiselect standard -d-i pkgsel/include string openssh-server build-essential lvm2 ethtool +d-i pkgsel/include string openssh-server build-essential lvm2 ethtool sg3-utils lsscsi libaio-dev libtime-hires-perl d-i grub-installer/only_debian boolean true d-i grub-installer/with_other_os boolean true diff --git a/shared/unattended/Ubuntu-11-10.preseed b/shared/unattended/Ubuntu-11-10.preseed index c7ececca4..7b153f7fb 100644 --- a/shared/unattended/Ubuntu-11-10.preseed +++ b/shared/unattended/Ubuntu-11-10.preseed @@ -30,7 +30,7 @@ d-i mirror/udeb/components multiselect main, restricted, universe, multiverse tasksel tasksel/first multiselect standard -d-i pkgsel/include string openssh-server build-essential lvm2 ethtool +d-i pkgsel/include string openssh-server build-essential lvm2 ethtool sg3-utils lsscsi libaio-dev libtime-hires-perl d-i grub-installer/only_debian boolean true d-i grub-installer/with_other_os boolean true diff --git a/shared/unattended/Ubuntu-12-04.preseed b/shared/unattended/Ubuntu-12-04.preseed index c7ececca4..7b153f7fb 100644 --- a/shared/unattended/Ubuntu-12-04.preseed +++ b/shared/unattended/Ubuntu-12-04.preseed @@ -30,7 +30,7 @@ d-i mirror/udeb/components multiselect main, restricted, universe, multiverse tasksel tasksel/first multiselect standard -d-i pkgsel/include string openssh-server build-essential lvm2 ethtool +d-i pkgsel/include string openssh-server build-essential lvm2 ethtool sg3-utils lsscsi libaio-dev libtime-hires-perl d-i grub-installer/only_debian boolean true d-i grub-installer/with_other_os boolean true diff --git a/shared/unattended/Ubuntu-12-10.preseed b/shared/unattended/Ubuntu-12-10.preseed index 8cb534f02..f0d78414c 100644 --- a/shared/unattended/Ubuntu-12-10.preseed +++ b/shared/unattended/Ubuntu-12-10.preseed @@ -30,7 +30,7 @@ d-i mirror/udeb/components multiselect main, restricted, universe, multiverse tasksel tasksel/first multiselect standard -d-i pkgsel/include string openssh-server build-essential lvm2 ethtool +d-i pkgsel/include string openssh-server build-essential lvm2 ethtool sg3-utils lsscsi libaio-dev libtime-hires-perl d-i grub-installer/only_debian boolean true d-i grub-installer/with_other_os boolean true diff --git a/shared/unattended/Ubuntu-13-04.preseed b/shared/unattended/Ubuntu-13-04.preseed index 8cb534f02..f0d78414c 100644 --- a/shared/unattended/Ubuntu-13-04.preseed +++ b/shared/unattended/Ubuntu-13-04.preseed @@ -30,7 +30,7 @@ d-i mirror/udeb/components multiselect main, restricted, universe, multiverse tasksel tasksel/first multiselect standard -d-i pkgsel/include string openssh-server build-essential lvm2 ethtool +d-i pkgsel/include string openssh-server build-essential lvm2 ethtool sg3-utils lsscsi libaio-dev libtime-hires-perl d-i grub-installer/only_debian boolean true d-i grub-installer/with_other_os boolean true diff --git a/shared/unattended/win2003-32.sif b/shared/unattended/win2003-32.sif index 5d06d219b..c19e3228f 100644 --- a/shared/unattended/win2003-32.sif +++ b/shared/unattended/win2003-32.sif @@ -10,7 +10,7 @@ OemPreinstall = No UnattendSwitch = Yes CrashDumpSetting = 1 DriverSigningPolicy = ignore -OemPnPDriversPath = KVM_TEST_NETWORK_DRIVER_PATH +OemPnPDriversPath="KVM_TEST_NETWORK_DRIVER_PATH" WaitForReboot = no Repartition = yes @@ -23,20 +23,20 @@ TimeZone = 85 OemSkipWelcome = 1 [UserData] -ProductKey = KVM_TEST_CDKEY -FullName = "Autotest Mindless Drone" -OrgName = "Autotest" -ComputerName = * +ProductKey=KVM_TEST_CDKEY +FullName="Autotest Mindless Drone" +OrgName="Autotest" +ComputerName=* [LicenseFilePrintData] -AutoMode = PerServer -AutoUsers = 15 +AutoMode=PerServer +AutoUsers=15 [Identification] -JoinWorkgroup = WORKGROUP +JoinWorkgroup=WORKGROUP [Networking] -InstallDefaultComponents = Yes +InstallDefaultComponents=Yes [Components] @@ -50,17 +50,23 @@ Profiles = WindowsFirewall.TurnOffFirewall Mode = 0 [SetupParams] -local = "Local Area Connection" +local="Local Area Connection" [Display] -Xresolution = 1024 -YResolution = 768 +Xresolution=1024 +YResolution=768 [GuiRunOnce] -Command0 = "cmd /c KVM_TEST_VIRTIO_NETWORK_INSTALLER" -Command1 = "cmd /c sc config TlntSvr start= auto" -Command2 = "cmd /c netsh firewall set opmode disable" -Command3 = "cmd /c net start telnet" -Command4 = "cmd /c E:\setuprss.bat" -Command5 = "cmd /c netsh interface ip set address local dhcp" -Command6 = "cmd /c A:\finish.bat PROCESS_CHECK" +Command0="cmd /c echo OS install is completed > COM1" +Command1="cmd /c KVM_TEST_VIRTIO_NETWORK_INSTALLER" +Command2="cmd /c sc config TlntSvr start= auto" +Command3="cmd /c netsh firewall set opmode disable" +Command4="cmd /c net start telnet" +Command5="cmd /c E:\autoit3.exe E:\git\git.au3" +Command6="cmd /c E:\cfg\use_pmtmr.bat" +Command7="cmd /c netsh interface ip set address local dhcp" +Command8="cmd /c E:\setuprss.bat" +Command9="cmd /c start /wait E:\dotnetfx35.exe /lang:ENU /norestart /passive" +Command10="cmd /c E:\setupsp.bat" +Command11="cmd /c E:\software_install_32.bat" +Command12="cmd /c A:\finish.bat PROCESS_CHECK" diff --git a/shared/unattended/win2003-64.sif b/shared/unattended/win2003-64.sif index 5d06d219b..d64ab2168 100644 --- a/shared/unattended/win2003-64.sif +++ b/shared/unattended/win2003-64.sif @@ -10,7 +10,7 @@ OemPreinstall = No UnattendSwitch = Yes CrashDumpSetting = 1 DriverSigningPolicy = ignore -OemPnPDriversPath = KVM_TEST_NETWORK_DRIVER_PATH +OemPnPDriversPath="KVM_TEST_NETWORK_DRIVER_PATH" WaitForReboot = no Repartition = yes @@ -23,20 +23,20 @@ TimeZone = 85 OemSkipWelcome = 1 [UserData] -ProductKey = KVM_TEST_CDKEY -FullName = "Autotest Mindless Drone" -OrgName = "Autotest" -ComputerName = * +ProductKey=KVM_TEST_CDKEY +FullName="Autotest Mindless Drone" +OrgName="Autotest" +ComputerName=* [LicenseFilePrintData] -AutoMode = PerServer -AutoUsers = 15 +AutoMode=PerServer +AutoUsers=15 [Identification] -JoinWorkgroup = WORKGROUP +JoinWorkgroup=WORKGROUP [Networking] -InstallDefaultComponents = Yes +InstallDefaultComponents=Yes [Components] @@ -50,17 +50,22 @@ Profiles = WindowsFirewall.TurnOffFirewall Mode = 0 [SetupParams] -local = "Local Area Connection" +local="Local Area Connection" [Display] -Xresolution = 1024 -YResolution = 768 +Xresolution=1024 +YResolution=768 [GuiRunOnce] -Command0 = "cmd /c KVM_TEST_VIRTIO_NETWORK_INSTALLER" -Command1 = "cmd /c sc config TlntSvr start= auto" -Command2 = "cmd /c netsh firewall set opmode disable" -Command3 = "cmd /c net start telnet" -Command4 = "cmd /c E:\setuprss.bat" -Command5 = "cmd /c netsh interface ip set address local dhcp" -Command6 = "cmd /c A:\finish.bat PROCESS_CHECK" +Command0="cmd /c echo OS install is completed > COM1" +Command1="cmd /c KVM_TEST_VIRTIO_NETWORK_INSTALLER" +Command2="cmd /c sc config TlntSvr start= auto" +Command3="cmd /c netsh firewall set opmode disable" +Command4="cmd /c net start telnet" +Command5="cmd /c E:\autoit3.exe E:\git\git.au3" +Command6="cmd /c netsh interface ip set address local dhcp" +Command7="cmd /c E:\setuprss.bat" +Command8="cmd /c start /wait E:\dotnetfx35.exe /lang:ENU /norestart /passive" +Command9="cmd /c E:\setupsp.bat" +Command10="cmd /c E:\software_install_64.bat" +Command11="cmd /c A:\finish.bat PROCESS_CHECK" diff --git a/shared/unattended/win2008-32-autounattend.xml b/shared/unattended/win2008-32-autounattend.xml index fcf8766d6..2a943bb3d 100644 --- a/shared/unattended/win2008-32-autounattend.xml +++ b/shared/unattended/win2008-32-autounattend.xml @@ -39,7 +39,7 @@ 1 - 20000 + 30000 Primary @@ -64,7 +64,8 @@ /IMAGE/INDEX - 1 + + 3 @@ -149,11 +150,11 @@ 5 - %WINDIR%\System32\cmd /c bcdedit /set {current} bootstatuspolicy ignoreallfailures - 6 + %WINDIR%\System32\cmd /c E:\autoit3.exe E:\git\git.au3 + 6 - %WINDIR%\System32\cmd /c E:\setuprss.bat + %WINDIR%\System32\cmd /c bcdedit /set {current} bootstatuspolicy ignoreallfailures 7 @@ -161,9 +162,29 @@ 8 - %WINDIR%\System32\cmd /c A:\finish.bat PROCESS_CHECK + %WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_BALLOON_INSTALLER 9 + + %WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_QXL_INSTALLER + 10 + + + %WINDIR%\System32\cmd /c E:\setuprss.bat + 11 + + + %WINDIR%\System32\cmd /c E:\setupsp.bat + 12 + + + %WINDIR%\System32\cmd /c E:\software_install_32.bat + 13 + + + %WINDIR%\System32\cmd /c A:\finish.bat PROCESS_CHECK + 14 + 1 diff --git a/shared/unattended/win2008-64-autounattend.xml b/shared/unattended/win2008-64-autounattend.xml index f6af85d31..a4f06a556 100644 --- a/shared/unattended/win2008-64-autounattend.xml +++ b/shared/unattended/win2008-64-autounattend.xml @@ -12,7 +12,7 @@ 1 - 20000 + 30000 Primary @@ -36,7 +36,8 @@ /IMAGE/INDEX - 1 + + 3 @@ -138,41 +139,65 @@ - %WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_NETWORK_INSTALLER" + %WINDIR%\System32\cmd /c echo OS install is completed > COM1 1 - %WINDIR%\System32\cmd /c start /w pkgmgr /iu:"TelnetServer" + %WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_NETWORK_INSTALLER 2 - %WINDIR%\System32\cmd /c sc config TlntSvr start= auto + %WINDIR%\System32\cmd /c start /w pkgmgr /iu:"TelnetServer" 3 - %WINDIR%\System32\cmd /c netsh firewall set opmode disable + %WINDIR%\System32\cmd /c sc config TlntSvr start= auto 4 - %WINDIR%\System32\cmd /c net start telnet + %WINDIR%\System32\cmd /c netsh firewall set opmode disable 5 - %WINDIR%\System32\cmd /c bcdedit /set {current} bootstatuspolicy ignoreallfailures + %WINDIR%\System32\cmd /c net start telnet 6 - %WINDIR%\System32\cmd /c E:\setuprss.bat + %WINDIR%\System32\cmd /c bcdedit /set {current} bootstatuspolicy ignoreallfailures 7 - %WINDIR%\System32\cmd /c netsh interface ip set address "Local Area Connection" dhcp + %WINDIR%\System32\cmd /c E:\autoit3.exe E:\git\git.au3 8 - %WINDIR%\System32\cmd /c A:\finish.bat PROCESS_CHECK + %WINDIR%\System32\cmd /c netsh interface ip set address "Local Area Connection" dhcp 9 + + %WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_BALLOON_INSTALLER + 10 + + + %WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_QXL_INSTALLER + 11 + + + %WINDIR%\System32\cmd /c E:\setuprss.bat + 12 + + + %WINDIR%\System32\cmd /c E:\setupsp.bat + 13 + + + %WINDIR%\System32\cmd /c E:\software_install_64.bat + 14 + + + %WINDIR%\System32\cmd /c A:\finish.bat PROCESS_CHECK + 15 + true diff --git a/shared/unattended/win2008-r2-autounattend.xml b/shared/unattended/win2008-r2-autounattend.xml index f6af85d31..4fc3eef28 100644 --- a/shared/unattended/win2008-r2-autounattend.xml +++ b/shared/unattended/win2008-r2-autounattend.xml @@ -12,7 +12,7 @@ 1 - 20000 + 30000 Primary @@ -36,7 +36,8 @@ /IMAGE/INDEX - 1 + + 5 @@ -47,10 +48,6 @@ - - KVM_TEST_CDKEY - OnError - true Autotest Mindless Drone Autotest @@ -114,6 +111,13 @@ en-US en-US + + KVM_TEST_CDKEY + - %WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_NETWORK_INSTALLER" + %WINDIR%\System32\cmd /c echo OS install is completed > COM1 1 - %WINDIR%\System32\cmd /c start /w pkgmgr /iu:"TelnetServer" + %WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_NETWORK_INSTALLER" 2 - %WINDIR%\System32\cmd /c sc config TlntSvr start= auto + %WINDIR%\System32\cmd /c start /w pkgmgr /iu:"TelnetServer" 3 - %WINDIR%\System32\cmd /c netsh firewall set opmode disable + %WINDIR%\System32\cmd /c sc config TlntSvr start= auto 4 - %WINDIR%\System32\cmd /c net start telnet + %WINDIR%\System32\cmd /c netsh firewall set opmode disable 5 - %WINDIR%\System32\cmd /c bcdedit /set {current} bootstatuspolicy ignoreallfailures + %WINDIR%\System32\cmd /c net start telnet 6 - %WINDIR%\System32\cmd /c E:\setuprss.bat + %WINDIR%\System32\cmd /c bcdedit /set {current} bootstatuspolicy ignoreallfailures 7 - %WINDIR%\System32\cmd /c netsh interface ip set address "Local Area Connection" dhcp + %WINDIR%\System32\cmd /c E:\autoit3.exe E:\git\git.au3 8 - %WINDIR%\System32\cmd /c A:\finish.bat PROCESS_CHECK + %WINDIR%\System32\cmd /c bcdedit /set {current} USEPLATFORMCLOCK yes 9 + + %WINDIR%\System32\cmd /c netsh interface ip set address "Local Area Connection" dhcp + 10 + + + %WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_BALLOON_INSTALLER + 11 + + + %WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_QXL_INSTALLER + 12 + + + %WINDIR%\System32\cmd /c E:\setuprss.bat + 13 + + + %WINDIR%\System32\cmd /c E:\setupsp.bat + 14 + + + %WINDIR%\System32\cmd /c E:\software_install_64.bat + 15 + + + %WINDIR%\System32\cmd /c A:\finish.bat PROCESS_CHECK + 16 + true diff --git a/shared/unattended/win2012-autounattend.xml b/shared/unattended/win2012-autounattend.xml new file mode 100644 index 000000000..47e6b38db --- /dev/null +++ b/shared/unattended/win2012-autounattend.xml @@ -0,0 +1,213 @@ + + + + + + en-us + + 0409:00000409 + en-us + en-us + en-us + en-us + + + + + KVM_TEST_STORAGE_DRIVER_PATH + + + KVM_TEST_NETWORK_DRIVER_PATH + + + + + + OnError + + + + 1 + 30000 + Primary + + + + + true + false + NTFS + + C + 1 + 1 + + + 0 + true + + + + + + + /IMAGE/NAME + Windows Server 2012 SERVERDATACENTER + + + + 0 + 1 + + + + + + KVM_TEST_CDKEY + OnError + + true + + + + + + + + EnableAdmin + 1 + cmd /c net user Administrator /active:yes + + + UnfilterAdministratorToken + 2 + cmd /c reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v FilterAdministratorToken /t REG_DWORD /d 0 /f + + + + + 0409:00000409 + en-US + en-US + en-US + + + + + + + 1q2w3eP + true</PlainText> + </AdministratorPassword> + </UserAccounts> + <OOBE> + <HideEULAPage>true</HideEULAPage> + <NetworkLocation>Work</NetworkLocation> + <ProtectYourPC>1</ProtectYourPC> + <SkipUserOOBE>true</SkipUserOOBE> + <SkipMachineOOBE>true</SkipMachineOOBE> + </OOBE> + <AutoLogon> + <Password> + <Value>1q2w3eP</Value> + <PlainText>true</PlainText> + </Password> + <Enabled>true</Enabled> + <LogonCount>1000</LogonCount> + <Username>Administrator</Username> + </AutoLogon> + <FirstLogonCommands> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c echo OS install is completed > COM1</CommandLine> + <Order>1</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_NETWORK_INSTALLER</CommandLine> + <Order>2</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c start /w pkgmgr /iu:"TelnetServer"</CommandLine> + <Order>3</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c sc config TlntSvr start= auto</CommandLine> + <Order>4</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c netsh firewall set opmode disable</CommandLine> + <Order>5</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c net start telnet</CommandLine> + <Order>6</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c E:\autoit3.exe E:\git\git.au3</CommandLine> + <Order>7</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c bcdedit /set {current} USEPLATFORMCLOCK yes</CommandLine> + <Order>8</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c bcdedit /set {current} bootstatuspolicy ignoreallfailures</CommandLine> + <Order>9</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c netsh interface ip set address "Local Area Connection" dhcp</CommandLine> + <Order>10</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_BALLOON_INSTALLER</CommandLine> + <Order>11</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_QXL_INSTALLER</CommandLine> + <Order>12</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c E:\setuprss.bat</CommandLine> + <Order>13</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\Dism /online /enable-feature /featurename:NetFx3 /All /Source:D:\sources\sxs /LimitAccess</CommandLine> + <Order>14</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c E:\setupsp.bat</CommandLine> + <Order>15</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c A:\finish.bat PROCESS_CHECK</CommandLine> + <Order>16</Order> + </SynchronousCommand> + </FirstLogonCommands> + </component> + </settings> + <cpi:offlineImage cpi:source="wim:c:/install.wim#Windows Longhorn SERVERSTANDARD" + xmlns:cpi="urn:schemas-microsoft-com:cpi" /> +</unattend> diff --git a/shared/unattended/win7-32-autounattend.xml b/shared/unattended/win7-32-autounattend.xml index 878d1ce38..ae54717d6 100644 --- a/shared/unattended/win7-32-autounattend.xml +++ b/shared/unattended/win7-32-autounattend.xml @@ -40,7 +40,7 @@ <CreatePartitions> <CreatePartition wcm:action="add"> <Order>1</Order> - <Size>20000</Size> + <Size>30000</Size> <Type>Primary</Type> </CreatePartition> </CreatePartitions> @@ -136,41 +136,73 @@ </AutoLogon> <FirstLogonCommands> <SynchronousCommand wcm:action="add"> - <CommandLine>%WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_NETWORK_INSTALLER"</CommandLine> + <CommandLine>%WINDIR%\System32\cmd /c echo OS install is completed > COM1</CommandLine> <Order>1</Order> </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>%WINDIR%\System32\cmd /c start /w pkgmgr /iu:"TelnetServer"</CommandLine> + <CommandLine>%WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_NETWORK_INSTALLER</CommandLine> <Order>2</Order> </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>%WINDIR%\System32\cmd /c sc config TlntSvr start= auto</CommandLine> + <CommandLine>%WINDIR%\System32\cmd /c start /w pkgmgr /iu:"TelnetServer"</CommandLine> <Order>3</Order> </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>%WINDIR%\System32\cmd /c netsh firewall set opmode disable</CommandLine> + <CommandLine>%WINDIR%\System32\cmd /c sc config TlntSvr start= auto</CommandLine> <Order>4</Order> </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>%WINDIR%\System32\cmd /c net start telnet</CommandLine> + <CommandLine>%WINDIR%\System32\cmd /c netsh firewall set opmode disable</CommandLine> <Order>5</Order> </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>%WINDIR%\System32\cmd /c bcdedit /set {current} bootstatuspolicy ignoreallfailures</CommandLine> + <CommandLine>%WINDIR%\System32\cmd /c net start telnet</CommandLine> <Order>6</Order> </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>%WINDIR%\System32\cmd /c E:\setuprss.bat</CommandLine> + <CommandLine>%WINDIR%\System32\cmd /c E:\autoit3.exe E:\git\git.au3</CommandLine> <Order>7</Order> </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>%WINDIR%\System32\cmd /c netsh interface ip set address "Local Area Connection" dhcp</CommandLine> + <CommandLine>%WINDIR%\System32\cmd /c bcdedit /set {current} USEPLATFORMCLOCK yes</CommandLine> <Order>8</Order> </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>%WINDIR%\System32\cmd /c A:\finish.bat PROCESS_CHECK</CommandLine> + <CommandLine>%WINDIR%\System32\cmd /c bcdedit /set {current} bootstatuspolicy ignoreallfailures</CommandLine> <Order>9</Order> </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c E:\setuprss.bat</CommandLine> + <Order>10</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c netsh interface ip set address "Local Area Connection" dhcp</CommandLine> + <Order>11</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_BALLOON_INSTALLER</CommandLine> + <Order>12</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_QXL_INSTALLER</CommandLine> + <Order>13</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c E:\setuprss.bat</CommandLine> + <Order>14</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c E:\setupsp.bat</CommandLine> + <Order>15</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c E:\software_install_32.bat</CommandLine> + <Order>16</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c A:\finish.bat PROCESS_CHECK</CommandLine> + <Order>17</Order> + </SynchronousCommand> </FirstLogonCommands> </component> </settings> diff --git a/shared/unattended/win7-64-autounattend.xml b/shared/unattended/win7-64-autounattend.xml index 2321003f2..2bcb891bd 100644 --- a/shared/unattended/win7-64-autounattend.xml +++ b/shared/unattended/win7-64-autounattend.xml @@ -40,7 +40,7 @@ <CreatePartitions> <CreatePartition wcm:action="add"> <Order>1</Order> - <Size>20000</Size> + <Size>30000</Size> <Type>Primary</Type> </CreatePartition> </CreatePartitions> @@ -136,41 +136,69 @@ </AutoLogon> <FirstLogonCommands> <SynchronousCommand wcm:action="add"> - <CommandLine>%WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_NETWORK_INSTALLER"</CommandLine> + <CommandLine>%WINDIR%\System32\cmd /c echo OS install is completed > COM1</CommandLine> <Order>1</Order> </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>%WINDIR%\System32\cmd /c start /w pkgmgr /iu:"TelnetServer"</CommandLine> + <CommandLine>%WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_NETWORK_INSTALLER</CommandLine> <Order>2</Order> </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>%WINDIR%\System32\cmd /c sc config TlntSvr start= auto</CommandLine> + <CommandLine>%WINDIR%\System32\cmd /c start /w pkgmgr /iu:"TelnetServer"</CommandLine> <Order>3</Order> </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>%WINDIR%\System32\cmd /c netsh firewall set opmode disable</CommandLine> + <CommandLine>%WINDIR%\System32\cmd /c sc config TlntSvr start= auto</CommandLine> <Order>4</Order> </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>%WINDIR%\System32\cmd /c net start telnet</CommandLine> + <CommandLine>%WINDIR%\System32\cmd /c netsh firewall set opmode disable</CommandLine> <Order>5</Order> </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>%WINDIR%\System32\cmd /c bcdedit /set {current} bootstatuspolicy ignoreallfailures</CommandLine> + <CommandLine>%WINDIR%\System32\cmd /c net start telnet</CommandLine> <Order>6</Order> </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>%WINDIR%\System32\cmd /c E:\setuprss.bat</CommandLine> + <CommandLine>%WINDIR%\System32\cmd /c E:\autoit3.exe E:\git\git.au3</CommandLine> <Order>7</Order> </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>%WINDIR%\System32\cmd /c netsh interface ip set address "Local Area Connection" dhcp</CommandLine> + <CommandLine>%WINDIR%\System32\cmd /c bcdedit /set {current} USEPLATFORMCLOCK yes</CommandLine> <Order>8</Order> </SynchronousCommand> <SynchronousCommand wcm:action="add"> - <CommandLine>%WINDIR%\System32\cmd /c A:\finish.bat PROCESS_CHECK</CommandLine> + <CommandLine>%WINDIR%\System32\cmd /c bcdedit /set {current} bootstatuspolicy ignoreallfailures</CommandLine> <Order>9</Order> </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c netsh interface ip set address "Local Area Connection" dhcp</CommandLine> + <Order>10</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_BALLOON_INSTALLER</CommandLine> + <Order>11</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_QXL_INSTALLER</CommandLine> + <Order>12</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c E:\setuprss.bat</CommandLine> + <Order>13</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c E:\setupsp.bat</CommandLine> + <Order>14</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c E:\software_install_64.bat</CommandLine> + <Order>15</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c A:\finish.bat PROCESS_CHECK</CommandLine> + <Order>16</Order> + </SynchronousCommand> </FirstLogonCommands> </component> </settings> diff --git a/shared/unattended/win8-32-autounattend.xml b/shared/unattended/win8-32-autounattend.xml new file mode 100644 index 000000000..3a02b3142 --- /dev/null +++ b/shared/unattended/win8-32-autounattend.xml @@ -0,0 +1,211 @@ +<?xml version="1.0" encoding="utf-8"?> +<unattend xmlns="urn:schemas-microsoft-com:unattend"> + <settings pass="windowsPE"> + <component name="Microsoft-Windows-International-Core-WinPE" + processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" + language="neutral" versionScope="nonSxS" + xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <SetupUILanguage> + <UILanguage>en-us</UILanguage> + </SetupUILanguage> + <InputLocale>0409:00000409</InputLocale> + <SystemLocale>en-us</SystemLocale> + <UILanguage>en-us</UILanguage> + <UILanguageFallback>en-us</UILanguageFallback> + <UserLocale>en-us</UserLocale> + </component> + <component name="Microsoft-Windows-PnpCustomizationsWinPE" + processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" + language="neutral" versionScope="nonSxS" + xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <DriverPaths> + <PathAndCredentials wcm:keyValue="1" wcm:action="add"> + <Path>KVM_TEST_STORAGE_DRIVER_PATH</Path> + </PathAndCredentials> + <PathAndCredentials wcm:keyValue="2" wcm:action="add"> + <Path>KVM_TEST_NETWORK_DRIVER_PATH</Path> + </PathAndCredentials> + </DriverPaths> + </component> + <component name="Microsoft-Windows-Setup" + processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" + language="neutral" versionScope="nonSxS" + xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <DiskConfiguration> + <WillShowUI>OnError</WillShowUI> + <Disk wcm:action="add"> + <CreatePartitions> + <CreatePartition wcm:action="add"> + <Order>1</Order> + <Size>30000</Size> + <Type>Primary</Type> + </CreatePartition> + </CreatePartitions> + <ModifyPartitions> + <ModifyPartition wcm:action="add"> + <Active>true</Active> + <Extend>false</Extend> + <Format>NTFS</Format> + <Label>OS_Install</Label> + <Letter>C</Letter> + <Order>1</Order> + <PartitionID>1</PartitionID> + </ModifyPartition> + </ModifyPartitions> + <DiskID>0</DiskID> + <WillWipeDisk>true</WillWipeDisk> + </Disk> + </DiskConfiguration> + <ImageInstall> + <OSImage> + <InstallTo> + <DiskID>0</DiskID> + <PartitionID>1</PartitionID> + </InstallTo> + </OSImage> + </ImageInstall> + <UserData> + <ProductKey> + <Key>KVM_TEST_CDKEY</Key> + <WillShowUI>OnError</WillShowUI> + </ProductKey> + <AcceptEula>true</AcceptEula> + </UserData> + </component> + </settings> + <settings pass="specialize"> + <component name="Microsoft-Windows-Deployment" + processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" + language="neutral" versionScope="nonSxS" + xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <RunSynchronous> + <RunSynchronousCommand wcm:action="add"> + <Description>EnableAdmin</Description> + <Order>1</Order> + <Path>cmd /c net user Administrator /active:yes</Path> + </RunSynchronousCommand> + <RunSynchronousCommand wcm:action="add"> + <Description>UnfilterAdministratorToken</Description> + <Order>2</Order> + <Path>cmd /c reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v FilterAdministratorToken /t REG_DWORD /d 0 /f</Path> + </RunSynchronousCommand> + </RunSynchronous> + </component> + <component name="Microsoft-Windows-International-Core" + processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" + language="neutral" versionScope="nonSxS" + xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <InputLocale>0409:00000409</InputLocale> + <SystemLocale>en-US</SystemLocale> + <UILanguage>en-US</UILanguage> + <UserLocale>en-US</UserLocale> + </component> + </settings> + <settings pass="oobeSystem"> + <component name="Microsoft-Windows-Shell-Setup" + processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" + language="neutral" versionScope="nonSxS" + xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <UserAccounts> + <AdministratorPassword> + <Value>1q2w3eP</Value> + <PlainText>true</PlainText> + </AdministratorPassword> + </UserAccounts> + <OOBE> + <HideEULAPage>true</HideEULAPage> + <NetworkLocation>Work</NetworkLocation> + <ProtectYourPC>1</ProtectYourPC> + <SkipUserOOBE>true</SkipUserOOBE> + <SkipMachineOOBE>true</SkipMachineOOBE> + </OOBE> + <AutoLogon> + <Password> + <Value>1q2w3eP</Value> + <PlainText>true</PlainText> + </Password> + <Enabled>true</Enabled> + <LogonCount>1000</LogonCount> + <Username>Administrator</Username> + </AutoLogon> + <FirstLogonCommands> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c echo OS install is completed > COM1</CommandLine> + <Order>1</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_NETWORK_INSTALLER</CommandLine> + <Order>2</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c start /w pkgmgr /iu:"TelnetServer"</CommandLine> + <Order>3</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c sc config TlntSvr start= auto</CommandLine> + <Order>4</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c netsh firewall set opmode disable</CommandLine> + <Order>5</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c net start telnet</CommandLine> + <Order>6</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c E:\autoit3.exe E:\git\git.au3</CommandLine> + <Order>7</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c bcdedit /set {current} USEPLATFORMCLOCK yes</CommandLine> + <Order>8</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c bcdedit /set {current} bootstatuspolicy ignoreallfailures</CommandLine> + <Order>9</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c E:\setuprss.bat</CommandLine> + <Order>10</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c netsh interface ip set address "Local Area Connection" dhcp</CommandLine> + <Order>11</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_BALLOON_INSTALLER</CommandLine> + <Order>12</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_QXL_INSTALLER</CommandLine> + <Order>13</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c E:\setuprss.bat</CommandLine> + <Order>14</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\Dism /online /enable-feature /featurename:NetFx3 /All /Source:D:\sources\sxs /LimitAccess</CommandLine> + <Order>15</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c E:\setupsp.bat</CommandLine> + <Order>16</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c A:\finish.bat PROCESS_CHECK</CommandLine> + <Order>17</Order> + </SynchronousCommand> + </FirstLogonCommands> + </component> + </settings> + <cpi:offlineImage cpi:source="wim:c:/install.wim#Windows Longhorn SERVERSTANDARD" + xmlns:cpi="urn:schemas-microsoft-com:cpi" /> +</unattend> diff --git a/shared/unattended/win8-64-autounattend.xml b/shared/unattended/win8-64-autounattend.xml new file mode 100644 index 000000000..03fc58f59 --- /dev/null +++ b/shared/unattended/win8-64-autounattend.xml @@ -0,0 +1,207 @@ +<?xml version="1.0" encoding="utf-8"?> +<unattend xmlns="urn:schemas-microsoft-com:unattend"> + <settings pass="windowsPE"> + <component name="Microsoft-Windows-International-Core-WinPE" + processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" + language="neutral" versionScope="nonSxS" + xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <SetupUILanguage> + <UILanguage>en-us</UILanguage> + </SetupUILanguage> + <InputLocale>0409:00000409</InputLocale> + <SystemLocale>en-us</SystemLocale> + <UILanguage>en-us</UILanguage> + <UILanguageFallback>en-us</UILanguageFallback> + <UserLocale>en-us</UserLocale> + </component> + <component name="Microsoft-Windows-PnpCustomizationsWinPE" + processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" + language="neutral" versionScope="nonSxS" + xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <DriverPaths> + <PathAndCredentials wcm:keyValue="1" wcm:action="add"> + <Path>KVM_TEST_STORAGE_DRIVER_PATH</Path> + </PathAndCredentials> + <PathAndCredentials wcm:keyValue="2" wcm:action="add"> + <Path>KVM_TEST_NETWORK_DRIVER_PATH</Path> + </PathAndCredentials> + </DriverPaths> + </component> + <component name="Microsoft-Windows-Setup" + processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" + language="neutral" versionScope="nonSxS" + xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <DiskConfiguration> + <WillShowUI>OnError</WillShowUI> + <Disk wcm:action="add"> + <CreatePartitions> + <CreatePartition wcm:action="add"> + <Order>1</Order> + <Size>30000</Size> + <Type>Primary</Type> + </CreatePartition> + </CreatePartitions> + <ModifyPartitions> + <ModifyPartition wcm:action="add"> + <Active>true</Active> + <Extend>false</Extend> + <Format>NTFS</Format> + <Label>OS_Install</Label> + <Letter>C</Letter> + <Order>1</Order> + <PartitionID>1</PartitionID> + </ModifyPartition> + </ModifyPartitions> + <DiskID>0</DiskID> + <WillWipeDisk>true</WillWipeDisk> + </Disk> + </DiskConfiguration> + <ImageInstall> + <OSImage> + <InstallTo> + <DiskID>0</DiskID> + <PartitionID>1</PartitionID> + </InstallTo> + </OSImage> + </ImageInstall> + <UserData> + <ProductKey> + <Key>KVM_TEST_CDKEY</Key> + <WillShowUI>OnError</WillShowUI> + </ProductKey> + <AcceptEula>true</AcceptEula> + </UserData> + </component> + </settings> + <settings pass="specialize"> + <component name="Microsoft-Windows-Deployment" + processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" + language="neutral" versionScope="nonSxS" + xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <RunSynchronous> + <RunSynchronousCommand wcm:action="add"> + <Description>EnableAdmin</Description> + <Order>1</Order> + <Path>cmd /c net user Administrator /active:yes</Path> + </RunSynchronousCommand> + <RunSynchronousCommand wcm:action="add"> + <Description>UnfilterAdministratorToken</Description> + <Order>2</Order> + <Path>cmd /c reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v FilterAdministratorToken /t REG_DWORD /d 0 /f</Path> + </RunSynchronousCommand> + </RunSynchronous> + </component> + <component name="Microsoft-Windows-International-Core" + processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" + language="neutral" versionScope="nonSxS" + xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <InputLocale>0409:00000409</InputLocale> + <SystemLocale>en-US</SystemLocale> + <UILanguage>en-US</UILanguage> + <UserLocale>en-US</UserLocale> + </component> + </settings> + <settings pass="oobeSystem"> + <component name="Microsoft-Windows-Shell-Setup" + processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" + language="neutral" versionScope="nonSxS" + xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + <UserAccounts> + <AdministratorPassword> + <Value>1q2w3eP</Value> + <PlainText>true</PlainText> + </AdministratorPassword> + </UserAccounts> + <OOBE> + <HideEULAPage>true</HideEULAPage> + <NetworkLocation>Work</NetworkLocation> + <ProtectYourPC>1</ProtectYourPC> + <SkipUserOOBE>true</SkipUserOOBE> + <SkipMachineOOBE>true</SkipMachineOOBE> + </OOBE> + <AutoLogon> + <Password> + <Value>1q2w3eP</Value> + <PlainText>true</PlainText> + </Password> + <Enabled>true</Enabled> + <LogonCount>1000</LogonCount> + <Username>Administrator</Username> + </AutoLogon> + <FirstLogonCommands> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c echo OS install is completed > COM1</CommandLine> + <Order>1</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_NETWORK_INSTALLER</CommandLine> + <Order>2</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c start /w pkgmgr /iu:"TelnetServer"</CommandLine> + <Order>3</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c sc config TlntSvr start= auto</CommandLine> + <Order>4</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c netsh firewall set opmode disable</CommandLine> + <Order>5</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c net start telnet</CommandLine> + <Order>6</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c E:\autoit3.exe E:\git\git.au3</CommandLine> + <Order>7</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c bcdedit /set {current} USEPLATFORMCLOCK yes</CommandLine> + <Order>8</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c bcdedit /set {current} bootstatuspolicy ignoreallfailures</CommandLine> + <Order>9</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c netsh interface ip set address "Local Area Connection" dhcp</CommandLine> + <Order>10</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_BALLOON_INSTALLER</CommandLine> + <Order>11</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c KVM_TEST_VIRTIO_QXL_INSTALLER</CommandLine> + <Order>12</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c E:\setuprss.bat</CommandLine> + <Order>13</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\Dism /online /enable-feature /featurename:NetFx3 /All /Source:D:\sources\sxs /LimitAccess</CommandLine> + <Order>14</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c E:\setupsp.bat</CommandLine> + <Order>15</Order> + </SynchronousCommand> + <SynchronousCommand wcm:action="add"> + <CommandLine>%WINDIR%\System32\cmd /c A:\finish.bat PROCESS_CHECK</CommandLine> + <Order>16</Order> + </SynchronousCommand> + </FirstLogonCommands> + </component> + </settings> + <cpi:offlineImage cpi:source="wim:c:/install.wim#Windows Longhorn SERVERSTANDARD" + xmlns:cpi="urn:schemas-microsoft-com:cpi" /> +</unattend> diff --git a/shared/unattended/winxp32.sif b/shared/unattended/winxp32.sif index 5fc7c6f4c..6bfe8df28 100644 --- a/shared/unattended/winxp32.sif +++ b/shared/unattended/winxp32.sif @@ -1,76 +1,84 @@ [Data] -AutoPartition = 1 -MsDosInitiated = "0" -UnattendedInstall = "Yes" +AutoPartition=1 +MsDosInitiated="0" +UnattendedInstall="Yes" [Unattended] -Repartition = Yes -UnattendMode = FullUnattended -OemSkipEula = Yes -OemPreinstall = No -TargetPath = \WINDOWS -UnattendSwitch = Yes -CrashDumpSetting = 1 -DriverSigningPolicy = ignore -OemPnPDriversPath = KVM_TEST_NETWORK_DRIVER_PATH -WaitForReboot = no +Repartition=Yes +UnattendMode=FullUnattended +OemSkipEula=Yes +OemPreinstall=No +TargetPath=\WINDOWS +UnattendSwitch=Yes +CrashDumpSetting=1 +DriverSigningPolicy=ignore +OemPnPDriversPath="KVM_TEST_NETWORK_DRIVER_PATH" +WaitForReboot=no [GuiUnattended] -AdminPassword = "1q2w3eP" -EncryptedAdminPassword = NO -TimeZone = 85 -OemSkipWelcome = 1 -AutoLogon = Yes -AutoLogonCount = 1000 -OEMSkipRegional = 1 +AdminPassword="1q2w3eP" +EncryptedAdminPassword=NO +TimeZone=85 +OemSkipWelcome=1 +AutoLogon=Yes +AutoLogonCount=1000 +OEMSkipRegional=1 [UserData] -ProductKey = KVM_TEST_CDKEY -FullName = "Autotest Mindless Drone" -OrgName = "Autotest" -ComputerName = * +ProductKey=KVM_TEST_CDKEY +FullName="Autotest Mindless Drone" +OrgName="Autotest" +ComputerName=* [Identification] -JoinWorkgroup = WORKGROUP +JoinWorkgroup=WORKGROUP [Networking] -InstallDefaultComponents = Yes +InstallDefaultComponents=Yes [Proxy] -Proxy_Enable = 0 -Use_Same_Proxy = 0 +Proxy_Enable=0 +Use_Same_Proxy=0 [Components] -dialer = off -media_clips = off -media_utopia = off -msnexplr = off -netoc = off -OEAccess = off -templates = off -WMAccess = off -zonegames = off +dialer=off +media_clips=off +media_utopia=off +msnexplr=off +netoc=off +OEAccess=off +templates=off +WMAccess=off +zonegames=off [TerminalServices] -AllowConnections = 1 +AllowConnections=1 [WindowsFirewall] -Profiles = WindowsFirewall.TurnOffFirewall +Profiles=WindowsFirewall.TurnOffFirewall [WindowsFirewall.TurnOffFirewall] -Mode = 0 +Mode=0 [Branding] -BrandIEUsingUnattended = Yes +BrandIEUsingUnattended=Yes [Display] -Xresolution = 1024 -YResolution = 768 +Xresolution=1024 +YResolution=768 [GuiRunOnce] -Command0 = "cmd /c KVM_TEST_VIRTIO_NETWORK_INSTALLER" -Command1 = "cmd /c E:\setuprss.bat" -Command2 = "cmd /c netsh interface ip set address local dhcp" -Command3 = "cmd /c sc config tlntsvr start= auto" -Command4 = "cmd /c net start telnet" -Command5 = "cmd /c A:\finish.bat PROCESS_CHECK" +Command0="cmd /c echo OS install is completed > COM1" +Command1="cmd /c E:\autoit3.exe E:\git\git.au3" +Command2="cmd /c E:\cfg\screensave.bat" +Command3="cmd /c E:\cfg\use_pmtmr.bat" +Command4="cmd /c netsh interface ip set address local dhcp" +Command5="cmd /c E:\setuprss.bat" +Command6="cmd /c start /wait E:\dotnetfx35.exe /lang:ENU /norestart /passive" +Command7="cmd /c msiexec /i D:\SUPPORT\TOOLS\SUPTOOLS.MSI /q" +Command8="cmd /c md C:\sysprep & expand D:\SUPPORT\TOOLS\DEPLOY.CAB -F:* C:\sysprep" +Command9="cmd /c E:\setupsp.bat" +Command10="cmd /c sc config tlntsvr start= auto" +Command11="cmd /c net start telnet" +Command12="cmd /c E:\software_install_32.bat" +Command13="cmd /c A:\finish.bat PROCESS_CHECK" diff --git a/tests/autotest_regression.py b/tests/autotest_regression.py index e1c071002..3404dcab2 100644 --- a/tests/autotest_regression.py +++ b/tests/autotest_regression.py @@ -49,9 +49,16 @@ def run_autotest_regression(test, params, env): step1 = "autotest-server-install" try: + installer_file = "install-autotest-server.sh" + installer_url = ("https://raw.github.com/autotest/autotest/master" + "/contrib/%s" % installer_file) + # Download the install script and execute it - download_cmd = ("wget https://raw.github.com/autotest/autotest/master" - "/contrib/install-autotest-server.sh") + download_cmd = ("python -c 'from urllib2 import urlopen; " + "r = urlopen(\"%s\"); " + "f = open(\"%s\", \"w\"); " + "f.write(r.read())'" % (installer_url, + installer_file)) session_server.cmd(download_cmd) permission_cmd = ("chmod +x install-autotest-server.sh") session_server.cmd(permission_cmd) @@ -60,12 +67,12 @@ def run_autotest_regression(test, params, env): if autotest_commit: install_cmd += " -c %s" % autotest_commit session_server.cmd(install_cmd, timeout=autotest_install_timeout) - vm_server.copy_files_from(guest_path="/tmp/install-autotest-server*log", - host_path=test.resultsdir) except aexpect.ShellCmdError, e: for line in e.output.splitlines(): logging.error(line) step_failures.append(step1) + vm_server.copy_files_from(guest_path="/tmp/install-autotest-server*log", + host_path=test.resultsdir) top_commit = None try: @@ -194,7 +201,7 @@ def job_is_status(status): return False else: raise ValueError("Job %s does not show in the " - "output of %s" % list_jobs_cmd) + "output of %s" % (job_name, list_jobs_cmd)) def job_is_completed(): return job_is_status("Completed") @@ -214,7 +221,7 @@ def job_is_running(): # Wait for the session to become unresponsive if not utils_misc.wait_for(lambda: not session_client.is_responsive(), timeout=300): - raise error.ValueError("Client machine did not reboot") + raise ValueError("Client machine did not reboot") # Establish a new client session session_client = vm_client.wait_for_login(timeout=timeout) diff --git a/tests/boot.py b/tests/boot.py index 38c0bd07f..870b928f8 100644 --- a/tests/boot.py +++ b/tests/boot.py @@ -17,21 +17,28 @@ def run_boot(test, params, env): @param env: Dictionary with test environment. """ - error.context("Try to log into guest.", logging.info) - vm = env.get_vm(params["main_vm"]) - vm.verify_alive() timeout = float(params.get("login_timeout", 240)) - session = vm.wait_for_login(timeout=timeout) + vms = env.get_all_vms() + for vm in vms: + error.context("Try to log into guest '%s'." % vm.name, logging.info) + session = vm.wait_for_login(timeout=timeout) + session.close() if params.get("rh_perf_envsetup_script"): - utils_test.service_setup(vm, session, test.virtdir) - + for vm in vms: + session = vm.wait_for_login(timeout=timeout) + utils_test.service_setup(vm, session, test.virtdir) + session.close() if params.get("reboot_method"): - error.context("Reboot guest.", logging.info) - if params["reboot_method"] == "system_reset": - time.sleep(int(params.get("sleep_before_reset", 10))) + for vm in vms: + error.context("Reboot guest '%s'." % vm.name, logging.info) + if params["reboot_method"] == "system_reset": + time.sleep(int(params.get("sleep_before_reset", 10))) # Reboot the VM - for i in range(int(params.get("reboot_count", 1))): - session = vm.reboot(session, params["reboot_method"], 0, timeout) - - session.close() + session = vm.wait_for_login(timeout=timeout) + for i in range(int(params.get("reboot_count", 1))): + session = vm.reboot(session, + params["reboot_method"], + 0, + timeout) + session.close() diff --git a/tests/boot_savevm.py b/tests/boot_savevm.py index a79de410e..d1bae381e 100644 --- a/tests/boot_savevm.py +++ b/tests/boot_savevm.py @@ -34,9 +34,9 @@ def run_boot_savevm(test, params, env): vm.create(params=params) vm.verify_alive() # This shouldn't require logging in to guest - savevm_delay = float(params.get("savevm_delay")) - savevm_login_delay = float(params.get("savevm_login_delay")) - savevm_login_timeout = float(params.get("savevm_timeout")) + savevm_delay = float(params["savevm_delay"]) + savevm_login_delay = float(params["savevm_login_delay"]) + savevm_login_timeout = float(params["savevm_timeout"]) savevm_statedir = params.get("savevm_statedir", tempfile.gettempdir()) fd, savevm_statefile = tempfile.mkstemp(suffix='.img', prefix=vm.name+'-', dir=savevm_statedir) diff --git a/tests/cfg/autotest_control.cfg b/tests/cfg/autotest_control.cfg index 99214b57c..8b48f009e 100644 --- a/tests/cfg/autotest_control.cfg +++ b/tests/cfg/autotest_control.cfg @@ -30,6 +30,9 @@ - hackbench: test_control_file = hackbench.control - cpu_hotplug: + no RHEL.3.9 + no RHEL.4 + kill_vm = yes test_control_file = cpu_hotplug.control - monotonic_time: test_control_file = monotonic_time.control @@ -40,7 +43,14 @@ - rtc: test_control_file = rtc.control - iozone: + test_timeout = 4200 test_control_file = iozone.control + profilers += " sar iostat " + variants: + - aio_native: + image_aio = native + - aio_threads: + image_aio = threads - flail: test_control_file = flail.control - systemtap: @@ -72,5 +82,72 @@ - scsi-disk: drive_format_asd = scsi-disk - xfstests: + # Below packages requried to installed in guest before start test: + # xfsdump, xfsprogs xfsprogs-devel + no RHEL.3 RHEL.4 RHEL.5 RHEL.6 + kill_vm = yes + images += " stg1" + image_name_stg1 = "images/stg1" + image_format_stg1 = "qcow2" + image_size_stg1 = 2G + force_create_image_stg1 = yes + force_remove_image_stg1= yes test_timeout = 4800 test_control_file = xfstests.control + - linus_stress: + test_control_file = linus_stress.control + - signaltest: + test_control_file = signaltest.control + - parallel_dd: + test_timeout = 36000 + images += " stg" + image_format_stg = qcow2 + boot_drive_stg = yes + image_name_stg = images/storage + image_size_stg = 10G + force_create_image_stg = yes + test_control_file = parallel_dd.control + - compliebench: + test_control_file = compilebench.control + - fsstress: + test_timeout = 36000 + test_control_file = fsstress.control + - aiostress: + test_control_file = aiostress.control + variants: + - aio_native: + image_aio = native + - aio_threads: + image_aio = threads + - interbench: + test_control_file = interbench.control + - kernbench: + test_control_file = kernbench.control + - posixtest: + test_timeout = 3600 + test_control_file = posixtest.control + - rmaptest: + test_control_file = rmaptest.control + - synctest: + test_control_file = synctest.control + - tbench: + test_control_file = tbench.control + - tiobench: + test_timeout = 4200 + test_control_file = tiobench.control + variants: + - aio_native: + image_aio = native + - aio_threads: + image_aio = threads + - fio: + no RHEL.3 RHEL.4 + test_timeout =1800 + test_control_file = fio.control + - unixbench5: + no RHEL.3 RHEL.4 + test_timeout = 4200 + test_control_file = unixbench5.control + - wb_kupdate: + test_timeout =1800 + test_control_file = wb_kupdate.control diff --git a/tests/cfg/block_hotplug.cfg b/tests/cfg/block_hotplug.cfg index ede1ad2d2..364b9f887 100644 --- a/tests/cfg/block_hotplug.cfg +++ b/tests/cfg/block_hotplug.cfg @@ -7,7 +7,7 @@ find_pci_cmd = 'lspci | tail -n1' images += " stg0" boot_drive_stg0 = no - image_name_stg0 = storage0 + image_name_stg0 = images/storage0 image_size_stg0 = 1G remove_image_stg0 = yes force_create_image_stg0 = yes @@ -16,10 +16,12 @@ kill_vm_on_error = yes variants: - fmt_qcow2: + image_extra_params = "" image_format_stg = qcow2 image_format_stg0 = qcow2 image_format_stg1 = qcow2 - fmt_raw: + image_extra_params = "" image_format_stg = raw image_format_stg0 = raw image_format_stg1 = raw @@ -32,7 +34,7 @@ repeat_times = 2 images += " stg1" boot_drive_stg1 = no - image_name_stg1 = storage1 + image_name_stg1 = images/storage1 image_size_stg1 = 1G remove_image_stg1 = yes force_create_image_stg1 = yes diff --git a/tests/cfg/boot_savevm.cfg b/tests/cfg/boot_savevm.cfg index 75e73e63d..061f6919b 100644 --- a/tests/cfg/boot_savevm.cfg +++ b/tests/cfg/boot_savevm.cfg @@ -14,6 +14,7 @@ - default_savevm: - with_floppy: + no Host_RHEL.7 virt_test_type = qemu save_method = save_to_tag with_floppy = yes diff --git a/tests/cfg/dd_test.cfg b/tests/cfg/dd_test.cfg index ce02e992c..01c36f6d3 100644 --- a/tests/cfg/dd_test.cfg +++ b/tests/cfg/dd_test.cfg @@ -4,7 +4,7 @@ type = dd_test images += " stg1" create_image_stg1 = yes - image_name_stg1 = stg1 + image_name_stg1 = images/stg1 image_size_stg1 = 1M image_snapshot_stg1 = no drive_index_stg1 = 3 diff --git a/tests/cfg/enable_mq.cfg b/tests/cfg/enable_mq.cfg new file mode 100644 index 000000000..43bb5076b --- /dev/null +++ b/tests/cfg/enable_mq.cfg @@ -0,0 +1,4 @@ +- enable_mq: install setup image_copy unattended_install.cdrom + virt_test_type = qemu libvirt + only Linux + type = enable_mq diff --git a/tests/cfg/file_transfer.cfg b/tests/cfg/file_transfer.cfg index 3e314eeb0..d23416705 100644 --- a/tests/cfg/file_transfer.cfg +++ b/tests/cfg/file_transfer.cfg @@ -6,3 +6,9 @@ variants: - remote: transfer_type = remote + variants: + - no_vhostforce: + - vhostforce_off: + netdev_extra_params_nic1 += ',vhostforce=off' + - vhostforce_on: + netdev_extra_params_nic1 += ',vhostforce=on' diff --git a/tests/cfg/guest_suspend.cfg b/tests/cfg/guest_suspend.cfg index ea16b307a..b5faf80c3 100644 --- a/tests/cfg/guest_suspend.cfg +++ b/tests/cfg/guest_suspend.cfg @@ -44,7 +44,7 @@ type = clock_getres sub_test = guest_suspend - without_kvmclock: - cpu_model_flags += " -kvmclock" + cpu_model_flags += ",-kvmclock" variants: - guest_s3: guest_suspend_type = "mem" diff --git a/tests/cfg/lvm.cfg b/tests/cfg/lvm.cfg index efdf96240..7b9297051 100644 --- a/tests/cfg/lvm.cfg +++ b/tests/cfg/lvm.cfg @@ -2,11 +2,11 @@ virt_test_type = qemu libvirt only Linux images += ' stg1 stg2' - image_name_stg1 = storage_4k + image_name_stg1 = images/storage_4k image_cluster_size_stg1 = 4096 image_size_stg1 = 1G image_format_stg1 = qcow2 - image_name_stg2 = storage_64k + image_name_stg2 = images/storage_64k image_cluster_size_stg2 = 65536 image_size_stg2 = 1G image_format_stg2 = qcow2 diff --git a/tests/cfg/mac_change.cfg b/tests/cfg/mac_change.cfg index eaf01d0c6..37ee252da 100644 --- a/tests/cfg/mac_change.cfg +++ b/tests/cfg/mac_change.cfg @@ -2,3 +2,13 @@ virt_test_type = qemu libvirt type = mac_change kill_vm = yes + variants: + - down_change: + only Linux + shutdown_int = yes + int_shutdown_cmd = ifconfig %s down + int_activate_cmd = ifconfig %s up + - @up_change: + virtio_net: + no RHEL.5, RHEL.6.0, RHEL.6.1, RHEL.6.2, RHEL.6.3 + shutdown_int = no diff --git a/tests/cfg/unattended_install.cfg b/tests/cfg/unattended_install.cfg index 9ce8961b9..447d78c8c 100644 --- a/tests/cfg/unattended_install.cfg +++ b/tests/cfg/unattended_install.cfg @@ -18,7 +18,67 @@ # Set migrate_background to yes to run migration in parallel # migrate_background = yes image_verify_bootable = no - + # Copy boot image to results dir or not + # boot image will include the ks file or other files you need + # during install. Could be helpful to debug the install failed + # reasons. + # store_boot_disk = yes + # Backup images from nfs when install failed + # images_good = + # Mount point for your back up images + # dst_dir = + variants: + - aio_native: + image_aio = native + - aio_threads: + image_aio = threads + # Add some special type install + variants: + - @default_install: + #install for performance + - perf: + - multi_disk_install: + no ide + only unattended_install..cdrom + images += " stg stg2 stg3 stg4 stg5 stg6 stg7 stg8 stg9 stg10 stg11 stg12 stg13 stg14 stg15 stg16 stg17 stg18 stg19 stg20 stg21 stg22 stg23 stg24" + image_name_stg = images/storage + image_name_stg2 = images/storage2 + image_name_stg3 = images/storage3 + image_name_stg4 = images/storage4 + image_name_stg5 = images/storage5 + image_name_stg6 = images/storage6 + image_name_stg7 = images/storage7 + image_name_stg8 = images/storage8 + image_name_stg9 = images/storage9 + image_name_stg10 = images/storage10 + image_name_stg11 = images/storage11 + image_name_stg12 = images/storage12 + image_name_stg13 = images/storage13 + image_name_stg14 = images/storage14 + image_name_stg15 = images/storage15 + image_name_stg16 = images/storage16 + image_name_stg17 = images/storage17 + image_name_stg18 = images/storage18 + image_name_stg19 = images/storage19 + image_name_stg20 = images/storage20 + image_name_stg21 = images/storage21 + image_name_stg22 = images/storage22 + image_name_stg23 = images/storage23 + image_name_stg24 = images/storage24 + image_name_stg25 = images/storage25 + image_size_equal = 1G + - large_image: + only unattended_install.cdrom + only qcow2 qcow2v3 + image_size_image1 = 2300G + image_size = 2300G + - with_migration: + migrate_background = yes + - setting_cluster_size: + # qemu-kvm bug 812705 + no Host_RHEL.5 + cluster_size = 4096 + only qcow2 qcow2v3 # Way of delivering ks file into the guest variants: # Additional iso with kickstart is attached into the guest @@ -38,7 +98,6 @@ unattended_delivery_method = url # Image with kickstart is attached into the guest as floppy drive - floppy_ks: - only Linux unattended_delivery_method = floppy # Only perform a libvirt import. No cdroms, no floppies, no nothing - import: @@ -47,10 +106,16 @@ cdroms = "" floppy = "" timeout = 180 - variants: # Install guest from cdrom - cdrom: + + # set copy_to_local if you want copy files from nfs to local host before testing. + # local_dir: local folder used to save nfs file, kvm folder will be used by default. + # Both absolute path and relative path are supported in local_dir + # local_dir = /root/ + # copy_to_local = cdrom_cd1 cdrom_winutils + # TODO: is this needed for both kvm and libvirt? # This option is only used in windows installation case, # since linux use kernel/initrd option of qemu. diff --git a/tests/cfg/whql.cfg b/tests/cfg/whql.cfg index af3b7c18a..87ab96f05 100644 --- a/tests/cfg/whql.cfg +++ b/tests/cfg/whql.cfg @@ -203,6 +203,7 @@ - block_device: image_snapshot = yes images += " stg stg2 stg3 stg4" + image_extra_params = "" image_format_stg = raw image_name_stg = images/storage image_size_stg = 2G diff --git a/tests/enable_mq.py b/tests/enable_mq.py new file mode 100644 index 000000000..ea13cc7a6 --- /dev/null +++ b/tests/enable_mq.py @@ -0,0 +1,42 @@ +import logging, re +from autotest.client.shared import error +from virttest import utils_net + +@error.context_aware +def run_enable_mq(test, params, env): + """ + Enable MULTI_QUEUE feature in guest + + 1) Boot up VM(s) + 2) Login guests one by one + 3) Enable MQ for all virtio nics by ethtool -L + + @param test: QEMU test object. + @param params: Dictionary with the test parameters. + @param env: Dictionary with test environment. + """ + + login_timeout = int(params.get("login_timeout", 360)) + queues = int(params.get("queues", 1)) + vms = params.get("vms").split() + if queues == 1: + logging.info("No need to enable MQ feature for single queue") + return + + for vm in vms: + vm = env.get_vm(vm) + vm.verify_alive() + session = vm.wait_for_login(timeout=login_timeout) + for i, nic in enumerate(vm.virtnet): + if "virtio" in nic['nic_model']: + ifname = utils_net.get_linux_ifname(session, vm.get_mac_address(0)) + session.cmd_output("ethtool -L %s combined %d" + % (ifname, queues)) + o = session.cmd_output("ethtool -l %s" % ifname) + if len(re.findall("Combined:\s+%d\s" % queues, o)) != 2: + raise error.TestError("Fail to enable MQ feature of (%s)" + % nic.nic_name) + + logging.info("MQ feature of (%s) is enabled" % nic.nic_name) + + session.close() diff --git a/tests/jumbo.py b/tests/jumbo.py index 58a24bea9..7373ab29f 100644 --- a/tests/jumbo.py +++ b/tests/jumbo.py @@ -1,4 +1,4 @@ -import logging, commands, random, re +import logging, commands, random from autotest.client.shared import error from autotest.client import utils from virttest import utils_misc, utils_test, utils_net @@ -23,19 +23,6 @@ def run_jumbo(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ - def get_drive_num(session, path): - - """ - return file path drive - """ - cmd = "wmic datafile where \"path='%s'\" get drive" % path - info = session.cmd_output(cmd, timeout=360).strip() - drive_num = re.search(r'(\w):', info, re.M) - if not drive_num: - raise error.TestError("No path %s in your guest" % path) - return drive_num.group() - - timeout = int(params.get("login_timeout", 360)) mtu = params.get("mtu", "1500") max_icmp_pkt_size = int(mtu) - 28 @@ -75,9 +62,8 @@ def get_drive_num(session, path): "netconnectionid", connection_id, "pnpdeviceid") - devcon_path = r"\\devcon\\wxp_x86\\" - cd_num = get_drive_num(session, devcon_path) - copy_cmd = r"xcopy %s\devcon\wxp_x86\devcon.exe c:\ " % cd_num + cd_num = utils_misc.get_winutils_vol(session) + copy_cmd = r"xcopy %s:\devcon\wxp_x86\devcon.exe c:\ " % cd_num session.cmd(copy_cmd) @@ -180,5 +166,6 @@ def size_increase_ping(step=random.randrange(90, 110)): # Environment clean if session: session.close() - logging.info("Removing the temporary ARP entry") - utils.run("arp -d %s -i %s" % (ip, ifname)) + if utils.system("grep '%s.*%s' /proc/net/arp" % (ip, ifname)) == '0': + utils.run("arp -d %s -i %s" % (ip, ifname)) + logging.info("Removing the temporary ARP entry successfully") diff --git a/tests/kill_app.py b/tests/kill_app.py new file mode 100644 index 000000000..6f4467ddf --- /dev/null +++ b/tests/kill_app.py @@ -0,0 +1,57 @@ +""" +kill_app.py - Kill specific application. + +This test was created as a successor of almost the same rv_disconnect and +rv_video_close tests. +Simply close selected app. If app is not running, ends with error. Application +could be closed during migration or for any unwanted reason. This test checks +if application is running when it should . + +""" +import logging, os +from autotest.client.shared import error + +def run_kill_app(test, params, env): + """ + Test kills application. Application is given by name kill_app_name in + params. + It has to be defined if application is on guest or client with parameter + kill_on_vms which should contain name(s) of vm(s) (separated with ',') + + @param test: KVM test object. + @param params: Dictionary with the test parameters. + @param env: Dictionary with test environment. + """ + kill_on_vms = params.get("kill_on_vms", "") + vms = kill_on_vms.split(',') + app_name = params.get("kill_app_name", None) + logging.debug("vms %s", vms) + if not vms: + raise error.TestFail("Kill app test launched without any VM parameter") + else: + for vm in vms: + logging.debug("vm %s", vm) + if params.has_key(vm): + kill_app(vm, app_name, params, env) + +def kill_app(vm_name, app_name, params, env): + """ + Kill selected app on selected VM + + @params vm_name - VM name in parameters + @params app_name - name of application + """ + vm = env.get_vm(params[vm_name]) + + vm.verify_alive() + vm_session = vm.wait_for_login( + timeout=int(params.get("login_timeout", 360))) + #get PID of remote-viewer and kill it + logging.info("Get PID of %s", app_name) + vm_session.cmd("pgrep %s" % app_name) + + logging.info("Try to kill %s", app_name) + vm_session.cmd("pkill %s" % app_name \ + .split(os.path.sep)[-1]) + vm.verify_alive() + vm_session.close() diff --git a/tests/mac_change.py b/tests/mac_change.py index 6940851b9..fc861d42a 100644 --- a/tests/mac_change.py +++ b/tests/mac_change.py @@ -15,18 +15,6 @@ def run_mac_change(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ - def get_drive_num(session, path): - """ - return file path drive - """ - cmd = "wmic datafile where \"path='%s'\" get drive" % path - info = session.cmd_output(cmd, timeout=360).strip() - drive_num = re.search(r'(\w):', info, re.M) - if not drive_num: - raise error.TestError("No path %s in your guest" % path) - return drive_num.group() - - vm = env.get_vm(params["main_vm"]) vm.verify_alive() timeout = int(params.get("login_timeout", 360)) @@ -47,6 +35,10 @@ def get_drive_num(session, path): logging.info("The initial MAC address is %s", old_mac) if os_type == "linux": interface = utils_net.get_linux_ifname(session_serial, old_mac) + if params.get("shutdown_int", "yes") == "yes": + int_shutdown_cmd = params.get("int_shutdown_cmd", + "ifconfig %s down") + session_serial.cmd(int_shutdown_cmd % interface) else: connection_id = utils_net.get_windows_nic_attribute(session, @@ -62,17 +54,14 @@ def get_drive_num(session, path): "netconnectionid", connection_id, "pnpdeviceid") - devcon_path = r"\\devcon\\wxp_x86\\" - cd_drive = get_drive_num(session, devcon_path) - - copy_cmd = r"xcopy %s\devcon\wxp_x86\devcon.exe c:\ " % cd_drive + cd_drive = utils_misc.get_winutils_vol(session) + copy_cmd = r"xcopy %s:\devcon\wxp_x86\devcon.exe c:\ " % cd_drive session.cmd(copy_cmd) # Start change MAC address error.context("Changing MAC address to %s" % new_mac, logging.info) if os_type == "linux": - change_cmd = change_cmd_pattern % (interface, - interface, new_mac, interface) + change_cmd = change_cmd_pattern % (interface, new_mac) else: change_cmd = change_cmd_pattern % (int(nic_index), "".join(new_mac.split(":"))) @@ -83,6 +72,10 @@ def get_drive_num(session, path): error.context("Verify the new mac address, and restart the network", logging.info) if os_type == "linux": + if params.get("shutdown_int", "yes") == "yes": + int_activate_cmd = params.get("int_activate_cmd", + "ifconfig %s up") + session_serial.cmd(int_activate_cmd % interface) session_serial.cmd("ifconfig | grep -i %s" % new_mac) logging.info("Mac address change successfully, net restart...") dhclient_cmd = "dhclient -r && dhclient %s" % interface diff --git a/tests/netperf.py b/tests/netperf.py index 91c460935..fcc7a07ed 100644 --- a/tests/netperf.py +++ b/tests/netperf.py @@ -81,7 +81,7 @@ def run_netperf(test, params, env): """ def env_setup(session, ip, user, port, password): error.context("Setup env for %s" % ip) - ssh_cmd(session, "service iptables stop") + ssh_cmd(session, "service iptables stop; true") ssh_cmd(session, "echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore") netperf_dir = os.path.join(data_dir.get_root_dir(), "shared/deps") diff --git a/tests/rv_audio.py b/tests/rv_audio.py new file mode 100644 index 000000000..4834abb27 --- /dev/null +++ b/tests/rv_audio.py @@ -0,0 +1,123 @@ +""" +rv_audio.py - play audio playback / record on guest +and detect any pauses in the audio stream. + +Requires: rv_connect test + +""" +import logging +from autotest.client.shared import error, utils + +def verify_recording(recording, params): + """Tests whether something was actually recorded + + Threshold is a number of bytes which have to be zeros, in order to + record an unacceptable pause. + 11000 bytes is ~ 0.06236s (at 44100 Hz sampling, 16 bit depth + and stereo) + """ + rec = open(recording).read() + + disable_audio = params.get("disable_audio", "no") + threshold = int(params.get("rv_audio_threshold", "15000")) + config_test = params.get("config_test", None) + + if (len(rec) - rec.count('\0') < 50): + logging.info("Recording is empty") + if disable_audio != "yes": + return False + else: + return True + + pauses = [] + pause = False + try: + for index, value in enumerate(rec): + if value == '\0': + if not pause: + pauses.append([index]) + pause = True + else: + if pause: + pauses[-1].append(index-1) + pause = False + if (pauses[-1][1] - pauses[-1][0]) < threshold: + pauses.pop() + + if len(pauses): + logging.error("%d pauses detected:", len(pauses)) + for i in pauses: + logging.info("start: %10fs duration: %10fs" % ( + (float(i[0]) / (2*2*44100)), + (float(i[1]-i[0]) / (2*2*44100)) + )) + #Two small hiccups are allowed when migrating + if len(pauses) < 3 and config_test == "migration": + return True + else: + return False + else: + logging.info("No pauses detected") + + except IndexError: + #Too long pause, overflow in index + return False + + return True + +def run_rv_audio(test, params, env): + + guest_vm = env.get_vm(params["guest_vm"]) + guest_vm.verify_alive() + guest_session = guest_vm.wait_for_login( + timeout=int(params.get("login_timeout", 360))) + + client_vm = env.get_vm(params["client_vm"]) + client_vm.verify_alive() + client_session = client_vm.wait_for_login( + timeout=int(params.get("login_timeout", 360))) + + if(guest_session.cmd_status("ls %s" % params.get("audio_tgt"))): + print params.get("audio_src") + print params.get("audio_tgt") + guest_vm.copy_files_to( + params.get("audio_src"), + params.get("audio_tgt")) + if(client_session.cmd_status("ls %s" % params.get("audio_tgt"))): + client_vm.copy_files_to( + params.get("audio_src"), + params.get("audio_tgt")) + + if params.get("rv_record") == "yes": + logging.info("rv_record set; Testing recording") + player = client_vm.wait_for_login( + timeout=int(params.get("login_timeout", 360))) + recorder_session = guest_vm.wait_for_login( + timeout=int(params.get("login_timeout", 360))) + recorder_session_vm = guest_vm + else: + logging.info("rv_record not set; Testing playback") + player = guest_vm.wait_for_login( + timeout=int(params.get("login_timeout", 360))) + recorder_session = client_vm.wait_for_login( + timeout=int(params.get("login_timeout", 360))) + recorder_session_vm = client_vm + + player.cmd("aplay %s &> /dev/null &" % #starts playback + params.get("audio_tgt"), timeout = 30) + + if params.get("config_test", "no") == "migration": + bg = utils.InterruptedThread(guest_vm.migrate, kwargs={}) + bg.start() + + recorder_session.cmd("arecord -d %s -f cd -D hw:0,1 %s" % ( #records + params.get("audio_time","200"), #duration + params.get("audio_rec")), #target + timeout = 500) + + if params.get("config_test", "no") == "migration": + bg.join() + + recorder_session_vm.copy_files_from(params.get("audio_rec"),"./recorded.wav") + if not verify_recording("./recorded.wav", params): + raise error.TestFail("Test failed") diff --git a/tests/rv_clearx.py b/tests/rv_clearx.py new file mode 100644 index 000000000..b57c738c4 --- /dev/null +++ b/tests/rv_clearx.py @@ -0,0 +1,34 @@ +""" +This restarts the x server on all vms by killing gdm in order to eliminate any +side effects and running applications that might interfere with tests. +""" + +import logging +from autotest.client.shared import error +from virttest.aexpect import ShellCmdError +from virttest import utils_misc + +def is_pid_alive(session, pid): + + try: + session.cmd("ps -p %s" % pid) + except ShellCmdError: + return False + + return True + +def run_rv_clearx(test, params, env): + for vm_name in params.get("vms").split(): + vm = env.get_vm(vm_name) + logging.info("restarting X on: %s", vm_name) + session = vm.wait_for_login(username = "root", password = "123456", + timeout=int(params.get("login_timeout", 360))) + pid = session.cmd("pgrep Xorg") + session.cmd("killall Xorg") + + utils_misc.wait_for(lambda: is_pid_alive(session, pid), 10, 5, 0.2) + + try: + session.cmd("ps -C Xorg") + except: + raise error.TestFail("X not running") diff --git a/tests/rv_connect.py b/tests/rv_connect.py index 4b4d03cf7..a6037e231 100644 --- a/tests/rv_connect.py +++ b/tests/rv_connect.py @@ -5,20 +5,28 @@ Use example kickstart RHEL-6-spice.ks """ -import logging, os +import logging, sys, socket from virttest.aexpect import ShellStatusError from virttest.aexpect import ShellProcessTerminatedError -from virttest import utils_net, utils_spice, remote +from virttest import utils_net, utils_spice, remote, utils_misc from autotest.client.shared import error -def send_ticket(client_vm, ticket): +def str_input(client_vm, ticket): """ sends spice_password trough vm.send_key() @param client_session - vm() object @param ticket - use params.get("spice_password") """ logging.info("Passing ticket '%s' to the remote-viewer.", ticket) + char_mapping = {":": "shift-semicolon", + ",": "comma", + ".": "dot", + "/": "slash", + "?": "shift-slash", + "=": "equal"} for character in ticket: + if character in char_mapping: + character = char_mapping[character] client_vm.send_key(character) client_vm.send_key("kp_enter") # send enter @@ -36,16 +44,6 @@ def print_rv_version(client_session, rv_binary): client_session.cmd(rv_binary + " --spice-gtk-version")) -def killall(client_session, pth): - """ - calls killall execname - @params client_session - @params pth - path or execname - """ - execname = pth.split(os.path.sep)[-1] - client_session.cmd("killall %s &> /dev/null" % execname, ok_status=[0, 1]) - - def launch_rv(client_vm, guest_vm, params): """ Launches rv_binary with args based on spice configuration @@ -58,14 +56,24 @@ def launch_rv(client_vm, guest_vm, params): """ rv_binary = params.get("rv_binary", "remote-viewer") host_ip = utils_net.get_host_ip_address(params) + if guest_vm.get_spice_var("listening_addr") == "ipv6": + host_ip = "[" + utils_misc.convert_ipv4_to_ipv6(host_ip) + "]" + check_spice_info = params.get("spice_info") + ssltype = params.get("ssltype") test_type = params.get("test_type") host_port = None full_screen = params.get("full_screen") + disable_audio = params.get("disable_audio", "no") display = params.get("display") - cmd = rv_binary + " --display=:0.0" ticket = None ticket_send = params.get("spice_password_send") qemu_ticket = params.get("qemu_password") + gencerts = params.get("gencerts") + certdb = params.get("certdb") + smartcard = params.get("smartcard") + menu = params.get("rv_menu", None) + #cmd var keeps final remote-viewer command line to be executed on client + cmd = rv_binary + " --display=:0.0" #If qemu_ticket is set, set the password of the VM using the qemu-monitor if qemu_ticket: @@ -89,9 +97,27 @@ def launch_rv(client_vm, guest_vm, params): #first character (it's '/') host_subj = guest_vm.get_spice_var("spice_x509_server_subj") host_subj = host_subj.replace('/', ',')[1:] + if ssltype == "invalid_explicit_hs": + host_subj = "Invalid Explicit HS" + else: + host_subj += host_ip + + # If it's invalid implicit, a remote-viewer connection + # will be attempted with the hostname, since ssl certs were + # generated with the ip address + hostname = socket.gethostname() + if ssltype == "invalid_implicit_hs": + spice_url = " spice://%s?tls-port=%s\&port=%s" % (hostname, + host_tls_port, host_port) + else: + spice_url = " spice://%s?tls-port=%s\&port=%s" % (host_ip, + host_tls_port, host_port) + + if menu == "yes": + line = spice_url + else: + cmd += spice_url - cmd += " spice://%s?tls-port=%s\&port=%s" % (host_ip, host_tls_port, - host_port) cmd += " --spice-ca-file=%s" % cacert if params.get("spice_client_host_subject") == "yes": @@ -108,7 +134,12 @@ def launch_rv(client_vm, guest_vm, params): cacert, cacert) else: host_port = guest_vm.get_spice_var("spice_port") - cmd += " spice://%s?port=%s" % (host_ip, host_port) + if menu == "yes": + #line to be sent through monitor once r-v is started + #without spice url + line = "spice://%s?port=%s" % (host_ip, host_port) + else: + cmd += " spice://%s?port=%s" % (host_ip, host_port) elif display == "vnc": raise NotImplementedError("remote-viewer vnc") @@ -121,6 +152,24 @@ def launch_rv(client_vm, guest_vm, params): logging.info("Remote Viewer Set to use Full Screen") cmd += " --full-screen" + if disable_audio == "yes": + logging.info("Remote Viewer Set to disable audio") + cmd += " --spice-disable-audio" + + # Check to see if the test is using a smartcard. + if smartcard == "yes": + logging.info("remote viewer Set to use a smartcard") + cmd += " --spice-smartcard" + + if certdb != None: + logging.debug("Remote Viewer set to use the following certificate" + " database: " + certdb) + cmd += " --spice-smartcard-db " + certdb + + if gencerts != None: + logging.debug("Remote Viewer set to use the following certs: " + + gencerts) + cmd += " --spice-smartcard-certificates " + gencerts cmd = "nohup " + cmd + " &> /dev/null &" # Launch it on background @@ -140,27 +189,71 @@ def launch_rv(client_vm, guest_vm, params): logging.debug("Ignoring a status exception, will check connection of" "remote-viewer later") + #Send command line through monitor since r-v was started without spice url + if menu == "yes": + utils_spice.wait_timeout(1) + str_input(client_vm, line) + client_vm.send_key("tab") + client_vm.send_key("tab") + client_vm.send_key("tab") + client_vm.send_key("kp_enter") + # client waits for user entry (authentication) if spice_password is set # use qemu monitor password if set, else check if the normal password is set if qemu_ticket: # Wait for remote-viewer to launch utils_spice.wait_timeout(5) - send_ticket(client_vm, qemu_ticket) + str_input(client_vm, qemu_ticket) elif ticket: if ticket_send: ticket = ticket_send utils_spice.wait_timeout(5) # Wait for remote-viewer to launch - send_ticket(client_vm, ticket) + str_input(client_vm, ticket) + utils_spice.wait_timeout(5) # Wait for conncetion to establish + is_rv_connected = True try: utils_spice.verify_established(client_vm, host_ip, host_port, rv_binary) except utils_spice.RVConnectError: if test_type == "negative": logging.info("remote-viewer connection failed as expected") + if ssltype in ("invalid_implicit_hs", "invalid_explicit_hs"): + #Check the qemu process output to verify what is expected + qemulog = guest_vm.process.get_output() + if "SSL_accept failed" in qemulog: + return + else: + raise error.TestFail("SSL_accept failed not shown in qemu" + + "process as expected.") + is_rv_connected = False else: raise error.TestFail("remote-viewer connection failed") + if test_type == "negative" and is_rv_connected: + raise error.TestFail("remote-viewer connection was established when" + + " it was supposed to be unsuccessful") + + #Get spice info + output = guest_vm.monitor.cmd("info spice") + logging.debug("INFO SPICE") + logging.debug(output) + + # Check to see if ipv6 address is reported back from qemu monitor + if (check_spice_info == "ipv6"): + logging.info("Test to check if ipv6 address is reported" + " back from the qemu monitor") + #Remove brackets from ipv6 host ip + if (host_ip[1:len(host_ip)-1] in output): + logging.info("Reported ipv6 address found in output from" + " 'info spice'") + else: + raise error.TestFail("ipv6 address not found from qemu monitor" + " command: 'info spice'") + else: + logging.info("Not checking the value of 'info spice'" + " from the qemu monitor") + #prevent from kill remote-viewer after test finish cmd = "disown -ar" client_session.cmd(cmd) diff --git a/tests/rv_disconnect.py b/tests/rv_disconnect.py deleted file mode 100644 index a72fe7228..000000000 --- a/tests/rv_disconnect.py +++ /dev/null @@ -1,38 +0,0 @@ -""" -rv_disconnect.py - disconnect remote-viewer - -Requires: connected binaries remote-viewer, Xorg, gnome session - -""" -import logging, os - -def run_rv_disconnect(test, params, env): - """ - Tests disconnection of remote-viewer. - - @param test: QEMU test object. @param params: Dictionary with the test parameters. - @param env: Dictionary with test environment. - """ - - guest_vm = env.get_vm(params["guest_vm"]) - guest_vm.verify_alive() - guest_session = guest_vm.wait_for_login( - timeout=int(params.get("login_timeout", 360))) - - client_vm = env.get_vm(params["client_vm"]) - client_vm.verify_alive() - client_session = client_vm.wait_for_login( - timeout=int(params.get("login_timeout", 360))) - - #get PID of remote-viewer and kill it - logging.info("Get PID of remote-viewer") - client_session.cmd("pgrep remote-viewer") - - logging.info("Try to kill remote-viewer") - client_session.cmd("pkill %s" % params.get("rv_binary")\ - .split(os.path.sep)[-1]) - - guest_vm.verify_alive() - - client_session.close() - guest_session.close() diff --git a/tests/rv_smartcard.py b/tests/rv_smartcard.py new file mode 100644 index 000000000..1b0339b42 --- /dev/null +++ b/tests/rv_smartcard.py @@ -0,0 +1,167 @@ +""" +rv_smartcard.py - Testing software smartcards using remote-viewer + +Requires: connected binaries remote-viewer, Xorg, gnome session + +The test also assumes that the guest is setup with the correct +options to handle smartcards. + +""" +import logging +from virttest import aexpect +from autotest.client.shared import error + + +def run_rv_smartcard(test, params, env): + """ + Tests disconnection of remote-viewer. + + @param test: QEMU test object. + @param params: Dictionary with the test parameters. + @param env: Dictionary with test environment. + """ + #Get the required parameters needed for the tests + cert_list = params.get("gencerts").split(",") + cert_db = params.get("certdb") + smartcard_testtype = params.get("smartcard_testtype") + listcerts_output = "" + certsinfo_output = "" + searchstr = params.get("certcheckstr") + certstr = params.get("certcheckstr2") + certcheck1 = params.get("certcheck3") + certcheck2 = params.get("certcheck4") + + guest_vm = env.get_vm(params["guest_vm"]) + guest_vm.verify_alive() + guest_session = guest_vm.wait_for_login( + timeout=int(params.get("login_timeout", 360)), + username="root", password="123456") + + client_vm = env.get_vm(params["client_vm"]) + client_vm.verify_alive() + + client_session = client_vm.wait_for_login( + timeout=int(params.get("login_timeout", 360)), + username="root", password="123456") + #Verify remote-viewer is running + try: + pid = client_session.cmd("pgrep remote-viewer") + logging.info("remote-viewer is running as PID %s", pid.strip()) + except: + raise error.TestFail("remote-viewer is not running") + + #verify the smart card reader can be seen + output = guest_session.cmd("lsusb") + logging.debug("lsusb output: " + output) + if "Gemplus GemPC433-Swap" in output: + logging.info("Smartcard reader, Gemplus GemPC433-Swap detected.") + else: + raise error.TestFail("No smartcard reader found") + + + if smartcard_testtype == "pkcs11_listcerts": + #pkcs11_listcerts not installed until Smart Card Support is installed + try: + output = guest_session.cmd_output("pkcs11_listcerts") + except aexpect.ShellTimeoutError: + #Expected to get a shell timeout error, + # listing certs prompts for PIN + try: + #Send a carriage return for PIN for token + listcerts_output = guest_session.cmd("") + except: + raise error.TestFail("Test failed trying to get the output" + " of pkcs11_listcerts") + + logging.info("Listing Certs available on the guest: " + + listcerts_output) + + for cert in cert_list: + subj_string = "CN=" + cert + if subj_string in listcerts_output: + logging.debug(subj_string + " has been found" + + " as a listed cert in the guest") + else: + raise error.TestFail("Certificate %s was not found as a listed" + " cert in the guest" % subj_string) + elif smartcard_testtype == "pklogin_finder": + #pkcs11_listcerts not installed until + #Smart Card Support is installed + try: + certsinfo_output = guest_session.cmd("pklogin_finder debug") + except aexpect.ShellTimeoutError: + #Expected to get a shell timeout error, + #listing certs prompts for PIN + try: + #Send a carriage return for PIN for token + certsinfo_output = guest_session.cmd("", ok_status=[0, 1]) + except: + raise error.TestFail("Test failed trying to get the output" + " of pklogin_finder") + testindex = certsinfo_output.find(searchstr) + if testindex >= 0: + string_aftercheck = certsinfo_output[testindex:] + + #Loop through the cert list. and check for the expected data, and + for index, cert in enumerate(cert_list): + subj_string = "CN=" + cert + checkstr = certstr + str(index+1) + testindex = string_aftercheck.find(checkstr) + #print testindex + if testindex >= 0: + logging.debug("Found " + checkstr + "in output of pklogin") + string_aftercheck = string_aftercheck[testindex:] + testindex2 = string_aftercheck.find(subj_string) + if testindex >= 0: + logging.debug("Found " + subj_string + + "in output of pklogin") + string_aftercheck = string_aftercheck[testindex2:] + testindex3 = string_aftercheck.find(certcheck1) + if testindex3 >= 0: + logging.debug("Found " + certcheck1 + + "in output of pklogin") + string_aftercheck = string_aftercheck[testindex3:] + testindex4 = string_aftercheck.find(certcheck2) + if testindex4 >= 0: + logging.debug("Found " + certcheck2 + + "in output of pklogin") + else: + raise error.TestFail(certcheck2 + " not found" + " in output of pklogin " + "on the guest") + else: + raise error.TestFail(certcheck1 + " not found in " + "output of pklogin on the" + " guest") + else: + raise error.TestFail("Common name %s, not found " + "in pkogin_finder after software " + "smartcard was inserted into the " + "guest" % subj_string) + + else: + raise error.TestFail(checkstr + " not found in output of " + "pklogin on the guest") + + else: + raise error.TestFail(searchstr + " not found in output of pklogin" + " on the guest") + + logging.info("Certs Info on the guest: " + certsinfo_output) + else: + raise error.TestFail("Please specify a valid smartcard testype") + + #Do some cleanup, remove the certs on the client + #for each cert listed by the test, create it on the client + for cert in cert_list: + cmd = "certutil " + cmd += "-D -n '" + cert + "' -d " + cert_db + try: + output = client_session.cmd(cmd) + except aexpect.ShellCmdError: + logging.warning("Deleting of %s certificate from the client failed", + cert) + logging.debug("Output of " + cmd + ": " + output) + + client_session.close() + guest_session.close() diff --git a/tests/rv_vdagent.py b/tests/rv_vdagent.py new file mode 100644 index 000000000..c4e93d9ce --- /dev/null +++ b/tests/rv_vdagent.py @@ -0,0 +1,97 @@ +""" +rv_vdagent.py - basic tests to verify, vdagent status, starting, stopping, +and restarting correctly. + +Requires: connected binaries remote-viewer, Xorg, gnome session + +""" +from autotest.client.shared import error +from virttest import utils_spice + +def run_rv_vdagent(test, params, env): + """ + Tests spice vdagent (starting, stopping, restarting, and status) + + @param test: QEMU test object. + @param params: Dictionary with the test parameters. + @param env: Dictionary with test environment. + """ + # Get necessary params + test_timeout = float(params.get("test_timeout", 600)) + vdagent_test = params.get("vdagent_test") + + guest_vm = env.get_vm(params["guest_vm"]) + guest_vm.verify_alive() + guest_root_session = guest_vm.wait_for_login( + timeout=int(params.get("login_timeout", 360)), + username="root", password="123456") + + client_vm = env.get_vm(params["client_vm"]) + client_vm.verify_alive() + client_session = client_vm.wait_for_login( + timeout=int(params.get("login_timeout", 360))) + + vdagent_status = utils_spice.get_vdagent_status(guest_root_session, test_timeout) + + #start test + if vdagent_test == "start": + if "running" in vdagent_status: + #stop the service prior to starting + utils_spice.stop_vdagent(guest_root_session, test_timeout) + utils_spice.start_vdagent(guest_root_session, test_timeout) + else: + utils_spice.start_vdagent(guest_root_session, test_timeout) + #Verify the status of vdagent is running + status = utils_spice.get_vdagent_status(guest_root_session, test_timeout) + if "running" in status: + pass + else: + raise error.TestFail("Vdagent status is not running after a start attempt.") + #stop test + elif vdagent_test == "stop": + if "stopped" in vdagent_status: + #start the service prior to stopping the service + utils_spice.start_vdagent(guest_root_session, test_timeout) + utils_spice.stop_vdagent(guest_root_session, test_timeout) + else: + utils_spice.stop_vdagent(guest_root_session, test_timeout) + #Verify the status of vdagent is stopped + status = utils_spice.get_vdagent_status(guest_root_session, test_timeout) + if "stopped" in status: + pass + else: + print "Status: " + status + raise error.TestFail("Vdagent status is not stopped after a stop attempt.") + #restart test when vdagent service is running + elif vdagent_test == "restart_start": + if "stopped" in vdagent_status: + #start the service prior to stopping the service + utils_spice.start_vdagent(guest_root_session, test_timeout) + utils_spice.restart_vdagent(guest_root_session, test_timeout) + else: + utils_spice.restart_vdagent(guest_root_session, test_timeout) + #Verify the status of vdagent is started + status = utils_spice.get_vdagent_status(guest_root_session, test_timeout) + if "running" in status: + pass + else: + raise error.TestFail("Vdagent status is not started after a restart attempt.") + #restart test when vdagent service is stopped + elif vdagent_test == "restart_stop": + if "running" in vdagent_status: + #start the service prior to stopping the service + utils_spice.stop_vdagent(guest_root_session, test_timeout) + utils_spice.restart_vdagent(guest_root_session, test_timeout) + else: + utils_spice.restart_vdagent(guest_root_session, test_timeout) + #Verify the status of vdagent is started + status = utils_spice.get_vdagent_status(guest_root_session, test_timeout) + if "running" in status: + pass + else: + raise error.TestFail("Vdagent status is not started after a restart attempt.") + else: + raise error.TestFail("No test to run, check value of vdagent_test") + + client_session.close() + guest_root_session.close() diff --git a/tests/rv_video.py b/tests/rv_video.py new file mode 100644 index 000000000..c2a3670a8 --- /dev/null +++ b/tests/rv_video.py @@ -0,0 +1,82 @@ +""" +rv_video.py - Starts video player +Video is played in a loop, usually kill_app +test should be called later to close totem. + +Requires: binaries Xorg, totem, gnome-session + Test starts video player + +""" +import logging, os +from virttest import utils_misc, remote + + +def launch_totem(guest_session, params): + """ + Launch Totem player + + @param guest_vm - vm object + """ + + totem_version = guest_session.cmd('totem --version') + logging.info("Totem version: %s", totem_version) + + #repeat parameters for totem + logging.info("Set up video repeat to '%s' to the Totem.", + params.get("repeat_video")) + + if params.get("repeat_video") == "yes": + cmd = "gconftool-2 --set /apps/totem/repeat -t bool true" + else: + cmd = "gconftool-2 --set /apps/totem/repeat -t bool false" + + guest_session.cmd(cmd) + + cmd = "export DISPLAY=:0.0" + guest_session.cmd(cmd) + + #fullscreen parameters for totem + if params.get("fullscreen"): + fullscreen = " --fullscreen " + else: + fullscreen = "" + + cmd = "nohup totem %s %s --display=:0.0 --play &> /dev/null &" \ + % (fullscreen, params.get("destination_video_file_path")) + guest_session.cmd(cmd) + +def deploy_video_file(test, vm_obj, params): + """ + Deploy video file into destination on vm + + @param vm_obj - vm object + @param params: Dictionary with the test parameters. + """ + source_video_file = params.get("source_video_file") + video_dir = os.path.join("deps", source_video_file) + video_path = utils_misc.get_path(test.virtdir, video_dir) + + remote.copy_files_to(vm_obj.get_address(), 'scp', + params.get("username"), + params.get("password"), + params.get("shell_port"), + video_path, + params.get("destination_video_file_path")) + +def run_rv_video(test, params, env): + """ + Test of video through spice + + @param test: KVM test object. + @param params: Dictionary with the test parameters. + @param env: Dictionary with test environment. + """ + + guest_vm = env.get_vm(params["guest_vm"]) + guest_vm.verify_alive() + guest_session = guest_vm.wait_for_login( + timeout=int(params.get("login_timeout", 360))) + deploy_video_file(test, guest_vm, params) + + launch_totem(guest_session, params) + guest_session.close() diff --git a/tests/rv_vmshutdown.py b/tests/rv_vmshutdown.py index a5ba1c966..7269d258f 100644 --- a/tests/rv_vmshutdown.py +++ b/tests/rv_vmshutdown.py @@ -71,7 +71,7 @@ def run_rv_vmshutdown(test, params, env): #wait for the guest vm to be shutoff logging.info("Waiting for the guest VM to be shutoff") - utils_misc.wait_for(guest_vm.is_dead, 70, 30, 1, "waiting...") + utils_misc.wait_for(guest_vm.is_dead, 90, 30, 1, "waiting...") logging.info("Guest VM is now shutoff") #Verify there was a clean exit by diff --git a/tests/smartcard_setup.py b/tests/smartcard_setup.py new file mode 100644 index 000000000..814bbccfe --- /dev/null +++ b/tests/smartcard_setup.py @@ -0,0 +1,73 @@ +""" +smartcard_setup.py - Used as a setup test for smartcard tests. + +Before doing a remote viewer connection there is some setup required +for smartcard tests: + +On the client, certs that will be put into the smartcard will need +to be generated. + +""" +import logging +from virttest import utils_misc, utils_spice, aexpect +from autotest.client.shared import error + +def run_smartcard_setup(test, params, env): + """ + Simple setup test to create certs on the client to be passed to VM's + smartcard. + + @param test: QEMU test object. + @param params: Dictionary with the test parameters. + @param env: Dictionary with test environment. + """ + # Get necessary params + cert_list = params.get("gencerts").split(",") + cert_db = params.get("certdb") + self_sign = params.get("self_sign") + cert_trustargs = params.get("trustargs") + + logging.debug("Cert List:") + for cert in cert_list: + logging.debug(cert) + logging.debug(cert_trustargs) + logging.debug("CN=" + cert) + logging.debug(cert_db) + + + client_vm = env.get_vm(params["client_vm"]) + client_vm.verify_alive() + + client_session = client_vm.wait_for_login( + timeout=int(params.get("login_timeout", 360)), + username="root", password="123456") + + #generate a random string, used to create a random key for the certs + randomstring = utils_misc.generate_random_string(2048) + cmd = "echo '" + randomstring + "' > /tmp/randomtext.txt" + output = client_session.cmd(cmd) + #output2 = client_session.cmd("cat /tmp/randomtext.txt") + utils_spice.wait_timeout(5) + + #for each cert listed by the test, create it on the client + for cert in cert_list: + cmd = "certutil " + if self_sign: + cmd += " -x " + cmd += "-t '" + cert_trustargs + "' -S -s " + "'CN=" + cert + cmd += "' -n '" + cert + "' -d " + cert_db + cmd += " -z " + "/tmp/randomtext.txt" + logging.debug(cmd) + output = client_session.cmd(cmd) + logging.debug("Cert Created: " + output) + + cmd = "certutil -L -d " + cert_db + output = client_session.cmd(cmd) + logging.info("Listing all certs on the client: " + output) + + #Verify that all the certs have been generated on the client + for cert in cert_list: + if not(cert in output): + raise error.TestFail("Certificate %s not found" % cert) + + client_session.close() diff --git a/tests/trans_hugepage_memory_stress.py b/tests/trans_hugepage_memory_stress.py index 573522760..3da966bb9 100644 --- a/tests/trans_hugepage_memory_stress.py +++ b/tests/trans_hugepage_memory_stress.py @@ -1,7 +1,14 @@ import logging, os -from autotest.client.shared import error, utils +from autotest.client.shared import error +from autotest.client import utils from virttest import utils_test +try: + from autotest.client.shared import utils_memory +except ImportError: + from virttest.staging import utils_memory + + @error.context_aware def run_trans_hugepage_memory_stress(test, params, env): """ @@ -31,9 +38,10 @@ def run_trans_hugepage_memory_stress(test, params, env): try: # Allocated free memory to hugetlbfs - mem_free = int(utils.read_from_meminfo('MemFree')) / 1024 - mem_swap = int(utils.read_from_meminfo('SwapFree')) / 1024 - hugepage_size = int (utils.read_from_meminfo('Hugepagesize')) / 1024 + mem_free = int(utils_memory.read_from_meminfo('MemFree')) / 1024 + mem_swap = int(utils_memory.read_from_meminfo('SwapFree')) / 1024 + hugepage_size = (int (utils_memory.read_from_meminfo('Hugepagesize')) + / 1024) nr_hugetlbfs = (mem_free + mem_swap - mem - qemu_mem) / hugepage_size fd = open(hugetlbfs_path, "w") fd.write(str(nr_hugetlbfs)) @@ -41,7 +49,7 @@ def run_trans_hugepage_memory_stress(test, params, env): error.context("Memory stress test") - nr_ah.append(int(utils.read_from_meminfo('AnonHugePages'))) + nr_ah.append(int(utils_memory.read_from_meminfo('AnonHugePages'))) if nr_ah[0] <= 0: raise error.TestFail("VM is not using transparent hugepage") @@ -50,7 +58,7 @@ def run_trans_hugepage_memory_stress(test, params, env): utils_test.run_virt_sub_test(test, params, env, sub_type=memory_stress_test) - nr_ah.append(int(utils.read_from_meminfo('AnonHugePages'))) + nr_ah.append(int(utils_memory.read_from_meminfo('AnonHugePages'))) logging.debug("The huge page using for guest is: %s" % nr_ah) if nr_ah[1] <= nr_ah[0]: diff --git a/tests/trans_hugepage_relocated.py b/tests/trans_hugepage_relocated.py index d87d9c523..f23c30cdb 100644 --- a/tests/trans_hugepage_relocated.py +++ b/tests/trans_hugepage_relocated.py @@ -1,8 +1,13 @@ import logging, time, commands, os, re from autotest.client.shared import error -from autotest.client import utils from virttest import utils_test +try: + from autotest.client.shared import utils_memory +except ImportError: + from virttest.staging import utils_memory + + def run_trans_hugepage_relocated(test, params, env): """ Transparent hugepage relocated test with quantification. @@ -20,7 +25,7 @@ def run_trans_hugepage_relocated(test, params, env): def nr_hugepage_check(sleep_time, wait_time): time_last = 0 while True: - value = int(utils.read_from_meminfo("AnonHugePages")) + value = int(utils_memory.read_from_meminfo("AnonHugePages")) nr_hugepages.append(value) time_stamp = time.time() if time_last != 0: @@ -39,8 +44,8 @@ def nr_hugepage_check(sleep_time, wait_time): vm.verify_alive() session = vm.wait_for_login(timeout=login_timeout) - free_memory = utils.read_from_meminfo("MemFree") - hugepage_size = utils.read_from_meminfo("Hugepagesize") + free_memory = utils_memory.read_from_meminfo("MemFree") + hugepage_size = utils_memory.read_from_meminfo("Hugepagesize") mem = params.get("mem") vmsm = int(mem) + 128 hugetlbfs_path = params.get("hugetlbfs_path", "/proc/sys/vm/nr_hugepages") diff --git a/tests/unattended_install.py b/tests/unattended_install.py index 736c0da32..aed4b9349 100644 --- a/tests/unattended_install.py +++ b/tests/unattended_install.py @@ -1,11 +1,13 @@ import logging, time, re, os, tempfile, ConfigParser -import threading +import threading, shutil import xml.dom.minidom +import errno from autotest.client.shared import error, iso9660 from autotest.client import utils from virttest import virt_vm, utils_misc, utils_disk from virttest import qemu_monitor, remote, syslog_server -from virttest import http_server, data_dir, utils_net +from virttest import http_server, data_dir, utils_net, utils_test +from virttest import funcatexit # Whether to print all shell commands called @@ -118,6 +120,7 @@ def __init__(self, test, params, vm): root_dir = data_dir.get_data_dir() self.deps_dir = os.path.join(test.virtdir, 'deps') self.unattended_dir = os.path.join(test.virtdir, 'unattended') + self.results_dir = test.debugdir self.params = params self.attributes = ['kernel_args', 'finish_program', 'cdrom_cd1', @@ -126,17 +129,24 @@ def __init__(self, test, params, vm): 'floppy_name', 'cdrom_unattended', 'boot_path', 'kernel_params', 'extra_params', 'qemu_img_binary', 'cdkey', 'finish_program', 'vm_type', - 'process_check', 'vfd_size'] + 'process_check', 'vfd_size', 'cdrom_mount_point', + 'floppy_mount_point', 'cdrom_virtio', + 'virtio_floppy', 're_driver_match', + 're_hardware_id', 'driver_in_floppy'] for a in self.attributes: setattr(self, a, params.get(a, '')) - if self.install_virtio == 'yes': - v_attributes = ['virtio_floppy', 'virtio_storage_path', - 'virtio_network_path', 'virtio_oemsetup_id', - 'virtio_network_installer_path'] - for va in v_attributes: - setattr(self, va, params.get(va, '')) + # Will setup the virtio attributes + v_attributes = ['virtio_floppy', 'virtio_storage_path', + 'virtio_network_path', 'virtio_oemsetup_id', + 'virtio_network_installer_path', + 'virtio_balloon_installer_path', + 'virtio_qxl_installer_path', + 'virtio_scsi_cdrom'] + + for va in v_attributes: + setattr(self, va, params.get(va, '')) self.tmpdir = test.tmpdir @@ -162,6 +172,13 @@ def __init__(self, test, params, vm): if getattr(self, 'cdrom_unattended'): self.cdrom_unattended = os.path.join(root_dir, self.cdrom_unattended) + + if getattr(self, 'virtio_floppy'): + self.virtio_floppy = os.path.join(root_dir, self.virtio_floppy) + + if getattr(self, 'cdrom_virtio'): + self.cdrom_virtio = os.path.join(root_dir, self.cdrom_virtio) + if getattr(self, 'kernel'): self.kernel = os.path.join(root_dir, self.kernel) if getattr(self, 'initrd'): @@ -203,6 +220,91 @@ def __init__(self, test, params, vm): self.vm = vm + @error.context_aware + def get_driver_hardware_id(self, driver, run_cmd=True): + """ + Get windows driver's hardware id from inf files. + + @param dirver: Configurable driver name. + @param run_cmd: Use hardware id in windows cmd command or not. + @param return: Windows driver's hardware id + """ + if not os.path.exists(self.cdrom_mount_point): + os.mkdir(self.cdrom_mount_point) + if not os.path.exists(self.floppy_mount_point): + os.mkdir(self.floppy_mount_point) + if not os.path.ismount(self.cdrom_mount_point): + utils.system("mount %s %s -o loop" % (self.cdrom_virtio, + self.cdrom_mount_point), timeout=60) + if not os.path.ismount(self.floppy_mount_point): + utils.system("mount %s %s -o loop" % (self.virtio_floppy, + self.floppy_mount_point), timeout=60) + drivers_d = [] + driver_link = None + if self.driver_in_floppy is not None: + driver_in_floppy = self.driver_in_floppy + drivers_d = driver_in_floppy.split() + else: + drivers_d.append('qxl.inf') + for driver_d in drivers_d: + if driver_d in driver: + driver_link = os.path.join(self.floppy_mount_point, driver) + if driver_link is None: + driver_link = os.path.join(self.cdrom_mount_point, driver) + try: + txt = open(driver_link, "r").read() + hwid = re.findall(self.re_hardware_id, txt)[-1].rstrip() + if run_cmd: + hwid = '^&'.join(hwid.split('&')) + return hwid + except Exception, e: + logging.error("Fail to get hardware id with exception: %s" % e) + + + @error.context_aware + def update_driver_hardware_id(self, driver): + """ + Update driver string with the hardware id get from inf files + + @driver: driver string + @return new driver string + """ + if 'hwid' in driver: + if 'hwidcmd' in driver: + run_cmd = True + else: + run_cmd = False + if self.re_driver_match is not None: + d_str = self.re_driver_match + else: + d_str = "(\S+)\s*hwid" + + drivers_in_floppy = [] + if self.driver_in_floppy is not None: + drivers_in_floppy = self.driver_in_floppy.split() + + + mount_point = self.cdrom_mount_point + storage_path = self.cdrom_virtio + for driver_in_floppy in drivers_in_floppy: + if driver_in_floppy in driver: + mount_point = self.floppy_mount_point + storage_path = self.virtio_floppy + break + + d_link = re.findall(d_str, driver)[0].split(":")[1] + d_link = "/".join(d_link.split("\\\\")[1:]) + hwid = utils_test.get_driver_hardware_id(d_link, mount_point, + storage_path, + run_cmd=run_cmd) + if hwid: + driver = driver.replace("hwidcmd", hwid.strip()) + else: + raise error.TestError("Can not find hwid from the driver" + " inf file") + return driver + + def answer_kickstart(self, answer_path): """ Replace KVM_TEST_CDKEY (in the unattended file) with the cdkey @@ -266,28 +368,39 @@ def answer_windows_ini(self, answer_path): else: parser.remove_option('Unattended', 'OemPnPDriversPath') - # Replace the virtio installer command - if self.install_virtio == 'yes': - driver = self.virtio_network_installer_path - else: - driver = 'dir' - - dummy_re = 'KVM_TEST_VIRTIO_NETWORK_INSTALLER' - installer = parser.get('GuiRunOnce', 'Command0') - if dummy_re in installer: - installer = re.sub(dummy_re, driver, installer) - parser.set('GuiRunOnce', 'Command0', installer) + dummy_re_dirver = {'KVM_TEST_VIRTIO_NETWORK_INSTALLER': + 'virtio_network_installer_path', + 'KVM_TEST_VIRTIO_BALLOON_INSTALLER': + 'virtio_balloon_installer_path', + 'KVM_TEST_VIRTIO_QXL_INSTALLER': + 'virtio_qxl_installer_path'} + dummy_re = "" + for dummy in dummy_re_dirver: + if dummy_re: + dummy_re += "|%s" % dummy + else: + dummy_re = dummy # Replace the process check in finish command dummy_process_re = r'\bPROCESS_CHECK\b' for opt in parser.options('GuiRunOnce'): - process_check = parser.get('GuiRunOnce', opt) - if re.search(dummy_process_re, process_check): + check = parser.get('GuiRunOnce', opt) + if re.search(dummy_process_re, check): process_check = re.sub(dummy_process_re, - "%s" % self.process_check, - process_check) + "%s" % self.process_check, + check) parser.set('GuiRunOnce', opt, process_check) - + elif re.findall(dummy_re, check): + dummy = re.findall(dummy_re, check)[0] + driver = getattr(self, dummy_re_dirver[dummy]) + if driver.endswith("msi"): + driver = 'msiexec /passive /package ' + driver + elif 'INSTALLER' in dummy: + driver = self.update_driver_hardware_id(driver) + elif driver is None: + driver = 'dir' + check = re.sub(dummy, driver, check) + parser.set('GuiRunOnce', opt, check) # Now, writing the in memory config state to the unattended file fp = open(answer_path, 'w') parser.write(fp) @@ -308,8 +421,12 @@ def answer_windows_xml(self, answer_path): if self.cdkey: # First, replacing the CDKEY product_key = doc.getElementsByTagName('ProductKey')[0] - key = product_key.getElementsByTagName('Key')[0] - key_text = key.childNodes[0] + if product_key.getElementsByTagName('Key'): + key = product_key.getElementsByTagName('Key')[0] + key_text = key.childNodes[0] + else: + key_text = product_key.childNodes[0] + assert key_text.nodeType == doc.TEXT_NODE key_text.data = self.cdkey else: @@ -320,6 +437,8 @@ def answer_windows_xml(self, answer_path): # component PnpCustomizationsWinPE Element Node if self.install_virtio == 'yes': paths = doc.getElementsByTagName("Path") + if self.virtio_scsi_cdrom == 'yes': + self.virtio_network_path = self.virtio_storage_path values = [self.virtio_storage_path, self.virtio_network_path] for path, value in zip(paths, values): path_text = path.childNodes[0] @@ -336,22 +455,36 @@ def answer_windows_xml(self, answer_path): # Last but not least important, replacing the virtio installer command # And process check in finish command command_lines = doc.getElementsByTagName("CommandLine") + dummy_re_dirver = {'KVM_TEST_VIRTIO_NETWORK_INSTALLER': + 'virtio_network_installer_path', + 'KVM_TEST_VIRTIO_BALLOON_INSTALLER': + 'virtio_balloon_installer_path', + 'KVM_TEST_VIRTIO_QXL_INSTALLER': + 'virtio_qxl_installer_path'} + process_check_re = 'PROCESS_CHECK' + dummy_re = "" + for dummy in dummy_re_dirver: + if dummy_re: + dummy_re += "|%s" % dummy + else: + dummy_re = dummy + for command_line in command_lines: command_line_text = command_line.childNodes[0] assert command_line_text.nodeType == doc.TEXT_NODE - dummy_re = 'KVM_TEST_VIRTIO_NETWORK_INSTALLER' - process_check_re = 'PROCESS_CHECK' - if (self.install_virtio == 'yes' and - hasattr(self, 'virtio_network_installer_path')): - driver = self.virtio_network_installer_path - else: - driver = 'dir' - if driver.endswith("msi"): - driver = 'msiexec /passive /package ' + driver - if dummy_re in command_line_text.data: + + if re.findall(dummy_re, command_line_text.data): + dummy = re.findall(dummy_re, command_line_text.data)[0] + driver = getattr(self, dummy_re_dirver[dummy]) + + if driver.endswith("msi"): + driver = 'msiexec /passive /package ' + driver + elif 'INSTALLER' in dummy: + driver = self.update_driver_hardware_id(driver) t = command_line_text.data t = re.sub(dummy_re, driver, t) command_line_text.data = t + if process_check_re in command_line_text.data: t = command_line_text.data t = re.sub(process_check_re, self.process_check, t) @@ -785,6 +918,12 @@ def setup(self): self.medium) if self.unattended_file and (self.floppy or self.cdrom_unattended): self.setup_boot_disk() + if self.params.get("store_boot_disk") == "yes": + logging.info("Sotre the boot disk to result directory for" + " further debug") + src_dir = self.floppy or self.cdrom_unattended + dst_dir = self.results_dir + shutil.copy(src_dir, dst_dir) # Update params dictionary as some of the values could be updated for a in self.attributes: @@ -820,6 +959,15 @@ def terminate_syslog_server_thread(): return False +def copy_file_from_nfs(src, dst, mount_point, image_name): + logging.info("Test failed before the install process start." + " So just copy a good image from nfs for following tests.") + utils_misc.mount(src, mount_point, "nfs", perm="ro") + image_src = utils_misc.get_path(mount_point, image_name) + shutil.copy(image_src, dst) + utils_misc.umount(src, mount_point, "nfs") + + @error.context_aware def run_unattended_install(test, params, env): """ @@ -831,7 +979,54 @@ def run_unattended_install(test, params, env): @param params: Dictionary with the test parameters. @param env: Dictionary with test environment. """ + @error.context_aware + def copy_images(): + error.base_context("Copy image from NFS after installation failure") + image_copy_on_error = params.get("image_copy_on_error", "yes") + if "yes" in image_copy_on_error: + try: + error.context("Quit qemu-kvm before copying guest image") + vm.monitor.quit() + except Exception, e: + logging.warn(e) + from autotest.client.virt.tests import image_copy + error.context("Copy image from NFS Server") + image_copy.run_image_copy(test, params, env) + + image = '%s.%s' % (params['image_name'], params['image_format']) + image_name = os.path.basename(image) + src = params.get('images_good') + dst = '%s/%s' % (data_dir.get_data_dir(), image) + mount_point = params.get("dst_dir") + if mount_point and src: + funcatexit.register(env, params.get("type"), copy_file_from_nfs, src, + dst, mount_point, image_name) + vm = env.get_vm(params["main_vm"]) + local_dir = params.get("local_dir") + if local_dir: + local_dir = utils_misc.get_path(test.bindir, local_dir) + else: + local_dir = test.bindir + if params.get("copy_to_local"): + for param in params.get("copy_to_local").split(): + l_value = params.get(param) + if l_value: + need_copy = True + nfs_link = utils_misc.get_path(test.bindir, l_value) + i_name = os.path.basename(l_value) + local_link = os.path.join(local_dir, i_name) + if os.path.isfile(local_link): + file_hash = utils.hash_file(local_link, "md5") + expected_hash = utils.hash_file(nfs_link, "md5") + if file_hash == expected_hash: + need_copy = False + if need_copy: + msg = "Copy %s to %s in local host." % (i_name, local_link) + error.context(msg, logging.info) + utils.get_file(nfs_link, local_link) + params[param] = local_link + unattended_install_config = UnattendedInstallConfig(test, params, vm) unattended_install_config.setup() @@ -841,7 +1036,7 @@ def run_unattended_install(test, params, env): post_finish_str = params.get("post_finish_str", "Post set up finished") - install_timeout = int(params.get("timeout", 3000)) + install_timeout = int(params.get("install_timeout", 3000)) migrate_background = params.get("migrate_background") == "yes" if migrate_background: @@ -853,6 +1048,27 @@ def run_unattended_install(test, params, env): error.context("waiting for installation to finish") start_time = time.time() + + try: + serial_name = vm.serial_ports[0] + except IndexError: + raise virt_vm.VMConfigMissingError(vm.name, "isa_serial") + except AttributeError: + serial_name = "libvirt" + + log_file = utils_misc.get_path(test.debugdir, + "serial-%s-%s.log" % (serial_name, + vm.name)) + serial_log_msg = "" + serial_log_file = None + + # As the the install process start. We may need collect informations from + # the image. So use the test case instead this simple function in the + # following code. + if mount_point and src: + funcatexit.unregister(env, params.get("type"), copy_file_from_nfs, + src, dst, mount_point, image_name) + while (time.time() - start_time) < install_timeout: try: vm.verify_alive() @@ -862,11 +1078,38 @@ def run_unattended_install(test, params, env): if params.get("wait_no_ack", "no") == "yes": break else: + # Print out the original exception before copying images. + logging.error(e) + copy_images() raise e - test.verify_background_errors() - finish_signal = vm.serial_console.get_output() + + try: + test.verify_background_errors() + except Exception, e: + copy_images() + raise e + + # To ignore the try:except:finally problem in old version of python + try: + try: + serial_log_file = open(log_file, 'r') + serial_log_msg = serial_log_file.read() + except Exception, e: + if e.errno == errno.ENOENT: + logging.warn("Log file '%s' doesn't exist," + " just create it.", log_file) + try: + open(log_file, 'w').close() + except Exception: + pass + else: + logging.warn("Can not read from serail log file: %s", e) + finally: + if serial_log_file and not serial_log_file.closed: + serial_log_file.close() + if (params.get("wait_no_ack", "no") == "no" and - (post_finish_str in finish_signal)): + (post_finish_str in serial_log_msg)): break # Due to libvirt automatically start guest after import @@ -883,6 +1126,9 @@ def run_unattended_install(test, params, env): else: time.sleep(1) else: + logging.warn("Timeout elapsed while waiting for install to finish." + "Will run image_copy to copy image from NFS.") + copy_images() raise error.TestFail("Timeout elapsed while waiting for install to " "finish") diff --git a/virt.py b/virt.py index 8316d8e82..c7b72e140 100644 --- a/virt.py +++ b/virt.py @@ -121,7 +121,7 @@ def run_once(self, params): f.close() # Preprocess try: - env_process.preprocess(self, params, env) + params = env_process.preprocess(self, params, env) finally: env.save() # Run the test function diff --git a/virttest/aexpect.py b/virttest/aexpect.py index 08646cd28..97ccdd5f3 100755 --- a/virttest/aexpect.py +++ b/virttest/aexpect.py @@ -342,7 +342,7 @@ def run_fg(command, output_func=None, output_prefix="", timeout=1.0): return (status, output) -class Spawn: +class Spawn(object): """ This class is used for spawning and controlling a child process. @@ -457,6 +457,10 @@ def __init__(self, command=None, a_id=None, auto_close=False, echo=False, # The following two functions are defined to make sure the state is set # exclusively by the constructor call as specified in __getinitargs__(). + def __reduce__(self): + return self.__class__, (self.__getinitargs__()) + + def __getstate__(self): pass @@ -722,6 +726,10 @@ def __init__(self, command=None, a_id=None, auto_close=False, echo=False, self._start_thread() + def __reduce__(self): + return self.__class__, (self.__getinitargs__()) + + def __getinitargs__(self): return Spawn.__getinitargs__(self) + (self.termination_func, self.termination_params, @@ -919,6 +927,10 @@ def __init__(self, command=None, a_id=None, auto_close=True, echo=False, output_func, output_params, output_prefix) + def __reduce__(self): + return self.__class__, (self.__getinitargs__()) + + def __getinitargs__(self): return Tail.__getinitargs__(self) @@ -1201,6 +1213,10 @@ def __init__(self, command=None, a_id=None, auto_close=True, echo=False, self.status_test_command = status_test_command + def __reduce__(self): + return self.__class__, (self.__getinitargs__()) + + def __getinitargs__(self): return Expect.__getinitargs__(self) + (self.prompt, self.status_test_command) diff --git a/virttest/build_helper.py b/virttest/build_helper.py index 287990873..928e11f11 100644 --- a/virttest/build_helper.py +++ b/virttest/build_helper.py @@ -75,8 +75,7 @@ def _parse_params(self): else: logging.debug('Git repo %s tag: %s' % (self.name, self.tag)) - self.key_id = None - self.key_server = None + self.key_file = None tag_signed = self.params.get('%s_tag_signed' % config_prefix) if tag_signed is None: logging.warning('Git repo %s tag is not signed' % self.name) @@ -84,10 +83,15 @@ def _parse_params(self): 'made by whomever claims to have made it ' '(dangerous)') else: - self.key_server, self.key_id = tag_signed.split(":") - logging.debug('Git repo %s tag %s was signed with GPG key ID %s ' - 'present on key server %s', self.name, self.tag, - self.key_id, self.key_server) + self.key_file = os.path.join(data_dir.get_data_dir(), 'gpg', + tag_signed) + if os.path.isfile(self.key_file): + logging.debug('Git repo %s tag %s will be verified with public ' + 'key file %s', self.name, self.tag, self.key_file) + else: + raise error.TestError('GPG public key file %s not found, will ' + 'not proceed with testing' % + self.key_file) self.cmd = os_dep.command('git') @@ -106,12 +110,14 @@ def execute(self): if self.tag: utils.system('git checkout %s' % self.tag) - if self.key_server is not None and self.key_id is not None: + if self.key_file is not None: try: - logging.debug('Downloading GPG key ID %s from key server ' - '%s', self.key_id, self.key_server) - utils.system('gpg --batch --keyserver %s --recv-keys %s' % - (self.key_server, self.key_id)) + gnupg_home = os.path.join(os.path.dirname(self.key_file), + 'gnupg') + if not os.path.isdir(gnupg_home): + os.makedirs(gnupg_home) + os.environ['GNUPGHOME'] = gnupg_home + utils.system('gpg --import %s' % self.key_file) logging.debug('Verifying if tag is actually signed with ' 'GPG key ID %s' % self.key_id) utils.system('git tag -v %s' % self.tag) diff --git a/virttest/cartesian_config.py b/virttest/cartesian_config.py index 65b88b5f9..3b8f17685 100755 --- a/virttest/cartesian_config.py +++ b/virttest/cartesian_config.py @@ -535,6 +535,9 @@ def dump(self, indent, recurse=False): child.dump(indent + 3, recurse) +match_subtitute = re.compile("\$\{(.+)\}") + + def _subtitution(value, d): """ Only optimization string Template subtitute is quite expensive operation. @@ -545,8 +548,19 @@ def _subtitution(value, d): @return: Substituted string """ if "$" in value: - st = string.Template(value) - return st.safe_substitute(d) + start = 0 + st = "" + try: + match = match_subtitute.search(value, start) + while match: + val = eval(match.group(1), None, d) + st += value[start:match.start()] + str(val) + start = match.end() + match = match_subtitute.search(value, start) + except: + pass + st += value[start:len(value)] + return st else: return value @@ -1015,10 +1029,11 @@ def match(self, line, pos): elif char in tokens_map: token = tokens_map[char]() elif char == "\"": - pos, char = li.next() chars = "" + pos, char = li.next() while char != "\"": chars += char + pos, char = li.next() yield LString(chars) elif char == "#": break diff --git a/virttest/cartesian_config_unittest.py b/virttest/cartesian_config_unittest.py index 8680559c5..b0eba75c7 100755 --- a/virttest/cartesian_config_unittest.py +++ b/virttest/cartesian_config_unittest.py @@ -339,7 +339,9 @@ def testVariableAssignment(self): var += a var <= b system = 2 - s.* ?= ${tests}4 + ddd = ${tests + str(int(system) + 3)}4 + error = ${tests + str(system + 3)}4 + s.* ?= ${tests + "ahoj"}4 s.* ?+= c s.* ?<= d system += 4 @@ -349,7 +351,9 @@ def testVariableAssignment(self): {'dep': [], 'name': '(tests=system1)', 'shortname': '(tests=system1)', - 'system': 'dsystem14c4', + 'system': 'dsystem1ahoj4c4', + 'ddd': 'system154', + 'error': '${tests + str(system + 3)}4', 'tests': 'system1', 'var': 'b2atest'}, ], diff --git a/virttest/env_process.py b/virttest/env_process.py index 70a6e2831..5d8b3b09b 100644 --- a/virttest/env_process.py +++ b/virttest/env_process.py @@ -2,8 +2,8 @@ from autotest.client import utils from autotest.client.shared import error import aexpect, qemu_monitor, ppm_utils, test_setup, virt_vm -import libvirt_vm, video_maker, utils_misc, storage, qemu_storage -import remote, data_dir, utils_net +import video_maker, utils_misc, storage, qemu_storage, utils_libvirtd +import remote, data_dir, utils_net, utils_disk try: @@ -28,27 +28,23 @@ def preprocess_image(test, params, image_name): """ base_dir = params.get("images_base_dir", data_dir.get_data_dir()) - if params.get("storage_type") == "iscsi": - iscsidev = qemu_storage.Iscsidev(params, base_dir, image_name) - params["image_name"] = iscsidev.setup() - else: - image_filename = storage.get_image_filename(params, - base_dir) + image_filename = storage.get_image_filename(params, + base_dir) - create_image = False + create_image = False - if params.get("force_create_image") == "yes": - create_image = True - elif (params.get("create_image") == "yes" and not - os.path.exists(image_filename)): - create_image = True + if params.get("force_create_image") == "yes": + create_image = True + elif (params.get("create_image") == "yes" and not + os.path.exists(image_filename)): + create_image = True - if params.get("backup_image_before_testing", "no") == "yes": - image = qemu_storage.QemuImg(params, base_dir, image_name) - image.backup_image(params, base_dir, "backup", True, True) - if create_image: - image = qemu_storage.QemuImg(params, base_dir, image_name) - image.create(params) + if params.get("backup_image_before_testing", "no") == "yes": + image = qemu_storage.QemuImg(params, base_dir, image_name) + image.backup_image(params, base_dir, "backup", True, True) + if create_image: + image = qemu_storage.QemuImg(params, base_dir, image_name) + image.create(params) def preprocess_vm(test, params, env, name): @@ -77,6 +73,8 @@ def preprocess_vm(test, params, env, name): start_vm = False if params.get("restart_vm") == "yes": + if vm.is_alive(): + vm.destroy(gracefully=True, free_mac_addresses=False) start_vm = True elif params.get("migration_mode"): start_vm = True @@ -109,7 +107,10 @@ def preprocess_vm(test, params, env, name): if params.get("mac_changeable") == "yes": utils_net.update_mac_ip_address(vm, params) else: - # Don't start the VM, just update its params + # Update params of VM. + if params.get("kill_vm_before_test") == "yes": + # Destroy the VM if kill_vm_before_test = "yes". + vm.destroy(gracefully=True, free_mac_addresses=False) vm.devices = None vm.params = params @@ -117,8 +118,8 @@ def preprocess_vm(test, params, env, name): if params.get("paused_after_start_vm") == "yes": pause_vm = True - #Check the status of vm - if not vm.is_alive(): + # Check the status of vm + if (not vm.is_alive()) or (vm.is_paused()): pause_vm = False if pause_vm: @@ -134,36 +135,32 @@ def postprocess_image(test, params, image_name): """ clone_master = params.get("clone_master", None) base_dir = data_dir.get_data_dir() - if params.get("storage_type") == "iscsi": - iscsidev = qemu_storage.Iscsidev(params, base_dir, image_name) - iscsidev.cleanup() - else: - image = qemu_storage.QemuImg(params, base_dir, image_name) - if params.get("check_image") == "yes": - try: - if clone_master is None: - image.check_image(params, base_dir) - elif clone_master == "yes": - if image_name in params.get("master_images_clone").split(): - image.check_image(params, base_dir) - if params.get("restore_image", "no") == "yes": - image.backup_image(params, base_dir, "restore", True) - except Exception, e: - if params.get("restore_image_on_check_error", "no") == "yes": - image.backup_image(params, base_dir, "restore", True) - if params.get("remove_image_on_check_error", "no") == "yes": - cl_images = params.get("master_images_clone", "") - if image_name in cl_images.split(): - image.remove() - raise e - if params.get("restore_image_after_testing", "no") == "yes": - image.backup_image(params, base_dir, "restore", True) - if params.get("remove_image") == "yes": + image = qemu_storage.QemuImg(params, base_dir, image_name) + if params.get("check_image") == "yes": + try: if clone_master is None: - image.remove() + image.check_image(params, base_dir) elif clone_master == "yes": if image_name in params.get("master_images_clone").split(): + image.check_image(params, base_dir) + if params.get("restore_image", "no") == "yes": + image.backup_image(params, base_dir, "restore", True) + except Exception, e: + if params.get("restore_image_on_check_error", "no") == "yes": + image.backup_image(params, base_dir, "restore", True) + if params.get("remove_image_on_check_error", "no") == "yes": + cl_images = params.get("master_images_clone", "") + if image_name in cl_images.split(): image.remove() + raise e + if params.get("restore_image_after_testing", "no") == "yes": + image.backup_image(params, base_dir, "restore", True) + if params.get("remove_image") == "yes": + if clone_master is None: + image.remove() + elif clone_master == "yes": + if image_name in params.get("master_images_clone").split(): + image.remove() def postprocess_vm(test, params, env, name): @@ -210,7 +207,7 @@ def postprocess_vm(test, params, env, name): kill_vm_timeout = float(params.get("kill_vm_timeout", 0)) if kill_vm_timeout: utils_misc.wait_for(vm.is_dead, kill_vm_timeout, 0, 1) - vm.destroy(gracefully = params.get("kill_vm_gracefully") == "yes") + vm.destroy(gracefully=params.get("kill_vm_gracefully") == "yes") def process_command(test, params, env, command, command_timeout, @@ -263,18 +260,25 @@ def _call_image_func(): for vm_name in params.objects("vms"): vm_params = params.object_params(vm_name) vm = env.get_vm(vm_name) - for image_name in vm_params.objects("images"): - image_params = vm_params.object_params(image_name) - # Call image_func for each image - unpause_vm = False - if vm is not None and vm.is_alive() and not vm.is_paused(): - vm.pause() - unpause_vm = True - try: - image_func(test, image_params, image_name) - finally: - if unpause_vm: - vm.resume() + unpause_vm = False + if vm is not None and vm.is_alive() and not vm.is_paused(): + vm.pause() + unpause_vm = True + try: + err = "" + for image_name in vm_params.objects("images"): + image_params = vm_params.object_params(image_name) + # Call image_func for each image + try: + image_func(test, image_params, image_name) + except Exception, details: + err += "\n%s: %s" % (image_name, details) + if err: + raise virt_vm.VMImageCheckError("Error(s) occured " + "while processing images: %s" % err) + finally: + if unpause_vm: + vm.resume() else: for image_name in params.objects("images"): image_params = params.object_params(image_name) @@ -324,6 +328,12 @@ def preprocess(test, params, env): brcfg = test_setup.PrivateBridgeConfig(params_pb) brcfg.setup() + base_dir = data_dir.get_data_dir() + if params.get("storage_type") == "iscsi": + iscsidev = qemu_storage.Iscsidev(params, base_dir, "iscsi") + params["image_name"] = iscsidev.setup() + params["image_raw_device"] = "yes" + # Start tcpdump if it isn't already running if "address_cache" not in env: env["address_cache"] = {} @@ -418,7 +428,7 @@ def preprocess(test, params, env): h = test_setup.HugePageConfig(params) h.setup() if params.get("vm_type") == "libvirt": - libvirt_vm.libvirtd_restart() + utils_libvirtd.libvirtd_restart() if params.get("setup_thp") == "yes": thp = test_setup.TransparentHugePageConfig(test, params) @@ -435,7 +445,47 @@ def preprocess(test, params, env): int(params.get("pre_command_timeout", "600")), params.get("pre_command_noncritical") == "yes") - #Clone master image from vms. + + # if you want set "pci=nomsi" before test, set "disable_pci_msi = yes" + # and pci_msi_sensitive = "yes" + if params.get("pci_msi_sensitive", "no") == "yes": + disable_pci_msi = params.get("disable_pci_msi", "no") + image_filename = storage.get_image_filename(params, + data_dir.get_data_dir()) + grub_file = params.get("grub_file", "/boot/grub2/grub.cfg") + kernel_cfg_pos_reg = params.get("kernel_cfg_pos_reg", + r".*vmlinuz-\d+.*") + msi_keyword = params.get("msi_keyword", " pci=nomsi") + + disk_obj = utils_disk.GuestFSModiDisk(image_filename) + kernel_config_ori = disk_obj.read_file(grub_file) + kernel_config = re.findall(kernel_cfg_pos_reg, kernel_config_ori) + if not kernel_config: + raise error.TestError("Cannot find the kernel config, reg is %s" % + kernel_cfg_pos_reg) + kernel_config_line = kernel_config[0] + + kernel_need_modify = False + if disable_pci_msi == "yes": + if not re.findall(msi_keyword, kernel_config_line): + kernel_config_set = kernel_config_line + msi_keyword + kernel_need_modify = True + else: + if re.findall(msi_keyword, kernel_config_line): + kernel_config_set = re.sub(msi_keyword, "", kernel_config_line) + kernel_need_modify = True + + if kernel_need_modify: + for vm in env.get_all_vms(): + if vm: + vm.destroy() + env.unregister_vm(vm.name) + disk_obj.replace_image_file_content(grub_file, kernel_config_line, + kernel_config_set) + logging.debug("Guest cmdline 'pci=nomsi' setting is: [ %s ]" % + disable_pci_msi) + + # Clone master image from vms. base_dir = data_dir.get_data_dir() if params.get("master_images_clone"): for vm_name in params.get("vms").split(): @@ -450,7 +500,7 @@ def preprocess(test, params, env): image_obj.clone_image(params, vm_name, image, base_dir) # Preprocess all VMs and images - if params.get("not_preprocess","no") == "no": + if params.get("not_preprocess", "no") == "no": process(test, params, env, preprocess_image, preprocess_vm) # Start the screendump thread @@ -462,6 +512,8 @@ def preprocess(test, params, env): args=(test, params, env)) _screendump_thread.start() + return params + @error.context_aware def postprocess(test, params, env): @@ -473,9 +525,15 @@ def postprocess(test, params, env): @param env: The environment (a dict-like object). """ error.context("postprocessing") + err = "" # Postprocess all VMs and images - process(test, params, env, postprocess_image, postprocess_vm, vm_first=True) + try: + process(test, params, env, postprocess_image, postprocess_vm, + vm_first=True) + except Exception, details: + err += "\nPostprocess: %s" % str(details).replace('\\n', '\n ') + logging.error(details) # Terminate the screendump thread global _screendump_thread, _screendump_thread_termination_event @@ -560,24 +618,50 @@ def postprocess(test, params, env): del env["tcpdump"] if params.get("setup_hugepages") == "yes": - h = test_setup.HugePageConfig(params) - h.cleanup() - if params.get("vm_type") == "libvirt": - libvirt_vm.libvirtd_restart() + try: + h = test_setup.HugePageConfig(params) + h.cleanup() + if params.get("vm_type") == "libvirt": + utils_libvirtd.libvirtd_restart() + except Exception, details: + err += "\nHP cleanup: %s" % str(details).replace('\\n', '\n ') + logging.error(details) if params.get("setup_thp") == "yes": - thp = test_setup.TransparentHugePageConfig(test, params) - thp.cleanup() + try: + thp = test_setup.TransparentHugePageConfig(test, params) + thp.cleanup() + except Exception, details: + err += "\nTHP cleanup: %s" % str(details).replace('\\n', '\n ') + logging.error(details) if params.get("setup_ksm") == "yes": - ksm = test_setup.KSMConfig(params, env) - ksm.cleanup(env) + try: + ksm = test_setup.KSMConfig(params, env) + ksm.cleanup(env) + except Exception, details: + err += "\nKSM cleanup: %s" % str(details).replace('\\n', '\n ') + logging.error(details) # Execute any post_commands if params.get("post_command"): - process_command(test, params, env, params.get("post_command"), - int(params.get("post_command_timeout", "600")), - params.get("post_command_noncritical") == "yes") + try: + process_command(test, params, env, params.get("post_command"), + int(params.get("post_command_timeout", "600")), + params.get("post_command_noncritical") == "yes") + except Exception, details: + err += "\nPostprocess command: %s" % str(details).replace('\n', + '\n ') + logging.error(details) + + base_dir = data_dir.get_data_dir() + if params.get("storage_type") == "iscsi": + try: + iscsidev = qemu_storage.Iscsidev(params, base_dir, "iscsi") + iscsidev.cleanup() + except Exception, details: + err += "\niscsi cleanup: %s" % str(details).replace('\\n', '\n ') + logging.error(details) setup_pb = False for nic in params.get('nics', "").split(): @@ -588,8 +672,15 @@ def postprocess(test, params, env): setup_pb = params.get("netdst") == 'private' if setup_pb: - brcfg = test_setup.PrivateBridgeConfig() - brcfg.cleanup() + try: + brcfg = test_setup.PrivateBridgeConfig() + brcfg.cleanup() + except Exception, details: + err += "\nPB cleanup: %s" % str(details).replace('\\n', '\n ') + logging.error(details) + + if err: + raise virt_vm.VMError("Failures occured while postprocess:%s" % err) def postprocess_on_error(test, params, env): @@ -717,7 +808,7 @@ def _take_screendumps(test, params, env): time_inactive = time.time() - inactivity[vm] if time_inactive > inactivity_treshold: msg = ("%s screen is inactive for more than %d s (%d min)" % - (vm.name, time_inactive, time_inactive/60)) + (vm.name, time_inactive, time_inactive / 60)) if inactivity_watcher == "error": try: raise virt_vm.VMScreenInactiveError(vm, diff --git a/virttest/libvirt_vm.py b/virttest/libvirt_vm.py index 0af1cdb53..d37a4665b 100644 --- a/virttest/libvirt_vm.py +++ b/virttest/libvirt_vm.py @@ -11,75 +11,6 @@ import data_dir, xml_utils -def libvirtd_restart(): - """ - Restart libvirt daemon. - """ - try: - utils.run("service libvirtd restart") - logging.debug("Restarted libvirtd successfuly") - return True - except error.CmdError, detail: - logging.error("Failed to restart libvirtd:\n%s", detail) - return False - - -def libvirtd_stop(): - """ - Stop libvirt daemon. - """ - try: - utils.run("service libvirtd stop") - logging.debug("Stop libvirtd successfuly") - return True - except error.CmdError, detail: - logging.error("Failed to stop libvirtd:\n%s", detail) - return False - - -def libvirtd_start(): - """ - Start libvirt daemon. - """ - try: - utils.run("service libvirtd start") - logging.debug("Start libvirtd successfuly") - return True - except error.CmdError, detail: - logging.error("Failed to start libvirtd:\n%s", detail) - return False - - -def service_libvirtd_control(action): - """ - Libvirtd control by action, if cmd executes successfully, - return True, otherwise return False. - If the action is status, return True when it's running, - otherwise return False. - @ param action: start|stop|status|restart|condrestart| - reload|force-reload|try-restart - """ - actions = ['start', 'stop', 'restart', 'condrestart', 'reload', - 'force-reload', 'try-restart'] - if action in actions: - try: - utils.run("service libvirtd %s" % action) - logging.debug("%s libvirtd successfuly", action) - return True - except error.CmdError, detail: - logging.error("Failed to %s libvirtd:\n%s", action, detail) - return False - elif action == "status": - cmd_result = utils.run("service libvirtd status", ignore_status=True) - if re.search("running", cmd_result.stdout.strip()): - logging.info("Libvirtd service is running") - return True - else: - return False - else: - raise error.TestError("Unknown action: %s" % action) - - def normalize_connect_uri(connect_uri): """ Processes connect_uri Cartesian into something virsh can use @@ -1442,7 +1373,8 @@ def start(self, autoconsole=True): " vm %s" % (index, self.name)) logging.debug("Starting vm '%s'", self.name) - if virsh.start(self.name, uri=self.connect_uri): + result = virsh.start(self.name, uri=self.connect_uri) + if not result.exit_status: # Wait for the domain to be created has_started = utils_misc.wait_for(func=self.is_alive, timeout=60, text=("waiting for domain %s " diff --git a/virttest/libvirt_xml/nodedev_xml.py b/virttest/libvirt_xml/nodedev_xml.py index 57307d0f3..913901860 100644 --- a/virttest/libvirt_xml/nodedev_xml.py +++ b/virttest/libvirt_xml/nodedev_xml.py @@ -40,9 +40,9 @@ class SystemXML(CAPXML): class for capability which type is system. """ __slots__ = CAPXML.__slots__ + ('product', 'hdware_vendor', - 'hdware_serial', 'hdware_uuid', - 'firmware_vendor','firmversion' - 'firm_release_date') + 'hdware_serial', 'hdware_uuid', + 'firmware_vendor','firmversion' + 'firm_release_date') __sysfs_sub_path__ = 'dmi/id/' @@ -100,17 +100,17 @@ class for capability whose type is pci. def __init__(self, virsh_instance=base.virsh): accessors.XMLElementInt('domain', self, parent_xpath='/', - tag_name='domain', radix=16) + tag_name='domain') accessors.XMLElementInt('bus', self, parent_xpath='/', - tag_name='bus', radix=16) + tag_name='bus') accessors.XMLElementInt('slot', self, parent_xpath='/', - tag_name='slot', radix=16) + tag_name='slot') accessors.XMLElementInt('function', self, parent_xpath='/', - tag_name='function', radix=16) + tag_name='function') accessors.XMLAttribute('product_id', self, parent_xpath='/', - tag_name='product', attribute='id') + tag_name='product', attribute='id') accessors.XMLAttribute('vendor_id', self, parent_xpath='/', - tag_name='vendor', attribute='id') + tag_name='vendor', attribute='id') super(PCIXML, self).__init__(virsh_instance=virsh_instance) self.xml = ( ' <capability type=\'pci\'></capability>') @@ -123,8 +123,8 @@ def make_sysfs_sub_path(domain, bus, slot, function): pci_bus_path = ("%04x:%02x" % (domain, bus)) pci_device_path = ("%04x:%02x:%02x.%01x" % (domain, bus, slot, function)) - pci_sysfs_sub_path = ("pci_bus/%s/device/%s" % - (pci_bus_path, pci_device_path)) + pci_sysfs_sub_path = ("pci_bus/%s/device/%s" + % (pci_bus_path, pci_device_path)) return pci_sysfs_sub_path @@ -178,9 +178,10 @@ class NodedevXMLBase(base.LibvirtXMLBase): """ __slots__ = base.LibvirtXMLBase.__slots__ + ('name', 'parent', - 'cap_type', 'cap', 'sysfs_main_path') + 'cap_type', 'cap', + 'sysfs_main_path') - __schema_name__ = "device" + __schema_name__ = "nodedev" __sysfs_dir__ = "/sys/class" @@ -199,7 +200,7 @@ def __init__(self, virsh_instance=base.virsh): accessors.XMLElementText('parent', self, parent_xpath='/', tag_name='parent') accessors.XMLAttribute('cap_type', self, parent_xpath='/', - tag_name='capability', attribute='type') + tag_name='capability', attribute='type') super(NodedevXMLBase, self).__init__(virsh_instance=virsh_instance) self.xml = '<device></device>' @@ -299,36 +300,33 @@ def new_from_dumpxml(dev_name, virsh_instance=base.virsh): dumpxml_result = virsh_instance.nodedev_dumpxml(dev_name) if dumpxml_result.exit_status: raise xcepts.LibvirtXMLError("Nodedev_dumpxml %s failed.\n" - "Error: %s." % (dumpxml_result.stderr)) + "Error: %s." + % (dev_name, dumpxml_result.stderr)) nodedevxml.xml = dumpxml_result.stdout return nodedevxml - @staticmethod - def get_key2value_dict(dev_name): + def get_key2value_dict(self): """ Get the dict which contain key and value in xml. key: keys in nodedev xml need to check. value: value in xml for the key. """ - nodedevxml = NodedevXML.new_from_dumpxml(dev_name) - capxml = nodedevxml.cap + capxml = self.cap key2value_dict = capxml.get_key2value_dict() return key2value_dict - @staticmethod - def get_key2syspath_dict(dev_name): + def get_key2syspath_dict(self): """ Get the dict which contains key and path. key: keys in nodedev xml need to check. syspath: the abs path for the file stores info for the key. """ - nodedevxml = NodedevXML.new_from_dumpxml(dev_name) - sysfs_path = nodedevxml.get_sysfs_path() - capxml = nodedevxml.cap + sysfs_path = self.get_sysfs_path() + capxml = self.cap key2filename_dict = capxml.__class__.get_key2filename_dict() key2syspath_dict = {} diff --git a/virttest/libvirt_xml/vm_xml.py b/virttest/libvirt_xml/vm_xml.py index eb7da38d7..8dd47c064 100644 --- a/virttest/libvirt_xml/vm_xml.py +++ b/virttest/libvirt_xml/vm_xml.py @@ -272,7 +272,7 @@ def __init__(self, hypervisor_type='kvm', virsh_instance=base.virsh): @staticmethod # static method (no self) needed b/c calls VMXML.__new__ - def new_from_dumpxml(vm_name, virsh_instance=virsh): + def new_from_dumpxml(vm_name, options="", virsh_instance=virsh): """ Return new VMXML instance from virsh dumpxml command @@ -282,7 +282,7 @@ def new_from_dumpxml(vm_name, virsh_instance=virsh): """ # TODO: Look up hypervisor_type on incoming XML vmxml = VMXML(virsh_instance=virsh_instance) - vmxml['xml'] = virsh_instance.dumpxml(vm_name) + vmxml['xml'] = virsh_instance.dumpxml(vm_name, options=options) return vmxml @@ -296,14 +296,18 @@ def get_device_class(type_name): def undefine(self): """Undefine this VM with libvirt retaining XML in instance""" - # Allow any exceptions to propigate up - self.virsh.remove_domain(self.vm_name) + return self.virsh.remove_domain(self.vm_name) def define(self): """Define VM with virsh from this instance""" - # Allow any exceptions to propigate up - self.virsh.define(self.xml) + result = self.virsh.define(self.xml) + if result.exit_status: + logging.debug("Define %s failed.\n" + "Detail: %s." + % (self.vm_name, result.stderr)) + return False + return True @staticmethod @@ -322,13 +326,9 @@ def vm_rename(vm, new_name, uuid=None, virsh_instance=base.virsh): virsh_instance=virsh_instance) backup = vmxml.copy() # can't do in-place rename, must operate on XML - try: - vmxml.undefine() - # All failures trip a single exception - except error.CmdError, detail: + if not vmxml.undefine(): del vmxml # clean up temporary files - raise xcepts.LibvirtXMLError("Error reported while undefining VM:\n" - "%s" % detail) + raise xcepts.LibvirtXMLError("Error reported while undefining VM") # Alter the XML vmxml.vm_name = new_name if uuid is None: @@ -340,14 +340,17 @@ def vm_rename(vm, new_name, uuid=None, virsh_instance=base.virsh): vm.uuid = uuid # Re-define XML to libvirt logging.debug("Rename %s to %s.", vm.name, new_name) + # error message for failed define + error_msg = "Error reported while defining VM:\n" try: - vmxml.define() + if not vmxml.define(): + raise xcepts.LibvirtXMLError(error_msg + "%s" + % vmxml.get('xml')) except error.CmdError, detail: del vmxml # clean up temporary files # Allow exceptions thrown here since state will be undefined backup.define() - raise xcepts.LibvirtXMLError("Error reported while defining VM:\n%s" - % detail) + raise xcepts.LibvirtXMLError(error_msg + "%s" % detail) # Keep names uniform vm.name = new_name return vm @@ -372,6 +375,19 @@ def set_vm_vcpus(vm_name, value, virsh_instance=base.virsh): # when it goes out of scope here. + def check_cpu_mode(self, mode): + """ + Check input cpu mode invalid or not. + + @param mode: the mode of cpu:'host-model'... + """ + # Possible values for the mode attribute are: + # "custom", "host-model", "host-passthrough" + cpu_mode = ["custom", "host-model", "host-passthrough"] + if mode.strip() not in cpu_mode: + raise xcepts.LibvirtXMLError("The cpu mode '%s' is invalid!" % mode) + + def get_disk_all(self): """ Return VM's disk from XML definition, None if not set @@ -458,7 +474,6 @@ def set_primary_serial(vm_name, dev_type, port, path=None, @param dev_type: the type of serial:pty,file... @param port: the port of serial @param path: the path of serial, it is not necessary for pty - # TODO: More features """ vmxml = VMXML.new_from_dumpxml(vm_name, virsh_instance=virsh_instance) xmltreefile = vmxml.dict_get('xml') @@ -490,18 +505,7 @@ def set_primary_serial(vm_name, dev_type, port, path=None, vmxml.define() - def get_iface_all(self): - """ - Get a dict with interface's mac and node. - """ - iface_nodes = self.xmltreefile.find('devices').findall('interface') - interfaces = {} - for node in iface_nodes: - mac_addr = node.find('mac').get('address') - interfaces[mac_addr] = node - return interfaces - - + #TODO: Deprecate method in favor of VMXML.devices.interface @staticmethod def get_iface_by_mac(vm_name, mac, virsh_instance=base.virsh): """ @@ -529,25 +533,94 @@ def get_iface_by_mac(vm_name, mac, virsh_instance=base.virsh): return None - def check_cpu_mode(self, mode): + #TODO: Deprecate method in favor of VMXML.devices.interface + @staticmethod + def get_iface_dev(vm_name, options="", virsh_instance=base.virsh): """ - Check input cpu mode invalid or not. + Return VM's interface device from XML definition, None if not set + """ + vmxml = VMXML.new_from_dumpxml(vm_name, virsh_instance=virsh_instance) + ifaces = vmxml.get_iface_all() + if ifaces: + return ifaces.keys() + return None - @param mode: the mode of cpu:'host-model'... + + #TODO: Deprecate method in favor of VMXML.devices.interface + @staticmethod + def get_iftune_params(vm_name, options="", virsh_instance=base.virsh): """ - # Possible values for the mode attribute are: - # "custom", "host-model", "host-passthrough" - cpu_mode = ["custom", "host-model", "host-passthrough"] - if mode.strip() not in cpu_mode: - raise xcepts.LibvirtXMLError("The cpu mode '%s' is invalid!" % mode) + Return VM's interface tuning setting from XML definition + """ + vmxml = VMXML.new_from_dumpxml(vm_name, options=options, + virsh_instance=virsh_instance) + xmltreefile = vmxml.dict_get('xml') + iftune_params = {} + bandwidth = None + try: + bandwidth = xmltreefile.find('devices').find( + 'interface').find('bandwidth') + try: + iftune_params['inbound'] = bandwidth.find( + 'inbound').get('average') + iftune_params['outbound'] = bandwidth.find( + 'outbound').get('average') + except AttributeError: + logging.error("Can't find <inbound> or <outbound> element") + except AttributeError: + logging.error("Can't find <bandwidth> element") + + return iftune_params + + + #TODO: Deprecate method in favor of VMXML.devices.interface + def get_iface_all(self): + """ + Get a dict with interface's mac and node. + """ + iface_nodes = self.xmltreefile.find('devices').findall('interface') + interfaces = {} + for node in iface_nodes: + mac_addr = node.find('mac').get('address') + interfaces[mac_addr] = node + return interfaces + + + #TODO: Deprecate method in favor of VMXML.devices.interface + def get_net_all(self): + """ + Return VM's net from XML definition, None if not set + """ + net_nodes = self.xmltreefile.find('devices').findall('interface') + nets = {} + for node in net_nodes: + dev = node.find('target').get('dev') + nets[dev] = node + return nets + #TODO: Deprecate method in favor of VMXML.devices.interface + @staticmethod + def get_net_dev(vm_name): + """ + Get net device of a defined VM's nets. + + @param: vm_name: Name of defined vm. + """ + vmxml = VMXML.new_from_dumpxml(vm_name) + nets = vmxml.get_net_all() + if nets != None: + return nets.keys() + return None + + + # TODO: Deprecate method in favor of VMCPUXML.mode @staticmethod def set_cpu_mode(vm_name, mode='host-model'): """ Set cpu's mode of VM. - @param vm_name: Name of defined vm to set primary serial. + @param vm_name: Name of defined vm @param mode: the mode of cpu:'host-model'... """ vmxml = VMXML.new_from_dumpxml(vm_name) @@ -683,5 +756,3 @@ def add_feature(self, value): xmltreefile = self.dict_get('xml') cpu_node = xmltreefile.find('/cpu') xml_utils.ElementTree.SubElement(cpu_node, 'feature', {'name': value}) - #TODO: Add function to create from xml_utils.TemplateXML() - # def new_from_template(...) diff --git a/virttest/libvirt_xml_unittest.py b/virttest/libvirt_xml_unittest.py index 295e90150..0c940950e 100755 --- a/virttest/libvirt_xml_unittest.py +++ b/virttest/libvirt_xml_unittest.py @@ -649,13 +649,16 @@ def test_new_from_dumpxml(self): def test_get_key2value_dict(self): NodedevXML = nodedev_xml.NodedevXML - result = NodedevXML.get_key2value_dict('pci_0000_00_00_0') + xml = NodedevXML.new_from_dumpxml('pci_0000_00_00_0') + result = xml.get_key2value_dict() + self.assertTrue(isinstance(result, dict)) def test_get_key2syspath_dict(self): NodedevXML = nodedev_xml.NodedevXML - result = NodedevXML.get_key2syspath_dict('pci_0000_00_00_0') + xml = NodedevXML.new_from_dumpxml('pci_0000_00_00_0') + result = xml.get_key2syspath_dict() self.assertTrue(isinstance(result, dict)) diff --git a/virttest/openvswitch.py b/virttest/openvswitch.py index 57ad63dd4..a59641d17 100644 --- a/virttest/openvswitch.py +++ b/virttest/openvswitch.py @@ -5,11 +5,14 @@ import common from autotest.client import utils, os_dep from autotest.client.shared import error -from versionable_class import VersionableClass +from versionable_class import VersionableClass, Manager, factory import utils_misc +# Register to class manager. +man = Manager(__name__) -class ServiceManagerInterface(VersionableClass): + +class ServiceManagerInterface(object): def __new__(cls, *args, **kargs): ServiceManagerInterface.master_class = ServiceManagerInterface return super(ServiceManagerInterface, cls).__new__(cls, *args, **kargs) @@ -42,51 +45,53 @@ def status(self, service_name): " implemented in child class") -class ServiceManagerSystemD(ServiceManagerInterface, VersionableClass): +class ServiceManagerSysvinit(ServiceManagerInterface): @classmethod - def is_right_version(cls, version): - if version == "systemd": + def _is_right_ver(cls): + version = cls.get_version() + if version == "init": return True return False + def stop(self, service_name): - utils.run("systemctl stop %s.service" % (service_name)) + utils.run("/etc/init.d/%s stop" % (service_name)) def start(self, service_name): - utils.run("systemctl start %s.service" % (service_name)) + utils.run("/etc/init.d/%s start" % (service_name)) def restart(self, service_name): - utils.run("systemctl restart %s.service" % (service_name)) - - - def status(self, service_name): - utils.run("systemctl show %s.service" % (service_name)) + utils.run("/etc/init.d/%s restart" % (service_name)) -class ServiceManagerSysvinit(ServiceManagerInterface, VersionableClass): +class ServiceManagerSystemD(ServiceManagerSysvinit): @classmethod - def is_right_version(cls, version): - if version == "init": + def _is_right_ver(cls): + version = cls.get_version() + if version == "systemd": return True return False - def stop(self, service_name): - utils.run("/etc/init.d/%s stop" % (service_name)) + utils.run("systemctl stop %s.service" % (service_name)) def start(self, service_name): - utils.run("/etc/init.d/%s start" % (service_name)) + utils.run("systemctl start %s.service" % (service_name)) def restart(self, service_name): - utils.run("/etc/init.d/%s restart" % (service_name)) + utils.run("systemctl restart %s.service" % (service_name)) -class ServiceManager(ServiceManagerInterface): - pass + def status(self, service_name): + utils.run("systemctl show %s.service" % (service_name)) + + +class ServiceManager(VersionableClass): + __master__ = ServiceManagerSystemD class OpenVSwitchControl(object): @@ -219,75 +224,48 @@ def check_port_in_br(self, br_name, port_name): raise NotImplementedError() -class OpenVSwitchControlCli(OpenVSwitchControl, VersionableClass): - """ - Class select the best matches control class for installed version - of OpenVSwitch. - """ - def __new__(cls, db_path=None, db_socket=None, db_pidfile=None, - ovs_pidfile=None, dbschema=None, install_prefix=None): - OpenVSwitchControlCli.master_class = OpenVSwitchControlCli - return super(OpenVSwitchControlCli, cls).__new__(cls, db_path, - db_socket, - db_pidfile, - ovs_pidfile, - dbschema, - install_prefix) - - -class OpenVSwitchControlDB(OpenVSwitchControl, VersionableClass): - """ - Class select the best matches control class for installed version - of OpenVSwitch. - """ - - def __new__(cls, db_path=None, db_socket=None, db_pidfile=None, - ovs_pidfile=None, dbschema=None, install_prefix=None): - OpenVSwitchControlDB.master_class = OpenVSwitchControlDB - return super(OpenVSwitchControlDB, cls).__new__(cls, db_path, - db_socket, - db_pidfile, - ovs_pidfile, - dbschema, - install_prefix) - - -class OpenVSwitchControlDB_140(OpenVSwitchControlDB, VersionableClass): +class OpenVSwitchControlDB_140(OpenVSwitchControl): """ Don't use this class directly. This class is automatically selected by OpenVSwitchControl. """ @classmethod - def is_right_version(cls, version): + def _is_right_ver(cls): """ Check condition for select control class. @param version: version of OpenVSwtich """ + version = cls.get_version() if version is not None: int_ver = cls.convert_version_to_int(version) - if int_ver <= 140: + if int_ver >= 140: return True return False #TODO: implement database manipulation methods. -class OpenVSwitchControlCli_140(OpenVSwitchControlCli, VersionableClass): +class OpenVSwitchControlDB_CNT(VersionableClass): + __master__ = OpenVSwitchControlDB_140 + + +class OpenVSwitchControlCli_140(OpenVSwitchControl): """ Don't use this class directly. This class is automatically selected by OpenVSwitchControl. """ @classmethod - def is_right_version(cls, version): + def _is_right_ver(cls): """ Check condition for select control class. @param version: version of OpenVSwtich """ + version = cls.get_version() if version is not None: int_ver = cls.convert_version_to_int(version) - if int_ver <= 140: + if int_ver >= 140: return True return False @@ -378,17 +356,14 @@ def port_to_br(self, port_name): return bridge -class OpenVSwitchSystem(OpenVSwitchControlCli, OpenVSwitchControlDB): +class OpenVSwitchControlCli_CNT(VersionableClass): + __master__ = OpenVSwitchControlCli_140 + + +class OpenVSwitchSystem(OpenVSwitchControlCli_CNT, OpenVSwitchControlDB_CNT): """ OpenVSwtich class. """ - def __new__(cls, db_path=None, db_socket=None, db_pidfile=None, - ovs_pidfile=None, dbschema=None, install_prefix=None): - return super(OpenVSwitchSystem, cls).__new__(cls, db_path, db_socket, - db_pidfile, ovs_pidfile, - dbschema, install_prefix) - - def __init__(self, db_path=None, db_socket=None, db_pidfile=None, ovs_pidfile=None, dbschema=None, install_prefix=None): """ @@ -400,9 +375,9 @@ def __init__(self, db_path=None, db_socket=None, db_pidfile=None, @param ovs_pidfile: Path of OVS ovs-vswitchd pid. @param install_prefix: Path where is openvswitch installed. """ - super(OpenVSwitchSystem, self).__init__(self, db_path, db_socket, - db_pidfile, ovs_pidfile, - dbschema, install_prefix) + sup = super(man[self.__class__, OpenVSwitchSystem], self) + sup.__init__(self, db_path, db_socket, db_pidfile, ovs_pidfile, + dbschema, install_prefix) self.cleanup = False self.pid_files_path = None @@ -473,7 +448,7 @@ def init_system(self): """ Create new dbfile without any configuration. """ - sm = ServiceManager() + sm = factory(ServiceManager)() try: if utils.load_module("openvswitch"): sm.restart("openvswitch") @@ -495,13 +470,6 @@ class OpenVSwitch(OpenVSwitchSystem): """ OpenVSwtich class. """ - def __new__(cls, tmpdir, db_path=None, db_socket=None, db_pidfile=None, - ovs_pidfile=None, dbschema=None, install_prefix=None): - return super(OpenVSwitch, cls).__new__(cls, db_path, db_socket, - db_pidfile, ovs_pidfile, - dbschema, install_prefix) - - def __init__(self, tmpdir, db_path=None, db_socket=None, db_pidfile=None, ovs_pidfile=None, dbschema=None, install_prefix=None): """ @@ -514,8 +482,9 @@ def __init__(self, tmpdir, db_path=None, db_socket=None, db_pidfile=None, @param ovs_pidfile: Path of OVS ovs-vswitchd pid. @param install_prefix: Path where is openvswitch installed. """ - super(OpenVSwitch, self).__init__(db_path, db_socket, db_pidfile, - ovs_pidfile, dbschema, install_prefix) + super(man[self, OpenVSwitch], self).__init__(db_path, db_socket, + db_pidfile, ovs_pidfile, + dbschema, install_prefix) self.tmpdir = "/%s/openvswitch" % (tmpdir) try: os.mkdir(self.tmpdir) diff --git a/virttest/qemu_devices.py b/virttest/qemu_devices.py index 77ace8b79..03d1f5f52 100644 --- a/virttest/qemu_devices.py +++ b/virttest/qemu_devices.py @@ -26,7 +26,10 @@ class OrderedDict(dict): @warning: This is not the full OrderedDict implementation! """ def itervalues(self, *args, **kwargs): - return sorted(dict.itervalues(self, *args, **kwargs), + return (_[1] for _ in sorted(dict.iteritems(self, *args, **kwargs))) + + def iteritems(self, *args, **kwargs): + return sorted(dict.iteritems(self, *args, **kwargs), key=lambda item: item[0]) @@ -100,8 +103,8 @@ def set_param(self, option, value, option_type=None): elif value in ['no', 'off', False]: self.params[option] = "off" elif value or value == 0: - if option_type is 'NEED_QUOTE': - self.params[option] = "'%s'" % value + if value == "EMPTY_STRING": + self.params[option] = '""' else: self.params[option] = value elif value is None and option in self.params: @@ -138,7 +141,7 @@ def __str__(self): def __eq__(self, dev2): """ @return: True when devs are similar, False when different. """ try: - for check_attr in ('cmdline', 'readconfig', 'hotplug_hmp', + for check_attr in ('cmdline', 'hotplug_hmp', 'hotplug_qmp'): try: _ = getattr(self, check_attr)() @@ -234,10 +237,6 @@ def verify_hotplug(self, out, monitor): """ return out - def readconfig(self): - """ @return: readconfig-like config of this device """ - raise NotImplementedError - class QStringDevice(QBaseDevice): """ @@ -246,7 +245,7 @@ class QStringDevice(QBaseDevice): "%(type)s,id=%(id)s,addr=%(addr)s" -- params will be used to subst %()s """ def __init__(self, dev_type, params=None, aobject=None, - parent_bus=None, child_bus=None, cmdline="", readconfig=""): + parent_bus=None, child_bus=None, cmdline=""): """ @param dev_type: type of this component @param params: component's parameters @@ -254,34 +253,25 @@ def __init__(self, dev_type, params=None, aobject=None, @param parent_bus: bus(es), in which this device is plugged in @param child_bus: bus, which this device provides @param cmdline: cmdline string - @param readconfig: readconfig string """ super(QStringDevice, self).__init__(dev_type, params, aobject, parent_bus, child_bus) self._cmdline = cmdline - self._readconfig = readconfig def cmdline(self): """ @return: cmdline command to define this device """ try: - return self._cmdline % self.params + if self._cmdline: + return self._cmdline % self.params except KeyError, details: raise KeyError("Param %s required for cmdline is not present in %s" % (details, self.str_long())) - def readconfig(self): - """ @return: readconfig-like config of this device """ - try: - return self._readconfig % self.params - except KeyError, details: - raise KeyError("Param %s required for readconfig is not present in" - " %s" % (details, self.str_long())) - class QCustomDevice(QBaseDevice): """ Representation of the '-$option $param1=$value1,$param2...' qemu object. - This representation handles only cmdline and readconfig outputs. + This representation handles only cmdline. """ def __init__(self, dev_type, params=None, aobject=None, parent_bus=None, child_bus=None): @@ -295,26 +285,14 @@ def cmdline(self): """ @return: cmdline command to define this device """ out = "-%s " % self.type for key, value in self.params.iteritems(): - out += "%s=%s," % (key, value) + if value != "NO_EQUAL_STRING": + out += "%s=%s," % (key, value) + else: + out += "%s," % key if out[-1] == ',': out = out[:-1] return out - def readconfig(self): - """ @return: readconfig-like config of this device """ - out = "[%s" % self.type - if self.get_qid(): - out += ' "%s"' % self.get_qid() - out += "]\n" - for key, value in self.params.iteritems(): - if key == "id": - continue - if value.startswith("'") and value.endswith("'"): - out += ' %s = "%s"\n' % (key, value[1:-1]) - else: - out += ' %s = "%s"\n' % (key, value) - return out - class QDevice(QCustomDevice): """ @@ -397,10 +375,10 @@ def __getitem__(self, item): elif item in self.badbus.itervalues(): return item elif item: - for device in self.bus: + for device in self.bus.itervalues(): if device.get_aid() == item: return device - for device in self.badbus: + for device in self.badbus.itervalues(): if device.get_aid() == item: return device raise KeyError("Device %s is not in %s" % (item, self)) @@ -552,7 +530,11 @@ def _dev2addr(self, device): """ addr = [] for key in self.addr_items: - addr.append(device.get_param(key)) + value = device.get_param(key) + if value is None: + addr.append(None) + else: + addr.append(int(value)) return addr def _set_first_addr(self, addr_pattern): @@ -624,10 +606,10 @@ def _update_device_props(self, device, addr): @param device: QBaseDevice device @param addr: internal address [addr1, addr2, ...] """ - if device.get_param(self.bus_item): + if device.get_param(self.bus_item) is not None: device.set_param(self.bus_item, self.busid) for i in xrange(len(self.addr_items)): - if device.get_param(self.addr_items[i]): + if device.get_param(self.addr_items[i]) is not None: device.set_param(self.addr_items[i], addr[i]) def insert(self, device, strict_mode=False, force=False): @@ -648,7 +630,14 @@ def insert(self, device, strict_mode=False, force=False): device.set_param(self.bus_item, self.busid) else: return False - addr_pattern = self._dev2addr(device) + try: + addr_pattern = self._dev2addr(device) + except (ValueError, LookupError): + if force: + err += "BasicAddress, " + addr_pattern = [None] * len(self.addr_items) + else: + return False addr = self.get_free_slot(addr_pattern) if addr is None: if force: @@ -880,7 +869,8 @@ class DevContainer(object): Device container class """ # General methods - def __init__(self, qemu_binary, vmname, strict_mode=False): + def __init__(self, qemu_binary, vmname, strict_mode=False, + workaround_qemu_qmp_crash=False): """ @param qemu_binary: qemu binary @param vm: related VM @@ -892,18 +882,21 @@ def get_hmp_cmds(qemu_binary): "stdio -vnc none" % qemu_binary, timeout=10, ignore_status=True, verbose=False) - _ = re.findall(r'^([^\| ]+\|?\w+)', _, re.M) + _ = re.findall(r'^([^\| \[\n]+\|?\w+)', _, re.M) hmp_cmds = [] for cmd in _: if '|' not in cmd: - hmp_cmds.append(cmd) + if cmd != 'The': + hmp_cmds.append(cmd) else: hmp_cmds.extend(cmd.split('|')) return hmp_cmds - def get_qmp_cmds(qemu_binary): + def get_qmp_cmds(qemu_binary, workaround_qemu_qmp_crash=False): """ @return: list of qmp commands """ - cmds = utils.system_output('echo -e \'' + cmds = None + if not workaround_qemu_qmp_crash: + cmds = utils.system_output('echo -e \'' '{ "execute": "qmp_capabilities" }\n' '{ "execute": "query-commands", "id": "RAND91" }\n' '{ "execute": "quit" }\'' @@ -933,7 +926,7 @@ def get_qmp_cmds(qemu_binary): self.__machine_types = utils.system_output("%s -M ?" % qemu_binary, timeout=10, ignore_status=True, verbose=False) self.__hmp_cmds = get_hmp_cmds(qemu_binary) - self.__qmp_cmds = get_qmp_cmds(qemu_binary) + self.__qmp_cmds = get_qmp_cmds(qemu_binary, workaround_qemu_qmp_crash) self.vmname = vmname self.strict_mode = strict_mode == 'yes' self.__devices = [] @@ -1078,7 +1071,7 @@ def str_long(self): out += device.str_long() if out[-1] == '\n': out = out[:-1] - return out + "]" + return out def str_bus_short(self): """ Short representation of all buses """ @@ -1299,31 +1292,14 @@ def cmdline(self): """ out = "" for device in self.__devices: - if device.cmdline(): - out += " %s" % device.cmdline() - return out - - def readconfig(self): - """ - Creates -readconfig-like config for all defined devices. - @return: list, where first item is -readconfig-like config for all - inserted devices. and second item are cmdline options of - devices, which don't have -readconfig fmt specified - """ - out = ["", ""] - for device in self.__devices: - if device.readconfig(): - out[0] += "%s\n\n" % device.readconfig() - elif device.cmdline(): - out[1] += "%s " % device.cmdline() - if out[0]: - out[0] = out[0][:-2] - if out[1]: - out[1] = out[1][:-1] - return out + _out = device.cmdline() + if _out: + out += " %s" % _out + if out: + return out[1:] # Machine related methods - def machine_by_variables(self, params=None): + def machine_by_params(self, params=None): """ Choose the used machine and set the default devices accordingly @param params: VM params diff --git a/virttest/qemu_devices_unittest.py b/virttest/qemu_devices_unittest.py new file mode 100755 index 000000000..60fc4b07c --- /dev/null +++ b/virttest/qemu_devices_unittest.py @@ -0,0 +1,960 @@ +#!/usr/bin/python +""" +This is a unittest for qemu_devices library. + +@author: Lukas Doktor <ldoktor@redhat.com> +@copyright: 2012 Red Hat, Inc. +""" +__author__ = """Lukas Doktor (ldoktor@redhat.com)""" + +import re, unittest, os +import common +from autotest.client.shared.test_utils import mock +import qemu_devices, data_dir + +UNITTEST_DATA_DIR = os.path.join(data_dir.get_root_dir(), "virttest", "unittest_data") + +# Dummy variables +# qemu-1.5.0 human monitor help output +QEMU_HMP = open(os.path.join(UNITTEST_DATA_DIR, "qemu-1.5.0__hmp_help")).read() +# qemu-1.5.0 QMP monitor commands output +QEMU_QMP = open(os.path.join(UNITTEST_DATA_DIR, "qemu-1.5.0__qmp_help")).read() +# qemu-1.5.0 -help +QEMU_HELP = open(os.path.join(UNITTEST_DATA_DIR, "qemu-1.5.0__help")).read() +# qemu-1.5.0 -devices ? +QEMU_DEVICES = open(os.path.join(UNITTEST_DATA_DIR, "qemu-1.5.0__devices_help")).read() +# qemu-1.5.0 -M ? +QEMU_MACHINE = open(os.path.join(UNITTEST_DATA_DIR, "qemu-1.5.0__machine_help")).read() + + +class Devices(unittest.TestCase): + """ set of qemu devices tests """ + def test_q_base_device(self): + """ QBaseDevice tests """ + qdevice = qemu_devices.QBaseDevice('MyType', + {'ParamA': 'ValueA', 'AUTOREMOVE': None}, + 'Object1', + {'type': 'pci'}) + self.assertEqual(qdevice['ParamA'], 'ValueA', 'Param added during ' + '__init__ is corrupted %s != %s' % (qdevice['ParamA'], + 'ValueA')) + qdevice['ParamA'] = 'ValueB' + qdevice.set_param('BoolTrue', True) + qdevice.set_param('BoolFalse', 'off', bool) + qdevice['Empty'] = 'EMPTY_STRING' + + out = """MyType + aid = None + aobject = Object1 + parent_bus = {'type': 'pci'} + child_bus = () + params: + ParamA = ValueB + BoolTrue = on + BoolFalse = off + Empty = "" +""" + self.assertEqual(qdevice.str_long(), out, "Device output doesn't match" + "\n%s\n\n%s" % (qdevice.str_long(), out)) + + def test_q_string_device(self): + """ QStringDevice tests """ + qdevice = qemu_devices.QStringDevice('MyType', {'addr': '0x7'}, + cmdline='-qdevice ahci,addr=%(addr)s') + self.assertEqual(qdevice.cmdline(), '-qdevice ahci,addr=0x7', "Cmdline" + " doesn't match expected one:\n%s\n%s" + % (qdevice.cmdline(), '-qdevice ahci,addr=0x7')) + + def test_q_device(self): + """ QDevice tests """ + qdevice = qemu_devices.QDevice('ahci', {'addr': '0x7'}) + + self.assertEqual(str(qdevice), "a'ahci'", "Alternative name error %s " + "!= %s" % (str(qdevice), "a'ahci'")) + + qdevice['id'] = 'ahci1' + self.assertEqual(str(qdevice), "q'ahci1'", "Id name error %s " + "!= %s" % (str(qdevice), "q'ahci1'")) + + exp = "device_add addr=0x7,driver=ahci,id=ahci1" + out = qdevice.hotplug_hmp() + self.assertEqual(out, exp, "HMP command corrupted:\n%s\n%s" + % (out, exp)) + + exp = ("('device_add', OrderedDict([('addr', '0x7'), " + "('driver', 'ahci'), ('id', 'ahci1')]))") + out = str(qdevice.hotplug_qmp()) + self.assertEqual(out, exp, "QMP command corrupted:\n%s\n%s" + % (out, exp)) + + +class Buses(unittest.TestCase): + """ Set of bus-representation tests """ + def test_q_sparse_bus(self): + """ Sparse bus tests (general bus testing) """ + bus = qemu_devices.QSparseBus('bus', + (['addr1', 'addr2', 'addr3'], [2, 6, 4]), + 'my_bus', + 'bus_type', + 'autotest_bus') + + qdevice = qemu_devices.QDevice + + # Correct records + params = {'addr1': '0', 'addr2': '0', 'addr3': '0', 'bus': 'my_bus'} + dev = qdevice('dev1', params, parent_bus={'type': 'bus_type'}) + exp = True + out = bus.insert(dev, False, False) + self.assertEqual(out, exp, "Failed to add device; %s != %s\n%s\n\n%s" + % (out, exp, dev.str_long(), bus.str_long())) + + params = {'addr1': '1', 'addr2': '0', 'addr3': '0', 'bus': 'my_bus'} + dev = qdevice('dev2', params, parent_bus={'type': 'bus_type'}) + exp = True + out = bus.insert(dev, False, False) + self.assertEqual(out, exp, "Failed to add device; %s != %s\n%s\n\n%s" + % (out, exp, dev.str_long(), bus.str_long())) + + params = {'addr1': '1', 'addr2': '1', 'addr3': '0', 'bus': 'my_bus'} + dev = qdevice('dev3', params, parent_bus={'type': 'bus_type'}) + exp = True + out = bus.insert(dev, False, False) + self.assertEqual(out, exp, "Failed to add device; %s != %s\n%s\n\n%s" + % (out, exp, dev.str_long(), bus.str_long())) + + params = {'addr1': '1', 'addr2': '1', 'addr3': '1', 'bus': 'my_bus'} + dev = qdevice('dev4', params, parent_bus={'type': 'bus_type'}) + exp = True + out = bus.insert(dev, False, False) + self.assertEqual(out, exp, "Failed to add device; %s != %s\n%s\n\n%s" + % (out, exp, dev.str_long(), bus.str_long())) + + params = {'addr1': '1', 'bus': 'my_bus'} + dev = qdevice('dev5', params, parent_bus={'type': 'bus_type'}) + exp = True + out = bus.insert(dev, False, False) + self.assertEqual(out, exp, "Failed to add device; %s != %s\n%s\n\n%s" + % (out, exp, dev.str_long(), bus.str_long())) + + params = {'bus': 'my_bus'} + dev = qdevice('dev6', params, parent_bus={'type': 'bus_type'}) + exp = True + out = bus.insert(dev, False, False) + self.assertEqual(out, exp, "Failed to add device; %s != %s\n%s\n\n%s" + % (out, exp, dev.str_long(), bus.str_long())) + + params = {} + dev = qdevice('dev7', params, parent_bus={'type': 'bus_type'}) + exp = True + out = bus.insert(dev, False, False) + self.assertEqual(out, exp, "Failed to add device; %s != %s\n%s\n\n%s" + % (out, exp, dev.str_long(), bus.str_long())) + + # Compare short repr + exp = ("my_bus(bus_type): {0-0-0:a'dev1',0-0-1:a'dev6',0-0-2:a'dev7'," + "1-0-0:a'dev2',1-0-1:a'dev5',1-1-0:a'dev3',1-1-1:a'dev4'} {}") + out = str(bus.str_short()) + self.assertEqual(out, exp, "Short representation corrupted:\n%s\n%s" + "\n\n%s" % (out, exp, bus.str_long())) + + # Incorrect records + # Used address + params = {'addr1': '0', 'addr2': '0', 'addr3': '0', 'bus': 'my_bus'} + dev = qdevice('devI1', params, parent_bus={'type': 'bus_type'}) + exp = None + out = bus.insert(dev, False, False) + self.assertEqual(out, exp, "Added bad device; %s != %s\n%s\n\n%s" + % (out, exp, dev.str_long(), bus.str_long())) + + # Out of range address + params = {'addr1': '0', 'addr2': '6', 'addr3': '0', 'bus': 'my_bus'} + dev = qdevice('devI2', params, parent_bus={'type': 'bus_type'}) + exp = False + out = bus.insert(dev, False, False) + self.assertEqual(out, exp, "Added bad device; %s != %s\n%s\n\n%s" + % (out, exp, dev.str_long(), bus.str_long())) + + # Incorrect bus name + params = {'bus': 'other_bus'} + dev = qdevice('devI3', params, parent_bus={'type': 'bus_type'}) + exp = False + out = bus.insert(dev, False, False) + self.assertEqual(out, exp, "Added bad device; %s != %s\n%s\n\n%s" + % (out, exp, dev.str_long(), bus.str_long())) + + # Compare short repr + exp = ("my_bus(bus_type): {0-0-0:a'dev1',0-0-1:a'dev6',0-0-2:a'dev7'," + "1-0-0:a'dev2',1-0-1:a'dev5',1-1-0:a'dev3',1-1-1:a'dev4'} {}") + out = str(bus.str_short()) + self.assertEqual(out, exp, "Short representation corrupted:\n%s\n%s" + "\n\n%s" % (out, exp, bus.str_long())) + + # Forced records + # Used address + params = {'addr1': '0', 'addr2': '0', 'addr3': '0', 'bus': 'my_bus'} + dev = qdevice('devB1', params, parent_bus={'type': 'bus_type'}) + exp = "(errors: UsedSlot)" + out = bus.insert(dev, False, True) + self.assertEqual(exp in out, True, "%s not in %s\n%s\n\n%s" + % (exp, out, dev.str_long(), bus.str_long())) + + # Out of range address + params = {'addr1': '0', 'addr2': '6', 'addr3': '0', 'bus': 'my_bus'} + dev = qdevice('devB2', params, parent_bus={'type': 'bus_type'}) + exp = "(errors: BadAddr([0, 6, 0]))" + out = bus.insert(dev, False, True) + self.assertEqual(exp in out, True, "%s not in %s\n%s\n\n%s" + % (exp, out, dev.str_long(), bus.str_long())) + + # Incorrect bus name + params = {'bus': 'other_bus'} + dev = qdevice('devB3', params, parent_bus={'type': 'bus_type'}) + exp = "(errors: BusId)" + out = bus.insert(dev, False, True) + self.assertEqual(exp in out, True, "%s not in %s\n%s\n\n%s" + % (exp, out, dev.str_long(), bus.str_long())) + + # Compare short repr + exp = ("my_bus(bus_type): {0-0-0:a'dev1',0-0-1:a'dev6',0-0-2:a'dev7'," + "0-0-3:a'devB3',1-0-0:a'dev2',1-0-1:a'dev5',1-1-0:a'dev3'," + "1-1-1:a'dev4'} {0-0-0(2x):a'devB1',o0-6-0:a'devB2'}") + out = str(bus.str_short()) + self.assertEqual(out, exp, "Short representation corrupted:\n%s\n%s" + "\n\n%s" % (out, exp, bus.str_long())) + + # Compare long repr + exp = """Bus my_bus, type=bus_type +Slots: +---------------< 1-0-0 >--------------- + device + aid = None + aobject = None + parent_bus = {'type': 'bus_type'} + child_bus = () + params: + bus = my_bus + addr2 = 0 + addr3 = 0 + addr1 = 1 + driver = dev2 +---------------< 1-0-1 >--------------- + device + aid = None + aobject = None + parent_bus = {'type': 'bus_type'} + child_bus = () + params: + bus = my_bus + addr1 = 1 + driver = dev5 +---------------< 1-1-1 >--------------- + device + aid = None + aobject = None + parent_bus = {'type': 'bus_type'} + child_bus = () + params: + bus = my_bus + addr2 = 1 + addr3 = 1 + addr1 = 1 + driver = dev4 +---------------< 1-1-0 >--------------- + device + aid = None + aobject = None + parent_bus = {'type': 'bus_type'} + child_bus = () + params: + bus = my_bus + addr2 = 1 + addr3 = 0 + addr1 = 1 + driver = dev3 +---------------< 0-0-1 >--------------- + device + aid = None + aobject = None + parent_bus = {'type': 'bus_type'} + child_bus = () + params: + bus = my_bus + driver = dev6 +---------------< 0-0-0 >--------------- + device + aid = None + aobject = None + parent_bus = {'type': 'bus_type'} + child_bus = () + params: + bus = my_bus + addr2 = 0 + addr3 = 0 + addr1 = 0 + driver = dev1 +---------------< 0-0-3 >--------------- + device + aid = None + aobject = None + parent_bus = {'type': 'bus_type'} + child_bus = () + params: + bus = my_bus + driver = devB3 +---------------< 0-0-2 >--------------- + device + aid = None + aobject = None + parent_bus = {'type': 'bus_type'} + child_bus = () + params: + driver = dev7 + +---------------< o0-6-0 >--------------- + device + aid = None + aobject = None + parent_bus = {'type': 'bus_type'} + child_bus = () + params: + bus = my_bus + addr2 = 6 + addr3 = 0 + addr1 = 0 + driver = devB2 +---------------< 0-0-0(2x) >--------------- + device + aid = None + aobject = None + parent_bus = {'type': 'bus_type'} + child_bus = () + params: + bus = my_bus + addr2 = 0 + addr3 = 0 + addr1 = 0 + driver = devB1 +""" + out = str(bus.str_long()) + self.assertEqual(out, exp, "Long representation corrupted:\n%s\n%s" + % (repr(out), exp)) + + # Low level functions + # Get device by object + exp = dev + out = bus.get(dev) + self.assertEqual(out, exp, "Failed to get device from bus:\n%s\n%s" + "\n\n%s" % (out, exp, bus.str_long())) + + dev.aid = 'bad_device3' + exp = dev + out = bus.get('bad_device3') + self.assertEqual(out, exp, "Failed to get device from bus:\n%s\n%s" + "\n\n%s" % (out, exp, bus.str_long())) + + exp = None + out = bus.get('missing_bad_device') + self.assertEqual(out, exp, "Got device while expecting None:\n%s\n%s" + "\n\n%s" % (out, exp, bus.str_long())) + + # Remove all devices + devs = [dev for dev in bus] + for dev in devs: + bus.remove(dev) + + exp = 'Bus my_bus, type=bus_type\nSlots:\n\n' + out = str(bus.str_long()) + self.assertEqual(out, exp, "Long representation corrupted:\n%s\n%s" + % (out, exp)) + + def test_q_pci_bus(self): + """ PCI bus tests """ + bus = qemu_devices.QPCIBus('pci.0', 'pci', 'my_pci') + qdevice = qemu_devices.QDevice + + # Good devices + params = {'addr': '0'} + dev = qdevice('dev1', params, parent_bus={'type': 'pci'}) + exp = True + out = bus.insert(dev, False, False) + self.assertEqual(out, exp, "Failed to add device; %s != %s\n%s\n\n%s" + % (out, exp, dev.str_long(), bus.str_long())) + + params = {'addr': 10, 'bus': 'pci.0'} + dev = qdevice('dev2', params, parent_bus={'type': 'pci'}) + exp = True + out = bus.insert(dev, False, False) + self.assertEqual(out, exp, "Failed to add device; %s != %s\n%s\n\n%s" + % (out, exp, dev.str_long(), bus.str_long())) + + params = {'addr': '0x1f'} + dev = qdevice('dev3', params, parent_bus={'type': 'pci'}) + exp = True + out = bus.insert(dev, False, False) + self.assertEqual(out, exp, "Failed to add device; %s != %s\n%s\n\n%s" + % (out, exp, dev.str_long(), bus.str_long())) + + # Compare short repr + exp = ("pci.0(pci): [a'dev1',None,None,None,None,None,None,None,None," + "None,a'dev2',None,None,None,None,None,None,None,None,None," + "None,None,None,None,None,None,None,None,None,None,None," + "a'dev3'] {}") + out = str(bus.str_short()) + self.assertEqual(out, exp, "Short representation corrupted:\n%s\n%s" + "\n\n%s" % (out, exp, bus.str_long())) + + # Incorrect records + # Used address + params = {'addr': 0} + dev = qdevice('devI1', params, parent_bus={'type': 'pci'}) + exp = None + out = bus.insert(dev, False, False) + self.assertEqual(out, exp, "Added bad device; %s != %s\n%s\n\n%s" + % (out, exp, dev.str_long(), bus.str_long())) + + # Out of range address + params = {'addr': '0xffff'} + dev = qdevice('devI2', params, parent_bus={'type': 'pci'}) + exp = False + out = bus.insert(dev, False, False) + self.assertEqual(out, exp, "Added bad device; %s != %s\n%s\n\n%s" + % (out, exp, dev.str_long(), bus.str_long())) + + # Compare short repr + exp = ("pci.0(pci): [a'dev1',None,None,None,None,None,None,None,None," + "None,a'dev2',None,None,None,None,None,None,None,None,None," + "None,None,None,None,None,None,None,None,None,None,None," + "a'dev3'] {}") + out = str(bus.str_short()) + self.assertEqual(out, exp, "Short representation corrupted:\n%s\n%s" + "\n\n%s" % (out, exp, bus.str_long())) + + # Forced records + # Used address + params = {'addr': '0x0'} + dev = qdevice('devB1', params, parent_bus={'type': 'pci'}) + exp = "(errors: UsedSlot)" + out = bus.insert(dev, False, True) + self.assertEqual(exp in out, True, "%s not in %s\n%s\n\n%s" + % (exp, out, dev.str_long(), bus.str_long())) + + # Out of range address + params = {'addr': '0xffff'} + dev = qdevice('devB2', params, parent_bus={'type': 'pci'}) + exp = "(errors: BadAddr([65535]))" + out = bus.insert(dev, False, True) + self.assertEqual(exp in out, True, "%s not in %s\n%s\n\n%s" + % (exp, out, dev.str_long(), bus.str_long())) + + # Incorrect bus name + params = {'bus': 'other_bus'} + dev = qdevice('devB3', params, parent_bus={'type': 'pci'}) + exp = "(errors: BusId)" + out = bus.insert(dev, False, True) + self.assertEqual(exp in out, True, "%s not in %s\n%s\n\n%s" + % (exp, out, dev.str_long(), bus.str_long())) + + # Compare short repr + exp = ("pci.0(pci): [a'dev1',a'devB3',None,None,None,None,None,None," + "None,None,a'dev2',None,None,None,None,None,None,None,None," + "None,None,None,None,None,None,None,None,None,None,None,None," + "a'dev3'] {0x0(2x):a'devB1',o0xffff:a'devB2'}") + out = str(bus.str_short()) + self.assertEqual(out, exp, "Short representation corrupted:\n%s\n%s" + "\n\n%s" % (out, exp, bus.str_long())) + + def test_q_pci_bus_strict(self): + """ PCI bus tests in strict_mode (enforce additional options) """ + bus = qemu_devices.QPCIBus('pci.0', 'pci', 'my_pci') + qdevice = qemu_devices.QDevice + + params = {} + bus.insert(qdevice('dev1', params, parent_bus={'type': 'pci'}), True) + bus.insert(qdevice('dev2', params, parent_bus={'type': 'pci'}), True) + bus.insert(qdevice('dev3', params, parent_bus={'type': 'pci'}), True) + params = {'addr': '0x1f'} + bus.insert(qdevice('dev1', params, parent_bus={'type': 'pci'}), True) + params = {'addr': 30} + bus.insert(qdevice('dev1', params, parent_bus={'type': 'pci'}), True) + params = {'addr': 12} + bus.insert(qdevice('dev1', params, parent_bus={'type': 'pci'}), True) + + # All devices will have 'addr' set as we are in the strict mode + exp = """Bus pci.0, type=pci +Slots: +---------------< 0x0 >--------------- + device + aid = None + aobject = None + parent_bus = {'type': 'pci'} + child_bus = () + params: + driver = dev1 + bus = pci.0 + addr = 0x0 +---------------< 0x1 >--------------- + device + aid = None + aobject = None + parent_bus = {'type': 'pci'} + child_bus = () + params: + driver = dev2 + bus = pci.0 + addr = 0x1 +---------------< 0x2 >--------------- + device + aid = None + aobject = None + parent_bus = {'type': 'pci'} + child_bus = () + params: + driver = dev3 + bus = pci.0 + addr = 0x2 +---------------< 0x3 >--------------- + None +---------------< 0x4 >--------------- + None +---------------< 0x5 >--------------- + None +---------------< 0x6 >--------------- + None +---------------< 0x7 >--------------- + None +---------------< 0x8 >--------------- + None +---------------< 0x9 >--------------- + None +---------------< 0xa >--------------- + None +---------------< 0xb >--------------- + None +---------------< 0xc >--------------- + device + aid = None + aobject = None + parent_bus = {'type': 'pci'} + child_bus = () + params: + addr = 0xc + driver = dev1 + bus = pci.0 +---------------< 0xd >--------------- + None +---------------< 0xe >--------------- + None +---------------< 0xf >--------------- + None +---------------< 0x10 >--------------- + None +---------------< 0x11 >--------------- + None +---------------< 0x12 >--------------- + None +---------------< 0x13 >--------------- + None +---------------< 0x14 >--------------- + None +---------------< 0x15 >--------------- + None +---------------< 0x16 >--------------- + None +---------------< 0x17 >--------------- + None +---------------< 0x18 >--------------- + None +---------------< 0x19 >--------------- + None +---------------< 0x1a >--------------- + None +---------------< 0x1b >--------------- + None +---------------< 0x1c >--------------- + None +---------------< 0x1d >--------------- + None +---------------< 0x1e >--------------- + device + aid = None + aobject = None + parent_bus = {'type': 'pci'} + child_bus = () + params: + addr = 0x1e + driver = dev1 + bus = pci.0 +---------------< 0x1f >--------------- + device + aid = None + aobject = None + parent_bus = {'type': 'pci'} + child_bus = () + params: + addr = 0x1f + driver = dev1 + bus = pci.0 + +""" + out = str(bus.str_long()) + self.assertEqual(out, exp, "Long representation corrupted:\n%s\n%s" + % (repr(out), exp)) + + +class Container(unittest.TestCase): + """ Tests related to the abstract representation of qemu machine """ + def setUp(self): + self.god = mock.mock_god(ut=self) + self.god.stub_function(qemu_devices.utils, "system_output") + + def tearDown(self): + self.god.unstub_all() + + def create_qdev(self, vm_name='vm1'): + """ @return: Initialized qemu_devices.DevContainer object """ + qemu_cmd = '/usr/bin/qemu_kvm' + qemu_devices.utils.system_output.expect_call('%s -help' % qemu_cmd, + timeout=10, ignore_status=True, verbose=False + ).and_return(QEMU_HELP) + qemu_devices.utils.system_output.expect_call("%s -device ? 2>&1" + % qemu_cmd, timeout=10, + ignore_status=True, verbose=False + ).and_return(QEMU_DEVICES) + qemu_devices.utils.system_output.expect_call("%s -M ?" % qemu_cmd, + timeout=10, ignore_status=True, verbose=False + ).and_return(QEMU_MACHINE) + cmd = "echo -e 'help\nquit' | %s -monitor stdio -vnc none" % qemu_cmd + qemu_devices.utils.system_output.expect_call(cmd, timeout=10, + ignore_status=True, verbose=False + ).and_return(QEMU_HMP) + cmd = ('echo -e \'{ "execute": "qmp_capabilities" }\n' + '{ "execute": "query-commands", "id": "RAND91" }\n' + '{ "execute": "quit" }\'' + '| %s -qmp stdio -vnc none | grep return |' + ' grep RAND91' % qemu_cmd) + qemu_devices.utils.system_output.expect_call(cmd, timeout=10, + ignore_status=True, verbose=False + ).and_return('') + + cmd = ('echo -e \'{ "execute": "qmp_capabilities" }\n' + '{ "execute": "query-commands", "id": "RAND91" }\n' + '{ "execute": "quit" }\' | (sleep 1; cat )' + '| %s -qmp stdio -vnc none | grep return |' + ' grep RAND91' % qemu_cmd) + qemu_devices.utils.system_output.expect_call(cmd, timeout=10, + ignore_status=True, verbose=False + ).and_return(QEMU_QMP) + + qdev = qemu_devices.DevContainer(qemu_cmd, vm_name, False) + + self.god.check_playback() + return qdev + + def test_qdev_functional(self): + """ Test basic qdev workflow """ + qdev = self.create_qdev('vm1') + + # Add basic 'pc' devices + for dev in qdev.machine_by_params({'machine_type': 'pc'}): + out = qdev.insert(dev, False) + self.assertEqual(out, None, "Failed to insert device, ret=%s\n%s" + % (out, qdev.str_long())) + + exp = r"""Devices of vm1: +machine + aid = __0 + aobject = None + parent_bus = \(\) + child_bus = \(.*QPCIBus.*\) + params: +i440FX + aid = __1 + aobject = None + parent_bus = \({'type': 'pci'},\) + child_bus = \(\) + params: + addr = 0x0 +PIIX3 + aid = __2 + aobject = None + parent_bus = \({'type': 'pci'},\) + child_bus = \(\) + params: + addr = 0x1""" + out = qdev.str_long() + self.assertNotEqual(re.match(exp, out), None, 'Long representation is' + 'corrupted:\n%s\n%s' % (out, exp)) + + exp = (r"Buses of vm1\n pci.0\(pci\): \[t'i440FX',t'PIIX3'%s\] {}" + % (',None' * 30)) + out = qdev.str_bus_short() + self.assertNotEqual(re.match(exp, out), None, 'Bus representation is' + 'corrupted:\n%s\n%s' % (out, exp)) + + # Insert some good devices + qdevice = qemu_devices.QDevice + + # Device with child bus + bus = qemu_devices.QSparseBus('bus', [['addr'], [6]], 'hba1.0', 'hba', + 'a_hba') + dev = qdevice('HBA', {'id': 'hba1', 'addr': 10}, + parent_bus={'type': 'pci'}, child_bus=bus) + out = qdev.insert(dev, False) + self.assertEqual(out, None, "Failed to insert device, ret=%s\n%s" + % (out, qdev.str_long())) + + # Device inside a child bus by type (most common) + dev = qdevice('dev', {}, parent_bus={'type': 'hba'}) + out = qdev.insert(dev, False) + self.assertEqual(out, None, "Failed to insert device, ret=%s\n%s" + % (out, qdev.str_long())) + + # Device inside a child bus by autotest_id + dev = qdevice('dev', {}, 'autotest_remove', {'aobject': 'a_hba'}) + out = qdev.insert(dev, False) + self.assertEqual(out, None, "Failed to insert device, ret=%s\n%s" + % (out, qdev.str_long())) + + # Device inside a child bus by busid + dev = qdevice('dev', {}, 'autoremove', {'busid': 'hba1.0'}) + out = qdev.insert(dev, False) + self.assertEqual(out, None, "Failed to insert device, ret=%s\n%s" + % (out, qdev.str_long())) + + # Check the representation + exp = ("Devices of vm1: [t'machine',t'i440FX',t'PIIX3',hba1,a'dev'," + "a'dev',a'dev']") + out = qdev.str_short() + self.assertEqual(out, exp, "Short representation is corrupted:\n%s\n%s" + % (out, exp)) + exp = (r"Buses of vm1" + r"\n hba1.0\(hba\): {0:a'dev',1:a'dev',2:a'dev'} {}" + r"\n pci.0\(pci\): \[t'i440FX',t'PIIX3'%s,hba1%s\] {}" + % (',None' * 8, ',None' * 21)) + out = qdev.str_bus_short() + self.assertNotEqual(re.match(exp, out), None, 'Bus representation is' + 'corrupted:\n%s\n%s' % (out, exp)) + + # Force insert bad devices: No matching bus + dev = qdevice('baddev', {}, 'badbus', {'type': 'missing_bus'}) + self.assertRaises(qemu_devices.DeviceInsertError, qdev.insert, dev, + False) + out = qdev.insert(dev, True) + self.assertEqual("No matching bus" in out, True, "Incorrect output of " + "force insertion of the bad dev, ret=%s\n%s" + % (out, qdev.str_long())) + + # Force insert bad devices: Incorrect addr + dev = qdevice('baddev', {'addr': 'bad_value'}, 'badaddr', + {'type': 'pci'}) + self.assertRaises(qemu_devices.DeviceInsertError, qdev.insert, dev, + False) + out = qdev.insert(dev, True) + self.assertEqual("errors: BasicAddress" in out, True, "Incorrect " + "output of force insertion of the bad dev, ret=%s\n%s" + % (out, qdev.str_long())) + + # Force insert bad devices: Duplicite qid + dev = qdevice('baddev', {'id': 'hba1'}, 'badid') + self.assertRaises(qemu_devices.DeviceInsertError, qdev.insert, dev, + False) + out = qdev.insert(dev, True) + self.assertEqual("Devices qid hba1 already used in VM" in out, True, + "Incorrect output of force insertion of the bad dev, " + "ret=%s\n%s" % (out, qdev.str_long())) + + # Check the representation + exp = ("Devices of vm1: [t'machine',t'i440FX',t'PIIX3',hba1,a'dev'," + "a'dev',a'dev',a'baddev',a'baddev',hba1__0]") + out = qdev.str_short() + self.assertEqual(out, exp, "Short representation is corrupted:\n%s\n%s" + % (out, exp)) + exp = (r"Buses of vm1" + r"\n hba1.0\(hba\): {0:a'dev',1:a'dev',2:a'dev'} {}" + r"\n pci.0\(pci\): \[t'i440FX',t'PIIX3',a'baddev'%s,hba1%s\] " + r"{}" % (',None' * 7, ',None' * 21)) + out = qdev.str_bus_short() + self.assertNotEqual(re.match(exp, out), None, 'Bus representation is' + 'corrupted:\n%s\n%s' % (out, exp)) + + # Now representation contains some devices, play with it a bit + # length + out = len(qdev) + self.assertEqual(out, 10, "Length of qdev is incorrect: %s != %s" + % (out, 10)) + + # compare + qdev2 = self.create_qdev('vm1') + self.assertNotEqual(qdev, qdev2, "This qdev matches empty one:" + "\n%s\n%s" % (qdev, qdev2)) + self.assertNotEqual(qdev2, qdev, "Empty qdev matches current one:" + "\n%s\n%s" % (qdev, qdev2)) + for _ in xrange(10): + qdev2.insert(qdevice()) + self.assertNotEqual(qdev, qdev2, "This qdev matches different one:" + "\n%s\n%s" % (qdev, qdev2)) + self.assertNotEqual(qdev2, qdev, "Other qdev matches this one:\n%s\n%s" + % (qdev, qdev2)) + + # cmdline + exp = ("-M pc -device id=hba1,addr=0xa,driver=HBA -device driver=dev " + "-device driver=dev -device driver=dev -device driver=baddev " + "-device addr=0x2,driver=baddev -device id=hba1,driver=baddev") + out = qdev.cmdline() + self.assertEqual(out, exp, 'Corrupted qdev.cmdline() output:\n%s\n%s' + % (out, exp)) + + # get_by_qid (currently we have 2 devices of the same qid) + out = qdev.get_by_qid('hba1') + self.assertEqual(len(out), 2, 'Incorrect number of devices by qid ' + '"hba1": %s != 2\n%s' % (len(out), qdev.str_long())) + + # Remove some devices + # Remove based on aid + out = qdev.remove('hba1__0') + self.assertEqual(out, None, 'Failed to remove device:\n%s\nRepr:\n%s' + % ('hba1__0', qdev.str_long())) + + # Remove device which contains other devices + out = qdev.remove('hba1') + self.assertEqual(out, None, 'Failed to remove device:\n%s\nRepr:\n%s' + % ('hba1', qdev.str_long())) + + # Check the representation + exp = ("Devices of vm1: [t'machine',t'i440FX',t'PIIX3',a'baddev'," + "a'baddev']") + out = qdev.str_short() + self.assertEqual(out, exp, "Short representation is corrupted:\n%s\n%s" + % (out, exp)) + exp = (r"Buses of vm1" + r"\n pci.0\(pci\): \[t'i440FX',t'PIIX3',a'baddev'%s\] " + r"{}" % (',None' * 29)) + out = qdev.str_bus_short() + self.assertNotEqual(re.match(exp, out), None, 'Bus representation is' + 'corrupted:\n%s\n%s' % (out, exp)) + + # pylint: disable=W0212 + def test_qdev_low_level(self): + """ Test low level functions """ + qdev = self.create_qdev('vm1') + + # Representation state (used for hotplug or other nasty things) + qdev._set_dirty() + out = qdev.get_state() + self.assertEqual(out, 1, "qdev state is incorrect %s != %s" % (out, 1)) + + qdev._set_dirty() + out = qdev.get_state() + self.assertEqual(out, 2, "qdev state is incorrect %s != %s" % (out, 1)) + + qdev._set_clean() + out = qdev.get_state() + self.assertEqual(out, 1, "qdev state is incorrect %s != %s" % (out, 1)) + + qdev._set_clean() + out = qdev.get_state() + self.assertEqual(out, 0, "qdev state is incorrect %s != %s" % (out, 1)) + + # __create_unique_aid + dev = qemu_devices.QDevice() + qdev.insert(dev) + out = dev.get_aid() + self.assertEqual(out, '__0', "incorrect aid %s != %s" % (out, '__0')) + + dev = qemu_devices.QDevice(None, {'id': 'qid'}) + qdev.insert(dev) + out = dev.get_aid() + self.assertEqual(out, 'qid', "incorrect aid %s != %s" % (out, 'qid')) + + dev = qemu_devices.QDevice(None, {'id': 'qid'}) + qdev.insert(dev, True) + out = dev.get_aid() + self.assertEqual(out, 'qid__0', "incorrect aid %s != %s" + % (out, 'qid__0')) + + dev = qemu_devices.QDevice(None, {'id': 'qid__1'}) + qdev.insert(dev, True) + out = dev.get_aid() + self.assertEqual(out, 'qid__1', "incorrect aid %s != %s" + % (out, 'qid__1')) + + dev = qemu_devices.QDevice(None, {'id': 'qid'}) + qdev.insert(dev, True) + out = dev.get_aid() + self.assertEqual(out, 'qid__2', "incorrect aid %s != %s" + % (out, 'qid__2')) + + # has_option + out = qdev.has_option('device') + self.assertEqual(out, True) + + out = qdev.has_option('missing_option') + self.assertEqual(out, False) + + # has_device + out = qdev.has_device('ide-drive') + self.assertEqual(out, True) + + out = qdev.has_device('missing_device') + self.assertEqual(out, False) + + # get_help_text + out = qdev.get_help_text() + self.assertEqual(out, QEMU_HELP) + + # has_hmp_cmd + self.assertTrue(qdev.has_hmp_cmd('pcie_aer_inject_error')) + self.assertTrue(qdev.has_hmp_cmd('c')) + self.assertTrue(qdev.has_hmp_cmd('cont')) + self.assertFalse(qdev.has_hmp_cmd('off')) + self.assertFalse(qdev.has_hmp_cmd('\ndump-guest-memory')) + self.assertFalse(qdev.has_hmp_cmd('The')) + + # has_qmp_cmd + self.assertTrue(qdev.has_qmp_cmd('device_add')) + self.assertFalse(qdev.has_qmp_cmd('RAND91')) + + # Add some buses + bus1 = qemu_devices.QPCIBus('pci.0', 'pci', 'a_pci0') + qdev.insert(qemu_devices.QDevice(child_bus=bus1)) + bus2 = qemu_devices.QPCIBus('pci.1', 'pci', 'a_pci1') + qdev.insert(qemu_devices.QDevice(child_bus=bus2)) + bus3 = qemu_devices.QPCIBus('pci.2', 'pci', 'a_pci2') + qdev.insert(qemu_devices.QDevice(child_bus=bus3)) + bus4 = qemu_devices.QPCIBus('pcie.0', 'pcie', 'a_pcie0') + qdev.insert(qemu_devices.QDevice(child_bus=bus4)) + + # get_buses (all buses of this type) + out = qdev.get_buses({'type': 'pci'}) + self.assertEqual(len(out), 3, 'get_buses should return 3 buses but ' + 'returned %s instead:\n%s' % (len(out), out)) + + # get_first_free_bus (last added bus of this type) + out = qdev.get_first_free_bus({'type': 'pci'}, [None]) + self.assertEqual(bus3, out) + + # fill the first pci bus + for _ in xrange(32): + qdev.insert(qemu_devices.QDevice(parent_bus={'type': 'pci'})) + + # get_first_free_bus (last one is full, return the previous one) + out = qdev.get_first_free_bus({'type': 'pci'}, [None]) + self.assertEqual(bus2, out) + + # list_named_buses + out = qdev.list_missing_named_buses('pci.', 'pci', 5) + self.assertEqual(len(out), 2, 'Number of missing named buses is ' + 'incorrect: %s != %s\n%s' % (len(out), 2, out)) + out = qdev.list_missing_named_buses('pci.', 'abc', 5) + self.assertEqual(len(out), 5, 'Number of missing named buses is ' + 'incorrect: %s != %s\n%s' % (len(out), 2, out)) + + # idx_of_next_named_bus + out = qdev.idx_of_next_named_bus('pci.') + self.assertEqual(out, 3, 'Incorrect idx of next named bus: %s !=' + ' %s' % (out, 3)) + # pylint: enable=W0212 + + +if __name__ == "__main__": + unittest.main() diff --git a/virttest/qemu_monitor.py b/virttest/qemu_monitor.py index d1c802f5a..f998cfa2a 100644 --- a/virttest/qemu_monitor.py +++ b/virttest/qemu_monitor.py @@ -277,6 +277,22 @@ def _log_lines(self, log_str): pass + def correct(self, cmd): + """ + Automatic conversion "-" and "_" in commands if the translate command + is supported commands; + """ + def translate(cmd): + return "-".join( re.split("[_-]", cmd)) + + if not self._has_command(cmd): + for _cmd in self._supported_cmds: + if translate(_cmd) == translate(cmd): + logging.info("Convert command %s -> %s", cmd, _cmd) + return _cmd + return cmd + + def is_responsive(self): """ Return True iff the monitor is responsive. @@ -696,46 +712,61 @@ def live_snapshot(self, device, snapshot_file, snapshot_format="qcow2"): return self.cmd(cmd) - def block_stream(self, device, speed=None, base=None): + def block_stream(self, device, speed=None, base=None, + cmd="block_stream", correct=True): """ Start block-stream job; @param device: device ID @param speed: int type, lmited speed(B/s) @param base: base file + @param correct: auto correct command, correct by default @return: The command's output """ - cmd = "block-stream %s" % device + if correct: + cmd = self.correct(cmd) + self.verify_supported_cmd(cmd) + cmd += " %s" % device if speed is not None: - cmd = "%s %sB" % (cmd, speed) + cmd += " %sB" % speed if base: - cmd = "%s %s" % (cmd, base) + cmd += " %s" % base return self.cmd(cmd) - def set_block_job_speed(self, device, speed=0): + def set_block_job_speed(self, device, speed=0, + cmd="block_job_set_speed", correct=True): """ Set limited speed for runnig job on the device @param device: device ID @param speed: int type, limited speed(B/s) + @param correct: auto correct command, correct by default @return: The command's output """ - cmd = "block-job-set-speed %s %sB" % (device, speed) + if correct: + cmd = self.correct(cmd) + self.verify_supported_cmd(cmd) + cmd += " %s %sB" % (device, speed) return self.cmd(cmd) - def cancel_block_job(self, device): + def cancel_block_job(self, device, cmd="block_job_cancel", correct=True): """ Cancel running block stream/mirror job on the device @param device: device ID + @param correct: auto correct command, correct by default @return: The command's output """ - return self.send_args_cmd("block-job-cancel %s" % device) + if correct: + cmd = self.correct(cmd) + self.verify_supported_cmd(cmd) + cmd += " %s" % device + return self.send_args_cmd(cmd) def query_block_job(self, device): @@ -783,7 +814,7 @@ def get_backingfile(self, device): def block_mirror(self, device, target, speed, sync, format, mode, - cmd="__com.redhat_drive-mirror"): + cmd="drive_mirror", correct=True): """ Start mirror type block device copy job @@ -794,25 +825,27 @@ def block_mirror(self, device, target, speed, sync, format, mode, @param mode: target image create mode, 'absolute-paths' or 'existing' @param format: target image format @param cmd: block mirror command + @param correct: auto correct command, correct by default @return: The command's output """ + if correct: + cmd = self.correct(cmd) self.verify_supported_cmd(cmd) - args = " ".join([device, target, format]) - if cmd.startswith("__com.redhat"): - if mode == "existing": - args = "-n %s" % args - if sync == "full": - args ="-f %s" % args - else: - if speed: - args = "%s %sB" % (args, speed) + args = " %s %s %s" % (device, target, format) + info = str(self.cmd("help %s" % cmd)) + if (mode == "existing") and "-n" in info: + args = "-n %s" % args + if (sync == "full") and "-f" in info: + args ="-f %s" % args + if (speed is not None) and ("speed" in info): + args = "%s %s" % (args, speed) cmd = "%s %s" % (cmd, args) return self.cmd(cmd) def block_reopen(self, device, new_image_file, image_format, - cmd="__com.redhat_drive-reopen"): + cmd="block_job_complete", correct=True): """ Reopen new target image @@ -820,13 +853,17 @@ def block_reopen(self, device, new_image_file, image_format, @param new_image_file: new image file name @param image_format: new image file format @param cmd: image reopen command + @param correct: auto correct command, correct by default @return: The command's output """ + if correct: + cmd = self.correct(cmd) self.verify_supported_cmd(cmd) - args = device - if cmd.startswith("__com.redhat"): - args += " ".join([new_image_file, image_format]) + args = "%s" % device + info = str(self.cmd("help %s" % cmd)) + if "format" in info: + args += " %s %s" % (new_image_file, image_format) cmd = "%s %s" % (cmd, args) return self.cmd(cmd) @@ -1419,6 +1456,24 @@ def clear_events(self): self._lock.release() + def clear_event(self, name): + """ + Clear a kinds of events in events list only. + + @raise MonitorLockError: Raised if the lock cannot be acquired + """ + if not self._acquire_lock(): + raise MonitorLockError("Could not acquire exclusive lock to clear " + "QMP event list") + while True: + event = self.get_event(name) + if event: + self._events.remove(event) + else: + break + self._lock.release() + + def get_greeting(self): """ Return QMP greeting message. @@ -1472,7 +1527,7 @@ def send_args_cmd(self, cmdlines, timeout=CMD_TIMEOUT, convert=True): try: if re.match("^[0-9]+$", opt[1]): value = int(opt[1]) - elif re.match("^[0-9]+.[0-9]*$", opt[1]): + elif re.match("^[0-9]+\.[0-9]*$", opt[1]): value = float(opt[1]) elif "True" in opt[1] or "true" in opt[1]: value = True @@ -1621,48 +1676,62 @@ def live_snapshot(self, device, snapshot_file, snapshot_format="qcow2"): return self.cmd("blockdev-snapshot-sync", args) - def block_stream(self, device, speed=None, base=None): + def block_stream(self, device, speed=None, base=None, + cmd="block-stream", correct=True): """ Start block-stream job; @param device: device ID @param speed: int type, limited speed(B/s) @param base: base file + @param correct: auto correct command, correct by default @return: The command's output """ + if correct: + cmd = self.correct(cmd) + self.verify_supported_cmd(cmd) args = {"device": device} if speed is not None: args["speed"] = speed if base: args["base"] = base - return self.cmd("block-stream", args) + return self.cmd(cmd, args) - def set_block_job_speed(self, device, speed=0): + def set_block_job_speed(self, device, speed=0, + cmd="block-job-set-speed", correct=True): """ Set limited speed for runnig job on the device @param device: device ID @param speed: int type, limited speed(B/s) + @param correct: auto correct command, correct by default @return: The command's output """ + if correct: + cmd = self.correct(cmd) + self.verify_supported_cmd(cmd) args = {"device": device, "speed": speed} - return self.cmd("block-job-set-speed", args) + return self.cmd(cmd, args) - def cancel_block_job(self, device): + def cancel_block_job(self, device, cmd="block-job-cancel", correct=True): """ Cancel running block stream/mirror job on the device @param device: device ID + @param correct: auto correct command, correct by default @return: The command's output """ + if correct: + cmd = self.correct(cmd) + self.verify_supported_cmd(cmd) args = {"device": device} - return self.cmd("block-job-cancel", args) + return self.cmd(cmd, args) def query_block_job(self, device): @@ -1702,7 +1771,7 @@ def get_backingfile(self, device): def block_mirror(self, device, target, speed, sync, format, mode, - cmd="__com.redhat_drive-mirror"): + cmd="drive-mirror", correct=True): """ Start mirror type block device copy job @@ -1714,9 +1783,12 @@ def block_mirror(self, device, target, speed, sync, format, mode, @param mode: 'absolute-paths' or 'existing' @param format: target image format @param cmd: block mirror command + @param correct: auto correct command, correct by default @return: The command's output """ + if correct: + cmd = self.correct(cmd) self.verify_supported_cmd(cmd) args = {"device": device, "target": target} @@ -1734,7 +1806,7 @@ def block_mirror(self, device, target, speed, sync, format, mode, def block_reopen(self, device, new_image_file, image_format, - cmd="__com.redhat_drive-reopen"): + cmd="block-job-complete", correct=True): """ Reopen new target image; @@ -1742,12 +1814,15 @@ def block_reopen(self, device, new_image_file, image_format, @param new_image_file: new image file name @param image_format: new image file format @param cmd: image reopen command + @param correct: auto correct command, correct by default @return: the command's output """ + if correct: + cmd = self.correct(cmd) self.verify_supported_cmd(cmd) args = {"device": device} - if cmd.startswith("__com.redhat"): + if cmd.startswith("__"): args["new-image-file"] = new_image_file args["format"] = image_format return self.cmd(cmd, args) diff --git a/virttest/qemu_vm.py b/virttest/qemu_vm.py index a2924c99e..0a92e270f 100644 --- a/virttest/qemu_vm.py +++ b/virttest/qemu_vm.py @@ -581,8 +581,8 @@ def add_log_anaconda(devices): dev.set_param('backend', 'socket') dev.set_param('id', chardev_id) dev.set_param("path", filename) - dev.set_param("server", True, bool) - dev.set_param("wait", False, bool) + dev.set_param("server", 'NO_EQUAL_STRING') + dev.set_param("nowait", 'NO_EQUAL_STRING') devices.insert(dev) dev = QDevice('virtio-serial-pci', parent_bus={'type': 'pci'}) dev.set_param("id", vioser_id) @@ -793,7 +793,7 @@ def add_drive(devices, filename, index=None, fmt=None, cache=None, def add_nic(devices, vlan, model=None, mac=None, device_id=None, netdev_id=None, nic_extra_params=None, pci_addr=None, - bootindex=None): + bootindex=None, queues=1): if model == 'none': return if devices.has_option("device"): @@ -821,6 +821,8 @@ def add_nic(devices, vlan, model=None, mac=None, device_id=None, dev.set_param('model', model) dev.set_param('macaddr', mac, 'NEED_QUOTE') dev.set_param('id', device_id, 'NEED_QUOTE') + if int(queues) > 1 and "virtio" in model: + dev.set_param('mq', 'on') if devices.has_option("netdev"): dev.set_param('netdev', netdev_id) else: @@ -844,6 +846,10 @@ def add_net(devices, vlan, nettype, ifname=None, tftp=None, cmd = " -netdev %s,id=%s" % (mode, netdev_id) if vhost: cmd += ",%s" % vhost + enable_vhostfd = params.get("enable_vhostfd", "yes") + if vhost == 'vhost=on' and enable_vhostfd == 'yes': + vhostfd = os.open("/dev/vhost-net", os.O_RDWR) + cmd += ",vhostfd=%s" % vhostfd if netdev_extra_params: cmd += "%s" % netdev_extra_params else: @@ -1011,33 +1017,56 @@ def set_value(opt_string, key, fallback=None): spice_opts.append(fallback) s_port = str(utils_misc.find_free_port(*port_range)) if optget("spice_port") == "generate": - self.spice_options['spice_port'] = s_port - spice_opts.append("port=%s" % s_port) + if not self.is_alive(): + self.spice_options['spice_port'] = s_port + spice_opts.append("port=%s" % s_port) + self.spice_port = s_port + else: + self.spice_options['spice_port'] = self.spice_port + spice_opts.append("port=%s" % self.spice_port) else: set_value("port=%s", "spice_port") set_value("password=%s", "spice_password", "disable-ticketing") - set_yes_no_value("disable_copy_paste", - yes_value="disable-copy-paste") + if optget("listening_addr") == "ipv4": + host_ip = utils_net.get_host_ip_address(self.params) + self.spice_options['listening_addr'] = "ipv4" + spice_opts.append("addr=%s" % host_ip) + #set_value("addr=%s", "listening_addr", ) + elif optget("listening_addr") == "ipv6": + host_ip = utils_net.get_host_ip_address(self.params) + host_ip_ipv6 = utils_misc.convert_ipv4_to_ipv6(host_ip) + self.spice_options['listening_addr'] = "ipv6" + spice_opts.append("addr=%s" % host_ip_ipv6) + + set_yes_no_value("disable_copy_paste", yes_value="disable-copy-paste") set_value("addr=%s", "spice_addr") if optget("spice_ssl") == "yes": # SSL only part t_port = str(utils_misc.find_free_port(*tls_port_range)) if optget("spice_tls_port") == "generate": - self.spice_options['spice_tls_port'] = t_port - spice_opts.append("tls-port=%s" % t_port) + if not self.is_alive(): + self.spice_options['spice_tls_port'] = t_port + spice_opts.append("tls-port=%s" % t_port) + self.spice_tls_port = t_port + else: + self.spice_options['spice_tls_port'] = self.spice_tls_port + spice_opts.append("tls-port=%s" % self.spice_tls_port) else: set_value("tls-port=%s", "spice_tls_port") prefix = optget("spice_x509_prefix") - if (not os.path.exists(prefix) and + if ((prefix is None or not os.path.exists(prefix)) and (optget("spice_gen_x509") == "yes")): # Generate spice_x509_* is not always necessary, # Regenerate them will make your existing VM # not longer accessiable via encrypted spice. c_subj = optget("spice_x509_cacert_subj") s_subj = optget("spice_x509_server_subj") + #If CN is not specified, add IP of host + if s_subj[-3:] == "CN=": + s_subj += utils_net.get_host_ip_address(self.params) passwd = optget("spice_x509_key_password") secure = optget("spice_x509_secure") @@ -1158,7 +1187,9 @@ def add_cpu_flags(devices, cpu_model, flags=None, vendor_id=None, if vendor_id: cmd += ",vendor=\"%s\"" % vendor_id if flags: - cmd += ",%s" % flags + if not flags.startswith(","): + cmd += "," + cmd += "%s" % flags if family is not None: cmd += ",family=%s" % family return cmd @@ -1268,6 +1299,13 @@ def add_option_rom(devices, opt_rom): return " -option-rom %s" % opt_rom + def add_smartcard(devices, sc_chardev, sc_id): + sc_cmd = " -device usb-ccid,id=ccid0" + sc_cmd += " -chardev " + sc_chardev + sc_cmd += ",id=" + sc_id + ",name=smartcard" + sc_cmd += " -device ccid-card-passthru,chardev=" + sc_id + + return sc_cmd # End of command line option wrappers @@ -1321,11 +1359,6 @@ def add_option_rom(devices, opt_rom): # Set the X11 display parameter if requested if params.get("x11_display"): cmd += "DISPLAY=%s " % params.get("x11_display") - # Update LD_LIBRARY_PATH for built libraries (libspice-server) - library_path = os.path.join(self.root_dir, 'build', 'lib') - if os.path.isdir(library_path): - library_path = os.path.abspath(library_path) - cmd += "LD_LIBRARY_PATH=%s " % library_path if params.get("qemu_audio_drv"): cmd += "QEMU_AUDIO_DRV=%s " % params.get("qemu_audio_drv") # Add command prefix for qemu-kvm. like taskset, valgrind and so on @@ -1345,7 +1378,8 @@ def add_option_rom(devices, opt_rom): # Start constructing devices representation devices = qemu_devices.DevContainer(qemu_binary, self.name, - params.get('strict_mode')) + params.get('strict_mode'), + params.get('workaround_qemu_qmp_crash') == "always") StrDev = qemu_devices.QStringDevice QDevice = qemu_devices.QDevice @@ -1356,7 +1390,7 @@ def add_option_rom(devices, opt_rom): # Add the VM's name devices.insert(StrDev('vmname', cmdline=add_name(devices, name))) - devs = devices.machine_by_variables(params) + devs = devices.machine_by_params(params) for dev in devs: devices.insert(dev) @@ -1632,12 +1666,15 @@ def add_option_rom(devices, opt_rom): else: tapfds = None ifname = nic.get('ifname') + queues = nic.get("queues", 1) # Handle the '-net nic' part + queues = nic.get("queues", 1) + add_nic(devices, vlan, nic_model, mac, device_id, netdev_id, nic_extra, nic_params.get("nic_pci_addr"), - bootindex) - queues = nic.get("queues", 1) + bootindex, queues) + # Handle the '-net tap' or '-net user' or '-netdev' part cmd = add_net(devices, vlan, nettype, ifname, tftp, bootp, redirs, netdev_id, netdev_extra, @@ -1905,15 +1942,16 @@ def add_option_rom(devices, opt_rom): "spice_zlib_glz_wan_compression", "spice_streaming_video", "spice_agent_mouse", "spice_playback_compression", "spice_ipv4", "spice_ipv6", "spice_x509_cert_file", - "disable_copy_paste", "spice_seamless_migration" + "disable_copy_paste", "spice_seamless_migration", + "listening_addr" ) - for skey in spice_keys: - value = params.get(skey, None) - if value: - self.spice_options[skey] = value + for skey in spice_keys: + value = params.get(skey, None) + if value: + self.spice_options[skey] = value - cmd += add_spice() + cmd += add_spice() if cmd: devices.insert(StrDev('display', cmdline=cmd)) @@ -2024,6 +2062,12 @@ def add_option_rom(devices, opt_rom): if params.get("enable_sga") == "yes": devices.insert(StrDev('sga', cmdline=add_sga(devices))) + if params.get("smartcard", "no") == "yes": + sc_chardev = params.get("smartcard_chardev") + sc_id = params.get("smartcard_id") + devices.insert(StrDev('smartcard', + cmdline=add_smartcard(devices, sc_chardev, sc_id))) + if params.get("enable_watchdog", "no") == "yes": cmd = add_watchdog(devices, params.get("watchdog_device_type", None), @@ -2241,6 +2285,10 @@ def create(self, name=None, params=None, root_dir=None, logging.debug(self.devices.str_short()) logging.debug(self.devices.str_bus_short()) qemu_command = self.devices.cmdline() + except error.TestNAError: + # TestNAErrors should be kept as-is so we generate SKIP + # results instead of bogus FAIL results + raise except Exception: for nic in self.virtnet: self._nic_tap_remove_helper(nic) @@ -2397,11 +2445,9 @@ def create(self, name=None, params=None, root_dir=None, raise e logging.debug("VM appears to be alive with PID %s", self.get_pid()) - - o = self.monitor.info("cpus") - vcpu_thread_pattern = params.get("vcpu_thread_pattern", - "thread_id=(\d+)") - self.vcpu_threads = re.findall(vcpu_thread_pattern, str(o)) + vcpu_thread_pattern = self.params.get("vcpu_thread_pattern", + r"thread_id.?[:|=]\s*(\d+)") + self.vcpu_threads = self.get_vcpu_pids(vcpu_thread_pattern) o = commands.getoutput("ps aux") self.vhost_threads = re.findall("\w+\s+(\d+)\s.*\[vhost-%s\]" % self.get_pid(), o) @@ -2751,20 +2797,16 @@ def get_vnc_port(self): return self.vnc_port - def get_vcpu_pids(self, params): + def get_vcpu_pids(self, vcpu_thread_pattern): """ Return the list of vcpu PIDs @return: the list of vcpu PIDs """ - vcpu_thread_pattern = params.get("vcpu_thread_pattern", - "thread_id=(\d+)") return [int(_) for _ in re.findall(vcpu_thread_pattern, str(self.monitor.info("cpus")))] - - def get_shared_meminfo(self): """ Returns the VM's shared memory information. @@ -2964,6 +3006,8 @@ def activate_nic(self, nic_index_or_name): if nic.has_key('mac'): device_add_cmd += ",mac=%s" % nic.mac device_add_cmd += ",id=%s" % nic.nic_name + if int(nic['queues']) > 1 and nic['nic_model'] == 'virtio-net-pci': + device_add_cmd += ",mq=on" device_add_cmd += nic.get('nic_extra_params', '') if nic.has_key('romfile'): device_add_cmd += ",romfile=%s" % nic.romfile @@ -3173,11 +3217,15 @@ def migrate(self, timeout=virt_vm.BaseVM.MIGRATE_TIMEOUT, protocol="tcp", if (self.params["display"] == "spice" and not (protocol == "exec" and "gzip" in migration_exec_cmd_src)): host_ip = utils_net.get_host_ip_address(self.params) - dest_port = clone.spice_options['spice_port'] - if self.params["spice_ssl"] == "yes": - dest_tls_port = clone.spice_options["spice_tls_port"] - cert_subj = clone.spice_options["spice_x509_server_subj"] - cert_subj = "\"%s\"" % cert_subj.replace('/', ',')[1:] + dest_port = clone.spice_options.get('spice_port', '') + if self.params.get("spice_ssl") == "yes": + dest_tls_port = clone.spice_options.get("spice_tls_port", + "") + cert_s = clone.spice_options.get("spice_x509_server_subj", + "") + cert_subj = "%s" % cert_s.replace('/',',')[1:] + cert_subj += host_ip + cert_subj = "\"%s\"" % cert_subj else: dest_tls_port = "" cert_subj = "" @@ -3186,47 +3234,24 @@ def migrate(self, timeout=virt_vm.BaseVM.MIGRATE_TIMEOUT, protocol="tcp", "spice_migrate_info", "client_migrate_info"] - if self.monitor.protocol == "human": - out = self.monitor.cmd("help", debug=False) - for command in commands: - if "\n%s" % command in out: - # spice_migrate_info requires host_ip, dest_port - if command in commands[:2]: - command = "%s %s %s %s %s" % (command, host_ip, - dest_port, dest_tls_port, - cert_subj) - # client_migrate_info also requires protocol - else: - command = "%s %s %s %s %s %s" % (command, - self.params['display'], - host_ip, dest_port, - dest_tls_port, cert_subj) - break - self.monitor.cmd(command) - - elif self.monitor.protocol == "qmp": - out = self.monitor.cmd_obj({"execute": "query-commands"}) - for command in commands: - if {'name': command} in out['return']: - # spice_migrate_info requires host_ip, dest_port - if command in commands[:2]: - command_dict = {"execute": command, - "arguments": - {"hostname": host_ip, - "port": dest_port, - "tls-port": dest_tls_port, - "cert-subject": cert_subj}} - # client_migrate_info also requires protocol - else: - command_dict = {"execute": command, - "arguments": - {"protocol": self.params['display'], - "hostname": host_ip, - "port": dest_port, - "tls-port": dest_tls_port, - "cert-subject": cert_subj}} - break - self.monitor.cmd_obj(command_dict) + for command in commands: + try: + self.monitor.verify_supported_cmd(command) + except qemu_monitor.MonitorNotSupportedCmdError: + continue + # spice_migrate_info requires host_ip, dest_port + # client_migrate_info also requires protocol + cmdline = "%s %s" % (command, host_ip) + if command == "client_migrate_info": + cmdline += " %s" % self.params['display'] + if dest_port: + cmdline += " %s" % dest_port + if dest_tls_port: + cmdline += " %s" % dest_tls_port + if cert_subj: + cmdline += " %s" % cert_subj + break + self.monitor.send_args_cmd(cmdline,convert=False) if protocol in [ "tcp", "rdma", "x-rdma" ]: if local: @@ -3394,7 +3419,8 @@ def send_key(self, keystr): # For compatibility with versions of QEMU that do not recognize all # key names: replace keyname with the hex value from the dict, which # QEMU will definitely accept - key_mapping = {"comma": "0x33", + key_mapping = {"semicolon": "0x27", + "comma": "0x33", "dot": "0x34", "slash": "0x35"} for key, value in key_mapping.items(): @@ -3425,7 +3451,9 @@ def save_to_file(self, path): self.monitor.migrate("exec:cat>%s" % path, wait=False) utils_misc.wait_for( # no monitor.migrate-status method - lambda : "status: completed" in self.monitor.info("migrate"), + lambda : + re.search("(status.*completed)", + str(self.monitor.info("migrate")), re.M), self.MIGRATE_TIMEOUT, 2, 2, "Waiting for save to %s to complete" % path) # Restore the speed and downtime to default values @@ -3591,19 +3619,22 @@ def live_snapshot(self, base_file, snapshot_file, return current_file - def block_stream(self, device, speed, base=None): + def block_stream(self, device, speed, base=None, correct=True): """ start to stream block device, aka merge snapshot; @param device: device ID; @param speed: limited speed, default unit B/s; @param base: base file; + @param correct: auto correct cmd, correct by default """ - return self.monitor.block_stream(device, speed, base) + cmd = self.params.get("block_stream_cmd", "block-stream") + return self.monitor.block_stream(device, speed, base, + cmd, correct=correct) def block_mirror(self, device, target, speed, sync, - format, mode="absolute-paths"): + format, mode="absolute-paths", correct=True): """ Mirror block device to target file; @@ -3614,42 +3645,49 @@ def block_mirror(self, device, target, speed, sync, destination; @param mode: new image open mode @param format: target image format + @param correct: auto correct cmd, correct by default """ - cmd = self.params.get("block_mirror_cmd", "__com.redhat_drive-mirror") - return self.monitor.block_mirror(device, target, speed, - sync, format, mode, cmd) + cmd = self.params.get("block_mirror_cmd", "drive-mirror") + return self.monitor.block_mirror(device, target, speed, sync, + format, mode, cmd, correct=correct) - def block_reopen(self, device, new_image, format="qcow2"): + def block_reopen(self, device, new_image, format="qcow2", correct=True): """ Reopen a new image, no need to do this step in rhel7 host @param device: device ID @param new_image: new image filename @param format: new image format + @param correct: auto correct cmd, correct by default """ - cmd = self.params.get("block_reopen_cmd", "__com.redhat_drive-reopen") - return self.monitor.block_reopen(device, new_image, format, cmd) + cmd = self.params.get("block_reopen_cmd", "block-job-complete") + return self.monitor.block_reopen(device, new_image, + format, cmd, correct=correct) - def cancel_block_job(self, device): + def cancel_block_job(self, device, correct=True): """ cancel active job on the image_file @param device: device ID - @param timeout: seconds wait job cancel timeout, default is 3s + @param correct: auto correct cmd, correct by default """ - return self.monitor.cancel_block_job(device) + cmd = self.params.get("block_job_cancel_cmd", "block-job-cancel") + return self.monitor.cancel_block_job(device, cmd, correct=correct) - def set_job_speed(self, device, speed="0"): + def set_job_speed(self, device, speed="0", correct=True): """ set max speed of block job; @param device: device ID @param speed: max speed of block job + @param correct: auto correct cmd, correct by default """ - return self.monitor.set_block_job_speed(device, speed) + cmd = self.params.get("set_block_job_speed", "block-job-set-speed") + return self.monitor.set_block_job_speed(device, speed, + cmd, correct=correct) def get_job_status(self, device): diff --git a/virttest/remote.py b/virttest/remote.py index 264724846..1bb75ab53 100644 --- a/virttest/remote.py +++ b/virttest/remote.py @@ -1,10 +1,10 @@ """ Functions and classes used for logging into guests and transferring files. """ -import logging, time, re +import logging, time, re, os, shutil, tempfile import aexpect, utils_misc, rss_client from autotest.client.shared import error -from autotest.client import utils +import data_dir class LoginError(Exception): def __init__(self, msg, output): @@ -664,3 +664,163 @@ def copy_files_from(address, client, username, password, port, remote_path, c = rss_client.FileDownloadClient(address, port, log_func) c.download(remote_path, local_path, timeout) c.close() + + +class RemoteFile(object): + """ + Class to handle the operations of file on remote host or guest. + """ + def __init__(self, address, client, username, password, port, + remote_path, limit="", log_filename=None, + verbose=False, timeout=600): + """ + Initialization of RemoteFile class. + + @param address: Address of remote host(guest) + @param client: Type of transfer client + @param username: Username (if required) + @param password: Password (if requried) + @param remote_path: Path of file which we want to edit on remote. + @param limit: Speed limit of file transfer. + @param log_filename: If specified, log all output to this file(SCP only) + @param verbose: If True, log some stats using logging.debug (RSS only) + @param timeout: The time duration (in seconds) to wait for the + transfer tocomplete. + """ + self.address = address + self.client = client + self.username = username + self.password = password + self.port = port + self.remote_path = remote_path + self.limit = limit + self.log_filename = log_filename + self.verbose = verbose + self.timeout = timeout + + #Get a local_path and all actions is taken on it. + filename = os.path.basename(self.remote_path) + + #Get a local_path. + tmp_dir = data_dir.get_tmp_dir() + local_file = tempfile.NamedTemporaryFile(prefix=("%s_" % filename), + dir=tmp_dir) + self.local_path = local_file.name + local_file.close() + + #Get a backup_path. + back_dir = data_dir.get_backing_data_dir() + backup_file = tempfile.NamedTemporaryFile(prefix=("%s_" % filename), + dir=tmp_dir) + self.backup_path = backup_file.name + backup_file.close() + + #Get file from remote. + self._pull_file() + #Save a backup. + shutil.copy(self.local_path, self.backup_path) + + def __del__(self): + """ + Called when the instance is about to be destroyed. + """ + self._reset_file() + if os.path.exists(self.backup_path): + os.remove(self.backup_path) + if os.path.exists(self.local_path): + os.remove(self.local_path) + + def _pull_file(self): + """ + Copy file from remote to local. + """ + if self.client == "test": + shutil.copy(self.remote_path, self.local_path) + else: + copy_files_from(self.address, self.client, self.username, + self.password, self.port, self.remote_path, + self.local_path, self.limit, self.log_filename, + self.verbose, self.timeout) + + def _push_file(self): + """ + Copy file from local to remote. + """ + if self.client == "test": + shutil.copy(self.local_path, self.remote_path) + else: + copy_files_to(self.address, self.client, self.username, + self.password, self.port, self.local_path, + self.remote_path, self.limit, self.log_filename, + self.verbose, self.timeout) + def _reset_file(self): + """ + Copy backup from local to remote. + """ + if self.client == "test": + shutil.copy(self.backup_path, self.remote_path) + else: + copy_files_to(self.address, self.client, self.username, + self.password, self.port, self.backup_path, + self.remote_path, self.limit, self.log_filename, + self.verbose, self.timeout) + + + def _read_local(self): + """ + Read file on local_path. + + @return: string list got from readlines(). + """ + local_file = open(self.local_path, "r") + lines = local_file.readlines() + local_file.close() + return lines + + def _write_local(self, lines): + """ + Write file on local_path. Call writelines method of File. + """ + local_file = open(self.local_path, "w") + local_file.writelines(lines) + local_file.close() + + def add(self, line_list): + """ + Append lines in line_list into file on remote. + """ + lines = self._read_local() + for line in line_list: + lines.append("\n%s" % line) + self._write_local(lines) + self._push_file() + + def sub(self, pattern2repl_dict): + """ + Replace the string which match the pattern + to the value contained in pattern2repl_dict. + """ + lines = self._read_local() + for pattern, repl in pattern2repl_dict.items(): + for index in range(len(lines)): + line = lines[index] + lines[index] = re.sub(pattern, repl, line) + self._write_local(lines) + self._push_file() + + def remove(self, pattern_list): + """ + Remove the lines in remote file which matchs a pattern + in pattern_list. + """ + lines = self._read_local() + for pattern in pattern_list: + for index in range(len(lines)): + line = lines[index] + if re.match(pattern, line): + lines.remove(line) + #Check this line is the last one or not. + if (not line.endswith('\n') and (index >0)): + lines[index-1] = lines[index-1].rstrip("\n") + self._write_local(lines) + self._push_file() diff --git a/virttest/remote_unittest.py b/virttest/remote_unittest.py new file mode 100755 index 000000000..f25d84000 --- /dev/null +++ b/virttest/remote_unittest.py @@ -0,0 +1,73 @@ +#!/usr/bin/python + +import unittest, os +import common, remote, data_dir + +class RemoteFileTest(unittest.TestCase): + tmp_dir = data_dir.get_tmp_dir() + test_file_path = os.path.join(tmp_dir, "remote_file") + default_data = ["RemoteFile Test.\n", "Pattern Line."] + + def __del__(self): + if os.path.exists(self.test_file_path): + os.remove(self.test_file_path) + + def _new_remote_file(self): + if os.path.exists(self.test_file_path): + os.remove(self.test_file_path) + test_file = open(self.test_file_path, "w") + test_file.writelines(self.default_data) + test_file.close() + remote_file = remote.RemoteFile(None, "test", None, None, None, + self.test_file_path) + return remote_file + + def _read_test_file(self): + test_file = open(self.test_file_path, "r") + test_data = test_file.readlines() + test_file.close() + return test_data + + def testAdd(self): + remote_file = self._new_remote_file() + _add_list = ["add_line_1", "add_line_2", "add_line_3"] + remote_file.add(_add_list) + test_data = self._read_test_file() + except_data = ["RemoteFile Test.\n", + "Pattern Line.\n", + "add_line_1\n", + "add_line_2\n", + "add_line_3"] + for index in range(len(except_data)): + self.assertEqual(except_data[index], test_data[index]) + del remote_file + test_data = self._read_test_file() + self.assertEqual(test_data, self.default_data) + + def testSub(self): + remote_file = self._new_remote_file() + _pattern2repl = {r"Remote":"Local", r"^Pat.*$":"Replace Line"} + remote_file.sub(_pattern2repl) + test_data = self._read_test_file() + except_data = ["LocalFile Test.\n", + "Replace Line"] + for index in range(len(except_data)): + self.assertEqual(except_data[index], test_data[index]) + del remote_file + test_data = self._read_test_file() + self.assertEqual(test_data, self.default_data) + + def testRemove(self): + remote_file = self._new_remote_file() + _pattern_list = [r"^Pattern"] + remote_file.remove(_pattern_list) + test_data = self._read_test_file() + except_data = ["RemoteFile Test."] + for index in range(len(except_data)): + self.assertEqual(except_data[index], test_data[index]) + del remote_file + test_data = self._read_test_file() + self.assertEqual(test_data, self.default_data) + +if __name__ == "__main__": + unittest.main() diff --git a/virttest/staging/__init__.py b/virttest/staging/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/virttest/staging/service.py b/virttest/staging/service.py new file mode 100644 index 000000000..8f1e35d8f --- /dev/null +++ b/virttest/staging/service.py @@ -0,0 +1,786 @@ +# Copyright(c) 2013 Intel Corporation. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms and conditions of the GNU General Public License, +# version 2, as published by the Free Software Foundation. +# +# This program is distributed in the hope it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. +# +# The full GNU General Public License is included in this distribution in +# the file called "COPYING". + +import os +import re +import logging + +from autotest.client.shared import error +from tempfile import mktemp +from autotest.client import utils + + +_COMMAND_TABLE_DOC = """ + +Taken from http://fedoraproject.org/wiki/SysVinit_to_Systemd_Cheatsheet + +service frobozz start +systemctl start frobozz.service + Used to start a service (not reboot persistent) + +service frobozz stop +systemctl stop frobozz.service + Used to stop a service (not reboot persistent) + +service frobozz restart +systemctl restart frobozz.service + Used to stop and then start a service + +service frobozz reload +systemctl reload frobozz.service + When supported, reloads the config file without interrupting pending operations. + +service frobozz condrestart +systemctl condrestart frobozz.service + Restarts if the service is already running. + +service frobozz status +systemctl status frobozz.service + Tells whether a service is currently running. + +ls /etc/rc.d/init.d/ +systemctl list-unit-files --type=service (preferred) + Used to list the services that can be started or stopped +ls /lib/systemd/system/*.service /etc/systemd/system/*.service + Used to list all the services and other units + +chkconfig frobozz on +systemctl enable frobozz.service + Turn the service on, for start at next boot, or other trigger. + +chkconfig frobozz off +systemctl disable frobozz.service + Turn the service off for the next reboot, or any other trigger. + +chkconfig frobozz +systemctl is-enabled frobozz.service + Used to check whether a service is configured to start or not in the current environment. + +chkconfig --list +systemctl list-unit-files --type=service(preferred) +ls /etc/systemd/system/*.wants/ + Print a table of services that lists which runlevels each is configured on or off + +chkconfig frobozz --list +ls /etc/systemd/system/*.wants/frobozz.service + Used to list what levels this service is configured on or off + +chkconfig frobozz --add +systemctl daemon-reload + Used when you create a new service file or modify any configuration + + +""" + + +def sys_v_init_result_parser(command): + """ + Parse results from sys_v style commands. + + :param command: command. + :type command: str. + :return: different from the command. + command is status: return true if service is running. + command is is_enabled: return true if service is enalbled. + command is list: return a dict from service name to status. + command is others: return true if operate success. + """ + if command == "status": + def method(cmdResult): + """ + Parse method for service XXX status. + + Returns True if XXX is running. + Returns False if XXX is stopped. + Returns None if XXX is unrecognized. + """ + # If service is stopped, exit_status is also not zero. + # So, we can't use exit_status to check result. + output = cmdResult.stdout.lower() + # Returns None if XXX is unrecognized. + if re.search(r"unrecognized", output): + return None + # Returns False if XXX is stopped. + dead_flags = [r"stopped", r"not running", r"dead"] + for flag in dead_flags: + if re.search(flag, output): + return False + # If output does not contain a dead flag, check it with "running". + return bool(re.search(r"running", output)) + return method + elif command == "list": + def method(cmdResult): + """ + Parse method for service XXX list. + + Return dict from service name to status. + + e.g: + {"sshd": {0: 'off', 1: 'off', 2: 'off', 3: 'off', 4: 'off', 5: 'off', 6: 'off'}, + "vsftpd": {0: 'off', 1: 'off', 2: 'off', 3: 'off', 4: 'off', 5: 'off', 6: 'off'}, + "xinetd": {'discard-dgram:': 'off', 'rsync:': 'off'...'chargen-stream:': 'off'}, + ... + } + """ + if cmdResult.exit_status: + raise error.CmdError(cmdResult.command, cmdResult) + # The final dict to return. + _service2statusOnTarget_dict = {} + # Dict to store status on every target for each service. + _status_on_target = {} + # Dict to store the status for service based on xinetd. + _service2statusOnXinet_dict = {} + lines = cmdResult.stdout.strip().splitlines() + for line in lines: + sublines = line.strip().split() + if len(sublines) == 8: + # Service and status on each target. + service_name = sublines[0] + # Store the status of each target in _status_on_target. + for target in range(7): + status = sublines[target + 1].split(":")[-1] + _status_on_target[target] = status + _service2statusOnTarget_dict[service_name] = _status_on_target.copy() + + elif len(sublines) == 2: + # Service based on xinetd. + service_name = sublines[0].strip(":") + status = sublines[-1] + _service2statusOnXinet_dict[service_name] = status + + else: + # Header or some lines useless. + continue + # Add xinetd based service in the main dict. + _service2statusOnTarget_dict["xinetd"] = _service2statusOnXinet_dict + return _service2statusOnTarget_dict + return method + else: + return _ServiceResultParser.default_method + + +def systemd_result_parser(command): + """ + Parse results from systemd style commands. + + :param command: command. + :type command: str. + :return: different from the command. + command is status: return true if service is running. + command is is_enabled: return true if service is enalbled. + command is list: return a dict from service name to status. + command is others: return true if operate success. + """ + if command == "status": + def method(cmdResult): + """ + Parse method for systemctl status XXX.service. + + Returns True if XXX.service is running. + Returns False if XXX.service is stopped. + Returns None if XXX.service is not loaded. + """ + # If service is stopped, exit_status is also not zero. + # So, we can't use exit_status to check result. + output = cmdResult.stdout + # Returns None if XXX is not loaded. + if not re.search(r"Loaded: loaded", output): + return None + # Check it with Active status. + return (output.count("Active: active") > 0) + return method + elif command == "list": + def method(cmdResult): + """ + Parse method for systemctl list XXX.service. + + Return a dict from service name to status. + + e.g: + {"sshd": "enabled", + "vsftpd": "disabled", + "systemd-sysctl": "static", + ... + } + """ + if cmdResult.exit_status: + raise error.CmdError(cmdResult.command, cmdResult) + # Dict to store service name to status. + _service2status_dict = {} + lines = cmdResult.stdout.strip().splitlines() + for line in lines: + sublines = line.strip().split() + if (not len(sublines) == 2) or (not sublines[0].endswith("service")): + # Some lines useless. + continue + service_name = sublines[0].rstrip(".service") + status = sublines[-1] + _service2status_dict[service_name] = status + return _service2status_dict + return method + else: + return _ServiceResultParser.default_method + + +def sys_v_init_command_generator(command): + """ + Generate lists of command arguments for sys_v style inits. + + :param command: start,stop,restart, etc. + :type command: str + :return: list of commands to pass to utils.run or similar function + :rtype: list + """ + command_name = "service" + if command == "is_enabled": + command_name = "chkconfig" + command = "" + elif command == 'enable': + command_name = "chkconfig" + command = "on" + elif command == 'disable': + command_name = "chkconfig" + command = "off" + elif command == 'list': + # noinspection PyUnusedLocal + def list_command(service_name): + return ["chkconfig", "--list"] + return list_command + elif command == "set_target": + def set_target_command(target): + target = convert_systemd_target_to_runlevel(target) + return ["telinit", target] + return set_target_command + + def method(service_name): + return [command_name, service_name, command] + return method + + +def systemd_command_generator(command): + """ + Generate list of command line argument strings for systemctl. + One argument per string for compatibility Popen + + WARNING: If systemctl detects that it is running on a tty it will use color, + pipe to $PAGER, change column sizes and not truncate unit names. + Use --no-pager to suppress pager output, or set PAGER=cat in the environment. + You may need to take other steps to suppress color output. + See https://bugzilla.redhat.com/show_bug.cgi?id=713567 + + :param command: start,stop,restart, etc. + :type command: str + :return: list of command and arguments to pass to utils.run or similar functions + :rtype: list + """ + command_name = "systemctl" + if command == "is_enabled": + command = "is-enabled" + elif command == "list": + # noinspection PyUnusedLocal + def list_command(service_name): + # systemctl pipes to `less` or $PAGER by default. Workaround this + # add '--full' to avoid systemctl truncates service names. + return [command_name, "list-unit-files", + "--type=service", "--no-pager", "--full"] + return list_command + elif command == "set_target": + def set_target_command(target): + return [command_name, "isolate", target] + return set_target_command + + def method(service_name): + return [command_name, command, "%s.service" % service_name] + return method + + +COMMANDS = ( + "start", + "stop", + "reload", + "restart", + "condrestart", + "status", + "enable", + "disable", + "is_enabled", + "list", + "set_target", +) + + +class _ServiceResultParser(object): + """ + A class that contains staticmethods to parse the result of service command. + """ + + def __init__(self, result_parser, command_list=COMMANDS): + """ + Create staticmethods for each command in command_list using setattr and the + result_parser + + :param result_parser: function that generates functions that parse the result of command. + :type result_parser: function + :param command_list: list of all the commands, e.g. start, stop, restart, etc. + :type command_list: list + """ + self.commands = command_list + for command in self.commands: + setattr(self, command, result_parser(command)) + + @staticmethod + def default_method(cmdResult): + """ + Default method to parse result from command which is not 'list' nor 'status'. + + Returns True if command was executed successfully. + """ + if cmdResult.exit_status: + logging.debug(cmdResult) + return False + else: + return True + + +class _ServiceCommandGenerator(object): + """ + A class that contains staticmethods that generate partial functions that + generate command lists for starting/stopping services. + """ + + def __init__(self, command_generator, command_list=COMMANDS): + """ + Create staticmethods for each command in command_list using setattr and the + command_generator + + :param command_generator: function that generates functions that generate lists of command strings + :type command_generator: function + :param command_list: list of all the commands, e.g. start, stop, restart, etc. + :type command_list: list + """ + self.commands = command_list + for command in self.commands: + setattr(self, command, command_generator(command)) + + +def _get_name_of_init(run=utils.run): + """ + Internal function to determine what executable is PID 1, + aka init by checking /proc/1/exe + :return: executable name for PID 1, aka init + :rtype: str + """ + # /proc/1/comm was added in 2.6.33 and is not in RHEL6.x, so use cmdline + # Non-root can read cmdline + # return os.path.basename(open("/proc/1/cmdline").read().split(chr(0))[0]) + # readlink /proc/1/exe requires root + # inspired by openvswitch.py:ServiceManagerInterface.get_version() + output = run("readlink /proc/1/exe").stdout.strip() + return os.path.basename(output) + + +def get_name_of_init(run=utils.run): + """ + Determine what executable is PID 1, aka init by checking /proc/1/exe + This init detection will only run once and cache the return value. + + :return: executable name for PID 1, aka init + :rtype: str + """ + # _init_name is explicitly undefined so that we get the NameError on first access + # pylint: disable=W0601 + global _init_name + try: + return _init_name + except (NameError, AttributeError): + _init_name = _get_name_of_init(run) + return _init_name + + +class _SpecificServiceManager(object): + + def __init__(self, service_name, service_command_generator, service_result_parser, run=utils.run): + """ + Create staticmethods that call utils.run with the given service_name + for each command in service_command_generator. + + lldpad = SpecificServiceManager("lldpad", + auto_create_specific_service_command_generator()) + lldpad.start() + lldpad.stop() + + :param service_name: init service name or systemd unit name + :type service_name: str + :param service_command_generator: a sys_v_init or systemd command generator + :type service_command_generator: _ServiceCommandGenerator + :param run: function that executes the commands and return CmdResult object, default utils.run + :type run: function + """ + for cmd in service_command_generator.commands: + setattr(self, cmd, + self.generate_run_function(run, + getattr(service_result_parser, cmd), + getattr(service_command_generator, cmd), + service_name)) + + @staticmethod + def generate_run_function(run_func, parse_func, command, service_name): + """ + Generate the wrapped call to utils.run for the given service_name. + + :param run_func: function to execute command and return CmdResult object. + :type run_func: function + :param parse_func: function to parse the result from run. + :type parse_func: function + :param command: partial function that generates the command list + :type command: function + :param service_name: init service name or systemd unit name + :type service_name: str + :return: wrapped utils.run function. + :rtype: function + """ + def run(**kwargs): + """ + Wrapped utils.run invocation that will start, stop, restart, etc. a service. + + :param kwargs: extra arguments to utils.run, .e.g. timeout. But not for ignore_status. + We need a CmdResult to parse and raise a error.TestError if command failed. + We will not let the CmdError out. + :return: result of parse_func. + """ + # If run_func is utils.run by default, we need to set + # ignore_status = True. Otherwise, skip this setting. + if run_func is utils.run: + logging.debug("Setting ignore_status to True.") + kwargs["ignore_status"] = True + result = run_func(" ".join(command(service_name)), **kwargs) + return parse_func(result) + return run + + +class _GenericServiceManager(object): + """ + Base class for SysVInitServiceManager and SystemdServiceManager. + """ + + def __init__(self, service_command_generator, service_result_parser, run=utils.run): + """ + Create staticmethods for each service command, e.g. start, stop, restart. + These staticmethods take as an argument the service to be started or stopped. + + systemd = SpecificServiceManager(auto_create_specific_service_command_generator()) + systemd.start("lldpad") + systemd.stop("lldpad") + + :param service_command_generator: a sys_v_init or systemd command generator + :type service_command_generator: _ServiceCommandGenerator + :param run: function to call the run the commands, default utils.run + :type run: function + """ + #### create staticmethods in class attributes (not used) + # for cmd in service_command_generator.commands: + # setattr(self.__class__, cmd, + # staticmethod(self.generate_run_function(run, getattr(service_command_generator, cmd)))) + #### create functions in instance attributes + for cmd in service_command_generator.commands: + setattr(self, cmd, + self.generate_run_function(run, + getattr(service_result_parser, cmd), + getattr(service_command_generator, cmd))) + + @staticmethod + def generate_run_function(run_func, parse_func, command): + """ + Generate the wrapped call to utils.run for the service command, "service" or "systemctl" + + :param run_func: utils.run + :type run_func: function + :param command: partial function that generates the command list + :type command: function + :return: wrapped utils.run function. + :rtype: function + """ + def run(service="", **kwargs): + """ + Wrapped utils.run invocation that will start, stop, restart, etc. a service. + + :param service: service name, e.g. crond, dbus, etc. + :param kwargs: extra arguments to utils.run, .e.g. timeout. But not for ignore_status. + We need a CmdResult to parse and raise a error.TestError if command failed. + We will not let the CmdError out. + :return: result of parse_func. + """ + # If run_func is utils.run by default, we need to set + # ignore_status = True. Otherwise, skip this setting. + if run_func is utils.run: + logging.debug("Setting ignore_status to True.") + kwargs["ignore_status"] = True + result = run_func(" ".join(command(service)), **kwargs) + return parse_func(result) + return run + + +class _SysVInitServiceManager(_GenericServiceManager): + """ + Concrete class that implements the SysVInitServiceManager + """ + + def __init__(self, service_command_generator, service_result_parser, run=utils.run): + """ + Create the GenericServiceManager for SysV services. + + :param service_command_generator: + :type service_command_generator: _ServiceCommandGenerator + :param run: function to call to run the commands, default utils.run + :type run: function + """ + super(_SysVInitServiceManager, self).__init__(service_command_generator, + service_result_parser, run) + + # @staticmethod + # def change_default_runlevel(runlevel='3'): + # """ + # Set the default sys_v runlevel + # + # :param runlevel: sys_v runlevel to set as default in inittab + # :type runlevel: str + # """ + # raise NotImplemented + + +def convert_sysv_runlevel(level): + """ + Convert runlevel to systemd target. + + :param level: sys_v runlevel + :type level: str or int + :return: systemd target + :rtype: str + :raise ValueError: when runlevel is unknown + """ + runlevel = str(level) + if runlevel == '0': + target = "poweroff.target" + elif runlevel in ['1', "s", "single"]: + target = "rescue.target" + elif runlevel in ['2', '3', '4']: + target = "multi-user.target" + elif runlevel == '5': + target = "graphical.target" + elif runlevel == '6': + target = "reboot.target" + else: + raise ValueError("unknown runlevel %s" % level) + return target + + +def convert_systemd_target_to_runlevel(target): + """ + Convert systemd target to runlevel. + + :param target: systemd target + :type target: str + :return: sys_v runlevel + :rtype: str + :raise ValueError: when systemd target is unknown + """ + if target == "poweroff.target": + runlevel = '0' + elif target == "rescue.target": + runlevel = 's' + elif target == "multi-user.target": + runlevel = '3' + elif target == "graphical.target": + runlevel = '5' + elif target == "reboot.target": + runlevel = '6' + else: + raise ValueError("unknown target %s" % target) + return runlevel + + +class _SystemdServiceManager(_GenericServiceManager): + """ + Concrete class that implements the SystemdServiceManager + """ + + def __init__(self, service_command_generator, service_result_parser, run=utils.run): + """ + Create the GenericServiceManager for systemd services. + + :param service_command_generator: + :type service_command_generator: _ServiceCommandGenerator + :param run: function to call to run the commands, default utils.run + :type run: function + """ + super(_SystemdServiceManager, self).__init__(service_command_generator, + service_result_parser, run) + + @staticmethod + def change_default_runlevel(runlevel='multi-user.target'): + # atomic symlinking, symlink and then rename + """ + Set the default systemd target. + Create the symlink in a temp directory and then use + atomic rename to move the symlink into place. + + :param runlevel: default systemd target + :type runlevel: str + """ + tmp_symlink = mktemp(dir="/etc/systemd/system") + os.symlink("/usr/lib/systemd/system/%s" % runlevel, tmp_symlink) + os.rename(tmp_symlink, "/etc/systemd/system/default.target") + + +_command_generators = {"init": sys_v_init_command_generator, + "systemd": systemd_command_generator} + +_result_parsers = {"init": sys_v_init_result_parser, + "systemd": systemd_result_parser} + +_service_managers = {"init": _SysVInitServiceManager, + "systemd": _SystemdServiceManager} + + +def _get_service_result_parser(run=utils.run): + """ + Get the ServiceResultParser using the auto-detect init command. + + :return: ServiceResultParser fro the current init command. + :rtype: _ServiceResultParser + """ + # pylint: disable=W0601 + global _service_result_parser + try: + return _service_result_parser + except NameError: + result_parser = _result_parsers[get_name_of_init(run)] + _service_result_parser = _ServiceResultParser(result_parser) + return _service_result_parser + + +def _get_service_command_generator(run=utils.run): + """ + Lazy initializer for ServiceCommandGenerator using the auto-detect init command. + + :return: ServiceCommandGenerator for the current init command. + :rtype: _ServiceCommandGenerator + """ + # _service_command_generator is explicitly undefined so that we get the NameError on first access + # pylint: disable=W0601 + global _service_command_generator + try: + return _service_command_generator + except NameError: + command_generator = _command_generators[get_name_of_init(run)] + _service_command_generator = _ServiceCommandGenerator( + command_generator) + return _service_command_generator + + +def ServiceManager(run=utils.run): + """ + Detect which init program is being used, init or systemd and return a + class has methods to start/stop services. + + # Get the system service manager + service_manager = ServiceManager() + + # Stating service/unit "sshd" + service_manager.start("sshd") + + # Getting a list of available units + units = service_manager.list() + + # Disabling and stopping a list of services + services_to_disable = ['ntpd', 'httpd'] + for s in services_to_disable: + service_manager.disable(s) + service_manager.stop(s) + + :return: SysVInitServiceManager or SystemdServiceManager + :rtype: _GenericServiceManager + """ + service_manager = _service_managers[get_name_of_init(run)] + # _service_command_generator is explicitly undefined so that we get the NameError on first access + # pylint: disable=W0601 + global _service_manager + try: + return _service_manager + except NameError: + _service_manager = service_manager(_get_service_command_generator(run), + _get_service_result_parser(run)) + return _service_manager + + +def _auto_create_specific_service_result_parser(run=utils.run): + """ + Create a class that will create partial functions that generate result_parser + for the current init command. + + :return: A ServiceResultParser for the auto-detected init command. + :rtype: _ServiceResultParser + """ + result_parser = _result_parsers[get_name_of_init(run)] + # remove list method + command_list = [c for c in COMMANDS if c not in ["list", "set_target"]] + return _ServiceResultParser(result_parser, command_list) + + +def _auto_create_specific_service_command_generator(run=utils.run): + """ + Create a class that will create partial functions that generate commands + for the current init command. + + lldpad = SpecificServiceManager("lldpad", + auto_create_specific_service_command_generator()) + lldpad.start() + lldpad.stop() + + :return: A ServiceCommandGenerator for the auto-detected init command. + :rtype: _ServiceCommandGenerator + """ + command_generator = _command_generators[get_name_of_init(run)] + # remove list method + command_list = [c for c in COMMANDS if c not in ["list", "set_target"]] + return _ServiceCommandGenerator(command_generator, command_list) + + +def SpecificServiceManager(service_name, run=utils.run): + """ + + # Get the specific service manager for sshd + sshd = SpecificServiceManager("sshd") + sshd.start() + sshd.stop() + sshd.reload() + sshd.restart() + sshd.condrestart() + sshd.status() + sshd.enable() + sshd.disable() + sshd.is_enabled() + + :param service_name: systemd unit or init.d service to manager + :type service_name: str + :return: SpecificServiceManager that has start/stop methods + :rtype: _SpecificServiceManager + """ + return _SpecificServiceManager(service_name, + _auto_create_specific_service_command_generator(run), + _get_service_result_parser(run), run) diff --git a/virttest/utils_cgroup.py b/virttest/staging/utils_cgroup.py similarity index 50% rename from virttest/utils_cgroup.py rename to virttest/staging/utils_cgroup.py index c0055f4af..361279f38 100755 --- a/virttest/utils_cgroup.py +++ b/virttest/staging/utils_cgroup.py @@ -6,11 +6,17 @@ @copyright: 2011 Red Hat Inc. @author: Lukas Doktor <ldoktor@redhat.com> """ -import logging, os, shutil, subprocess, time, re +import logging, os, shutil, subprocess, time, re, random, commands from tempfile import mkdtemp from autotest.client import utils from autotest.client.shared import error +try: + from autotest.client.shared import service +except ImportError: + import service + + class Cgroup(object): """ Cgroup handling class. @@ -50,22 +56,131 @@ def initialize(self, modules): % self.module) - def mk_cgroup(self, pwd=None): + def __get_cgroup_pwd(self, cgroup): + """ + Get cgroup's full path + + @param: cgroup: cgroup name + @return: cgroup's full path + """ + if not isinstance(cgroup, str): + raise error.TestError("cgroup type isn't string!") + return os.path.join(self.root, cgroup) + '/' + + + def get_cgroup_name(self, pwd=None): + """ + Get cgroup's name + + @param: pwd: cgroup name + @return: cgroup's name + """ + if pwd is None: + # root cgroup + return None + if isinstance(pwd, int): + pwd = self.cgroups[pwd] + # self.root is "/cgroup/blkio," not "/cgroup/blkio/" + # cgroup is "/cgroup/blkio/test" or "/cgroup/blkio/test/test" + # expected cgroup name is test/ or test/test/ + if pwd.startswith(self.root + '/'): + return pwd[len(self.root) + 1:] + return None + + + def get_cgroup_index(self, cgroup): + """ + Get cgroup's index in cgroups + + @param: cgroup: cgroup name + @return: index of cgroup + """ + try: + if self.__get_cgroup_pwd(cgroup) not in self.cgroups: + raise error.TestFail("%s not exists!" % cgroup) + cgroup_pwd = self.__get_cgroup_pwd(cgroup) + return self.cgroups.index(cgroup_pwd) + except error.CmdError: + raise error.TestFail("Find index failed!") + + + def mk_cgroup_cgcreate(self, pwd=None, cgroup=None): + """ + Make a cgroup by cgcreate command + + @params: cgroup: Maked cgroup name + @return: last cgroup index + """ + try: + parent_cgroup = self.get_cgroup_name(pwd) + if cgroup is None: + range = "abcdefghijklmnopqrstuvwxyz0123456789" + sub_cgroup = "cgroup-" + "".join(random.sample(range + + range.upper(), 6)) + else: + sub_cgroup = cgroup + if parent_cgroup is None: + cgroup = sub_cgroup + else: + # Parent cgroup:test. Created cgroup:test1. + # Whole cgroup name is "test/test1" + cgroup = os.path.join(parent_cgroup, sub_cgroup) + if self.__get_cgroup_pwd(cgroup) in self.cgroups: + raise error.TestFail("%s exists!" % cgroup) + cgcreate_cmd = "cgcreate -g %s:%s" % (self.module, cgroup) + utils.run(cgcreate_cmd, ignore_status=False) + pwd = self.__get_cgroup_pwd(cgroup) + self.cgroups.append(pwd) + return len(self.cgroups) - 1 + except error.CmdError: + raise error.TestFail("Make cgroup by cgcreate failed!") + + + def mk_cgroup(self, pwd=None, cgroup=None): """ Creates new temporary cgroup @param pwd: where to create this cgroup (default: self.root) - @return: 0 when PASSED + @param cgroup: desired cgroup name + @return: last cgroup index """ - if pwd == None: + if pwd is None: pwd = self.root if isinstance(pwd, int): pwd = self.cgroups[pwd] try: - pwd = mkdtemp(prefix='cgroup-', dir=pwd) + '/' + if cgroup and self.__get_cgroup_pwd(cgroup) in self.cgroups: + raise error.TestFail("%s exists!" % cgroup) + if not cgroup: + pwd = mkdtemp(prefix='cgroup-', dir=pwd) + '/' + else: + pwd = os.path.join(pwd, cgroup) + '/' + if not os.path.exists(pwd): + os.mkdir(pwd) except Exception, inst: raise error.TestError("cg.mk_cgroup(): %s" % inst) self.cgroups.append(pwd) - return pwd + return len(self.cgroups) - 1 + + + def cgexec(self, cgroup, cmd, args=""): + """ + Execute command in desired cgroup + + @param: cgroup: Desired cgroup + @param: cmd: Executed command + @param: args: Executed command's parameters + """ + try: + args_str = "" + if len(args): + args_str = " ".join(args) + cgexec_cmd = ("cgexec -g %s:%s %s %s" % + (self.module, cgroup, cmd, args_str)) + status, output = commands.getstatusoutput(cgexec_cmd) + return status, output + except error.CmdError, detail: + raise error.TestFail("Execute %s in cgroup failed!\n%s" % + (cmd, detail)) def rm_cgroup(self, pwd): @@ -86,6 +201,79 @@ def rm_cgroup(self, pwd): raise error.TestError("cg.rm_cgroup(): %s" % inst) + def cgdelete_all_cgroups(self): + """ + Delete all cgroups in the module + """ + try: + for cgroup_pwd in self.cgroups: + # Ignore sub cgroup + cgroup = self.get_cgroup_name(cgroup_pwd) + if cgroup.count("/") > 0: + continue + self.cgdelete_cgroup(cgroup, True) + except error.CmdError: + raise error.TestFail("cgdelete all cgroups in %s failed!" + % self.module) + + + def cgdelete_cgroup(self, cgroup, recursive=False): + """ + Delete desired cgroup. + + @params cgroup: desired cgroup + @params force:If true, sub cgroup can be deleted with parent cgroup + """ + try: + cgroup_pwd = self.__get_cgroup_pwd(cgroup) + if cgroup_pwd not in self.cgroups: + raise error.TestError("%s doesn't exist!" % cgroup) + cmd = "cgdelete %s:%s" % (self.module, cgroup) + if recursive: + cmd += " -r" + utils.run(cmd, ignore_status=False) + self.cgroups.remove(cgroup_pwd) + except error.CmdError, detail: + raise error.TestFail("cgdelete %s failed!\n%s" % + (cgroup, detail)) + + + def cgclassify_cgroup(self, pid, cgroup): + """ + Classify pid into cgroup + + @param pid: pid of the process + @param cgroup: cgroup name + """ + try: + cgroup_pwd = self.__get_cgroup_pwd(cgroup) + if cgroup_pwd not in self.cgroups: + raise error.TestError("%s doesn't exist!" % cgroup) + cgclassify_cmd = ("cgclassify -g %s:%s %d" % + (self.module, cgroup, pid)) + utils.run(cgclassify_cmd, ignore_status=False) + except error.CmdError, detail: + raise error.TestFail("Classify process to tasks file failed!:%s" % + detail) + + + def get_pids(self, pwd=None): + """ + Get all pids in cgroup + + @params: pwd: cgroup directory + @return: all pids(list) + """ + if pwd == None: + pwd = self.root + if isinstance(pwd, int): + pwd = self.cgroups[pwd] + try: + return [_.strip() for _ in open(os.path.join(pwd, 'tasks'), 'r')] + except Exception, inst: + raise error.TestError("cg.get_pids(): %s" % inst) + + def test(self, cmd): """ Executes cgroup_client.py with cmd parameter. @@ -110,7 +298,7 @@ def is_cgroup(self, pid, pwd): """ if isinstance(pwd, int): pwd = self.cgroups[pwd] - if open(pwd + '/tasks').readlines().count("%d\n" % pid) > 0: + if open(os.path.join(pwd, 'tasks')).readlines().count("%d\n" % pid) > 0: return 0 else: return -1 @@ -131,17 +319,18 @@ def set_cgroup(self, pid, pwd=None): @param pid: pid of the process @param pwd: cgroup directory """ - if pwd == None: + if pwd is None: pwd = self.root if isinstance(pwd, int): pwd = self.cgroups[pwd] try: - open(pwd+'/tasks', 'w').write(str(pid)) + open(os.path.join(pwd, 'tasks'), 'w').write(str(pid)) except Exception, inst: raise error.TestError("cg.set_cgroup(): %s" % inst) if self.is_cgroup(pid, pwd): raise error.TestError("cg.set_cgroup(): Setting %d pid into %s " - "cgroup failed" % (pid, pwd)) + "cgroup failed" % (pid, pwd)) + def set_root_cgroup(self, pid): """ @@ -159,13 +348,13 @@ def get_property(self, prop, pwd=None): @param pwd: cgroup directory @return: [] values or None when FAILED """ - if pwd == None: + if pwd is None: pwd = self.root if isinstance(pwd, int): pwd = self.cgroups[pwd] try: # Remove tailing '\n' from each line - ret = [_[:-1] for _ in open(pwd+prop, 'r').readlines()] + ret = [_[:-1] for _ in open(os.path.join(pwd, prop), 'r')] if ret: return ret else: @@ -210,7 +399,7 @@ def set_property(self, prop, value, pwd=None, check=True, checkprop=None): @param checkprop: override prop when checking the value """ value = str(value) - if pwd == None: + if pwd is None: pwd = self.root if isinstance(pwd, int): pwd = self.cgroups[pwd] @@ -233,6 +422,42 @@ def set_property(self, prop, value, pwd=None, check=True, checkprop=None): % (repr(check), repr(_values))) + def cgset_property(self, prop, value, pwd=None, check=True, checkprop=None): + """ + Sets the property value by cgset command + + @param: prop: property name (file) + @param: value: desired value + @param pwd: cgroup directory + @param check: check the value after setup / override checking value + @param checkprop: override prop when checking the value + """ + if pwd is None: + pwd = self.root + if isinstance(pwd, int): + pwd = self.cgroups[pwd] + try: + cgroup = self.get_cgroup_name(pwd) + cgset_cmd = "cgset -r %s='%s' %s" % (prop, value, cgroup) + utils.run(cgset_cmd, ignore_status=False) + except error.CmdError, detail: + raise error.TestFail("Modify %s failed!:\n%s" % (prop, detail)) + + if check is not False: + if check is True: + check = value + if checkprop is None: + checkprop = prop + _values = self.get_property(checkprop, + self.get_cgroup_index(cgroup)) + # Sanitize non printable characters before check + check = " ".join(check.split()) + if check not in _values: + raise error.TestError("cg.set_property(): Setting failed: " + "desired = %s, real values = %s" + % (repr(check), repr(_values))) + + def smoke_test(self): """ Smoke test @@ -241,10 +466,10 @@ def smoke_test(self): pwd = self.mk_cgroup() ps = self.test("smoke") - if ps == None: + if ps is None: raise error.TestError("cg.smoke_test: Couldn't create process") - if (ps.poll() != None): + if (ps.poll() is not None): raise error.TestError("cg.smoke_test: Process died unexpectidly") # New process should be a root member @@ -260,8 +485,8 @@ def smoke_test(self): except error.TestError: pass else: - raise error.TestError("cg.smoke_test: Unexpected successful deletion" - " of the used cgroup") + raise error.TestError("cg.smoke_test: Unexpected successful" + " deletion of the used cgroup") # Return the process into the root cgroup self.set_root_cgroup(ps.pid) @@ -272,7 +497,7 @@ def smoke_test(self): # Finish the process ps.stdin.write('\n') time.sleep(2) - if (ps.poll() == None): + if (ps.poll() is None): raise error.TestError("cg.smoke_test: Process is not finished") @@ -280,12 +505,19 @@ class CgroupModules(object): """ Handles the list of different cgroup filesystems. """ - def __init__(self): + def __init__(self, mountdir=None): self.modules = [] self.modules.append([]) self.modules.append([]) self.modules.append([]) - self.mountdir = mkdtemp(prefix='cgroup-') + '/' + if mountdir is None: + self.mountdir = mkdtemp(prefix='cgroup-') + '/' + self.rm_mountdir = True + else: + self.mountdir = mountdir + self.rm_mountdir = False + + def __del__(self): """ @@ -299,15 +531,18 @@ def __del__(self): logging.warn("CGM: Couldn't unmount %s directory: %s", self.modules[1][i], failure_detail) try: - shutil.rmtree(self.mountdir) + if self.rm_mountdir: + # If delete /cgroup/, this action will break cgroup service. + shutil.rmtree(self.mountdir) except Exception: logging.warn("CGM: Couldn't remove the %s directory", self.mountdir) + def init(self, _modules): """ Checks the mounted modules and if necessary mounts them into tmp mountdir. - @param _modules: Desired modules. + @param _modules: Desired modules.'memory','cpu,cpuset'... @return: Number of initialized modules. """ logging.debug("Desired cgroup modules: %s", _modules) @@ -323,8 +558,10 @@ def init(self, _modules): for module in _modules: # Is it already mounted? i = False + _module = set(module.split(',')) for mount in mounts: - if module in mount[3].split(','): + # 'memory' or 'memory,cpuset' + if _module.issubset(mount[3].split(',')): self.modules[0].append(module) self.modules[1].append(mount[1] + '/') self.modules[2].append(False) @@ -332,13 +569,15 @@ def init(self, _modules): break if not i: # Not yet mounted - os.mkdir(self.mountdir + module) + module_path = os.path.join(self.mountdir, module) + if not os.path.exists(module_path): + os.mkdir(module_path) cmd = ('mount -t cgroup -o %s %s %s' % - (module, module, self.mountdir + module)) + (module, module, module_path)) try: utils.run(cmd) self.modules[0].append(module) - self.modules[1].append(self.mountdir + module) + self.modules[1].append(module_path) self.modules[2].append(True) except error.CmdError: logging.info("Cgroup module '%s' not available", module) @@ -384,12 +623,14 @@ def get_load_per_cpu(_stats=None): def get_cgroup_mountpoint(controller): - controller_list = [ 'cpuacct', 'cpu', 'memory', 'cpuset', - 'devices', 'freezer', 'blkio', 'netcls' ] + """ + Get desired controller's mountpoint - if controller not in controller_list: + @controller: Desired controller + @return: controller's mountpoint + """ + if controller not in get_all_controllers(): raise error.TestError("Doesn't support controller <%s>" % controller) - f_cgcon = open("/proc/mounts", "rU") cgconf_txt = f_cgcon.read() f_cgcon.close() @@ -397,6 +638,25 @@ def get_cgroup_mountpoint(controller): return mntpt[0] +def get_all_controllers(): + """ + Get all controllers used in system + + @return: all used controllers(controller_list) + """ + try: + result = utils.run("lssubsys", ignore_status=False) + controllers_str = result.stdout.strip() + controller_list = [] + for controller in controllers_str.splitlines(): + controller_sub_list = controller.split(",") + controller_list += controller_sub_list + except error.CmdError: + controller_list = [ 'cpuacct', 'cpu', 'memory', 'cpuset', + 'devices', 'freezer', 'blkio', 'netcls' ] + return controller_list + + def resolve_task_cgroup_path(pid, controller): """ Resolving cgroup mount path of a particular task @@ -406,14 +666,8 @@ def resolve_task_cgroup_path(pid, controller): @return: resolved path for cgroup controllers of a given pid """ - - # Initialise cgroup controller list - controller_list = [ 'cpuacct', 'cpu', 'memory', 'cpuset', - 'devices', 'freezer', 'blkio', 'netcls' ] - - if controller not in controller_list: + if controller not in get_all_controllers(): raise error.TestError("Doesn't support controller <%s>" % controller) - root_path = get_cgroup_mountpoint(controller) proc_cgroup = "/proc/%d/cgroup" % pid @@ -421,41 +675,79 @@ def resolve_task_cgroup_path(pid, controller): raise NameError('File %s does not exist\n Check whether cgroup \ installed in the system' % proc_cgroup) - f = open(proc_cgroup, 'r') - proc_cgroup_txt = f.read() - f.close + try: + proc_file = open(proc_cgroup, 'r') + proc_cgroup_txt = proc_file.read() + finally: + proc_file.close() mount_path = re.findall(r":%s:(\S*)\n" % controller, proc_cgroup_txt) - path = root_path + mount_path[0] - return path + return os.path.join(root_path, mount_path[0]) -def service_cgconfig_control(action): +class CgconfigService(object): """ - Cgconfig control by action. + Cgconfig service class. + """ + def __init__(self): + self._service_manager = service.SpecificServiceManager("cgconfig") + + + def _service_cgconfig_control(self, action): + """ + Cgconfig control by action. + + If cmd executes successfully, return True, otherwise return False. + If the action is status, return True when it's running, otherwise return + False. + + @param: action: cgconfig service action + """ + if not hasattr(self._service_manager, action): + raise error.TestError("Unknown action: %s" % action) + return getattr(self._service_manager, action)() + + + def cgconfig_start(self): + """ + Sart cgconfig service + """ + return self._service_cgconfig_control("start") + + + def cgconfig_stop(self): + """ + Sop cgconfig service + """ + return self._service_cgconfig_control("stop") + + + def cgconfig_restart(self): + """ + Restart cgconfig service + """ + return self._service_cgconfig_control("restart") + + + def cgconfig_condrestart(self): + """ + Condrestart cgconfig service + """ + return self._service_cgconfig_control("condrestart") - If cmd executes successfully, return True, otherwise return False. - If the action is status, return True when it's running, otherwise return - False. - @ param action: start|stop|status|restart|condrestart + def cgconfig_is_running(self): + """ + Check cgconfig service status + """ + return self._service_cgconfig_control("status") + + +def all_cgroup_delete(): """ - actions = ['start', 'stop', 'restart', 'condrestart'] - if action in actions: - try: - utils.run("service cgconfig %s" % action) - logging.debug("%s cgconfig successfuly", action) - return True - except error.CmdError, detail: - logging.error("Failed to %s cgconfig:\n%s", action, detail) - return False - elif action == "status": - cmd_result = utils.run("service cgconfig status", ignore_status=True) - if (not cmd_result.exit_status and - cmd_result.stdout.strip()) == "Running": - logging.info("Cgconfig service is running") - return True - else: - return False - else: - raise error.TestError("Unknown action: %s" % action) + Clear all cgroups in system + """ + try: + utils.run("cgclear", ignore_status=False) + except error.CmdError, detail: + raise error.TestFail("Clear all cgroup failed!:\n%s" % detail) diff --git a/virttest/staging/utils_memory.py b/virttest/staging/utils_memory.py new file mode 100644 index 000000000..a9cd28802 --- /dev/null +++ b/virttest/staging/utils_memory.py @@ -0,0 +1,208 @@ +import re, glob, math, logging +from autotest.client import utils + + +# Returns total memory in kb +def read_from_meminfo(key): + cmd_result = utils.run('grep %s /proc/meminfo' % key, verbose=False) + meminfo = cmd_result.stdout + return int(re.search(r'\d+', meminfo).group(0)) + + +def memtotal(): + return read_from_meminfo('MemTotal') + + +def freememtotal(): + return read_from_meminfo('MemFree') + + +def rounded_memtotal(): + # Get total of all physical mem, in kbytes + usable_kbytes = memtotal() + # usable_kbytes is system's usable DRAM in kbytes, + # as reported by memtotal() from device /proc/meminfo memtotal + # after Linux deducts 1.5% to 5.1% for system table overhead + # Undo the unknown actual deduction by rounding up + # to next small multiple of a big power-of-two + # eg 12GB - 5.1% gets rounded back up to 12GB + mindeduct = 0.015 # 1.5 percent + maxdeduct = 0.055 # 5.5 percent + # deduction range 1.5% .. 5.5% supports physical mem sizes + # 6GB .. 12GB in steps of .5GB + # 12GB .. 24GB in steps of 1 GB + # 24GB .. 48GB in steps of 2 GB ... + # Finer granularity in physical mem sizes would require + # tighter spread between min and max possible deductions + + # increase mem size by at least min deduction, without rounding + min_kbytes = int(usable_kbytes / (1.0 - mindeduct)) + # increase mem size further by 2**n rounding, by 0..roundKb or more + round_kbytes = int(usable_kbytes / (1.0 - maxdeduct)) - min_kbytes + # find least binary roundup 2**n that covers worst-cast roundKb + mod2n = 1 << int(math.ceil(math.log(round_kbytes, 2))) + # have round_kbytes <= mod2n < round_kbytes*2 + # round min_kbytes up to next multiple of mod2n + phys_kbytes = min_kbytes + mod2n - 1 + phys_kbytes = phys_kbytes - (phys_kbytes % mod2n) # clear low bits + return phys_kbytes + + +def numa_nodes(): + node_paths = glob.glob('/sys/devices/system/node/node*') + nodes = [int(re.sub(r'.*node(\d+)', r'\1', x)) for x in node_paths] + return (sorted(nodes)) + + +def node_size(): + nodes = max(len(numa_nodes()), 1) + return ((memtotal() * 1024) / nodes) + + +def get_huge_page_size(): + output = utils.system_output('grep Hugepagesize /proc/meminfo') + return int(output.split()[1]) # Assumes units always in kB. :( + + +def get_num_huge_pages(): + raw_hugepages = utils.system_output('/sbin/sysctl vm.nr_hugepages') + return int(raw_hugepages.split()[2]) + + +def set_num_huge_pages(num): + utils.system('/sbin/sysctl vm.nr_hugepages=%d' % num) + + +def drop_caches(): + """Writes back all dirty pages to disk and clears all the caches.""" + utils.run("sync", verbose=False) + # We ignore failures here as this will fail on 2.6.11 kernels. + utils.run("echo 3 > /proc/sys/vm/drop_caches", ignore_status=True, + verbose=False) + + +def read_from_vmstat(key): + """ + Get specific item value from vmstat + + :param key: The item you want to check from vmstat + :type key: String + :return: The value of the item + :rtype: int + """ + vmstat = open("/proc/vmstat") + vmstat_info = vmstat.read() + vmstat.close() + return int(re.findall("%s\s+(\d+)" % key, vmstat_info)[0]) + + +def read_from_smaps(pid, key): + """ + Get specific item value from the smaps of a process include all sections. + + :param pid: Process id + :type pid: String + :param key: The item you want to check from smaps + :type key: String + :return: The value of the item in kb + :rtype: int + """ + smaps = open("/proc/%s/smaps" % pid) + smaps_info = smaps.read() + smaps.close() + + memory_size = 0 + for each_number in re.findall("%s:\s+(\d+)" % key, smaps_info): + memory_size += int(each_number) + + return memory_size + + +def read_from_numa_maps(pid, key): + """ + Get the process numa related info from numa_maps. This function + only use to get the numbers like anon=1. + + :param pid: Process id + :type pid: String + :param key: The item you want to check from numa_maps + :type key: String + :return: A dict using the address as the keys + :rtype: dict + """ + numa_maps = open("/proc/%s/numa_maps" % pid) + numa_map_info = numa_maps.read() + numa_maps.close() + + + numa_maps_dict = {} + numa_pattern = r"(^[\dabcdfe]+)\s+.*%s[=:](\d+)" % key + for address, number in re.findall(numa_pattern, numa_map_info, re.M): + numa_maps_dict[address] = number + + return numa_maps_dict + + +def get_buddy_info(chunk_sizes, nodes="all", zones="all"): + """ + Get the fragement status of the host. It use the same method + to get the page size in buddyinfo. + 2^chunk_size * page_size + The chunk_sizes can be string make up by all orders that you want to check + splited with blank or a mathematical expression with '>', '<' or '='. + For example: + The input of chunk_size could be: "0 2 4" + And the return will be: {'0': 3, '2': 286, '4': 687} + if you are using expression: ">=9" + the return will be: {'9': 63, '10': 225} + + :param chunk_size: The order number shows in buddyinfo. This is not + the real page size. + :type chunk_size: string + :param nodes: The numa node that you want to check. Default value is all + :type nodes: string + :param zones: The memory zone that you want to check. Default value is all + :type zones: string + :return: A dict using the chunk_size as the keys + :rtype: dict + """ + buddy_info = open("/proc/buddyinfo") + buddy_info_content = buddy_info.read() + buddy_info.close() + + re_buddyinfo = "Node\s+" + if nodes == "all": + re_buddyinfo += "(\d+)" + else: + re_buddyinfo += "(%s)" % "|".join(nodes.split()) + + if not re.findall(re_buddyinfo, buddy_info_content): + logging.warn("Can not find Nodes %s" % nodes) + return None + re_buddyinfo += ".*?zone\s+" + if zones == "all": + re_buddyinfo += "(\w+)" + else: + re_buddyinfo += "(%s)" % "|".join(zones.split()) + if not re.findall(re_buddyinfo, buddy_info_content): + logging.warn("Can not find zones %s" % zones) + return None + re_buddyinfo += "\s+([\s\d]+)" + + buddy_list = re.findall(re_buddyinfo, buddy_info_content) + + if re.findall("[<>=]", chunk_sizes) and buddy_list: + size_list = range(len(buddy_list[-1][-1].strip().split())) + chunk_sizes = [str(_) for _ in size_list if eval("%s %s" % (_, + chunk_sizes))] + + chunk_sizes = ' '.join(chunk_sizes) + + buddyinfo_dict = {} + for chunk_size in chunk_sizes.split(): + buddyinfo_dict[chunk_size] = 0 + for _, _, chunk_info in buddy_list: + chunk_info = chunk_info.strip().split()[int(chunk_size)] + buddyinfo_dict[chunk_size] += int(chunk_info) + + return buddyinfo_dict diff --git a/virttest/standalone_test.py b/virttest/standalone_test.py index 9a4988a02..c48288248 100644 --- a/virttest/standalone_test.py +++ b/virttest/standalone_test.py @@ -188,7 +188,7 @@ def run_once(self): # Preprocess try: - env_process.preprocess(self, params, env) + params = env_process.preprocess(self, params, env) finally: env.save() @@ -804,7 +804,7 @@ def run_tests(parser, options): # Add kvm module status dct["kvm_default"] = utils_misc.get_module_params( - dct.get("sysfs_dir", "sys"), "kvm") + dct.get("sysfs_dir", "/sys"), "kvm") if dct.get("skip") == "yes": continue diff --git a/virttest/unittest_data/qemu-1.5.0__devices_help b/virttest/unittest_data/qemu-1.5.0__devices_help new file mode 100644 index 000000000..723681430 --- /dev/null +++ b/virttest/unittest_data/qemu-1.5.0__devices_help @@ -0,0 +1,135 @@ +name "VGA", bus PCI +name "gus", bus ISA, desc "Gravis Ultrasound GF1" +name "tpci200", bus PCI, desc "TEWS TPCI200 IndustryPack carrier" +name "usb-storage", bus usb-bus +name "scsi-hd", bus SCSI, desc "virtual SCSI disk" +name "i82559a", bus PCI, desc "Intel i82559A Ethernet" +name "i82559b", bus PCI, desc "Intel i82559B Ethernet" +name "i82559c", bus PCI, desc "Intel i82559C Ethernet" +name "esp", bus System +name "sysbus-ohci", bus System, desc "OHCI USB Controller" +name "virtio-blk-pci", bus PCI, alias "virtio-blk" +name "vhost-scsi-pci", bus PCI +name "usb-uas", bus usb-bus +name "x3130-upstream", bus PCI, desc "TI X3130 Upstream Port of PCI Express Switch" +name "ide-drive", bus IDE, desc "virtual IDE disk or CD-ROM (legacy)" +name "virtio-9p-pci", bus PCI +name "cirrus-vga", bus PCI, desc "Cirrus CLGD 54xx VGA" +name "ide-hd", bus IDE, desc "virtual IDE disk" +name "ES1370", bus PCI, desc "ENSONIQ AudioPCI ES1370" +name "ioh3420", bus PCI, desc "Intel IOH device id 3420 PCIE Root Port" +name "virtio-rng-device", bus virtio-bus +name "isa-debug-exit", bus ISA +name "sga", bus ISA, desc "Serial Graphics Adapter" +name "scsi-block", bus SCSI, desc "SCSI block device passthrough" +name "pc-sysfw", bus System, desc "PC System Firmware" +name "usb-serial", bus usb-bus +name "cs4231a", bus ISA, desc "Crystal Semiconductor CS4231A" +name "usb-mouse", bus usb-bus +name "usb-hub", bus usb-bus +name "usb-net", bus usb-bus +name "ne2k_isa", bus ISA +name "icc-bridge", bus System +name "virtio-serial-device", bus virtio-bus +name "virtio-scsi-common", bus virtio-bus +name "scsi-generic", bus SCSI, desc "pass through generic scsi device (/dev/sg*)" +name "pcnet", bus PCI +name "lsi53c895a", bus PCI, alias "lsi" +name "vhost-scsi", bus virtio-bus +name "scsi-disk", bus SCSI, desc "virtual SCSI disk or CD-ROM (legacy)" +name "hda-micro", bus HDA, desc "HDA Audio Codec, duplex (speaker, microphone)" +name "xio3130-downstream", bus PCI, desc "TI X3130 Downstream Port of PCI Express Switch" +name "pci-serial-2x", bus PCI +name "virtserialport", bus virtio-serial-bus +name "usb-braille", bus usb-bus +name "pci-ohci", bus PCI, desc "Apple USB Controller" +name "scsi-cd", bus SCSI, desc "virtual SCSI CD-ROM" +name "q35-pcihost", bus System +name "usb-wacom-tablet", bus usb-bus, desc "QEMU PenPartner Tablet" +name "virtio-net-device", bus virtio-bus +name "ich9-intel-hda", bus PCI, desc "Intel HD Audio Controller (ich9)" +name "nec-usb-xhci", bus PCI +name "isa-serial", bus ISA +name "i82550", bus PCI, desc "Intel i82550 Ethernet" +name "i82551", bus PCI, desc "Intel i82551 Ethernet" +name "usb-bot", bus usb-bus +name "isa-debugcon", bus ISA +name "ide-cd", bus IDE, desc "virtual IDE CD-ROM" +name "SUNW,fdtwo", bus System +name "adlib", bus ISA, desc "Yamaha YM3812 (OPL2)" +name "ich9-usb-uhci1", bus PCI +name "ich9-usb-uhci2", bus PCI +name "pci-serial", bus PCI +name "isa-parallel", bus ISA +name "ich9-usb-uhci4", bus PCI +name "virtconsole", bus virtio-serial-bus +name "ich9-usb-uhci3", bus PCI +name "ich9-usb-uhci5", bus PCI +name "ich9-usb-uhci6", bus PCI +name "ne2k_pci", bus PCI +name "virtio-serial-pci", bus PCI, alias "virtio-serial" +name "hda-duplex", bus HDA, desc "HDA Audio Codec, duplex (line-out, line-in)" +name "intel-hda", bus PCI, desc "Intel HD Audio Controller (ich6)" +name "megasas", bus PCI, desc "LSI MegaRAID SAS 1078" +name "virtio-balloon-device", bus virtio-bus +name "i82559er", bus PCI, desc "Intel i82559ER Ethernet" +name "pci-serial-4x", bus PCI +name "hda-output", bus HDA, desc "HDA Audio Codec, output-only (line-out)" +name "i82562", bus PCI, desc "Intel i82562 Ethernet" +name "sysbus-ahci", bus System +name "usb-ccid", bus usb-bus, desc "CCID Rev 1.1 smartcard reader" +name "ivshmem", bus PCI +name "mch", bus PCI, desc "Host bridge" +name "ipoctal232", bus IndustryPack, desc "GE IP-Octal 232 8-channel RS-232 IndustryPack" +name "AC97", bus PCI, desc "Intel 82801AA AC97 Audio" +name "e1000", bus PCI, desc "Intel Gigabit Ethernet" +name "sysbus-fdc", bus System +name "usb-bt-dongle", bus usb-bus +name "virtio-rng-pci", bus PCI +name "usb-tablet", bus usb-bus +name "pci-testdev", bus PCI, desc "PCI Test Device" +name "isa-vga", bus ISA +name "vfio-pci", bus PCI, desc "VFIO-based PCI device assignment" +name "usb-kbd", bus usb-bus +name "cfi.pflash01", bus System +name "kvm-pci-assign", bus PCI, alias "pci-assign", desc "KVM-based PCI passthrough" +name "isa-applesmc", bus ISA +name "rtl8139", bus PCI +name "pvscsi", bus PCI +name "i82557a", bus PCI, desc "Intel i82557A Ethernet" +name "i82557b", bus PCI, desc "Intel i82557B Ethernet" +name "i82557c", bus PCI, desc "Intel i82557C Ethernet" +name "usb-audio", bus usb-bus +name "ib700", bus ISA +name "piix3-usb-uhci", bus PCI +name "i82801", bus PCI, desc "Intel i82801 Ethernet" +name "ccid-card-passthru", bus ccid-bus, desc "passthrough smartcard" +name "piix4-usb-uhci", bus PCI +name "smbus-eeprom", bus i2c-bus +name "vmware-svga", bus PCI +name "dc390", bus PCI, desc "Tekram DC-390 SCSI adapter" +name "isa-cirrus-vga", bus ISA +name "vmxnet3", bus PCI, desc "VMWare Paravirtualized Ethernet v3" +name "i82801b11-bridge", bus PCI +name "sb16", bus ISA, desc "Creative Sound Blaster 16" +name "xlnx,ps7-usb", bus System +name "am53c974", bus PCI, desc "AMD Am53c974 PCscsi-PCI SCSI adapter" +name "pci-bridge", bus PCI, desc "Standard PCI Bridge" +name "i82558a", bus PCI, desc "Intel i82558A Ethernet" +name "i82558b", bus PCI, desc "Intel i82558B Ethernet" +name "vt82c686b-usb-uhci", bus PCI +name "virtio-balloon-pci", bus PCI, alias "virtio-balloon" +name "isa-ide", bus ISA +name "ich9-usb-ehci1", bus PCI +name "ich9-ahci", bus PCI, alias "ahci" +name "usb-ehci", bus PCI +name "ich9-usb-ehci2", bus PCI +name "usb-host", bus usb-bus +name "i6300esb", bus PCI +name "exynos4210-ehci-usb", bus System +name "virtio-scsi-pci", bus PCI +name "virtio-blk-device", bus virtio-bus +name "pc-testdev", bus ISA +name "virtio-scsi-device", bus virtio-bus +name "virtio-9p-device", bus virtio-bus +name "virtio-net-pci", bus PCI, alias "virtio-net" \ No newline at end of file diff --git a/virttest/unittest_data/qemu-1.5.0__help b/virttest/unittest_data/qemu-1.5.0__help new file mode 100644 index 000000000..3295cf891 --- /dev/null +++ b/virttest/unittest_data/qemu-1.5.0__help @@ -0,0 +1,301 @@ +QEMU emulator version 1.5.0, Copyright (c) 2003-2008 Fabrice Bellard +usage: qemu-system-x86_64 [options] [disk_image] + +'disk_image' is a raw hard disk image for IDE hard disk 0 + +Standard options: +-h or -help display this help and exit +-version display version information and exit +-machine [type=]name[,prop[=value][,...]] + selects emulated machine ('-machine help' for list) + property accel=accel1[:accel2[:...]] selects accelerator + supported accelerators are kvm, xen, tcg (default: tcg) + kernel_irqchip=on|off controls accelerated irqchip support + kvm_shadow_mem=size of KVM shadow MMU + dump-guest-core=on|off include guest memory in a core dump (default=on) + mem-merge=on|off controls memory merge support (default: on) +-cpu cpu select CPU ('-cpu help' for list) +-smp n[,maxcpus=cpus][,cores=cores][,threads=threads][,sockets=sockets] + set the number of CPUs to 'n' [default=1] + maxcpus= maximum number of total cpus, including + offline CPUs for hotplug, etc + cores= number of CPU cores on one socket + threads= number of threads on one CPU core + sockets= number of discrete sockets in the system +-numa node[,mem=size][,cpus=cpu[-cpu]][,nodeid=node] +-add-fd fd=fd,set=set[,opaque=opaque] + Add 'fd' to fd 'set' +-set group.id.arg=value + set <arg> parameter for item <id> of type <group> + i.e. -set drive.$id.file=/path/to/image +-global driver.prop=value + set a global default for a driver property +-boot [order=drives][,once=drives][,menu=on|off] + [,splash=sp_name][,splash-time=sp_time][,reboot-timeout=rb_time][,strict=on|off] + 'drives': floppy (a), hard disk (c), CD-ROM (d), network (n) + 'sp_name': the file's name that would be passed to bios as logo picture, if menu=on + 'sp_time': the period that splash picture last if menu=on, unit is ms + 'rb_timeout': the timeout before guest reboot when boot failed, unit is ms +-m megs set virtual RAM size to megs MB [default=128] +-mem-path FILE provide backing storage for guest RAM +-mem-prealloc preallocate guest memory (use with -mem-path) +-k language use keyboard layout (for example 'fr' for French) +-audio-help print list of audio drivers and their options +-soundhw c1,... enable audio support + and only specified sound cards (comma separated list) + use '-soundhw help' to get the list of supported cards + use '-soundhw all' to enable all of them +-balloon none disable balloon device +-balloon virtio[,addr=str] + enable virtio balloon device (default) +-device driver[,prop[=value][,...]] + add device (based on driver) + prop=value,... sets driver properties + use '-device help' to print all possible drivers + use '-device driver,help' to print all possible properties +-name string1[,process=string2] + set the name of the guest + string1 sets the window title and string2 the process name (on Linux) +-uuid %08x-%04x-%04x-%04x-%012x + specify machine UUID + +Block device options: +-fda/-fdb file use 'file' as floppy disk 0/1 image +-hda/-hdb file use 'file' as IDE hard disk 0/1 image +-hdc/-hdd file use 'file' as IDE hard disk 2/3 image +-cdrom file use 'file' as IDE cdrom image (cdrom is ide1 master) +-drive [file=file][,if=type][,bus=n][,unit=m][,media=d][,index=i] + [,cyls=c,heads=h,secs=s[,trans=t]][,snapshot=on|off] + [,cache=writethrough|writeback|none|directsync|unsafe][,format=f] + [,serial=s][,addr=A][,id=name][,aio=threads|native] + [,readonly=on|off][,copy-on-read=on|off] + [[,bps=b]|[[,bps_rd=r][,bps_wr=w]]][[,iops=i]|[[,iops_rd=r][,iops_wr=w]] + use 'file' as a drive image +-mtdblock file use 'file' as on-board Flash memory image +-sd file use 'file' as SecureDigital card image +-pflash file use 'file' as a parallel flash image +-snapshot write to temporary files instead of disk image files +-hdachs c,h,s[,t] + force hard disk 0 physical geometry and the optional BIOS + translation (t=none or lba) (usually QEMU can guess them) +-fsdev fsdriver,id=id[,path=path,][security_model={mapped-xattr|mapped-file|passthrough|none}] + [,writeout=immediate][,readonly][,socket=socket|sock_fd=sock_fd] +-virtfs local,path=path,mount_tag=tag,security_model=[mapped-xattr|mapped-file|passthrough|none] + [,writeout=immediate][,readonly][,socket=socket|sock_fd=sock_fd] +-virtfs_synth Create synthetic file system image + +USB options: +-usb enable the USB driver (will be the default soon) +-usbdevice name add the host or guest USB device 'name' + +Display options: +-display sdl[,frame=on|off][,alt_grab=on|off][,ctrl_grab=on|off] + [,window_close=on|off]|curses|none| + vnc=<display>[,<optargs>] + select display type +-nographic disable graphical output and redirect serial I/Os to console +-curses use a curses/ncurses interface instead of SDL +-no-frame open SDL window without a frame and window decorations +-alt-grab use Ctrl-Alt-Shift to grab mouse (instead of Ctrl-Alt) +-ctrl-grab use Right-Ctrl to grab mouse (instead of Ctrl-Alt) +-no-quit disable SDL window close capability +-sdl enable SDL +-spice [port=port][,tls-port=secured-port][,x509-dir=<dir>] + [,x509-key-file=<file>][,x509-key-password=<file>] + [,x509-cert-file=<file>][,x509-cacert-file=<file>] + [,x509-dh-key-file=<file>][,addr=addr][,ipv4|ipv6] + [,tls-ciphers=<list>] + [,tls-channel=[main|display|cursor|inputs|record|playback]] + [,plaintext-channel=[main|display|cursor|inputs|record|playback]] + [,sasl][,password=<secret>][,disable-ticketing] + [,image-compression=[auto_glz|auto_lz|quic|glz|lz|off]] + [,jpeg-wan-compression=[auto|never|always]] + [,zlib-glz-wan-compression=[auto|never|always]] + [,streaming-video=[off|all|filter]][,disable-copy-paste] + [,agent-mouse=[on|off]][,playback-compression=[on|off]] + [,seamless-migration=[on|off]] + enable spice + at least one of {port, tls-port} is mandatory +-portrait rotate graphical output 90 deg left (only PXA LCD) +-rotate <deg> rotate graphical output some deg left (only PXA LCD) +-vga [std|cirrus|vmware|qxl|xenfb|none] + select video card type +-full-screen start in full screen +-vnc display start a VNC server on display + +i386 target only: +-win2k-hack use it when installing Windows 2000 to avoid a disk full bug +-no-fd-bootchk disable boot signature checking for floppy disks +-no-acpi disable ACPI +-no-hpet disable HPET +-acpitable [sig=str][,rev=n][,oem_id=str][,oem_table_id=str][,oem_rev=n][,asl_compiler_id=str][,asl_compiler_rev=n][,{data|file}=file1[:file2]...] + ACPI table description +-smbios file=binary + load SMBIOS entry from binary file +-smbios type=0[,vendor=str][,version=str][,date=str][,release=%d.%d] + specify SMBIOS type 0 fields +-smbios type=1[,manufacturer=str][,product=str][,version=str][,serial=str] + [,uuid=uuid][,sku=str][,family=str] + specify SMBIOS type 1 fields + +Network options: +-net nic[,vlan=n][,macaddr=mac][,model=type][,name=str][,addr=str][,vectors=v] + create a new Network Interface Card and connect it to VLAN 'n' +-net user[,vlan=n][,name=str][,net=addr[/mask]][,host=addr][,restrict=on|off] + [,hostname=host][,dhcpstart=addr][,dns=addr][,dnssearch=domain][,tftp=dir] + [,bootfile=f][,hostfwd=rule][,guestfwd=rule][,smb=dir[,smbserver=addr]] + connect the user mode network stack to VLAN 'n', configure its + DHCP server and enabled optional services +-net tap[,vlan=n][,name=str][,fd=h][,fds=x:y:...:z][,ifname=name][,script=file][,downscript=dfile][,helper=helper][,sndbuf=nbytes][,vnet_hdr=on|off][,vhost=on|off][,vhostfd=h][,vhostfds=x:y:...:z][,vhostforce=on|off][,queues=n] + connect the host TAP network interface to VLAN 'n' + use network scripts 'file' (default=/etc/qemu-ifup) + to configure it and 'dfile' (default=/etc/qemu-ifdown) + to deconfigure it + use '[down]script=no' to disable script execution + use network helper 'helper' (default=/usr/local/libexec/qemu-bridge-helper) to + configure it + use 'fd=h' to connect to an already opened TAP interface + use 'fds=x:y:...:z' to connect to already opened multiqueue capable TAP interfaces + use 'sndbuf=nbytes' to limit the size of the send buffer (the + default is disabled 'sndbuf=0' to enable flow control set 'sndbuf=1048576') + use vnet_hdr=off to avoid enabling the IFF_VNET_HDR tap flag + use vnet_hdr=on to make the lack of IFF_VNET_HDR support an error condition + use vhost=on to enable experimental in kernel accelerator + (only has effect for virtio guests which use MSIX) + use vhostforce=on to force vhost on for non-MSIX virtio guests + use 'vhostfd=h' to connect to an already opened vhost net device + use 'vhostfds=x:y:...:z to connect to multiple already opened vhost net devices + use 'queues=n' to specify the number of queues to be created for multiqueue TAP +-net bridge[,vlan=n][,name=str][,br=bridge][,helper=helper] + connects a host TAP network interface to a host bridge device 'br' + (default=br0) using the program 'helper' + (default=/usr/local/libexec/qemu-bridge-helper) +-net socket[,vlan=n][,name=str][,fd=h][,listen=[host]:port][,connect=host:port] + connect the vlan 'n' to another VLAN using a socket connection +-net socket[,vlan=n][,name=str][,fd=h][,mcast=maddr:port[,localaddr=addr]] + connect the vlan 'n' to multicast maddr and port + use 'localaddr=addr' to specify the host address to send packets from +-net socket[,vlan=n][,name=str][,fd=h][,udp=host:port][,localaddr=host:port] + connect the vlan 'n' to another VLAN using an UDP tunnel +-net dump[,vlan=n][,file=f][,len=n] + dump traffic on vlan 'n' to file 'f' (max n bytes per packet) +-net none use it alone to have zero network devices. If no -net option + is provided, the default is '-net nic -net user' +-netdev [user|tap|bridge|socket|hubport],id=str[,option][,option][,...] + +Character device options: +-chardev null,id=id[,mux=on|off] +-chardev socket,id=id[,host=host],port=host[,to=to][,ipv4][,ipv6][,nodelay] + [,server][,nowait][,telnet][,mux=on|off] (tcp) +-chardev socket,id=id,path=path[,server][,nowait][,telnet],[mux=on|off] (unix) +-chardev udp,id=id[,host=host],port=port[,localaddr=localaddr] + [,localport=localport][,ipv4][,ipv6][,mux=on|off] +-chardev msmouse,id=id[,mux=on|off] +-chardev vc,id=id[[,width=width][,height=height]][[,cols=cols][,rows=rows]] + [,mux=on|off] +-chardev ringbuf,id=id[,size=size] +-chardev file,id=id,path=path[,mux=on|off] +-chardev pipe,id=id,path=path[,mux=on|off] +-chardev pty,id=id[,mux=on|off] +-chardev stdio,id=id[,mux=on|off][,signal=on|off] +-chardev serial,id=id,path=path[,mux=on|off] +-chardev tty,id=id,path=path[,mux=on|off] +-chardev parallel,id=id,path=path[,mux=on|off] +-chardev parport,id=id,path=path[,mux=on|off] + +Device URL Syntax: +-iscsi [user=user][,password=password] + [,header-digest=CRC32C|CR32C-NONE|NONE-CRC32C|NONE + [,initiator-name=iqn] + iSCSI session parameters +Bluetooth(R) options: +-bt hci,null dumb bluetooth HCI - doesn't respond to commands +-bt hci,host[:id] + use host's HCI with the given name +-bt hci[,vlan=n] + emulate a standard HCI in virtual scatternet 'n' +-bt vhci[,vlan=n] + add host computer to virtual scatternet 'n' using VHCI +-bt device:dev[,vlan=n] + emulate a bluetooth device 'dev' in scatternet 'n' + +Linux/Multiboot boot specific: +-kernel bzImage use 'bzImage' as kernel image +-append cmdline use 'cmdline' as kernel command line +-initrd file use 'file' as initial ram disk +-dtb file use 'file' as device tree image + +Debug/Expert options: +-serial dev redirect the serial port to char device 'dev' +-parallel dev redirect the parallel port to char device 'dev' +-monitor dev redirect the monitor to char device 'dev' +-qmp dev like -monitor but opens in 'control' mode +-mon chardev=[name][,mode=readline|control][,default] +-debugcon dev redirect the debug console to char device 'dev' +-pidfile file write PID to 'file' +-singlestep always run in singlestep mode +-S freeze CPU at startup (use 'c' to start execution) +-realtime [mlock=on|off] + run qemu with realtime features + mlock=on|off controls mlock support (default: on) +-gdb dev wait for gdb connection on 'dev' +-s shorthand for -gdb tcp::1234 +-d item1,... enable logging of specified items (use '-d help' for a list of log items) +-D logfile output log to logfile (default stderr) +-L path set the directory for the BIOS, VGA BIOS and keymaps +-bios file set the filename for the BIOS +-enable-kvm enable KVM full virtualization support +-xen-domid id specify xen guest domain id +-xen-create create domain using xen hypercalls, bypassing xend + warning: should not be used when xend is in use +-xen-attach attach to existing xen domain + xend will use this when starting QEMU +-no-reboot exit instead of rebooting +-no-shutdown stop before shutdown +-loadvm [tag|id] + start right away with a saved state (loadvm in monitor) +-daemonize daemonize QEMU after initializing +-option-rom rom load a file, rom, into the option ROM space +-clock force the use of the given methods for timer alarm. + To see what timers are available use '-clock help' +-rtc [base=utc|localtime|date][,clock=host|rt|vm][,driftfix=none|slew] + set the RTC base and clock, enable drift fix for clock ticks (x86 only) +-icount [N|auto] + enable virtual instruction counter with 2^N clock ticks per + instruction +-watchdog i6300esb|ib700 + enable virtual hardware watchdog [default=none] +-watchdog-action reset|shutdown|poweroff|pause|debug|none + action when watchdog fires [default=reset] +-echr chr set terminal escape character instead of ctrl-a +-virtioconsole c + set virtio console +-show-cursor show cursor +-tb-size n set TB size +-incoming p prepare for incoming migration, listen on port p +-nodefaults don't create default devices +-chroot dir chroot to dir just before starting the VM +-runas user change to user id user just before starting the VM +-sandbox <arg> Enable seccomp mode 2 system call filter (default 'off'). +-readconfig <file> +-writeconfig <file> + read/write config file +-nodefconfig + do not load default config files at startup +-no-user-config + do not load user-provided config files at startup +-trace [events=<file>][,file=<file>] + specify tracing options +-enable-fips enable FIPS 140-2 compliance +-object TYPENAME[,PROP1=VALUE1,...] + create an new object of type TYPENAME setting properties + in the order they are specified. Note that the 'id' + property must be set. These objects are placed in the + '/objects' path. + +During emulation, the following keys are useful: +ctrl-alt-f toggle full screen +ctrl-alt-n switch to virtual console 'n' +ctrl-alt toggle mouse and keyboard grab + +When using -nographic, press 'ctrl-a h' to get some help. \ No newline at end of file diff --git a/virttest/unittest_data/qemu-1.5.0__hmp_help b/virttest/unittest_data/qemu-1.5.0__hmp_help new file mode 100644 index 000000000..90b2746f9 --- /dev/null +++ b/virttest/unittest_data/qemu-1.5.0__hmp_help @@ -0,0 +1,90 @@ +help +acl_add aclname match allow|deny [index] -- add a match rule to the access control list +acl_policy aclname allow|deny -- set default access control list policy +acl_remove aclname match -- remove a match rule from the access control list +acl_reset aclname -- reset the access control list +acl_show aclname -- list rules in the access control list +balloon target -- request VM to change its memory allocation (in MB) +block_job_cancel [-f] device -- stop an active background block operation (use -f + if the operation is currently paused) +block_job_complete device -- stop an active background block operation +block_job_pause device -- pause an active background block operation +block_job_resume device -- resume a paused background block operation +block_job_set_speed device speed -- set maximum speed for a background block operation +block_passwd block_passwd device password -- set the password of encrypted block devices +block_resize device size -- resize a block image +block_set_io_throttle device bps bps_rd bps_wr iops iops_rd iops_wr -- change I/O throttle limits for a block drive +block_stream device [speed [base]] -- copy data from a backing file into a block device +boot_set bootdevice -- define new values for the boot device list +change device filename [format] -- change a removable medium, optional format +chardev-add args -- add chardev +chardev-remove id -- remove chardev +client_migrate_info protocol hostname port tls-port cert-subject -- send migration info to spice/vnc client +closefd closefd name -- close a file descriptor previously passed via SCM rights +commit device|all -- commit changes to the disk images (if -snapshot is used) or backing files +cpu index -- set the default CPU +c|cont -- resume emulation +delvm tag|id -- delete a VM snapshot from its tag or id +device_add driver[,prop=value][,...] -- add device, like -device on the command line +device_del device -- remove device +drive_add [[<domain>:]<bus>:]<slot> +[file=file][,if=type][,bus=n] +[,unit=m][,media=d][,index=i] +[,cyls=c,heads=h,secs=s[,trans=t]] +[,snapshot=on|off][,cache=on|off] +[,readonly=on|off][,copy-on-read=on|off] -- add drive to PCI storage controller +drive_del device -- remove host block device +drive_mirror [-n] [-f] device target [format] -- initiates live storage + migration for a device. The device's contents are + copied to the new image file, including data that + is written after the command is started. + The -n flag requests QEMU to reuse the image found + in new-image-file, instead of recreating it from scratch. + The -f flag requests QEMU to copy the whole disk, + so that the result does not need a backing file. + +dump-guest-memory [-p] filename [begin] [length] -- dump guest memory to file + begin(optional): the starting physical address + length(optional): the memory size, in bytes +eject [-f] device -- eject a removable medium (use -f to force it) +expire_password protocol time -- set spice/vnc password expire-time +gdbserver [device] -- start gdbserver on given device (default 'tcp::1234'), stop with 'none' +getfd getfd name -- receive a file descriptor via SCM rights and assign it a name +help|? [cmd] -- show the help +host_net_add tap|user|socket|vde|dump [options] -- add host VLAN client +host_net_remove vlan_id name -- remove host VLAN client +hostfwd_add [vlan_id name] [tcp|udp]:[hostaddr]:hostport-[guestaddr]:guestport -- redirect TCP or UDP connections from host to guest (requires -net user) +hostfwd_remove [vlan_id name] [tcp|udp]:[hostaddr]:hostport -- remove host-to-guest TCP or UDP redirection +i /fmt addr -- I/O port read +info [subcommand] -- show various information about the system state +loadvm tag|id -- restore a VM snapshot from its tag or id +log item1[,...] -- activate logging of the specified items +logfile filename -- output logs to 'filename' +mce [-b] cpu bank status mcgstatus addr misc -- inject a MCE on the given CPU [and broadcast to other CPUs with -b option] +memsave addr size file -- save to disk virtual memory dump starting at 'addr' of size 'size' +migrate [-d] [-b] [-i] uri -- migrate to URI (using -d to not wait for completion) + -b for migration without shared storage with full copy of disk + -i for migration without shared storage with incremental copy of disk (base image shared between src and destination) +migrate_cancel -- cancel the current VM migration +migrate_set_cache_size value -- set cache size (in bytes) for XBZRLE migrations,the cache size will be rounded down to the nearest power of 2. +The cache size affects the number of cache misses.In case of a high cache miss ratio you need to increase the cache size +migrate_set_capability capability state -- Enable/Disable the usage of a capability for migration +migrate_set_downtime value -- set maximum tolerated downtime (in seconds) for migrations +migrate_set_speed value -- set maximum speed (in bytes) for migrations. Defaults to MB if no size suffix is specified, ie. B/K/M/G/T +mouse_button state -- change mouse button state (1=L, 2=M, 4=R) +mouse_move dx dy [dz] -- send mouse move events +mouse_set index -- set which mouse device receives events +nbd_server_add nbd_server_add [-w] device -- export a block device via NBD +nbd_server_start nbd_server_start [-a] [-w] host:port -- serve block devices on the given host and port +nbd_server_stop nbd_server_stop -- stop serving block devices using the NBD protocol +netdev_add [user|tap|socket|hubport],id=str[,prop=value][,...] -- add host network device +netdev_del id -- remove host network device +nmi -- inject an NMI on all guest's CPUs +o /fmt addr value -- I/O port write +pci_add auto|[[<domain>:]<bus>:]<slot> nic|storage [[vlan=n][,macaddr=addr][,model=type]] [file=file][,if=type][,bus=nr]... -- hot-add PCI device +pci_del [[<domain>:]<bus>:]<slot> -- hot remove PCI device +pcie_aer_inject_error [-a] [-c] id <error_status> [<tlp header> [<tlp header prefix>]] -- inject pcie aer error + -a for advisory non fatal error + -c for correctable error + <id> = qdev device id + <error_status> = error string or 32bit \ No newline at end of file diff --git a/virttest/unittest_data/qemu-1.5.0__machine_help b/virttest/unittest_data/qemu-1.5.0__machine_help new file mode 100644 index 000000000..1a9ca1419 --- /dev/null +++ b/virttest/unittest_data/qemu-1.5.0__machine_help @@ -0,0 +1,19 @@ +Supported machines are: +none empty machine +pc Standard PC (i440FX + PIIX, 1996) (alias of pc-i440fx-1.5) +pc-i440fx-1.5 Standard PC (i440FX + PIIX, 1996) (default) +pc-i440fx-1.4 Standard PC (i440FX + PIIX, 1996) +pc-1.3 Standard PC +pc-1.2 Standard PC +pc-1.1 Standard PC +pc-1.0 Standard PC +pc-0.15 Standard PC +pc-0.14 Standard PC +pc-0.13 Standard PC +pc-0.12 Standard PC +pc-0.11 Standard PC, qemu 0.11 +pc-0.10 Standard PC, qemu 0.10 +isapc ISA-only PC +q35 Standard PC (Q35 + ICH9, 2009) (alias of pc-q35-1.5) +pc-q35-1.5 Standard PC (Q35 + ICH9, 2009) +pc-q35-1.4 Standard PC (Q35 + ICH9, 2009) \ No newline at end of file diff --git a/virttest/unittest_data/qemu-1.5.0__qmp_help b/virttest/unittest_data/qemu-1.5.0__qmp_help new file mode 100644 index 000000000..e7a86623c --- /dev/null +++ b/virttest/unittest_data/qemu-1.5.0__qmp_help @@ -0,0 +1 @@ +{"return": [{"name": "chardev-remove"}, {"name": "chardev-add"}, {"name": "query-tpm-types"}, {"name": "query-tpm-models"}, {"name": "query-tpm"}, {"name": "query-target"}, {"name": "query-cpu-definitions"}, {"name": "query-machines"}, {"name": "device-list-properties"}, {"name": "qom-list-types"}, {"name": "change-vnc-password"}, {"name": "nbd-server-stop"}, {"name": "nbd-server-add"}, {"name": "nbd-server-start"}, {"name": "qom-get"}, {"name": "qom-set"}, {"name": "qom-list"}, {"name": "query-block-jobs"}, {"name": "query-balloon"}, {"name": "query-migrate-capabilities"}, {"name": "migrate-set-capabilities"}, {"name": "query-migrate"}, {"name": "query-command-line-options"}, {"name": "query-uuid"}, {"name": "query-name"}, {"name": "query-vnc"}, {"name": "query-mice"}, {"name": "query-status"}, {"name": "query-kvm"}, {"name": "query-pci"}, {"name": "query-cpus"}, {"name": "query-blockstats"}, {"name": "query-block"}, {"name": "query-chardev"}, {"name": "query-events"}, {"name": "query-commands"}, {"name": "query-version"}, {"name": "human-monitor-command"}, {"name": "qmp_capabilities"}, {"name": "add_client"}, {"name": "expire_password"}, {"name": "set_password"}, {"name": "block_set_io_throttle"}, {"name": "block_passwd"}, {"name": "query-fdsets"}, {"name": "remove-fd"}, {"name": "add-fd"}, {"name": "closefd"}, {"name": "getfd"}, {"name": "set_link"}, {"name": "balloon"}, {"name": "drive-mirror"}, {"name": "blockdev-snapshot-sync"}, {"name": "transaction"}, {"name": "block-job-complete"}, {"name": "block-job-resume"}, {"name": "block-job-pause"}, {"name": "block-job-cancel"}, {"name": "block-job-set-speed"}, {"name": "block-commit"}, {"name": "block-stream"}, {"name": "block_resize"}, {"name": "netdev_del"}, {"name": "netdev_add"}, {"name": "dump-guest-memory"}, {"name": "client_migrate_info"}, {"name": "migrate_set_downtime"}, {"name": "migrate_set_speed"}, {"name": "query-migrate-cache-size"}, {"name": "migrate-set-cache-size"}, {"name": "migrate_cancel"}, {"name": "migrate"}, {"name": "xen-set-global-dirty-log"}, {"name": "xen-save-devices-state"}, {"name": "ringbuf-read"}, {"name": "ringbuf-write"}, {"name": "inject-nmi"}, {"name": "pmemsave"}, {"name": "memsave"}, {"name": "cpu-add"}, {"name": "cpu"}, {"name": "send-key"}, {"name": "device_del"}, {"name": "device_add"}, {"name": "system_powerdown"}, {"name": "system_reset"}, {"name": "system_wakeup"}, {"name": "cont"}, {"name": "stop"}, {"name": "screendump"}, {"name": "change"}, {"name": "eject"}, {"name": "quit"}], "id": "RAND91"} \ No newline at end of file diff --git a/virttest/unittest_data/testcfg.huge/multi-host-tests.cfg b/virttest/unittest_data/testcfg.huge/multi-host-tests.cfg index f27ecc52f..dcd9c8b4b 100644 --- a/virttest/unittest_data/testcfg.huge/multi-host-tests.cfg +++ b/virttest/unittest_data/testcfg.huge/multi-host-tests.cfg @@ -24,7 +24,7 @@ variants: only pc only Fedora.17.64 cpu_model = "core2duo" - cpu_model_flags = "+sse3" + cpu_model_flags = ",+sse3" only migrate_multi_host # Runs qemu, f16 64 bit guest OS, install, boot, shutdown diff --git a/virttest/unittest_data/testcfg.huge/test1.cfg.repr.gz b/virttest/unittest_data/testcfg.huge/test1.cfg.repr.gz index 3a3d70f57..562707ffb 100644 Binary files a/virttest/unittest_data/testcfg.huge/test1.cfg.repr.gz and b/virttest/unittest_data/testcfg.huge/test1.cfg.repr.gz differ diff --git a/virttest/utils_disk.py b/virttest/utils_disk.py index 0d8539f62..8ffb3ec6f 100644 --- a/virttest/utils_disk.py +++ b/virttest/utils_disk.py @@ -3,8 +3,7 @@ @copyright: Red Hat Inc. """ - -import os, glob, shutil, tempfile, logging, ConfigParser +import os, glob, shutil, tempfile, logging, ConfigParser,re from autotest.client import utils from autotest.client.shared import error @@ -260,3 +259,135 @@ def close(self): cleanup(self.source_cdrom) logging.debug("unattended install CD image %s successfully created", self.path) + + +class GuestFSModiDisk(object): + """ + class of guest disk using guestfs lib to do some operation(like read/write) + on guest disk: + """ + + def __init__(self, disk): + try: + import guestfs + except ImportError: + install_cmd = "yum -y install python-libguestfs" + try: + utils.run(install_cmd) + import guestfs + except Exception: + raise error.TestNAError('We need python-libguestfs (or the ' + 'equivalent for your distro) for this ' + 'particular feature (modifying guest ' + 'files with libguestfs)') + + self.g = guestfs.GuestFS() + self.disk = disk + self.g.add_drive(disk) + logging.debug("Launch the disk %s, wait..." % self.disk) + self.g.launch() + + def os_inspects(self): + self.roots = self.g.inspect_os() + if self.roots: + return self.roots + else: + return None + + def mounts(self): + return self.g.mounts() + + def mount_all(self): + def compare (a, b): + if len(a[0]) > len(b[0]): + return 1 + elif len(a[0]) == len(b[0]): + return 0 + else: + return -1 + + roots = self.os_inspects() + if roots: + for root in roots: + mps = self.g.inspect_get_mountpoints(root) + mps.sort(compare) + for mp_dev in mps: + try: + msg = "Mount dev '%s' partitions '%s' to '%s'" + logging.info(msg % (root, mp_dev[1], mp_dev[0])) + self.g.mount(mp_dev[1], mp_dev[0]) + except RuntimeError as err_msg: + logging.info("%s (ignored)" % err_msg) + else: + raise error.TestError("inspect_vm: no operating systems found") + + def umount_all (self): + logging.debug("Umount all device partitions") + if self.mounts(): + self.g.umount_all() + + def read_file(self, file_name): + """ + read file from the guest disk, return the content of the file + + @Param file_name: the file you want to read. + """ + + try: + self.mount_all() + o = self.g.cat(file_name) + if o: + return o + else: + err_msg = "Can't read file '%s', check is it exist?" + raise error.TestError(err_msg % file_name) + finally: + self.umount_all() + + def write_to_image_file(self, file_name, content, w_append=False): + """ + wirte content to the file on the guest disk. + when using this method all the original content will be overriding. + if you don't hope your original data be override make: + 'w_append=True' + + @Param file_name: the file you want to write + @Param content: the content you want to write. + @Param w_append append the content or override + """ + + try: + self.mount_all() + if w_append: + self.g.write_append(file_name, content) + else: + self.g.write(file_name, content) + except Exception: + raise error.TestError("write '%s' to file '%s' error!" + % (content, file_name )) + finally: + self.umount_all() + + def replace_image_file_content(self, file_name, find_con, rep_con): + """ + replace file content matchs in the file with rep_con. + suport using Regular expression + + @Param file_name: the file you want to replace + @Param find_con: the orign content you want to replace. + @Param rep_con: the replace content you want. + """ + + try: + self.mount_all() + file_content = self.g.cat(file_name) + if file_content: + file_content_after_replace = re.sub(find_con, rep_con, + file_content) + if file_content != file_content_after_replace: + self.g.write(file_name, file_content_after_replace) + else: + err_msg = "Can't read file '%s', check is it exist?" + raise error.TestError(err_msg % file_name) + finally: + self.umount_all() diff --git a/virttest/utils_libguestfs.py b/virttest/utils_libguestfs.py index 5d9af6c15..4d6d54fed 100644 --- a/virttest/utils_libguestfs.py +++ b/virttest/utils_libguestfs.py @@ -2,11 +2,11 @@ libguestfs tools test utility functions. """ -import logging +import logging, signal from autotest.client import os_dep, utils from autotest.client.shared import error -import propcan +import aexpect, propcan class LibguestfsCmdError(Exception): @@ -30,7 +30,7 @@ def lgf_cmd_check(cmd): @param cmd: the cmd to use a libguest tool. @return: None if the cmd is not exist, otherwise return its path. """ - libguestfs_cmds = ['libguestfs_test_tool', 'guestfish', 'guestmount', + libguestfs_cmds = ['libguestfs-test-tool', 'guestfish', 'guestmount', 'virt-alignment-scan', 'virt-cat', 'virt-copy-in', 'virt-copy-out', 'virt-df', 'virt-edit', 'virt-filesystems', 'virt-format', 'virt-inspector', @@ -50,20 +50,15 @@ def lgf_cmd_check(cmd): return None -def lgf_command(cmd, **dargs): +def lgf_command(cmd, ignore_status=True, debug=False, timeout=60): """ Interface of libguestfs tools' commands. @param cmd: Command line to execute. - @param dargs: standardized command keywords. @return: CmdResult object. @raise: LibguestfsCmdError if non-zero exit status and ignore_status=False """ - ignore_status = dargs.get('ignore_status', True) - debug = dargs.get('debug', False) - timeout = dargs.get('timeout', 60) - if debug: logging.debug("Running command %s in debug mode.", cmd) @@ -88,13 +83,16 @@ class LibguestfsBase(propcan.PropCanBase): Base class of libguestfs tools. """ - __slots__ = ('ignore_status', 'debug', 'timeout') + __slots__ = ('ignore_status', 'debug', 'timeout', 'uri', 'lgf_exec') - def __init__(self, *args, **dargs): - init_dict = dict(*args, **dargs) - init_dict['ignore_status'] = init_dict.get('ignore_status', True) - init_dict['debug'] = init_dict.get('debug', False) - init_dict['timeout'] = init_dict.get('timeout', 60) + def __init__(self, lgf_exec="/bin/true", ignore_status=True, + debug=False, timeout=60, uri=None): + init_dict = {} + init_dict['ignore_status'] = ignore_status + init_dict['debug'] = debug + init_dict['timeout'] = timeout + init_dict['uri'] = uri + init_dict['lgf_exec'] = lgf_exec super(LibguestfsBase, self).__init__(init_dict) @@ -126,8 +124,459 @@ def set_debug(self, debug): logging.debug("Libguestfs debugging disabled") + def set_timeout(self, timeout): + """ + Accessor method for 'timeout' property, timeout should be digit + """ + if type(timeout) is int: + self.dict_set('timeout', timeout) + else: + try: + timeout = int(str(timeout)) + self.dict_set('timeout', timeout) + except ValueError: + logging.debug("Set timeout failed.") + + + def get_uri(self): + """ + Accessor method for 'uri' property that must exist + """ + # self.get() would call get_uri() recursivly + try: + return self.dict_get('uri') + except KeyError: + return None + + +# There are two ways to call guestfish: +# 1.Guestfish classies provided below(shell session) +# 2.guestfs module provided in system libguestfs package + +class Guestfish(LibguestfsBase): + """ + Execute guestfish, using a new guestfish shell each time. + """ + + __slots__ = LibguestfsBase.__slots__ + + def __init__(self, disk_img=None, ro_mode=False, + libvirt_domain=None, inspector=False, + uri=None): + """ + Initialize guestfish command with options. + + @param: disk_img: if it is not None, use option '-a disk'. + @param: ro_mode: only for disk_img. add option '--ro' if it is True. + @param: libvirt_domain: if it is not None, use option '-d domain'. + @param: inspector: guestfish mounts vm's disks automatically + @param: uri: guestfish's connect uri + """ + guestfs_exec = "guestfish" + if lgf_cmd_check(guestfs_exec) is None: + raise LibguestfsCmdError + + if uri: + guestfs_exec += " -c '%s'" % uri + + if disk_img: + guestfs_exec += " -a '%s'" % disk_img + if libvirt_domain: + guestfs_exec += " -d '%s'" % libvirt_domain + if ro_mode: + guestfs_exec += " --ro" + if inspector: + guestfs_exec += " -i" + + super(Guestfish, self).__init__(guestfs_exec) + + + def complete_cmd(self, command): + """ + Execute built-in command in a complete guestfish command + (Not a guestfish session). + command: guestfish [--options] [commands] + """ + guestfs_exec = self.dict_get('lgf_exec') + ignore_status = self.dict_get('ignore_status') + debug = self.dict_get('debug') + timeout = self.dict_get('timeout') + if command: + guestfs_exec += " %s" % command + return lgf_command(guestfs_exec, ignore_status, debug, timeout) + else: + raise LibguestfsCmdError("No built-in command was passed.") + + +class GuestfishSession(aexpect.ShellSession): + """ + A shell session of guestfish. + """ + + # Check output against list of known error-status strings + ERROR_REGEX_LIST = ['libguestfs: error:\s*'] + + def __init__(self, guestfs_exec=None, a_id=None, prompt=r"><fs>\s*"): + """ + Initialize guestfish session server, or client if id set. + + @param: guestfs_cmd: path to guestfish executable + @param: id: ID of an already running server, if accessing a running + server, or None if starting a new one. + @param prompt: Regular expression describing the shell's prompt line. + """ + # aexpect tries to auto close session because no clients connected yet + super(GuestfishSession, self).__init__(guestfs_exec, a_id, + prompt=prompt, + auto_close=False) + + + def cmd_status_output(self, cmd, timeout=60, internal_timeout=None, + print_func=None): + """ + Send a guestfish command and return its exit status and output. + + @param cmd: guestfish command to send (must not contain newline characters) + @param timeout: The duration (in seconds) to wait for the prompt to + return + @param internal_timeout: The timeout to pass to read_nonblocking + @param print_func: A function to be used to print the data being read + (should take a string parameter) + @return: A tuple (status, output) where status is the exit status and + output is the output of cmd + @raise ShellTimeoutError: Raised if timeout expires + @raise ShellProcessTerminatedError: Raised if the shell process + terminates while waiting for output + @raise ShellStatusError: Raised if the exit status cannot be obtained + @raise ShellError: Raised if an unknown error occurs + """ + out = self.cmd_output(cmd, timeout, internal_timeout, print_func) + for line in out.splitlines(): + if self.match_patterns(line, self.ERROR_REGEX_LIST) is not None: + return 1, out + return 0, out + + + def cmd_result(self, cmd, ignore_status=False): + """Mimic utils.run()""" + exit_status, stdout = self.cmd_status_output(cmd) + stderr = '' # no way to retrieve this separately + result = utils.CmdResult(cmd, stdout, stderr, exit_status) + if not ignore_status and exit_status: + raise error.CmdError(cmd, result, + "Guestfish Command returned non-zero exit status") + return result + + +class GuestfishPersistent(Guestfish): + """ + Execute operations using persistent guestfish session. + """ + + __slots__ = Guestfish.__slots__ + ('session_id', ) + + # Help detect leftover sessions + SESSION_COUNTER = 0 + + def __init__(self, disk_img=None, ro_mode=False, + libvirt_domain=None, inspector=False, + uri=None): + super(GuestfishPersistent, self).__init__(disk_img, ro_mode, + libvirt_domain, inspector, uri) + if self.get('session_id') is None: + # set_uri does not call when INITIALIZED = False + # and no session_id passed to super __init__ + self.new_session() + + # Check whether guestfish session is prepared. + guestfs_session = self.open_session() + if guestfs_session.cmd_status('is-ready', timeout=60) != 0: + logging.debug("Persistent guestfish session is not responding.") + raise aexpect.ShellStatusError(self.lgf_exec, 'is-ready') + + + def close_session(self): + """ + If a persistent session exists, close it down. + """ + try: + existing = self.open_session() + # except clause exits function + # Try to end session with inner command 'quit' + try: + existing.cmd("quit") + # It should jump to exception followed normally + except aexpect.ShellProcessTerminatedError: + self.__class__.SESSION_COUNTER -= 1 + self.dict_del('session_id') + return # guestfish session was closed normally + # Close with 'quit' did not respond + # So close with aexpect functions + if existing.is_alive(): + # try nicely first + existing.close() + if existing.is_alive(): + # Be mean, incase it's hung + existing.close(sig=signal.SIGTERM) + # Keep count: + self.__class__.SESSION_COUNTER -= 1 + self.dict_del('session_id') + except LibguestfsCmdError: + # Allow other exceptions to be raised + pass # session was closed already + + + def new_session(self): + """ + Open new session, closing any existing + """ + # Accessors may call this method, avoid recursion + guestfs_exec = self.dict_get('lgf_exec') # Must exist, can't be None + self.close_session() + # Always create new session + new_session = GuestfishSession(guestfs_exec) + # Keep count + self.__class__.SESSION_COUNTER += 1 + session_id = new_session.get_id() + self.dict_set('session_id', session_id) + + + def open_session(self): + """ + Return session with session_id in this class. + """ + try: + session_id = self.dict_get('session_id') + if session_id: + try: + return GuestfishSession(a_id=session_id) + except aexpect.ShellStatusError: + # session was already closed + self.dict_del('session_id') + raise LibguestfsCmdError( + "Open session '%s' failed." % session_id) + except KeyError: + raise LibguestfsCmdError("No session id.") + + + # Inner command for guestfish should be executed in a guestfish session + def inner_cmd(self, command): + """ + Execute inner command of guestfish in a pesistent session. + + @param command: inner command to be executed. + """ + session = self.open_session() + # Allow to raise error by default. + ignore_status = self.dict_get('ignore_status') + return session.cmd_result(command, ignore_status=ignore_status) + + + def add_drive(self, filename): + """ + add-drive - add an image to examine or modify + + This function is the equivalent of calling "add_drive_opts" with no + optional parameters, so the disk is added writable, with the format + being detected automatically. + """ + return self.inner_cmd("add-drive %s" % filename) + + + def add_drive_opts(self, filename, readonly=False, format=None, + iface=None, name=None): + """ + add-drive-opts - add an image to examine or modify. + + This function adds a disk image called "filename" to the handle. + "filename" may be a regular host file or a host device. + """ + cmd = "add-drive-opts %s" % filename + + if readonly: + cmd += " readonly:true" + else: + cmd += " readonly:false" + if format: + cmd += " format:%s" % format + if iface: + cmd += " iface:%s" % iface + if name: + cmd += " name:%s" % name + + return self.inner_cmd(cmd) + + + def add_drive_ro(self, filename): + """ + add-ro/add-drive-ro - add a drive in snapshot mode (read-only) + + This function is the equivalent of calling "add_drive_opts" with the + optional parameter "GUESTFS_ADD_DRIVE_OPTS_READONLY" set to 1, so the + disk is added read-only, with the format being detected automatically. + """ + return self.inner_cmd("add-drive-ro %s" % filename) + + + def add_domain(self, domain, libvirturi=None, readonly=False, iface=None, + live=False, allowuuid=False, readonlydisk=None): + """ + domain/add-domain - add the disk(s) from a named libvirt domain + + This function adds the disk(s) attached to the named libvirt domain + "dom". It works by connecting to libvirt, requesting the domain and + domain XML from libvirt, parsing it for disks, and calling + "add_drive_opts" on each one. + """ + cmd = "add-domain %s" % domain + + if libvirturi: + cmd += " libvirturi:%s" % libvirturi + if readonly: + cmd += " readonly:true" + else: + cmd += " readonly:false" + if iface: + cmd += " iface:%s" % iface + if live: + cmd += " live:true" + if allowuuid: + cmd += " allowuuid:true" + if readonlydisk: + cmd += " readonlydisk:%s" % readonlydisk + + return self.inner_cmd(cmd) + + + def run(self): + """ + run/launch - launch the qemu subprocess + + Internally libguestfs is implemented by running a virtual machine + using qemu. + """ + return self.inner_cmd("launch") + + + def df(self): + """ + df - report file system disk space usage + + This command runs the "df" command to report disk space used. + """ + return self.inner_cmd("df") + + + def list_partitions(self): + """ + list-partitions - list the partitions + + List all the partitions detected on all block devices. + """ + return self.inner_cmd("list-partitions") + + + def mount(self, device, mountpoint): + """ + mount - mount a guest disk at a position in the filesystem + + Mount a guest disk at a position in the filesystem. + """ + return self.inner_cmd("mount %s %s" % (device, mountpoint)) + + + def mount_ro(self, device, mountpoint): + """ + mount-ro - mount a guest disk, read-only + + This is the same as the "mount" command, but it mounts the + filesystem with the read-only (*-o ro*) flag. + """ + return self.inner_cmd("mount-ro %s %s" % (device, mountpoint)) + + + def mount_options(self, options, device, mountpoint): + """ + mount - mount a guest disk at a position in the filesystem + + Mount a guest disk at a position in the filesystem. + """ + return self.inner_cmd("mount %s %s %s" % (options, device, mountpoint)) + + + def mounts(self): + """ + mounts - show mounted filesystems + + This returns the list of currently mounted filesystems. + """ + return self.inner_cmd("mounts") + + + def mountpoints(self): + """ + mountpoints - show mountpoints + + This call is similar to "mounts". + That call returns a list of devices. + """ + return self.inner_cmd("mountpoints") + + + def read_file(self, path): + """ + read-file - read a file + + This calls returns the contents of the file "path" as a buffer. + """ + return self.inner_cmd("read-file %s" % path) + + + def cat(self, path): + """ + cat - list the contents of a file + + Return the contents of the file named "path". + """ + return self.inner_cmd("cat %s" % path) + + + def write(self, path, content): + """ + write - create a new file + + This call creates a file called "path". The content of the file + is the string "content" (which can contain any 8 bit data). + """ + return self.inner_cmd("write %s %s" % (path, content)) + + + def write_append(self, path, content): + """ + write-append - append content to end of file + + This call appends "content" to the end of file "path". + If "path" does not exist, then a new file is created. + """ + return self.inner_cmd("write-append %s %s" % (path, content)) + + + def inspect_os(self): + """ + inspect-os - inspect disk and return list of operating systems found + + This function uses other libguestfs functions and certain heuristics to + inspect the disk(s) (usually disks belonging to a virtual machine), + looking for operating systems. + """ + return self.inner_cmd("inspect-os") + + +##### libguestfs module functions follow ##### + def libguest_test_tool_cmd(qemuarg=None, qemudirarg=None, - timeoutarg=None, **dargs): + timeoutarg=None, ignore_status=True, + debug=False, timeout=60): """ Execute libguest-test-tool command. @@ -137,7 +586,7 @@ def libguest_test_tool_cmd(qemuarg=None, qemudirarg=None, @return: a CmdResult object @raise: raise LibguestfsCmdError """ - cmd = "libguest-test-tool" + cmd = "libguestfs-test-tool" if qemuarg is not None: cmd += " --qemu '%s'" % qemuarg if qemudirarg is not None: @@ -146,11 +595,12 @@ def libguest_test_tool_cmd(qemuarg=None, qemudirarg=None, cmd += " --timeout %s" % timeoutarg # Allow to raise LibguestfsCmdError if ignore_status is False. - return lgf_command(cmd, **dargs) + return lgf_command(cmd, ignore_status, debug, timeout) def virt_edit_cmd(disk_or_domain, file_path, options=None, - extra=None, expr=None, **dargs): + extra=None, expr=None, ignore_status=True, + debug=False, timeout=60): """ Execute virt-edit command to check whether it is ok. @@ -172,4 +622,4 @@ def virt_edit_cmd(disk_or_domain, file_path, options=None, if expr is not None: cmd += " -e '%s'" % expr - return lgf_command(cmd, **dargs) + return lgf_command(cmd, ignore_status, debug, timeout) diff --git a/virttest/utils_libguestfs_unittest.py b/virttest/utils_libguestfs_unittest.py new file mode 100755 index 000000000..ca054d72e --- /dev/null +++ b/virttest/utils_libguestfs_unittest.py @@ -0,0 +1,77 @@ +#!/usr/bin/python +import unittest, logging + +try: + import autotest.common as common +except ImportError: + import common + +from autotest.client import os_dep +import utils_libguestfs as lgf + + +class LibguestfsTest(unittest.TestCase): + def test_lgf_cmd_check(self): + cmds = ['virt-ls', 'virt-cat'] + for cmd in cmds: + try: + os_dep.command(cmd) + self.assertTrue(lgf.lgf_cmd_check(cmd)) + except ValueError: + logging.warning("Command %s not installed, skipping " + "unittest...", cmd) + + def test_lgf_cmd_check_raises(self): + cmds = ['virt-test-fail', ''] + for cmd in cmds: + self.assertRaises(lgf.LibguestfsCmdError, + lgf.lgf_cmd_check, cmd) + + def test_lgf_cmd(self): + cmd = "libguestfs-test-tool" + try: + os_dep.command(cmd) + self.assertEqual(lgf.lgf_command(cmd).exit_status, 0) + except ValueError: + logging.warning("Command %s not installed, skipping unittest...", + cmd) + + +class SlotsCheckTest(unittest.TestCase): + def test_LibguestfsBase_default_slots(self): + """Default slots' value check""" + lfb = lgf.LibguestfsBase() + self.assertEqual(lfb.ignore_status, True) + self.assertEqual(lfb.debug, False) + self.assertEqual(lfb.timeout, 60) + self.assertEqual(lfb.uri, None) + self.assertEqual(lfb.lgf_exec, "/bin/true") + + def test_LibguestfsBase_update_slots(self): + """Update slots""" + lfb = lgf.LibguestfsBase() + lfb.set_ignore_status(False) + self.assertEqual(lfb.ignore_status, False) + lfb.set_debug(True) + self.assertEqual(lfb.debug, True) + lfb.set_timeout(240) + self.assertEqual(lfb.timeout, 240) + + def test_Guestfish_slots(self): + """Test Guestfish slots""" + try: + gf = lgf.Guestfish() + self.assertEqual(gf.lgf_exec, "guestfish") + gf = lgf.Guestfish(disk_img="test.img", ro_mode=True, inspector=True) + self.assertEqual(gf.lgf_exec, "guestfish -a 'test.img' --ro -i") + gf = lgf.Guestfish(libvirt_domain="test", inspector=True, + uri="qemu+ssh://root@EXAMPLE/system") + gf_cmd = "guestfish -c 'qemu+ssh://root@EXAMPLE/system' -d 'test' -i" + self.assertEqual(gf.lgf_exec, gf_cmd) + except lgf.LibguestfsCmdError: + logging.warning("Command guestfish not present, skipping " + "unittest...") + + +if __name__ == "__main__": + unittest.main() diff --git a/virttest/utils_libvirtd.py b/virttest/utils_libvirtd.py new file mode 100644 index 000000000..c78b95565 --- /dev/null +++ b/virttest/utils_libvirtd.py @@ -0,0 +1,156 @@ +""" +Module to control libvirtd service. +""" +import logging, re +from virttest import remote, aexpect +from autotest.client.shared import error +from autotest.client import utils, os_dep + + +class LibvirtdError(Exception): + """ + Base Error of libvirtd. + """ + pass + + +class LibvirtdActionError(LibvirtdError): + """ + Error in service command. + """ + def __init__(self, action, detail): + LibvirtdError.__init__(self) + self.action = action + self.detail = detail + + def __str__(self): + return ('Failed to %s libvirtd.\n' + 'Detail: %s.' % (self.action, self.detail)) + + +class LibvirtdActionUnknownError(LibvirtdActionError): + """ + Error in service command when service name is unkown. + """ + def __init__(self, action): + self.action = action + self.detail = 'Action %s is Unknown.' % self.action + LibvirtdActionError.__init__(self, self.action, self.detail) + +try: + os_dep.command("libvirtd") + LIBVIRTD = "libvirtd" +except ValueError: + LIBVIRTD = None + logging.warning("Libvirtd service is not availible in host, " + "utils_libvirtd module will not function normally") + + +def service_libvirtd_control(action, remote_ip=None, + remote_pwd=None, remote_user='root', + libvirtd=LIBVIRTD): + """ + Libvirtd control by action, if cmd executes successfully, + return True, otherwise raise LibvirtActionError. + + If the action is status, return True when it's running, + otherwise return False. + + @ param action: start|stop|status|restart|condrestart| + reload|force-reload|try-restart + @ raise LibvirtdActionUnknownError: Action is not supported. + @ raise LibvirtdActionError: Take the action on libvirtd Failed. + """ + service_cmd = ('service %s %s' % (libvirtd, action)) + + actions = ['start', 'stop', 'restart', 'condrestart', 'reload', + 'force-reload', 'try-restart'] + + session = None + if remote_ip: + try: + session = remote.wait_for_login('ssh', remote_ip, '22', + remote_user, remote_pwd, + r"[\#\$]\s*$") + except remote.LoginError, detail: + raise LibvirtdActionError(action, detail) + + if action in actions: + try: + if session: + session.cmd(service_cmd) + else: + utils.run(service_cmd) + except (error.CmdError, aexpect.ShellError), detail: + raise LibvirtdActionError(action, detail) + + elif action == "status": + if session: + try: + status, output = session.cmd_status_output(service_cmd) + except aexpect.ShellError, detail: + raise LibvirtdActionError(action, detail) + if status: + raise LibvirtdActionError(action, output) + else: + cmd_result = utils.run(service_cmd, ignore_status=True) + if cmd_result.exit_status: + raise LibvirtdActionError(action, cmd_result.stderr) + output = cmd_result.stdout + + if re.search("running", output): + return True + else: + return False + else: + raise LibvirtdActionUnknownError(action) + + +def libvirtd_restart(): + """ + Restart libvirt daemon. + """ + try: + service_libvirtd_control('restart') + logging.debug("Restarted libvirtd successfuly") + return True + except LibvirtdActionError, detail: + logging.debug("Failed to restart libvirtd:\n%s", detail) + return False + + +def libvirtd_stop(): + """ + Stop libvirt daemon. + """ + try: + service_libvirtd_control('stop') + logging.debug("Stop libvirtd successfuly") + return True + except LibvirtdActionError, detail: + logging.debug("Failed to stop libvirtd:\n%s", detail) + return False + + +def libvirtd_start(): + """ + Start libvirt daemon. + """ + try: + service_libvirtd_control('start') + logging.debug("Start libvirtd successfuly") + return True + except LibvirtdActionError, detail: + logging.debug("Failed to start libvirtd:\n%s", detail) + return False + + +def libvirtd_is_running(): + """ + Check if libvirt service is running. + """ + try: + return service_libvirtd_control('status') + except LibvirtdActionError, detail: + logging.debug("Failed to get status of libvirtd:\n%s", detail) + return False diff --git a/virttest/utils_libvirtd_unittest.py b/virttest/utils_libvirtd_unittest.py new file mode 100755 index 000000000..71512a808 --- /dev/null +++ b/virttest/utils_libvirtd_unittest.py @@ -0,0 +1,23 @@ +#!/usr/bin/python + +import unittest +import common +from virttest import utils_libvirtd + +class UtilsLibvirtdTest(unittest.TestCase): + @unittest.skipIf(not utils_libvirtd.LIBVIRTD, "skip if libvirtd is not available") + def test_service_libvirtd_control(self): + service_libvirtd_control = utils_libvirtd.service_libvirtd_control + self.assertRaises(utils_libvirtd.LibvirtdActionUnknownError, + service_libvirtd_control, 'UnknowAction') + self.assertTrue(service_libvirtd_control('status') in (True, False)) + + def test_libvirtd_error(self): + action_list = ["restart", "start", "stop", "status"] + + for action in action_list: + self.assertRaises(utils_libvirtd.LibvirtdActionError, + utils_libvirtd.service_libvirtd_control, + action=action, libvirtd="") +if __name__ == "__main__": + unittest.main() diff --git a/virttest/utils_misc.py b/virttest/utils_misc.py index 6d12d5cb1..ed84cfaf9 100644 --- a/virttest/utils_misc.py +++ b/virttest/utils_misc.py @@ -429,7 +429,7 @@ def run_tests(parser, job): index += 1 # Add kvm module status - sysfs_dir = param_dict.get("sysfs_dir", "sys") + sysfs_dir = param_dict.get("sysfs_dir", "/sys") param_dict["kvm_default"] = get_module_params(sysfs_dir, 'kvm') if param_dict.get("skip") == "yes": @@ -1103,6 +1103,39 @@ def create_x509_dir(path, cacert_subj, server_subj, passphrase, utils.run(cmd) logging.info(cmd) +def convert_ipv4_to_ipv6(ipv4): + """ + Translates a passed in string of an ipv4 address to an ipv6 address. + + @param ipv4: a string of an ipv4 address + """ + + converted_ip = "::ffff:" + split_ipaddress = ipv4.split('.') + try: + socket.inet_aton(ipv4) + except socket.error: + raise ValueError("ipv4 to be converted is invalid") + if (len(split_ipaddress) != 4): + raise ValueError("ipv4 address is not in dotted quad format") + + for index, string in enumerate(split_ipaddress): + if index != 1: + test = str(hex(int(string)).split('x')[1]) + if len(test) == 1: + final = "0" + final+=test + test = final + else: + test = str(hex(int(string)).split('x')[1]) + if len(test) == 1: + final = "0" + final+=test+":" + test = final + else: + test += ":" + converted_ip += test + return converted_ip class NumaNode(object): """ @@ -1250,12 +1283,13 @@ def _make_up_pattern(flags): vendor_re = "vendor_id\s+:\s+(\w+)" cpu_flags_re = "flags\s+:\s+([\w\s]+)\n" - cpu_types = {"AuthenticAMD": ["Opteron_G4", "Opteron_G3", "Opteron_G2", - "Opteron_G1"], + cpu_types = {"AuthenticAMD": ["Opteron_G5", "Opteron_G4", "Opteron_G3", + "Opteron_G2", "Opteron_G1"], "GenuineIntel": ["SandyBridge", "Westmere", "Nehalem", "Penryn", "Conroe"]} - cpu_type_re = {"Opteron_G4": - "avx,xsave,aes,sse4.2|sse4_2,sse4.1|sse4_1,cx16,ssse3,sse4a", + cpu_type_re = {"Opteron_G5": "f16c,fma,tbm", + "Opteron_G4": + "avx,xsave,aes,sse4.2|sse4_2,sse4.1|sse4_1,cx16,ssse3,sse4a", "Opteron_G3": "cx16,sse4a", "Opteron_G2": "cx16", "Opteron_G1": "", @@ -1337,9 +1371,19 @@ def get_qemu_binary(params): """ Get the path to the qemu binary currently in use. """ - return get_path(os.path.join(data_dir.get_root_dir(), - params.get("vm_type")), - params.get("qemu_binary", "qemu")) + # Update LD_LIBRARY_PATH for built libraries (libspice-server) + qemu_binary_path = get_path(os.path.join(data_dir.get_root_dir(), + params.get("vm_type")), + params.get("qemu_binary", "qemu")) + + library_path = os.path.join(data_dir.get_root_dir(), params.get('vm_type'), 'install_root', 'lib') + if os.path.isdir(library_path): + library_path = os.path.abspath(library_path) + qemu_binary = "LD_LIBRARY_PATH=%s %s" % (library_path, qemu_binary_path) + else: + qemu_binary = qemu_binary_path + + return qemu_binary def get_qemu_img_binary(params): diff --git a/virttest/utils_net.py b/virttest/utils_net.py index 8dfbf3605..fd39916ec 100644 --- a/virttest/utils_net.py +++ b/virttest/utils_net.py @@ -4,6 +4,7 @@ from autotest.client import utils, os_dep from autotest.client.shared import error import propcan, utils_misc, arch, aexpect +from versionable_class import factory CTYPES_SUPPORT = True try: @@ -579,7 +580,7 @@ def wrap_init(*args, **kargs): global __ovs if __ovs is None: try: - __ovs = openvswitch.OpenVSwitchSystem() + __ovs = factory(openvswitch.OpenVSwitchSystem)() __ovs.init_system() if (not __ovs.check()): raise Exception("Check of OpenVSwitch failed.") diff --git a/virttest/utils_selinux.py b/virttest/utils_selinux.py index 5f895ed07..3cf3736b6 100644 --- a/virttest/utils_selinux.py +++ b/virttest/utils_selinux.py @@ -115,7 +115,7 @@ def get_context_from_str(string): @raise SelinuxError: if there is no context in string. """ - context_pattern = r"[a-z]*_u:[a-z]*_r:[a-z]*_t:[s,\-,0-9,:[c,\,,0-9]*]*" + context_pattern = r"[a-z,_]*_u:[a-z,_]*_r:[a-z,_]*_t:[s,\-,0-9,:[c,\,,0-9]*]*" if re.search(context_pattern, string): context_list = re.findall(context_pattern, string) return context_list[0] diff --git a/virttest/utils_selinux_unittest.py b/virttest/utils_selinux_unittest.py index 3262d745c..48108aaeb 100755 --- a/virttest/utils_selinux_unittest.py +++ b/virttest/utils_selinux_unittest.py @@ -32,9 +32,9 @@ def test_is_or_not_disabled(self): Test the method about selinux disabled. """ is_disabled = utils_selinux.is_disabled() - self.assertIn(is_disabled, [True, False]) + self.assertTrue(is_disabled in [True, False]) is_not_disabled = utils_selinux.is_not_disabled() - self.assertIn(is_not_disabled, [True, False]) + self.assertTrue(is_not_disabled in [True, False]) self.assertEqual(not is_disabled, is_not_disabled) def test_context(self): diff --git a/virttest/utils_spice.py b/virttest/utils_spice.py index d113165d2..94718d135 100644 --- a/virttest/utils_spice.py +++ b/virttest/utils_spice.py @@ -2,7 +2,7 @@ Common spice test utility functions. """ -import os, logging, time +import os, logging, time, sys from autotest.client.shared import error from aexpect import ShellCmdError, ShellStatusError, ShellTimeoutError @@ -131,6 +131,26 @@ def verify_vdagent(guest_session, test_timeout): " is available ------------") wait_timeout(3) +def get_vdagent_status(vm_session, test_timeout): + """ + Return the status of vdagent + @param vm_session: ssh session of the VM + @param test_timeout: timeout time for the cmd + """ + output = "" + cmd = "service spice-vdagentd status" + + wait_timeout(3) + try: + output = vm_session.cmd(cmd, print_func=logging.info, timeout=test_timeout) + except ShellCmdError: + #getting the status of vdagent stopped returns 3, which results in a ShellCmdError + return("stopped") + except: + print "Unexpected error:", sys.exc_info()[0] + raise error.TestFail("Failed attempting to get status of spice-vdagentd") + wait_timeout(3) + return(output) def verify_virtio(guest_session, test_timeout): """ diff --git a/virttest/utils_test.py b/virttest/utils_test.py index 4a9b5dc18..609417e7e 100644 --- a/virttest/utils_test.py +++ b/virttest/utils_test.py @@ -28,9 +28,20 @@ from autotest.client import utils, os_dep from autotest.client.tools import scan_results from autotest.client.shared.syncdata import SyncData, SyncListenServer -import aexpect, utils_misc, virt_vm, remote, storage, env_process, utils_cgroup +import aexpect, utils_misc, virt_vm, remote, storage, env_process import virttest +try: + from autotest.client.shared import utils_cgroup +except ImportError: + # TODO: Obsoleted path used prior autotest-0.15.2/virttest-2013.06.24 + from virttest.staging import utils_cgroup + +try: + from autotest.client.shared import utils_memory +except ImportError: + from virttest.staging import utils_memory + # Handle transition from autotest global_config (0.14.x series) to # settings (0.15.x onwards) try: @@ -1436,9 +1447,9 @@ def get_memory_info(lvms): try: meminfo = "Host: memfree = " - meminfo += str(int(utils.freememtotal()) / 1024) + "M; " + meminfo += str(int(utils_memory.freememtotal()) / 1024) + "M; " meminfo += "swapfree = " - mf = int(utils.read_from_meminfo("SwapFree")) / 1024 + mf = int(utils_memory.read_from_meminfo("SwapFree")) / 1024 meminfo += str(mf) + "M; " except Exception, e: raise error.TestFail("Could not fetch host free memory info, " @@ -1623,12 +1634,12 @@ def extract(vm, remote_path, dest_dir): """ basename = os.path.basename(remote_path) logging.debug("Extracting %s on VM %s", basename, vm.name) - session.cmd("rm -rf %s" % dest_dir) + session.cmd("rm -rf %s" % dest_dir, timeout=240) dirname = os.path.dirname(remote_path) session.cmd("cd %s" % dirname) session.cmd("mkdir -p %s" % os.path.dirname(dest_dir)) e_cmd = "tar xjvf %s -C %s" % (basename, os.path.dirname(dest_dir)) - output = session.cmd(e_cmd, timeout=120) + output = session.cmd(e_cmd, timeout=240) autotest_dirname = "" for line in output.splitlines()[1:]: autotest_dirname = line.split("/")[0] @@ -1650,9 +1661,25 @@ def get_results(base_results_dir): except OSError, detail: if detail.errno != errno.EEXIST: raise - vm.copy_files_from("%s/results/default/*" % base_results_dir, - guest_results_dir) - + # result info tarball to host result dir + session = vm.wait_for_login(timeout=360) + results_dir = "%s/results/default" % base_results_dir + results_tarball = "/tmp/results.tgz" + compress_cmd = "cd %s && " % results_dir + compress_cmd += "tar cjvf %s ./* --exclude=*core*" % results_tarball + session.cmd(compress_cmd, timeout=600) + vm.copy_files_from(results_tarball, guest_results_dir) + # cleanup autotest subprocess which not terminated, change PWD to + # avoid current connection kill by fuser command; + clean_cmd = "cd /tmp && fuser -k %s" % results_dir + session.sendline(clean_cmd) + session.cmd("rm -f %s" % results_tarball, timeout=240) + results_tarball = os.path.basename(results_tarball) + results_tarball = os.path.join(guest_results_dir, results_tarball) + uncompress_cmd = "tar xjvf %s -C %s" % (results_tarball, + guest_results_dir) + utils.run(uncompress_cmd) + utils.run("rm -f %s" % results_tarball) def get_results_summary(): """ @@ -1718,7 +1745,7 @@ def get_results_summary(): (autotest_parentdir, compressed_autotest_path, autotest_basename)) # Until we have nested virtualization, we don't need the virt test :) cmd += " --exclude=%s/tests/virt" % autotest_basename - cmd += " --exclude=%s/results" % autotest_basename + cmd += " --exclude=%s/results*" % autotest_basename cmd += " --exclude=%s/tmp" % autotest_basename cmd += " --exclude=%s/control*" % autotest_basename cmd += " --exclude=*.pyc" @@ -2221,7 +2248,7 @@ def find_substring(string, pattern1, pattern2=None): def get_driver_hardware_id(driver_path, mount_point="/tmp/mnt-virtio", storage_path="/tmp/prewhql.iso", - re_hw_id="(PCI.{14,50})\r\n", run_cmd=True): + re_hw_id="(PCI.{14,50})", run_cmd=True): """ Get windows driver's hardware id from inf files. @@ -2240,6 +2267,7 @@ def get_driver_hardware_id(driver_path, mount_point="/tmp/mnt-virtio", utils.system("mount %s %s -o loop" % (storage_path, mount_point), timeout=60) driver_link = os.path.join(mount_point, driver_path) + txt_file = "" try: txt_file = open(driver_link, "r") txt = txt_file.read() @@ -2251,7 +2279,9 @@ def get_driver_hardware_id(driver_path, mount_point="/tmp/mnt-virtio", return hwid except Exception, e: logging.error("Fail to get hardware id with exception: %s" % e) - utils.system("umount %s" % mount_point) + if txt_file: + txt_file.close() + utils.system("umount %s" % mount_point, ignore_status=True) return "" diff --git a/virttest/versionable_class.py b/virttest/versionable_class.py index e0792e6fd..bab80ad79 100644 --- a/virttest/versionable_class.py +++ b/virttest/versionable_class.py @@ -1,267 +1,360 @@ +import sys, types + + """ -VersionableClass provides class hierarchy which automatically select the right -version of a class. Class manipulation is used for this reason. -""" +Versioning system provides class hierarchy which automatically select the right +version of a class. Class and module manipulation is used for this reason. +By this reason is: + Advantage) Only one class with some version is working in one process. + It is possible use class variables. Others version of same + class have different class variables. Supports pickling. + Much cleaner debugging and faster running of code than + using of __getattribute__. + Disadvantage) It is necessary create class with + fatory(orig_class, params for is_right_ver) + access to specific class through class Manager. -class VersionableClass(object): - """ - VersionableClass provides class hierarchy which automatically select right - version of class. Class manipulation is used for this reason. - By this reason is: - Advantage) Only one version is working in one process. Class is changed in - whole process. - Disadvantage) Only one version is working in one process. - Example of usage (in base_utils_unittest): +Example of usage (in versionable_class_unittest): - class FooC(object): - pass - #Not implemented get_version -> not used for versioning. - class VCP(FooC, VersionableClass): - def __new__(cls, *args, **kargs): - VCP.master_class = VCP - return super(VCP, cls).__new__(cls, *args, **kargs) - - def foo(self): - pass - - class VC2(VCP, VersionableClass): - @staticmethod - def get_version(): - return "get_version_from_system" - - @classmethod - def is_right_version(cls, version): - if version is not None: - if "version is satisfied": - return True - return False +# SIMPLE EXAPMLE - def func1(self): - print "func1" +from versionable_class import Manager, factory, VersionableClass +#register module to class manager. Necessary for pickling. +man = Manager(__name__) +# pylint: disable=E1003 - def func2(self): - print "func2" +class VM(object): + @classmethod + def _is_right_ver(cls, version): + return version < 1 - # get_version could be inherited. - class VC3(VC2, VersionableClass): - @classmethod - def is_right_version(cls, version): - if version is not None: - if "version+1 is satisfied": - return True - return False + def __init__(self, *args, **kargs): + super(VM, self).__init__(*args, **kargs) + + def fn1(self): + print "fn1_VM" - def func2(self): - print "func2_2" - class M(VCP): - pass - m = M() # <- When class is constructed the right version is - # automatically selected. In this case VC3 is selected. - m.func2() # call VC3.func2(m) - m.func1() # call VC2.func1(m) - m.foo() # call VC1.foo(m) +class VM1(VM): + @classmethod + def _is_right_ver(cls, version): + return version >= 1 - # When controlled "program" version is changed then is necessary call - check_repair_versions or recreate object. + def __init__(self, *args, **kargs): + super(VM1, self).__init__(*args, **kargs) - m.check_repair_versions() + def fn1(self): + print "fn1_VM1" - # priority of class. (change place where is method searched first in group - # of verisonable class.) +class VM_container(test_vers.VersionableClass): + __master__ = VM1 - class PP(VersionableClass): - def __new__(cls, *args, **kargs): - PP.master_class = PP - return super(PP, cls).__new__(cls, *args, **kargs) - class PP2(PP, VersionableClass): - @staticmethod - def get_version(): - return "get_version_from_system" +o = test_vers.factory(VM_container, version=0) # return class. +o = o() # create instance of class +p = test_vers.factory(VM_container, version=2)() +o.fn1() +p.fn1() - @classmethod - def is_right_version(cls, version): - if version is not None: - if "version is satisfied": - return True + +# ADVANCED EXAPMLE + +from versionable_class import Manager, factory, VersionableClass +man = Manager(__name__) +# pylint: disable=E1003 + + +def qemu_verison(): + return 2 + + +class VM(object): + __slot__ = ["cls"] + + test_class_vm1 = None + + @classmethod + def _is_right_ver(cls, *args, **kargs): + ver = None + if "qemu_version" in kargs: + ver = kargs['qemu_version'] + else: + ver = qemu_verison() + if ver < 1: + return True + else: return False - def func1(self): - print "PP func1" - class N(VCP, PP): + def __new__(cls, *args, **kargs): + return super(VM, cls).__new__(cls, *args, **kargs) + + + def __init__(self, *args, **kargs): + super(VM, self).__init__() + self.cls = self.__class__.__name__ + + + def __str__(self): + return "%s" % self.cls + + + def func1(self): + print "VM_func1" + + + def func3(self): pass - n = N() - n.func1() # -> "func2" +class VM1(VM): + __slot__ = ["VM1_cls"] + @classmethod + def _is_right_ver(cls, *args, **kargs): + ver = None + if "qemu_version" in kargs: + ver = kargs['qemu_version'] + else: + ver = qemu_verison() + if ver > 1: + return True + else: + return False + + def __init__(self, *args, **kargs): + super(VM1, self).__init__(*args, **kargs) + self.cls = self.__class__.__name__ + self.VM1_cls = "VM1" + - n.set_priority_class(PP, [VCP, PP]) + def __str__(self): + return "%s" % self.cls - n.func1() # -> "PP func1" - Necessary for using: - 1) Subclass of versionable class must have implemented class methods - get_version and is_right_version. These two methods are necessary - for correct version section. Class without this method will be never - chosen like suitable class. + def func1(self): + super(VM1, self).func1() - 2) Every class derived from master_class have to add to class definition - inheritance from VersionableClass. Direct inheritance from Versionable - Class is use like a mark for manipulation with VersionableClass. - 3) Master of VersionableClass have to defined class variable - cls.master_class. - """ + def func2(self): + print "func2" + + + def func3(self): + pass + + +class VM_container(VersionableClass): + __master__ = VM1 + def __new__(cls, *args, **kargs): - cls.check_repair_versions() - return super(VersionableClass, cls).__new__(cls, *args, **kargs) + return super(man[cls, VM_container], cls).__new__(cls, *args, **kargs) - #VersionableClass class management class. - @classmethod - def check_repair_versions(cls, master_classes=None): - """ - Check version of versionable class and if version not - match repair version to correct version. +class BB(VM_container): + test_class_bb = None - @param master_classes: Check and repair only master_class. - @type master_classes: list. - """ - if master_classes is None: - master_classes = cls._find_versionable_baseclass() - for base in master_classes: - cls._check_repair_version_class(base) + def __new__(cls, *args, **kargs): + return super(man[cls, BB], cls).__new__(cls, *args, **kargs) - @classmethod - def set_priority_class(cls, prioritized_class, group_classes): + def func1(self): + super(man[self.__class__, BB], self).func1() + + + def func2(self): + super(man[self.__class__, BB], self).func2() +""" + + +def isclass(obj): + """ + :param obj: Object for inspection if obj is class. + :return: true if the object is a class. + """ + return isinstance(obj, (type, types.ClassType)) + + +class ModuleWrapper(object): + """ + Wrapper around module. + + Necessary for pickling of dynamic class. + """ + def __init__(self, wrapped): """ - Set class priority. Limited only for change bases class priority inside - one subclass.__bases__ after that continue to another class. + :param wrapped: module for wrapping. + :type wrapped: Module. """ - def change_position(ccls): - if not VersionableClass in ccls.__bases__: - bases = list(ccls.__bases__) - - index = None - remove_variant = None - for i, item in enumerate(ccls.__bases__): - if (VersionableClass in item.__bases__ and - item.master_class in group_classes): - if index is None: - index = i - if item.master_class is prioritized_class: - remove_variant = item - bases.remove(item) - break - else: - return + self.wrapped = wrapped - bases.insert(index, remove_variant) - ccls.__bases__ = tuple(bases) - def find_cls(ccls): - change_position(ccls) - for base in ccls.__bases__: - find_cls(base) + def __dir__(self): + return dir(self.wrapped) - find_cls(cls) + def __getattr__(self, name): + """ + Override method `__getattr__` allows manipulate with modules. - @classmethod - def _check_repair_version_class(cls, master_class): - version = None - for class_version in master_class._find_versionable_subclass(): - try: - version = class_version.get_version() - if class_version.is_right_version(version): - cls._switch_by_class(class_version) - break - except NotImplementedError: - continue + :param name: Name of specific object. + :type name: string. + :return: specific class when name of class starts with managed or + normal attribute from wrapped class. + """ + if not name in self.wrapped.__dict__: + if name.startswith("managed"): + cls_name = name.split("_") + cls = self.wrapped.__dict__[cls_name[1]] + m_cls, _ = Manager(self.wrapped.__name__, self).factory(cls, + _class_names=cls_name) + return m_cls else: - cls._switch_by_class(class_version) + cls = getattr(self.wrapped, name) + return cls - @classmethod - def _find_versionable_baseclass(cls): +class VersionableClass(object): + """ + Class used for marking of mutable class. + """ + def __new__(cls, *args, **kargs): """ - Find versionable class in master class. + If this method is invoked it means that something went wrong because + this class should be replaced by :class:`Manager` factory. """ - ver_class = [] - for superclass in cls.mro(): - if VersionableClass in superclass.__bases__: - ver_class.append(superclass.master_class) - - return set(ver_class) + raise Exception("Class %s is not prepared for usage. " + "You have to call versionable_class.factory(cls) " + "before you can use it" % (cls)) - @classmethod - def _find_versionable_subclass(cls): +class Manager(object): + def __init__(self, name, wrapper=None): """ - Find versionable subclasses which subclass.master_class == cls + Manager for module. + + :param name: Name of module. + :type name: string + :param wrapper: Module dictionary wrapper. Should be None. """ - subclasses = [cls] - for sub in cls.__subclasses__(): - if VersionableClass in list(sub.__bases__): - subclasses.extend(sub._find_versionable_subclass()) - return subclasses + __import__(name) + if not wrapper: + if not isinstance(sys.modules[name], ModuleWrapper): + self.wrapper = ModuleWrapper(sys.modules[name]) + sys.modules[name] = self.wrapper + else: + self.wrapper = sys.modules[name] + else: + self.wrapper = wrapper - @classmethod - def _switch_by_class(cls, new_class): + def factory(self, _class, *args, **kargs): """ - Finds all class with same master_class as new_class in class tree - and replaces them by new_class. + Create new class with right version of subclasses. - @param new_class: Class for replacing. + Goes through class structure and search subclasses with right version. + + :param _class: Class which should be prepared. + :type _class: class. + :param *args: Params for _is_right_ver function. + :param *kargs: Params for _is_right_ver function. """ - def find_replace_class(bases): - for base in bases: - if (VersionableClass in base.__bases__ and - base.master_class == new_class.master_class): - bnew = list(bases) - bnew[bnew.index(base)] = new_class - return tuple(bnew) + def add_to_structure(cl, new_bases): + if VersionableClass in cl.__mro__: + cls, cls_vn = self.factory(cl, *args, **kargs) + new_bases.append(cls) + return cls_vn + else: + new_bases.append(cl) + return "" + + + _class_names = None + if "_class_names" in kargs: + _class_names = kargs["_class_names"] + if (_class.__name__.startswith("managed") and + hasattr(_class, "__original_class__")): + _class = _class.__original_class__ + new_bases = [] + cls_ver_name = "" + if VersionableClass in _class.__bases__: # parent is VersionableClass + for m_cls in _class.__bases__: + if m_cls is VersionableClass: + mro = _class.__master__.__mro__ # Find good version. + if _class_names: + for cl in mro[:-1]: + if cl.__name__ in _class_names: + cls_ver_name += "_" + cl.__name__ + cls_ver_name += add_to_structure(cl, new_bases) + break + else: + for cl in mro[:-1]: + if cl._is_right_ver(*args, **kargs): + cls_ver_name += "_" + cl.__name__ + cls_ver_name += add_to_structure(cl, new_bases) + break + else: + cls_ver_name += add_to_structure(m_cls, new_bases) + else: + for m_cls in _class.__bases__: + if (VersionableClass in m_cls.__mro__ or + hasattr(m_cls, "__original_class__")): + cls, cls_vn = self.factory(m_cls, *args, **kargs) + new_bases.append(cls) + cls_ver_name += cls_vn else: - bnew = find_replace_class(base.__bases__) - if bnew: - base.__bases__ = bnew + new_bases.append(m_cls) + class_name = "managed_%s%s" % (_class.__name__, cls_ver_name) - bnew = find_replace_class(cls.__bases__) - if bnew: - cls.__bases__ = bnew + if hasattr(self.wrapper.wrapped, class_name): + # Don't override already created class. + return self.wrapper.wrapped.__dict__[class_name], cls_ver_name + class_dict = _class.__dict__.copy() + class_dict["__original_class__"] = _class + cls = type(class_name, tuple(new_bases), class_dict) + self.wrapper.wrapped.__dict__[class_name] = cls - # Method defined in part below must be defined in - # verisonable class subclass. + return cls, cls_ver_name - @classmethod - def get_version(cls): - """ - Get version of installed OpenVSwtich. - Must be re-implemented for in child class. - @return: Version or None when get_version is unsuccessful. - """ - raise NotImplementedError("Method 'get_verison' must be" - " implemented in child class") + def __getitem__(self, o_cls): + return self.getcls(*o_cls) - @classmethod - def is_right_version(cls, version): + def getcls(self, cls, orig_class): """ - Check condition for select control class. - Function must be re-implemented in new OpenVSwitchControl class. - Must be re-implemented for in child class. + Return class correspond class and original class. + + :param cls: class for which should be found derived alternative. + :type cls: class + :param orig_class: Original class + :type orig_class: class - @param version: version of OpenVSwtich + :return: Derived alternative class + :rtype: class """ - raise NotImplementedError("Method 'is_right_version' must be" - " implemented in child class") + for m_cls in cls.__mro__: + if hasattr(m_cls, "__original_class__"): + if m_cls.__original_class__ is orig_class: + return m_cls + elif m_cls is orig_class: + return m_cls + raise Exception("Couldn't find derived alternative in %s for" + " class %s" % (cls, orig_class)) + + +def factory(orig_cls, *args, **kargs): + """ + Create class with specific version. + + :param orig_class: Class from which should be derived good version. + :param *args: list of parameters for _ir_right_ver + :param *kargs: dict of named parameters for _ir_right_ver + :return: params specific class. + :rtype: class + """ + return Manager(orig_cls.__module__).factory(orig_cls, *args, **kargs)[0] diff --git a/virttest/versionable_class_unittest.py b/virttest/versionable_class_unittest.py index 34a808296..5f1b4dfe1 100755 --- a/virttest/versionable_class_unittest.py +++ b/virttest/versionable_class_unittest.py @@ -1,13 +1,283 @@ #!/usr/bin/python -import unittest, logging +import unittest, cPickle, sys try: import autotest.common as common except ImportError: import common from autotest.client.shared import base_utils from autotest.client.shared.test_utils import mock -import versionable_class +from versionable_class import Manager, factory, VersionableClass +man = Manager(__name__) + +# pylint: disable=E1003 + + +def qemu_verison(): + return 2 + + +class VM(object): + __slot__ = ["cls"] + + test_class_vm1 = None + + @classmethod + def _is_right_ver(cls, *args, **kargs): + ver = None + if "qemu_version" in kargs: + ver = kargs['qemu_version'] + else: + ver = qemu_verison() + if ver < 1: + return True + else: + return False + + + def __new__(cls, *args, **kargs): + return super(VM, cls).__new__(cls, *args, **kargs) + + + def __init__(self, *args, **kargs): + super(VM, self).__init__() + self.cls = self.__class__.__name__ + + + def __str__(self): + return "%s" % self.cls + + + def func1(self): + print "VM_func1" + + + def func3(self): + pass + + +class VM1(VM): + __slot__ = ["VM1_cls"] + @classmethod + def _is_right_ver(cls, *args, **kargs): + ver = None + if "qemu_version" in kargs: + ver = kargs['qemu_version'] + else: + ver = qemu_verison() + if ver > 1: + return True + else: + return False + + def __init__(self, *args, **kargs): + super(VM1, self).__init__(*args, **kargs) + self.cls = self.__class__.__name__ + self.VM1_cls = "VM1" + + + def __str__(self): + return "%s" % self.cls + + + def func1(self): + super(VM1, self).func1() + + + def func2(self): + print "func2" + + + def func3(self): + pass + + +class VM_container(VersionableClass): + __master__ = VM1 + + def __new__(cls, *args, **kargs): + return super(man[cls, VM_container], cls).__new__(cls, *args, **kargs) + + +class BB(VM_container): + test_class_bb = None + + def __new__(cls, *args, **kargs): + return super(man[cls, BB], cls).__new__(cls, *args, **kargs) + + + def func1(self): + super(man[self.__class__, BB], self).func1() + + + def func2(self): + super(man[self.__class__, BB], self).func2() + + +def system_version(): + return 2 + + +class System(object): + @classmethod + def _is_right_ver(cls, *args, **kargs): + ver = None + if "system_version" in kargs: + ver = kargs['system_version'] + else: + ver = system_version() + if ver < 1: + return True + else: + return False + + + def __init__(self, *args, **kargs): + super(System, self).__init__() + self.aa = self.__class__.__name__ + + + def __str__(self): + return "VM1 %s" % self.aa + + + +class System1(System): + @classmethod + def _is_right_ver(cls, *args, **kargs): + ver = None + if "system_version" in kargs: + ver = kargs['system_version'] + else: + ver = system_version() + if ver > 1: + return True + else: + return False + + def __init__(self, *args, **kargs): + super(System1, self).__init__(*args, **kargs) + self.aa = self.__class__.__name__ + + + def __str__(self): + return "VM1 %s" % self.aa + + +class System_Container(VersionableClass): + __master__ = System1 + + def __new__(cls, *args, **kargs): + return super(man[cls, System_Container], cls).__new__(cls, *args, **kargs) + + +class Q(object): + @classmethod + def _is_right_ver(cls, *args, **kargs): + ver = None + if "q_version" in kargs: + ver = kargs['q_version'] + else: + ver = system_version() + if ver < 1: + return True + else: + return False + + + def __init__(self, *args, **kargs): + super(Q, self).__init__() + self.cls = self.__class__.__name__ + + + def __str__(self): + return "%s" % self.cls + + + +class Q1(Q): + @classmethod + def _is_right_ver(cls, *args, **kargs): + ver = None + if "q_version" in kargs: + ver = kargs['q_version'] + else: + ver = system_version() + if ver > 1: + return True + else: + return False + + def __init__(self, *args, **kargs): + super(man[self.__class__, Q1], self).__init__(*args, **kargs) + self.cls = self.__class__.__name__ + + + def __str__(self): + return "%s" % self.cls + + +class Q_Container(VersionableClass): + __master__ = Q1 + + +class Sys(Q_Container): + @classmethod + def _is_right_ver(cls, *args, **kargs): + ver = None + if "system_version" in kargs: + ver = kargs['system_version'] + else: + ver = system_version() + if ver < 1: + return True + else: + return False + + + def __init__(self, *args, **kargs): + super(man[self.__class__, Sys], self).__init__(*args, **kargs) + self.cls = self.__class__.__name__ + + + def __str__(self): + return "%s" % self.cls + + + +class Sys1(Sys): + @classmethod + def _is_right_ver(cls, *args, **kargs): + ver = None + if "system_version" in kargs: + ver = kargs['system_version'] + else: + ver = system_version() + if ver > 1: + return True + else: + return False + + def __init__(self, *args, **kargs): + super(man[self.__class__, Sys1], self).__init__(*args, **kargs) + self.cls = self.__class__.__name__ + + + def __str__(self): + return "%s" % self.cls + + +class Sys_Container(VersionableClass): + __master__ = Sys1 + + def __new__(cls, *args, **kargs): + return super(man[cls, Sys_Container], cls).__new__(cls, *args, **kargs) + + +class AA(Sys_Container, BB, System_Container): + def __new__(cls, *args, **kargs): + return super(man[cls, AA], cls).__new__(cls, *args, **kargs) + class TestVersionableClass(unittest.TestCase): def setUp(self): @@ -21,225 +291,134 @@ def tearDown(self): self.god.unstub_all() - class FooC(object): - pass + def test_simple_versioning(self): + self.god.stub_function(VM, "func1") + self.god.stub_function(VM1, "func2") - #Not implemented get_version -> not used for versioning. - class VCP(FooC, versionable_class.VersionableClass): - def __new__(cls, *args, **kargs): - TestVersionableClass.VCP.version = 1 # Only for unittesting. - TestVersionableClass.VCP.master_class = TestVersionableClass.VCP - return (super(TestVersionableClass.VCP, cls) - .__new__(cls, *args, **kargs)) + VM1.func2.expect_call() + VM.func1.expect_call() + mm = factory(BB)() + # check class name. + self.assertEqual(str(mm), "managed_BB_VM1") + mm.func2() # call BB.func2(m) -> VM1.func2 + mm.func1() # call VM1.func1(m) -> VM.func1 - def foo(self): - pass + self.god.check_playback() - class VC2(VCP, versionable_class.VersionableClass): - @classmethod - def get_version(cls): - return cls.version - @classmethod - def is_right_version(cls, version): - if version is not None: - if version == 1: - return True - return False + def test_simple_create_by_params_v0(self): + def wrap(mm): + mm.VM1_cls - def func1(self): - logging.info("func1") + self.god.stub_function(VM, "func3") + self.god.stub_function(VM1, "func3") - def func2(self): - logging.info("func2") + VM.func3.expect_call() - # get_version could be inherited. - class VC3(VC2, versionable_class.VersionableClass): - @classmethod - def is_right_version(cls, version): - if version is not None: - if version == 2: - return True - return False + mm = factory(BB, qemu_version=0)() + # check class name. + self.assertEqual(str(mm), "managed_BB_VM") + mm.func3() # call VM1.func1(m) -> VM.func1 + self.assertRaises(AttributeError, wrap, mm) - def func2(self): - logging.info("func2_2") - - class PP(versionable_class.VersionableClass): - def __new__(cls, *args, **kargs): - TestVersionableClass.PP.version = 1 # Only for unittesting. - TestVersionableClass.PP.master_class = TestVersionableClass.PP - return (super(TestVersionableClass.PP, cls) - .__new__(cls, *args, **kargs)) - - class PP2(PP, versionable_class.VersionableClass): - @classmethod - def get_version(cls): - return cls.version - - @classmethod - def is_right_version(cls, version): - if version is not None: - if cls.version == 1: - return True - return False + self.god.check_playback() - def func1(self): - print "PP func1" + def test_simple_create_by_params_v1(self): + self.god.stub_function(VM, "func3") + self.god.stub_function(VM1, "func3") - class WP(versionable_class.VersionableClass): - def __new__(cls, *args, **kargs): - TestVersionableClass.WP.version = 1 # Only for unittesting. - TestVersionableClass.WP.master_class = TestVersionableClass.WP - return (super(TestVersionableClass.WP, cls) - .__new__(cls, *args, **kargs)) + VM1.func3.expect_call() - class WP2(WP, versionable_class.VersionableClass): - @classmethod - def get_version(cls): - return cls.version + mm = factory(BB, qemu_version=2)() + # check class name. + self.assertEqual(str(mm), "managed_BB_VM1") + mm.func3() # call VM1.func1(m) -> VM.func1 + self.assertEqual(mm.VM1_cls, "VM1") - def func1(self): - print "WP func1" + self.god.check_playback() - class N(VCP, PP): - pass + def test_sharing_data_in_same_version(self): + mm = factory(BB)() + bb = factory(BB)() + cc = factory(BB, qemu_version=0)() - class NN(N): - pass - class M(VCP): - pass + # Get corespond class in versionable class + man[bb.__class__, VM].test_class_vm1 = 1 + man[bb.__class__, BB].test_class_bb = 2 + man[cc.__class__, BB].test_class_bb = 3 + # check class name. + self.assertEqual(bb.__class__.test_class_vm1, + mm.__class__.test_class_vm1) + self.assertEqual(bb.__class__.test_class_bb, + mm.__class__.test_class_bb) - class MM(M): - pass + # In class hierarchy is class which don't have to be versioned + # because that first value should be equal and second one shouldn't. + self.assertEqual(bb.__class__.test_class_vm1, + cc.__class__.test_class_vm1) + self.assertNotEqual(bb.__class__.test_class_bb, + cc.__class__.test_class_bb) - class W(WP): - pass - def test_simple_versioning(self): - self.god.stub_function(TestVersionableClass.VCP, "foo") - self.god.stub_function(TestVersionableClass.VC2, "func1") - self.god.stub_function(TestVersionableClass.VC2, "func2") - self.god.stub_function(TestVersionableClass.VC3, "func2") - - TestVersionableClass.VC2.func2.expect_call() - TestVersionableClass.VC2.func1.expect_call() - TestVersionableClass.VCP.foo.expect_call() - TestVersionableClass.VC3.func2.expect_call() - - TestVersionableClass.VC2.func2.expect_call() - TestVersionableClass.VC2.func1.expect_call() - TestVersionableClass.VCP.foo.expect_call() - TestVersionableClass.VC3.func2.expect_call() - - m = TestVersionableClass.M() - m.func2() # call VC3.func2(m) - m.func1() # call VC2.func1(m) - m.foo() # call VC1.foo(m) - m.version = 2 - m.check_repair_versions() - m.func2() - - #m.version = 1 - #m.check_repair_versions() - - mm = TestVersionableClass.MM() - mm.func2() # call VC3.func2(m) - mm.func1() # call VC2.func1(m) - mm.foo() # call VC1.foo(m) - mm.version = 2 - mm.check_repair_versions() - mm.func2() + def test_complicated_versioning(self): + self.god.stub_function(VM, "func3") + self.god.stub_function(VM1, "func3") - self.god.check_playback() + VM1.func3.expect_call() - def test_set_class_priority(self): - self.god.stub_function(TestVersionableClass.VC2, "func1") - self.god.stub_function(TestVersionableClass.VC2, "func2") - self.god.stub_function(TestVersionableClass.VC3, "func2") - self.god.stub_function(TestVersionableClass.PP2, "func1") - - TestVersionableClass.VC2.func1.expect_call() - TestVersionableClass.PP2.func1.expect_call() - TestVersionableClass.VC3.func2.expect_call() - TestVersionableClass.PP2.func1.expect_call() - TestVersionableClass.VC2.func1.expect_call() - TestVersionableClass.VC2.func2.expect_call() - - m = TestVersionableClass.N() - m.func1() - m.set_priority_class(TestVersionableClass.PP, - [TestVersionableClass.PP, - TestVersionableClass.VCP]) - m.func1() - - m.version = 2 - m.check_repair_versions() - m.func2() - m.func1() - - m.set_priority_class(TestVersionableClass.VCP, - [TestVersionableClass.PP, - TestVersionableClass.VCP]) - - m.func1() - - m.version = 1 - m.check_repair_versions() - m.func2() + mm = factory(AA)() + # check class name. + self.assertEqual(str(mm), "managed_AA_Sys1_Q1_VM1_System1") + mm.func3() # call VM1.func1(m) -> VM.func1 self.god.check_playback() - def test_set_class_priority_deep(self): - self.god.stub_function(TestVersionableClass.VC2, "func1") - self.god.stub_function(TestVersionableClass.VC2, "func2") - self.god.stub_function(TestVersionableClass.VC3, "func2") - self.god.stub_function(TestVersionableClass.PP2, "func1") + def test_complicated_multiple_create_params(self): + self.god.stub_function(VM, "func3") + self.god.stub_function(VM1, "func3") - TestVersionableClass.VC2.func1.expect_call() - TestVersionableClass.PP2.func1.expect_call() - TestVersionableClass.VC3.func2.expect_call() - TestVersionableClass.PP2.func1.expect_call() - TestVersionableClass.VC2.func1.expect_call() - TestVersionableClass.VC2.func2.expect_call() + VM1.func3.expect_call() - m = TestVersionableClass.NN() - m.func1() - m.set_priority_class(TestVersionableClass.PP, - [TestVersionableClass.PP, - TestVersionableClass.VCP]) - m.func1() + mm = factory(AA, qemu_version=0, system_version=2, q_version=0)() + # check class name. + self.assertEqual(str(mm), "managed_AA_Sys1_Q_VM_System1") + mm.func3() # call VM1.func1(m) -> VM.func1 - m.version = 2 - m.check_repair_versions() - m.func2() - m.func1() + self.god.check_playback() - m.set_priority_class(TestVersionableClass.VCP, - [TestVersionableClass.PP, - TestVersionableClass.VCP]) - m.func1() + def test_pickleing(self): + """ + Test pickling for example save vm env. + """ + m = factory(AA, system_version=0, qemu_version=0)() + mm = factory(BB, qemu_version=3)() - m.version = 1 - m.check_repair_versions() - m.func2() + f = open("/tmp/pick", "w+") + cPickle.dump(m, f, cPickle.HIGHEST_PROTOCOL) + cPickle.dump(mm, f, cPickle.HIGHEST_PROTOCOL) + f.close() - self.god.check_playback() + # Delete classes for ensure that pickel works correctly. + name = m.__class__.__name__ + del m + del globals()[name] + + name = mm.__class__.__name__ + del mm + del globals()[name] + f = open("/tmp/pick", "r+") + c = cPickle.load(f) + cc = cPickle.load(f) + f.close() - def test_check_not_implemented(self): - m = TestVersionableClass.W() - self.assertEqual(m.__class__.__bases__, - tuple([TestVersionableClass.WP2]), - "Class should be WP2 (last defined class in class" - " hierarchy).") if __name__ == "__main__": unittest.main() diff --git a/virttest/virsh.py b/virttest/virsh.py index 97adb1871..00f91ae94 100644 --- a/virttest/virsh.py +++ b/virttest/virsh.py @@ -949,17 +949,9 @@ def start(name, **dargs): @param: name: VM name @param: dargs: standardized virsh function API keywords - @return: True operation was successful + @return: CmdResult object. """ - if is_alive(name, **dargs): - return True - dargs['ignore_status'] = False - try: - command("start %s" % (name), **dargs) - return True - except error.CmdError, detail: - logging.error("Start VM %s failed:\n%s", name, detail) - return False + return command("start %s" % name, **dargs) def shutdown(name, **dargs): @@ -999,7 +991,7 @@ def define(xml_path, **dargs): def undefine(name, **dargs): """ - Return True on successful domain undefine (after shutdown/destroy). + Return cmd result of domain undefine (after shutdown/destroy). @param: name: VM name @param: dargs: standardized virsh function API keywords @@ -1406,13 +1398,7 @@ def pool_info(name, **dargs): @param: dargs: standardized virsh function API keywords """ cmd = "pool-info %s" % name - dargs['ignore_status'] = False - try: - command(cmd, **dargs) - return True - except error.CmdError, detail: - logging.error("Pool %s doesn't exist:\n%s", name, detail) - return False + return command(cmd, **dargs) def pool_destroy(name, **dargs): @@ -1545,8 +1531,8 @@ def pool_undefine(name, extra="", **dargs): return command("pool-undefine %s %s" % (name, extra), **dargs) -def vol_create_as(vol_name, pool_name, capacity, allocation, frmt, \ - extra="", **dargs): +def vol_create_as(vol_name, pool_name, capacity, allocation, + frmt, extra="", **dargs): """ To create the volumes on different available pool @@ -1564,7 +1550,7 @@ def vol_create_as(vol_name, pool_name, capacity, allocation, frmt, \ if allocation: cmd += " --allocation %s" % (allocation) - if format: + if frmt: cmd += " --format %s" % (frmt) if extra: cmd += " %s" % (extra) @@ -2096,3 +2082,116 @@ def connect(connect_uri="", options="", **dargs): @return: CmdResult object. """ return command("connect %s %s" % (connect_uri, options), **dargs) + + +def domif_setlink(name, interface, state, options=None, **dargs): + """ + Set network interface stats for a running domain. + + @param: name: Name of domain + @param: interface: interface device + @param: state: new state of the device up or down + @param: options: command options. + @param: dargs: standardized virsh function API keywords + @return: CmdResult object + """ + cmd = "domif-setlink %s %s %s " % (name, interface, state) + if options: + cmd += " %s" % options + + return command(cmd, **dargs) + + +def domif_getlink(name, interface, options=None, **dargs): + """ + Get network interface stats for a running domain. + + @param: name: Name of domain + @param: interface: interface device + @param: options: command options. + @param: dargs: standardized virsh function API keywords + @return: domif state + """ + cmd = "domif-getlink %s %s " % (name, interface) + if options: + cmd += " %s" % options + return command(cmd, **dargs) + + +def domiftune(name, interface, options=None, inbound=None, + outbound=None, **dargs): + """ + Set/get parameters of a virtual interface + @param name: name of domain + @param interface: interface device (MAC Address) + @param inbound: control domain's incoming traffics + @param outbound: control domain's outgoing traffics + @param options: options may be live, config and current + @param dargs: standardized virsh function API keywords + @return: CmdResult instance + """ + cmd = "domiftune %s %s" %(name, interface) + if inbound: + cmd += " --inbound %s" % inbound + if outbound: + cmd += " --outbound %s" % outbound + if options: + cmd += " --%s" % options + return command(cmd, **dargs) + +def nodedev_list(options="", **dargs): + """ + List the node devices. + + @return: CmdResult object. + """ + cmd = "nodedev-list %s" % (options) + CmdResult = command(cmd, **dargs) + + return CmdResult + + +def nodedev_detach(name, options="", **dargs): + """ + Detach node device from host. + + @return: cmdresult object. + """ + cmd = ("nodedev-detach --device %s %s" % (name, options)) + CmdResult = command(cmd, **dargs) + + return CmdResult + + +def nodedev_dettach(name, options="", **dargs): + """ + Detach node device from host. + + @return: nodedev_detach(name). + """ + return nodedev_detach(name, options, **dargs) + + +def nodedev_reattach(name, options="", **dargs): + """ + If node device is detached, this action will + reattach it to its device driver. + + @return: cmdresult object. + """ + cmd = ("nodedev-reattach --device %s %s" % (name, options)) + CmdResult = command(cmd, **dargs) + + return CmdResult + + +def vcpucount(name, options, **dargs): + """ + Get the vcpu count of guest. + + @param name: name of domain. + @param options: options for vcpucoutn command. + @return: CmdResult object. + """ + cmd = "vcpucount %s %s" % (name, options) + return command(cmd, **dargs)