def __call__(self, vmi, *args, **kwargs): os = registry.lookup([], ios.IOSystem, vmi.cfg.interface_os) ver = registry.lookup([], ios.IVersionMajor, vmi.cfg.interface_os_version) mver = registry.lookup([], ios.IVersionMinor, vmi.cfg.interface_os_mversion) arch = registry.lookup([], ios.IArch, vmi.cfg.interface_os_arch) ovirt_ver = registry.lookup([], ios.IArch, vmi.cfg.interface_ovirt_version) os_info = ",".join(map(repr, [os, ver, mver, arch, ovirt_ver])) msg = "OS info: %s" % os_info utils.debug(vmi, msg) lookup_order = [[os, ver, mver, arch, ovirt_ver], [os, ver, mver, ovirt_ver], [os, ver, arch, ovirt_ver], [os, ver, ovirt_ver], [os, ovirt_ver], [os, ver, mver, arch], [os, ver, mver], [os, ver, arch], [os, ver], [os]] action = None iset = None for iset in lookup_order: if not all(iset): continue action = registry.lookup(iset, reg.IVmAction, self.name) if action: break if not action: msg = "Cannot find suitable implementation for: %s." % self.name raise utils.SpiceTestFail(vmi.test, msg) act_reqs = ",".join(map(repr, iset)) msg = "Call: %s, for OS interface: %s" % (self.name, act_reqs) utils.debug(vmi, msg) return action(vmi, *args, **kwargs)
def __init__(self, test, parameters, env): # Change log level here from info to debug: logging.getLogger().setLevel(logging.INFO) utils.extend_api_vm() logger.info("Start test %s", test.name) self.cfg = AttributeDict() self.cfg.update(parameters) self.vms = {} self.vt_test = test vm_names = self.cfg.vms.split() """Holds all VM objects.""" for name in vm_names: self.vms[name] = env.get_vm(name) try: self.vms[name].verify_alive() except virt_vm.VMDeadError as excp: raise utils.SpiceTestFail(self, "Required VM is dead: %s" % excp) self.kvms = {} """Spice KVM options per VM.""" for name in vm_names: self.kvms[name] = AttributeDict() for prm in KVM_SPICE_KNOWN_PARAMS: self.kvms[name][prm] = self.vms[name].get_spice_var(prm) if self.kvms[name][prm]: logger.info("VM %s spice server option %s is %s.", name, prm, self.kvms[name][prm]) """Config set per VM.""" self.cfg_vm = {} for name in vm_names: self.cfg_vm[name] = AttributeDict() self.cfg_vm[name].update(self.vms[name].get_params()) """Actions set per VM's OS.""" self.vm_info = {} for name in vm_names: self.vm_info[name] = VmInfo(self, name) """Ovirt.""" vm_roles = self.cfg.ovirt_vms.split() """Config set per Ovirt VM.""" for name in vm_roles: self.cfg_vm[name] = AttributeDict() vm_role_cfg = parameters.object_params(name) # See env_process.py: process(..., postprocess_vm,...) self.cfg_vm[name].update(vm_role_cfg) """Actions set per Ovirt VM's OS.""" for name in vm_roles: self.vm_info[name] = VmOvirtInfo(self, name)
def run(vt_test, test_params, env): """GUI tests for remote-viewer. 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. Raises ------ TestFail Test fails for expected behaviour. """ test = stest.ClientGuestTest(vt_test, test_params, env) cfg = test.cfg vmi_c = test.vmi_c vmi_g = test.vmi_g vm_c = test.vm_c # Screen lock is now disabled in kickstart file for source QCOW images of # SPICE-QE team (https://gitlab.cee.redhat.com/spiceqe/install-compose/ks). # act.lock_scr_off(vmi_c) act.turn_accessibility(vmi_c) act.x_active(vmi_c) act.x_active(vmi_g) if utils.vm_is_rhel8(vm_c): act.set_alt_python(vmi_c, "/usr/bin/python3") else: act.install_rpm(vmi_c, test.cfg_c.epel_rpm) act.install_rpm(vmi_c, test.cfg_c.dogtail_rpm) act.install_rpm(vmi_c, "xdotool") if utils.vm_is_rhel6(vm_c): # Activate accessibility for rhel6 act.reset_gui(vmi_c) # Copy tests to client VM. # Some tests could require established RV session, some of them, don't. is_connected = False if cfg.make_rv_connect: ssn = act.new_ssn(vmi_c, dogtail_ssn=vmi_c.vm.is_rhel8()) act.rv_connect(vmi_c, ssn) if not cfg.negative: act.rv_chk_con(vmi_c) is_connected = True logging.getLogger().setLevel(logging.DEBUG) tdir = act.cp2vm(vmi_c, cfg.client_tests) tpath = os.path.join(tdir, cfg.script) cmd = utils.Cmd('python', *tpath.split()) try: status, _ = act.rstatus(vmi_c, cmd, dogtail_ssn=vmi_c.vm.is_rhel8()) except Exception as e: a = traceback.format_exc() logger.info("Exception: %s: %s.", repr(e), a) if cfg.make_rv_connect: out = ssn.read_nonblocking() logger.info("RV log: %s.", str(out)) if status: raise utils.SpiceTestFail(test, "Test failed.")
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 act.x_active(test.vmi_c) act.x_active(test.vmi_g) ssn = act.new_ssn(test.vmi_c, dogtail_ssn=test.vmi_c.vm.is_rhel8()) act.rv_connect(test.vmi_c, ssn) act.clear_cb(test.vmi_g) act.clear_cb(test.vmi_c) if cfg.vdagent_action: if cfg.vdagent_action == "stop": act.service_vdagent(test.vmi_g, "mask") act.service_vdagent(test.vmi_g, cfg.vdagent_action) if cfg.guest2client: src = test.vmi_g dst = test.vmi_c elif cfg.client2guest: src = test.vmi_c dst = test.vmi_g success = False if cfg.copy_text: act.text2cb(src, cfg.text) try: text = act.cb2text(dst) except aexpect.exceptions.ShellCmdError: logger.info('Cannot paste from buffer.') else: if cfg.text in text: success = True elif cfg.copy_text_big: act.gen_text2cb(src, cfg.kbytes) act.cb2file(src, cfg.dump_file) md5src = act.md5sum(src, cfg.dump_file) try: act.cb2file(dst, cfg.dump_file) except aexpect.exceptions.ShellCmdError: logger.info('Cannot paste from buffer.') else: md5dst = act.md5sum(dst, cfg.dump_file) if md5src == md5dst: success = True elif cfg.copy_img: dst_img = os.path.join(act.dst_dir(src), cfg.test_image) act.imggen(src, dst_img, cfg.test_image_size) act.img2cb(src, dst_img) act.cb2img(src, cfg.dump_img) try: act.cb2img(dst, cfg.dump_img) except aexpect.exceptions.ShellCmdError: logger.info('Cannot paste from buffer.') else: md5src = act.md5sum(src, cfg.dump_img) md5dst = act.md5sum(dst, cfg.dump_img) if md5src == md5dst: success = True if cfg.negative and success or not cfg.negative and not success: raise utils.SpiceTestFail(test, "Test failed.")
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. Notes ----- Tests clean exit after shutting down the VM. Covers two cases: * Shutdown from the command line of the guest. * Shutdown from the qemu monitor. Verify after the shutdown: * Verifying the guest is down. * Verify the spice connection to the guest is no longer established. * Verify the remote-viewer process is not running. """ test = stest.ClientGuestTest(vt_test, test_params, env) cfg = test.cfg act.x_active(test.vmi_c) act.x_active(test.vmi_g) ssn = act.new_ssn(test.vmi_c, dogtail_ssn=test.vmi_c.vm.is_rhel8()) act.rv_connect(test.vmi_c, ssn) act.rv_chk_con(test.vmi_c) if test.cfg.shutdown_cmdline: test.vm_g.info("Shutting down from command line.") try: cmd = test.cfg_g.shutdown_command act.run(test.vmi_g, cmd, admin=True) except aexpect.ShellProcessTerminatedError: pass elif test.cfg.shutdown_qemu: test.vm_g.info("Shutting down from qemu monitor.") test.vm_g.monitor.system_powerdown() else: raise utils.SpiceTestFail(test, "Bad config.") # Test: guest VM is dead. @deco.retry(8, exceptions=(AssertionError, )) def is_dead(): assert test.vm_g.is_dead(), "VM is alive." is_dead() test.vm_g.info("VM is dead.") # Test: no network connection. try: act.rv_chk_con(test.vmi_c) except utils.SpiceUtilsError: pass else: raise utils.SpiceTestFail(test, "RV still connected.") # Test: no RV proccess on client. if act.proc_is_active(test.vmi_c, 'remote-viewer'): raise utils.SpiceTestFail(test, "RV is still running on the client.")
def test(vt_test, test_params, env): """Playback of audio stream tests for remote-viewer. 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. Raises ------ TestFail Test fails for expected behaviour. """ test = stest.ClientGuestTest(vt_test, test_params, env) cfg = test.cfg act.x_active(test.vmi_c) act.x_active(test.vmi_g) ssn_c = act.new_ssn(test.vmi_c) ssn_g = act.new_ssn(test.vmi_g) # Get default sink at the client. cmd = r"pacmd stat | grep 'Default sink name' | " \ r"sed -e 's/^.*[[:space:]]//'" try: def_sink = ssn_c.cmd(cmd).rstrip('\r\n') except aexpect.ShellCmdError as excp: raise utils.SpiceTestFail(test, "Test failed: %s" % str(excp)) logging.info("Default sink at client is: %s", def_sink) # Create RV session env_local = {} if cfg.rv_record: env_local["PULSE_SOURCE"] = "%s.monitor" % def_sink ssn = act.new_ssn(test.vmi_c) act.rv_connect(test.vmi_c, ssn, env=env_local) ret, out = commands.getstatusoutput(MAKE_WAV) if ret: errmsg = "Cannot generate specimen WAV file: %s" % out raise utils.SpiceTestFail(test, errmsg) play_cmd = "aplay %s &> /dev/null &" % cfg.audio_tgt rec_cmd = "arecord -d %s -f cd %s" % (cfg.audio_time, cfg.audio_rec) # Check test type if cfg.rv_record: logging.info("Recording test. Player is client. Recorder is guest.") player = ssn_c recorder = ssn_g vm_recorder = test.vm_g vm_player = test.vm_c else: logging.info("Playback test. Player is guest. Recorder is client.") env_var = "PULSE_SOURCE=%s.monitor" % def_sink rec_cmd = env_var + " " + rec_cmd player = ssn_g recorder = ssn_c vm_recorder = test.vm_c vm_player = test.vm_g vm_player.copy_files_to(SPECIMEN_FILE, cfg.audio_tgt) time.sleep(2) # wait till everything is set up player.cmd(play_cmd) if cfg.config_test == "migration": bguest = utils_misc.InterruptedThread(test.vm_g.migrate, kwargs={}) bguest.start() try: recorder.cmd(rec_cmd, timeout=500) except aexpect.ShellCmdError as excp: raise utils.SpiceTestFail(test, str(excp)) if cfg.config_test == "migration": bguest.join() vm_recorder.copy_files_from(cfg.audio_rec, RECORDED_FILE) if not verify_recording(RECORDED_FILE, cfg): raise utils.SpiceTestFail(test, "Cannot verify recorded file.") if cfg.rv_reconnect: act.rv_disconnect(test.vmi_c) act.rv_connect(test.vmi_c, ssn) try: recorder.cmd(rec_cmd, timeout=500) except aexpect.ShellCmdError as excp: raise utils.SpiceTestFail(test, str(excp)) vm_recorder.copy_files_from(cfg.audio_rec, RECORDED_FILE) if not verify_recording(RECORDED_FILE, cfg): raise utils.SpiceTestFail(test, "Cannot verify recorded file.")
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.")
def run(vt_test, test_params, env): """Tests for vdagent. 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.GuestTest(vt_test, test_params, env) cfg = test.cfg vmi = test.vmi act.x_active(vmi) active = act.service_vdagent(vmi, "status") if cfg.ttype == "start": if active: # spice-vdagentd.service must be masked before stopping, otherwise # is immediatelly started by spice-vdagentd.socket act.service_vdagent(vmi, "mask") act.service_vdagent(vmi, "stop") act.service_vdagent(vmi, "unmask") active = act.service_vdagent(vmi, "status") assert not active act.service_vdagent(vmi, "start") active = act.service_vdagent(vmi, "status") assert active elif cfg.ttype == "stop": if not active: act.service_vdagent(vmi, "start") active = act.service_vdagent(vmi, "status") assert active act.service_vdagent(vmi, "mask") act.service_vdagent(vmi, "stop") act.service_vdagent(vmi, "unmask") active = act.service_vdagent(vmi, "status") assert not active elif cfg.ttype == "restart_running": if not active: act.service_vdagent(vmi, "start") active = act.service_vdagent(vmi, "status") assert active act.service_vdagent(vmi, "restart") active = act.service_vdagent(vmi, "status") assert active elif cfg.ttype == "restart_stopped": if active: act.service_vdagent(vmi, "mask") act.service_vdagent(vmi, "stop") act.service_vdagent(vmi, "unmask") active = act.service_vdagent(vmi, "status") assert not active act.service_vdagent(vmi, "restart") active = act.service_vdagent(vmi, "status") assert active else: raise utils.SpiceTestFail(test, "Bad config.")