def METHOD_NAME(test, params, env):
    vm_name = params.get("main_vm")
    status_error = ("yes" == params.get("status_error", "no"))
    start_ga = ("yes" == params.get("start_ga", "yes"))
    prepare_channel = ("yes" == params.get("prepare_channel", "yes"))
    src_path = params.get("src_path")
    tgt_name = params.get("tgt_name", "org.qemu.guest_agent.0")
    restart_libvirtd = ("yes" == params.get("restart_libvirtd"))
    suspend_resume_guest = ("yes" == params.get("suspend_resume_guest"))
    hotunplug_ga = ("yes" == params.get("hotunplug_ga"))
    hotplug_ga_without_tgt_type = "yes" == params.get("hotplug_ga_without_tgt_type")
    loop_time = int(params.get("loop_time", '1'))
    dev_type = params.get("dev_type", "channel")
    dev_dict = eval(params.get("dev_dict", "{}"))
    label = params.get("con_label")
    vm = env.get_vm(vm_name)
    if src_path:
        socket_file_dir = os.path.dirname(src_path)
        if not os.path.exists(socket_file_dir):
            os.mkdir(socket_file_dir)
        shutil.chown(socket_file_dir, "qemu", "qemu")
        utils_selinux.set_context_of_file(filename=socket_file_dir,
                                          context=label)
    vmxml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)
    backup_xml = vmxml.copy()
    vmxml.remove_agent_channels()
    vmxml.sync()
    try:
        if prepare_channel:
            vm.prepare_guest_agent(start=start_ga, channel=True,
                                   source_path=src_path)
        if restart_libvirtd:
            utils_libvirtd.libvirtd_restart()
        if suspend_resume_guest:
            virsh.suspend(vm_name, debug=True)
            virsh.resume(vm_name, debug=True)
        if hotunplug_ga:
            ga_xml = get_ga_xml(vm, vm_name)
            result = virsh.detach_device(vm_name, ga_xml.xml)
            if result.exit_status:
                test.fail("hotunplug guest agent device failed, %s"
                          % result)
            vmxml = vm_xml.VMXML.new_from_dumpxml(vm_name)
            if vmxml.get_agent_channels():
                test.fail("hotunplug guest agent device failed as "
                          "guest agent xml still exists")
        else:
            if start_ga != check_ga_state(vm, vm_name):
                test.fail("guest agent device is not in correct state")
        if hotplug_ga_without_tgt_type:
            dev_obj = libvirt_vmxml.create_vm_device_by_type(dev_type, dev_dict)
            for i in range(loop_time):
                res = virsh.attach_device(vm.name, dev_obj.xml, debug=True)
                libvirt.check_exit_status(res, status_error)
            # Unsuccessful plugging of a device should not break the guest agent
            status_error = False
        check_ga_function(vm_name, status_error, hotunplug_ga)
    finally:
        vm.destroy()
        backup_xml.sync()