def run(test, params, env): """ Run tests with disk target configurations """ libvirt_version.is_libvirt_feature_supported(params) vm_name = params.get("main_vm") vm = env.get_vm(vm_name) at_dt = params.get('at_dt') cmds_in_guest = eval(params.get('cmds_in_guest')) target_rotation = params.get('target_rotation') backup_xml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name) try: if not at_dt: libvirt.set_vm_disk(vm, params) if not vm.is_alive(): vm.start() logging.debug(vm_xml.VMXML.new_from_dumpxml(vm_name)) vm_session = vm.wait_for_login() pkg_list = params.get("install_pkgs") if pkg_list: install_pkg(test, eval(pkg_list), vm_session) if at_dt: old_parts = utils_disk.get_parts_list(vm_session) disk_xml = create_second_disk(params) virsh.attach_device(vm_name, disk_xml, debug=True, ignore_status=False) pat_in_dumpxml = params.get('pattern_in_dumpxml') libvirt_vmxml.check_guest_xml(vm_name, pat_in_dumpxml, status_error=False) time.sleep(10) added_parts = utils_disk.get_added_parts(vm_session, old_parts) if not added_parts or len(added_parts) != 1: test.error("Only one new partition is expected in the VM, " "but found {}".format(added_parts)) cmd = cmds_in_guest[0] % added_parts[0] run_cmd_in_guest(test, vm_session, cmd) virsh.detach_device(vm_name, disk_xml, debug=True, ignore_status=False) cmd = cmds_in_guest[1] % added_parts[0] run_cmd_in_guest(test, vm_session, cmd, any_error=True) libvirt_vmxml.check_guest_xml(vm_name, pat_in_dumpxml, status_error=True) else: if cmds_in_guest: for cmd_index in range(0, len(cmds_in_guest)): any_error = False if not target_rotation and cmd_index == 0: any_error = True run_cmd_in_guest(test, vm_session, cmds_in_guest[cmd_index], any_error=any_error) finally: backup_xml.sync() source_file = params.get('source_file') if source_file: libvirt.delete_local_disk('file', source_file)
def detach_iface_device(vm_name, dev_type): """ Detach an interface from VM :param vm_name: VM's name :param dev_type: Interface device type """ iface = interface.Interface(dev_type) iface = vm_xml.VMXML.new_from_dumpxml(vm_name).devices.by_device_tag( "interface")[0] virsh.detach_device(vm_name, iface.xml, wait_for_event=True, debug=True, ignore_status=False) libvirt_vmxml.check_guest_xml(vm_name, dev_type, status_error=True)
def attach_iface_device(vm_name, dev_type, params): """ Attach an interface to VM :param vm_name: VM's name :param dev_type: Interface device type :param params: Dictionary with the test parameters """ status_error = "yes" == params.get('status_error', 'no') iface_dict = parse_iface_dict(params) iface = create_iface(dev_type, iface_dict) res = virsh.attach_device(vm_name, iface.xml, debug=True) libvirt.check_exit_status(res, status_error) libvirt_vmxml.check_guest_xml(vm_name, dev_type) # FIXME: Sleep for 20 secs to make iface work properly time.sleep(20)
def test_at_dt(): """ Test attach-detach interfaces """ if not pf_status: logging.info("Set pf state to down.") pf_iface_obj = utils_net.Interface(pf_name) pf_iface_obj.down() logging.info("Define network - %s.", params.get("net_name")) create_network(params) logging.debug("Remove VM's interface devices.") libvirt_vmxml.remove_vm_devices_by_type(vm, 'interface') vm.start() vm_session = vm.wait_for_serial_login(timeout=240) logging.info("Hotplug an interface to VM.") iface_dict = { "model": "virtio", "source": { 'network': params.get("net_name") } } iface = create_iface(iface_dict) res = virsh.attach_device(vm_name, iface.xml, debug=True) libvirt.check_exit_status(res, status_error) if not pf_status: logging.info("Set pf state to up then check again.") pf_iface_obj.up() virsh.attach_device(vm_name, iface.xml, debug=True, ignore_status=False) libvirt_vmxml.check_guest_xml(vm.name, params["net_name"]) sriov_base.check_vm_network_accessed(vm_session)