def cb2text(vmi): script = vmi.cfg.helper_cb dst_script = act.chk_deps(vmi, script) cmd = utils.Cmd(dst_script, "--cb2stdout") text = act.run(vmi, cmd) utils.info(vmi, "Get from clipboard: %s", text) return text
def clear_cb(vmi): """Use the script to clear clipboard. """ script = vmi.cfg.helper_cb dst_script = act.chk_deps(vmi, script) cmd = utils.Cmd(dst_script, "--clear") utils.info(vmi, "Clear clipboard.") act.run(vmi, cmd)
def img2cb(vmi, img): """Use the clipboard script to copy an image into the clipboard. """ script = vmi.cfg.helper_cb dst_script = act.chk_deps(vmi, script) cmd = utils.Cmd(dst_script, "--img2cb", img) utils.info(vmi, "Put image %s in clipboard.", img) act.run(vmi, cmd, timeout=60)
def imggen(vmi, img, size): """Generate an image file. """ script = vmi.cfg.helper_cb dst_script = act.chk_deps(vmi, script) cmd = utils.Cmd(dst_script, "--genimg", size, img) utils.info(vmi, "Generate an %s image of %s size %s.", img, size) act.run(vmi, cmd)
def text2cb(vmi, text): """Use the clipboard script to copy an image into the clipboard. """ script = vmi.cfg.helper_cb dst_script = act.chk_deps(vmi, script) params = "--txt2cb" cmd = utils.Cmd(dst_script, "--txt2cb", text) utils.info(vmi, "Put in clipboard: %s", text) act.run(vmi, cmd)
def cb2img(vmi, img): """ Parameters ---------- img : str Where to save img. """ script = vmi.cfg.helper_cb dst_script = act.chk_deps(vmi, script) cmd = utils.Cmd(dst_script, "--cb2img", img) utils.info(vmi, "Dump clipboard to image %s.", img) act.run(vmi, cmd, timeout=60)
def cb2file(vmi, fname): script = vmi.cfg.helper_cb dst_script = act.chk_deps(vmi, script) cmd = utils.Cmd(dst_script, "--cb2txtf", fname) utils.info(vmi, "Dump clipboard to file.", fname) act.run(vmi, cmd, timeout=300)
def gen_text2cb(vmi, kbytes): script = vmi.cfg.helper_cb dst_script = act.chk_deps(vmi, script) cmd = utils.Cmd(dst_script, "--kbytes2cb", size) utils.info(vmi, "Put %s kbytes of text to clipboard.", kbytes) act.run(vmi, cmd)
def run(vt_test, test_params, env): """Run remote-viewer at client VM. Parameters ---------- vt_test : avocado.core.plugins.vt.VirtTest QEMU test object. test_params : virttest.utils_params.Params Dictionary with the test parameters. env : virttest.utils_env.Env Dictionary with test environment. """ test = stest.ClientGuestTest(vt_test, test_params, env) cfg = test.cfg vmi_c = test.vmi_c vmi_g = test.vmi_g homedir_g = act.home_dir(vmi_g) success = False act.turn_accessibility(vmi_c) if utils.vm_is_rhel6(test.vm_c): # Activate accessibility for rhel6, BZ#1340160 for rhel7 act.reset_gui(vmi_c) act.x_active(vmi_c) act.x_active(vmi_g) ssn = act.new_ssn(vmi_c) act.rv_connect(vmi_c, ssn) # Nautilus cannot be docked to side when default resolution act.set_resolution(vmi_c, "1280x1024") if not utils.vm_is_rhel8(test.vm_c): act.install_rpm(vmi_c, vmi_c.cfg.dogtail_rpm) dst_script = act.chk_deps(vmi_c, cfg.helper_c) if cfg.locked: # enable screen lock cmd = utils.Cmd('rm', '-I', '/etc/dconf/db/local.d/screensaver') act.run(vmi_g, cmd, admin=True) cmd = utils.Cmd('dconf', 'update') act.run(vmi_g, cmd, admin=True) cmd = utils.Cmd('loginctl', 'lock-sessions') act.run(vmi_g, cmd, admin=True) logging.info('Locking gnome session on guest') if 'generate' in cfg.test_xfer_file: if cfg.copy_img: test_xfer_file = 'test.png' act.imggen(vmi_c, test_xfer_file, cfg.test_image_size) else: test_xfer_file = 'test.txt' act.gen_rnd_file(vmi_c, test_xfer_file, cfg.xfer_kbytes) elif 'http' in cfg.test_xfer_file: cmd = utils.Cmd('wget', cfg.test_xfer_file) act.run(vmi_c, cmd) test_xfer_file = os.path.basename(cfg.test_xfer_file) logger.info('Downloading %s', test_xfer_file) act.run(vmi_c, "nautilus 2>/dev/null &") if cfg.xfer_args: cmd = utils.Cmd(dst_script, cfg.xfer_args, test_xfer_file) else: cmd = utils.Cmd(dst_script, test_xfer_file) logger.info('Sending command to client: %s', cmd) try: act.run(vmi_c, cmd) except aexpect.exceptions.ShellCmdError: logger.info('Cannot transfer a file.') utils.SpiceTestFail(test, "Test failed.") md5src = act.md5sum(vmi_c, test_xfer_file) try: md5dst = act.md5sum( vmi_g, os.path.join(homedir_g, 'Downloads', test_xfer_file)) except aexpect.exceptions.ShellCmdError: logger.info('File is not transferred.') md5dst = None if md5src == md5dst: logger.info('%s transferred to guest VM', test_xfer_file) cmd1 = utils.Cmd('lsof') cmd2 = utils.Cmd('grep', '-q', '-s', test_xfer_file) cmd = utils.combine(cmd1, '|', cmd2) status, _ = act.rstatus(vmi_g, cmd) if status: logger.info('Transferred file %s is closed.', test_xfer_file) success = True elif cfg.xfer_args == '--negative': logger.info('File %s was not transferred.', test_xfer_file) success = True if not success: raise utils.SpiceTestFail(test, "Test failed.")