def prepare_for_migration(self, mig_data, migration_mode): """ Prepare destination of migration for migration. :param mig_data: Class with data necessary for migration. :param migration_mode: Migration mode for prepare machine. """ new_params = self._prepare_params(mig_data) new_params['migration_mode'] = migration_mode new_params['start_vm'] = 'yes' if self.params.get("migration_sync_vms", "no") == "yes": if mig_data.is_src(): self.vm_lock.acquire() env_process.process(self.test, new_params, self.env, env_process.preprocess_image, env_process.preprocess_vm) self.vm_lock.release() self._quick_check_vms(mig_data) # Send vms configuration to dst host. vms = cPickle.dumps([ self.env.get_vm(vm_name) for vm_name in mig_data.vms_name ]) self.env.get_vm(mig_data.vms_name[0]).monitor.info("qtree") SyncData(self.master_id(), self.hostid, mig_data.hosts, mig_data.mig_id, self.sync_server).sync(vms, timeout=240) elif mig_data.is_dst(): # Load vms configuration from src host. vms = cPickle.loads( SyncData(self.master_id(), self.hostid, mig_data.hosts, mig_data.mig_id, self.sync_server).sync(timeout=240)[mig_data.src]) for vm in vms: # Save config to env. Used for create machine. # When reuse_previous_config params is set don't check # machine. vm.address_cache = self.env.get("address_cache") self.env.register_vm(vm.name, vm) self.vm_lock.acquire() env_process.process(self.test, new_params, self.env, env_process.preprocess_image, env_process.preprocess_vm) vms[0].monitor.info("qtree") self.vm_lock.release() self._quick_check_vms(mig_data) else: self.vm_lock.acquire() env_process.process(self.test, new_params, self.env, env_process.preprocess_image, env_process.preprocess_vm) self.vm_lock.release() self._quick_check_vms(mig_data) self._check_vms(mig_data)
def __init__(self, test, params, env): super(TestMultihostMigration, self).__init__(test, params, env) self.srchost = self.params.get("hosts")[0] self.dsthost = self.params.get("hosts")[1] self.is_src = params["hostid"] == self.srchost self.vms = params["vms"].split() self.migrate_count = int(params.get("migrate_count", "1")) self.migration_timeout = int(params.get("migrate_timeout", "240")) self.time_command = params["time_command"] self.time_filter_re = params["time_filter_re"] self.time_format = params["time_format"] self.create_file = params["create_file"] self.diff_limit = float(params.get("time_diff_limit", "0.1")) self.start_ht = {} self.start_gt = {} self.diff_ht = {} self.diff_gt = {} self.id = { 'src': self.srchost, 'dst': self.dsthost, "type": "timedrift" } self.sync = SyncData(self.master_id(), self.hostid, self.hosts, self.id, self.sync_server)
def migration_scenario(self): error.context("Migration from %s to %s over protocol %s." % (self.srchost, self.dsthost, mig_protocol), logging.info) sync = SyncData(self.master_id(), self.hostid, self.hosts, self.id, self.sync_server) def start_worker(mig_data): """ force the Linux kernel to crash on src before migration :param mig_data: Data for migration """ super(TestMultihostMigration, self).start_worker_guest_kdump( mig_data, self.login_timeout, self.crash_kernel_prob_cmd, self.kernel_param_cmd, self.kdump_enable_cmd, self.nvcpu, self.crash_cmd) def check_worker(mig_data): """ check weather generate vmcore file on dst after migration :param mig_data: Data for migration """ super(TestMultihostMigration, self).check_worker_kdump( mig_data, self.vmcore_chk_cmd, self.vmcore_incomplete) super(TestMultihostMigration, self).ping_pong_migrate( mig_type, sync, start_worker, check_worker)
def migration_scenario(self): sync = SyncData(self.master_id(), self.hostid, self.hosts, self.id, self.sync_server) self.vm = params.get("vms").split()[0] address_cache = env.get("address_cache") if (self.hostid == self.master_id()): utils.run("dd if=/dev/urandom of=%s bs=1M" " count=%s" % (host_path, file_size)) self.vm_addr = self._prepare_vm(self.vm).get_address() end_event = threading.Event() bg = utils.InterruptedThread(self._copy_until_end, (end_event, )) self._hosts_barrier(self.hosts, self.id, "befor_mig", 120) sync.sync(address_cache, timeout=120) error.context( "ping-pong between host and guest while" " migrating", logging.info) self._run_and_migrate(bg, end_event, sync, migrate_count) # Check if guest lives. virt_remote.wait_for_login(shell_client, self.vm_addr, shell_port, guest_root, guest_pass, shell_prompt) self._hosts_barrier(self.hosts, self.id, "After_check", 120) error.context("comparing hashes", logging.info) orig_hash = client_utils.hash_file(host_path) returned_hash = client_utils.hash_file(host_path_returned) #Check all check sum wrong_check_sum = False for i in range(len(self.file_check_sums)): check_sum = self.file_check_sums[i] if check_sum != orig_hash: wrong_check_sum = True logging.error("Checksum in transfer number" " %d if wrong." % (i)) if wrong_check_sum: raise error.TestFail("Returned file hash (%s) differs from" " original one (%s)" % (returned_hash, orig_hash)) else: #clean temp utils.run("rm -rf %s" % (host_path)) utils.run("rm -rf %s" % (returned_hash)) error.context() else: self._hosts_barrier(self.hosts, self.id, "befor_mig", 260) address_cache.update(sync.sync(timeout=120)[self.master_id()]) logging.debug("Address cache updated to %s" % address_cache) self._slave_migrate(sync) #Wait for check if guest lives. self._hosts_barrier(self.hosts, self.id, "After_check", 120)
def migration_scenario(self): sync = SyncData(self.master_id(), self.hostid, self.hosts, self.id, self.sync_server) srchost = self.params.get("hosts")[0] dsthost = self.params.get("hosts")[1] vms = [params.get("vms").split()[0]] def worker(mig_data): vm = mig_data.vms[0] session = vm.wait_for_login(timeout=self.login_timeout) cpuflags.install_cpuflags_util_on_vm(test, vm, install_path, extra_flags="-msse3 -msse2") cmd = ("%s/cpuflags-test --stressmem %d,%d" % (os.path.join(install_path, "cpu_flags"), vm_mem * 4, vm_mem / 2)) logging.debug("Sending command: %s" % (cmd)) session.sendline(cmd) if self.master_id() == self.hostid: server_port = utils_misc.find_free_port(5200, 6000) server = listen_server(port=server_port) data_len = 0 sync.sync(server_port, timeout=120) client = server.socket.accept()[0] endtime = time.time() + 30 while endtime > time.time(): data_len += len(client.recv(2048)) client.close() server.close() self.link_speed = data_len / (30 * 1024 * 1024) logging.info("Link speed %d MB/s" % (self.link_speed)) ms = utils.convert_data_size(mig_speed, 'M') if (ms > data_len / 30): logging.warn("Migration speed %s MB/s is set faster than " "real link speed %d MB/s" % (mig_speed, self.link_speed)) else: self.link_speed = ms / (1024 * 1024) else: data = "" for _ in range(10000): data += "i" server_port = sync.sync(timeout=120)[self.master_id()] sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((self.master_id(), server_port)) try: endtime = time.time() + 10 while endtime > time.time(): sock.sendall(data) sock.close() except: pass self.migrate_wait(vms, srchost, dsthost, worker)
def _check_vms_dest(self, mig_data): mig_data.vm_ports = {} for vm in mig_data.vms: logging.info("Communicating to source migration port %s", vm.migration_port) mig_data.vm_ports[vm.name] = vm.migration_port if mig_data.params.get("host_mig_offline") != "yes": SyncData(self.master_id(), self.hostid, mig_data.hosts, mig_data.mig_id, self.sync_server).sync(mig_data.vm_ports, timeout=240)
def _check_vms_source(self, mig_data): start_mig_tout = mig_data.params.get("start_migration_timeout", None) if start_mig_tout is None: for vm in mig_data.vms: vm.wait_for_login(timeout=self.login_timeout) if mig_data.params.get("host_mig_offline") != "yes": sync = SyncData(self.master_id(), self.hostid, mig_data.hosts, mig_data.mig_id, self.sync_server) mig_data.vm_ports = sync.sync(timeout=240)[mig_data.dst] logging.info("Received from destination the migration port %s", str(mig_data.vm_ports))
def migration_scenario(self): srchost = self.params.get("hosts")[0] dsthost = self.params.get("hosts")[1] mig_port = None if params.get("hostid") == self.master_id(): mig_port = utils_misc.find_free_port(5200, 6000) sync = SyncData(self.master_id(), self.hostid, self.params.get("hosts"), { 'src': srchost, 'dst': dsthost, 'port': "ports" }, self.sync_server) mig_port = sync.sync(mig_port, timeout=120) mig_port = mig_port[srchost] logging.debug("Migration port %d" % (mig_port)) if params.get("hostid") != self.master_id(): s = self._connect_to_server(srchost, mig_port) try: fd = s.fileno() logging.debug("File descrtiptor %d used for" " migration." % (fd)) self.migrate_wait(["vm1"], srchost, dsthost, mig_mode="fd", params_append={"migration_fd": fd}) finally: s.close() else: s = self._create_server(mig_port) try: conn, _ = s.accept() fd = s.fileno() logging.debug("File descrtiptor %d used for" " migration." % (fd)) #Prohibits descriptor inheritance. flags = fcntl.fcntl(fd, fcntl.F_GETFD) flags |= fcntl.FD_CLOEXEC fcntl.fcntl(fd, fcntl.F_SETFD, flags) self.migrate_wait(["vm1"], srchost, dsthost, mig_mode="fd", params_append={"migration_fd": fd}) conn.close() finally: s.close()
def migration_scenario(self): from autotest.client.shared.syncdata import SyncData sync = SyncData(self.master_id(), self.hostid, self.hosts, self.id, self.sync_server) def worker(mig_data): vm = env.get_vm("vm1") session = vm.wait_for_login(timeout=self.login_timeout) install_cpuflags_test_on_vm(vm, install_path) Flags = check_cpuflags_work(vm, install_path, flags.all_possible_guest_flags) logging.info("Woking CPU flags: %s", str(Flags[0])) logging.info("Not working CPU flags: %s", str(Flags[1])) logging.warning("Flags works even if not defined on" " guest cpu flags: %s", str(Flags[0] - flags.guest_flags)) logging.warning("Not tested CPU flags: %s", str(Flags[2])) for cpu in disable_cpus: if cpu < smp: disable_cpu(session, cpu, True) else: logging.warning("There is no enouth cpu" " in Guest. It is trying to" "remove cpu:%s from guest with" " smp:%s.", cpu, smp) logging.debug("Guest_flags: %s", str(flags.guest_flags)) logging.debug("Working_flags: %s", str(Flags[0])) def check_worker(mig_data): vm = env.get_vm("vm1") vm.verify_illegal_instruction() session = vm.wait_for_login(timeout=self.login_timeout) really_disabled = check_online_cpus(session, smp, disable_cpus) not_disabled = set(really_disabled) & set(disable_cpus) if not_disabled: test.fail("Some of disabled cpus are " "online. This shouldn't " "happen. Cpus disabled on " "srchost:%s, Cpus not " "disabled on dsthost:%s" % (disable_cpus, not_disabled)) Flags = check_cpuflags_work(vm, install_path, flags.all_possible_guest_flags) logging.info("Woking CPU flags: %s", str(Flags[0])) logging.info("Not working CPU flags: %s", str(Flags[1])) logging.warning("Flags works even if not defined on" " guest cpu flags: %s", str(Flags[0] - flags.guest_flags)) logging.warning("Not tested CPU flags: %s", str(Flags[2])) self.ping_pong_migrate(sync, worker, check_worker)
def test(self): super(test_multihost_copy, self).test() copy_timeout = int(params.get("copy_timeout", 480)) checksum_timeout = int(params.get("checksum_timeout", 180)) pid = None sync_id = { 'src': self.srchost, 'dst': self.dsthost, "type": "file_trasfer" } filename = "orig" remove_file_cmd = params["remove_file_cmd"] % filename dst_file = params["dst_file"] % filename if self.is_src: # Starts in source vm = env.get_vm(self.vms[0]) vm.monitor.migrate_set_speed("1G") session = vm.wait_for_login(timeout=login_timeout) cdrom_dev_list = list_guest_cdroms(session) logging.debug("cdrom_dev_list: %s", cdrom_dev_list) cdrom = get_testing_cdrom_device(vm, session, cdrom_dev_list, self.serial_num) mount_point = get_cdrom_mount_point(session, cdrom, params) mount_cmd = params["mount_cdrom_cmd"] % (cdrom, mount_point) src_file = params["src_file"] % (mount_point, filename) copy_file_cmd = params["copy_file_cmd"] % (mount_point, filename) if params["os_type"] != "windows": error.context("Mount and copy data", logging.info) session.cmd(mount_cmd, timeout=30) error.context("File copying test", logging.info) session.cmd(remove_file_cmd) session.cmd(copy_file_cmd) pid = disk_copy(vm, src_file, dst_file, copy_timeout) sync = SyncData(self.mig.master_id(), self.mig.hostid, self.mig.hosts, sync_id, self.mig.sync_server) pid = sync.sync(pid, timeout=cdrom_prepare_timeout)[self.srchost] self.mig.migrate_wait([self.vms[0]], self.srchost, self.dsthost) if not self.is_src: # Starts in source vm = env.get_vm(self.vms[0]) session = vm.wait_for_login(timeout=login_timeout) error.context("Wait for copy finishing.", logging.info) cdrom_dev_list = list_guest_cdroms(session) cdrom = get_testing_cdrom_device(vm, session, cdrom_dev_list, self.serial_num) mount_point = get_cdrom_mount_point(session, cdrom, params) mount_cmd = params["mount_cdrom_cmd"] % (cdrom, mount_point) src_file = params["src_file"] % (mount_point, filename) md5sum_cmd = params["md5sum_cmd"] def is_copy_done(): if params["os_type"] == "windows": cmd = "tasklist /FI \"PID eq %s\"" % pid else: cmd = "ps -p %s" % pid return session.cmd_status(cmd) != 0 if not utils_misc.wait_for(is_copy_done, timeout=copy_timeout): raise error.TestFail("Wait for file copy finish timeout") error.context("Compare file on disk and on cdrom", logging.info) f1_hash = session.cmd(md5sum_cmd % dst_file, timeout=checksum_timeout).split()[0] f2_hash = session.cmd(md5sum_cmd % src_file, timeout=checksum_timeout).split()[0] if f1_hash.strip() != f2_hash.strip(): raise error.TestFail("On disk and on cdrom files are" " different, md5 mismatch") session.cmd(remove_file_cmd) self.mig._hosts_barrier(self.mig.hosts, self.mig.hosts, 'Finish_cdrom_test', login_timeout)
def migrate_wait(self, vms_name, srchost, dsthost, start_work=None, check_work=None, mig_mode="fd", params_append=None): vms_count = len(vms_name) mig_ports = [] if self.params.get("hostid") == srchost: last_port = 5199 for _ in range(vms_count): last_port = utils_misc.find_free_port(last_port + 1, 6000) mig_ports.append(last_port) sync = SyncData(self.master_id(), self.hostid, self.params.get("hosts"), {'src': srchost, 'dst': dsthost, 'port': "ports"}, self.sync_server) mig_ports = sync.sync(mig_ports, timeout=120) mig_ports = mig_ports[srchost] logging.debug("Migration port %s" % (mig_ports)) if self.params.get("hostid") != srchost: sockets = [] for mig_port in mig_ports: sockets.append(self._connect_to_server(srchost, mig_port)) try: fds = {} for s, vm_name in zip(sockets, vms_name): fds["migration_fd_%s" % vm_name] = s.fileno() logging.debug("File descriptors %s used for" " migration." % (fds)) super_cls = super(MultihostMigrationFd, self) super_cls.migrate_wait(vms_name, srchost, dsthost, start_work=start_work, mig_mode="fd", params_append=fds) finally: for s in sockets: s.close() else: sockets = [] for mig_port in mig_ports: sockets.append(self._create_server(mig_port)) try: conns = [] for s in sockets: conns.append(s.accept()[0]) fds = {} for conn, vm_name in zip(conns, vms_name): fds["migration_fd_%s" % vm_name] = conn.fileno() logging.debug("File descriptors %s used for" " migration." % (fds)) # Prohibits descriptor inheritance. for fd in fds.values(): flags = fcntl.fcntl(fd, fcntl.F_GETFD) flags |= fcntl.FD_CLOEXEC fcntl.fcntl(fd, fcntl.F_SETFD, flags) super_cls = super(MultihostMigrationFd, self) super_cls.migrate_wait(vms_name, srchost, dsthost, start_work=start_work, mig_mode="fd", params_append=fds) for conn in conns: conn.close() finally: for s in sockets: s.close()
def _hosts_barrier(self, hosts, session_id, tag, timeout): logging.debug("Barrier timeout: %d tags: %s" % (timeout, tag)) tags = SyncData(self.master_id(), self.hostid, hosts, "%s,%s,barrier" % (str(session_id), tag), self.sync_server).sync(tag, timeout) logging.debug("Barrier tag %s" % (tags))
def migrate_wait(self, vms_name, srchost, dsthost, start_work=None, check_work=None, mig_mode="exec", params_append=None): vms_count = len(vms_name) mig_ports = [] host_offline_migration = self.params.get("host_mig_offline") sync = SyncData(self.master_id(), self.hostid, self.params.get("hosts"), {'src': srchost, 'dst': dsthost, 'port': "ports"}, self.sync_server) mig_params = {} if host_offline_migration != "yes": if self.params.get("hostid") == dsthost: last_port = 5199 for _ in range(vms_count): last_port = utils_misc.find_free_port(last_port + 1, 6000) mig_ports.append(last_port) mig_ports = sync.sync(mig_ports, timeout=120) mig_ports = mig_ports[dsthost] logging.debug("Migration port %s" % (mig_ports)) mig_cmds = {} for mig_port, vm_name in zip(mig_ports, vms_name): mig_dst_cmd = "nc -l %s %s" % (dsthost, mig_port) mig_src_cmd = "nc %s %s" % (dsthost, mig_port) mig_params["migration_exec_cmd_src_%s" % (vm_name)] = mig_src_cmd mig_params["migration_exec_cmd_dst_%s" % (vm_name)] = mig_dst_cmd else: # Generate filenames for migration. mig_fnam = {} for vm_name in vms_name: while True: fnam = ("mig_" + utils.generate_random_string(6) + "." + vm_name) fpath = os.path.join(self.test.tmpdir, fnam) if (fnam not in mig_fnam.values() and not os.path.exists(fnam)): mig_fnam[vm_name] = fpath break mig_fs = sync.sync(mig_fnam, timeout=120) mig_cmds = {} # Prepare cmd and files. if self.params.get("hostid") == srchost: mig_src_cmd = "gzip -c > %s" for vm_name in vms_name: mig_params["migration_sfiles_path_%s" % (vm_name)] = ( mig_fs[srchost][vm_name]) mig_params["migration_dfiles_path_%s" % (vm_name)] = ( mig_fs[dsthost][vm_name]) mig_params["migration_exec_cmd_src_%s" % (vm_name)] = ( mig_src_cmd % mig_fs[srchost][vm_name]) if self.params.get("hostid") == dsthost: mig_dst_cmd = "gzip -c -d %s" for vm_name in vms_name: mig_params["migration_exec_cmd_dst_%s" % (vm_name)] = ( mig_dst_cmd % mig_fs[dsthost][vm_name]) logging.debug("Exec commands %s", mig_cmds) super_cls = super(MultihostMigrationExec, self) super_cls.migrate_wait(vms_name, srchost, dsthost, start_work=start_work, mig_mode=mig_mode, params_append=mig_params)
class test_multihost_eject(Multihost): def test(self): super(test_multihost_eject, self).test() self.mount_dir = params.get("mount_dir", None) format_floppy_cmd = params["format_floppy_cmd"] floppy = params["floppy_name"] second_floppy = params["second_floppy_name"] if not os.path.isabs(floppy): floppy = os.path.join(data_dir.get_data_dir(), floppy) if not os.path.isabs(second_floppy): second_floppy = os.path.join(data_dir.get_data_dir(), second_floppy) if not self.is_src: self.floppy = create_floppy(params) pid = None sync_id = { 'src': self.srchost, 'dst': self.dsthost, "type": "file_trasfer" } filename = "orig" if self.is_src: # Starts in source vm = env.get_vm(self.vms[0]) session = vm.wait_for_login(timeout=login_timeout) if self.mount_dir: # If linux session.cmd("rm -f %s" % (os.path.join(self.mount_dir, filename))) # If mount_dir specified, treat guest as a Linux OS # Some Linux distribution does not load floppy at boot # and Windows needs time to load and init floppy driver error.context("Prepare floppy for writing.") if self.mount_dir: # If linux lsmod = session.cmd("lsmod") if not 'floppy' in lsmod: session.cmd("modprobe floppy") else: time.sleep(20) if not floppy in vm.monitor.info("block"): raise error.TestFail("Wrong floppy image is placed in vm.") try: session.cmd(format_floppy_cmd) except aexpect.ShellCmdError, e: if e.status == 1: logging.error("First access to floppy failed, " " Trying a second time as a workaround") session.cmd(format_floppy_cmd) error.context("Check floppy") if self.mount_dir: # If linux session.cmd("mount -t vfat %s %s" % (guest_floppy_path, self.mount_dir), timeout=30) session.cmd("umount %s" % (self.mount_dir), timeout=30) written = None if self.mount_dir: filepath = os.path.join(self.mount_dir, "test.txt") session.cmd("echo 'test' > %s" % (filepath)) output = session.cmd("cat %s" % (filepath)) written = "test\n" else: # Windows version. filepath = "A:\\test.txt" session.cmd("echo test > %s" % (filepath)) output = session.cmd("type %s" % (filepath)) written = "test \n\n" if output != written: raise error.TestFail("Data read from the floppy differs" "from the data written to it." " EXPECTED: %s GOT: %s" % (repr(written), repr(output))) error.context("Change floppy.") vm.monitor.cmd("eject floppy0") vm.monitor.cmd("change floppy %s" % (second_floppy)) session.cmd(format_floppy_cmd) error.context("Mount and copy data") if self.mount_dir: # If linux session.cmd("mount -t vfat %s %s" % (guest_floppy_path, self.mount_dir), timeout=30) if not second_floppy in vm.monitor.info("block"): raise error.TestFail("Wrong floppy image is placed in vm.") sync = SyncData(self.mig.master_id(), self.mig.hostid, self.mig.hosts, sync_id, self.mig.sync_server) pid = sync.sync(pid, timeout=floppy_prepare_timeout)[self.srchost] self.mig.migrate_wait([self.vms[0]], self.srchost, self.dsthost) if not self.is_src: # Starts in destination vm = env.get_vm(self.vms[0]) session = vm.wait_for_login(timeout=login_timeout) written = None if self.mount_dir: filepath = os.path.join(self.mount_dir, "test.txt") session.cmd("echo 'test' > %s" % (filepath)) output = session.cmd("cat %s" % (filepath)) written = "test\n" else: # Windows version. filepath = "A:\\test.txt" session.cmd("echo test > %s" % (filepath)) output = session.cmd("type %s" % (filepath)) written = "test \n\n" if output != written: raise error.TestFail("Data read from the floppy differs" "from the data written to it." " EXPECTED: %s GOT: %s" % (repr(written), repr(output))) self.mig._hosts_barrier(self.mig.hosts, self.mig.hosts, 'finish_floppy_test', login_timeout)
def test(self): super(test_multihost_write, self).test() copy_timeout = int(params.get("copy_timeout", 480)) self.mount_dir = params["mount_dir"] format_floppy_cmd = params["format_floppy_cmd"] check_copy_path = params["check_copy_path"] pid = None sync_id = { 'src': self.srchost, 'dst': self.dsthost, "type": "file_trasfer" } filename = "orig" if self.is_src: # Starts in source vm = env.get_vm(self.vms[0]) session = vm.wait_for_login(timeout=login_timeout) if self.mount_dir: session.cmd("rm -f %s" % (os.path.join(self.mount_dir, filename))) session.cmd("rm -f %s" % (check_copy_path)) # If mount_dir specified, treat guest as a Linux OS # Some Linux distribution does not load floppy at boot # and Windows needs time to load and init floppy driver error.context("Prepare floppy for writing.") if self.mount_dir: lsmod = session.cmd("lsmod") if not 'floppy' in lsmod: session.cmd("modprobe floppy") else: time.sleep(20) session.cmd(format_floppy_cmd) error.context("Mount and copy data") if self.mount_dir: session.cmd("mount -t vfat %s %s" % (guest_floppy_path, self.mount_dir), timeout=30) error.context("File copying test") pid = lazy_copy(vm, os.path.join(self.mount_dir, filename), check_copy_path, copy_timeout) sync = SyncData(self.mig.master_id(), self.mig.hostid, self.mig.hosts, sync_id, self.mig.sync_server) pid = sync.sync(pid, timeout=floppy_prepare_timeout)[self.srchost] self.mig.migrate_wait([self.vms[0]], self.srchost, self.dsthost) if not self.is_src: # Starts in destination vm = env.get_vm(self.vms[0]) session = vm.wait_for_login(timeout=login_timeout) error.context("Wait for copy finishing.") status = int( session.cmd_status("kill %s" % pid, timeout=copy_timeout)) if not status in [0]: raise error.TestFail("Copy process was terminatted with" " error code %s" % (status)) session.cmd_status("kill -s SIGINT %s" % (pid), timeout=copy_timeout) error.context("Check floppy file checksum.") md5_cmd = params.get("md5_cmd") if md5_cmd: md5_floppy = session.cmd( "%s %s" % (params.get("md5_cmd"), os.path.join(self.mount_dir, filename))) try: md5_floppy = md5_floppy.split(" ")[0] except IndexError: error.TestError("Failed to get md5 from source file," " output: '%s'" % md5_floppy) md5_check = session.cmd( "%s %s" % (params.get("md5_cmd"), check_copy_path)) try: md5_check = md5_check.split(" ")[0] except IndexError: error.TestError("Failed to get md5 from source file," " output: '%s'" % md5_floppy) if md5_check != md5_floppy: raise error.TestFail( "There is mistake in copying," " it is possible to check file on vm.") session.cmd("rm -f %s" % (os.path.join(self.mount_dir, filename))) session.cmd("rm -f %s" % (check_copy_path)) self.mig._hosts_barrier(self.mig.hosts, self.mig.hosts, 'finish_floppy_test', login_timeout)
def test(self): super(test_multihost_copy, self).test() copy_timeout = int(params.get("copy_timeout", 480)) checksum_timeout = int(params.get("checksum_timeout", 180)) pid = None sync_id = { 'src': self.srchost, 'dst': self.dsthost, "type": "file_trasfer" } filename = "orig" if self.is_src: # Starts in source vm = env.get_vm(self.vms[0]) vm.monitor.migrate_set_speed("1G") session = vm.wait_for_login(timeout=login_timeout) output = session.get_command_output("ls /dev/cdrom*") cdrom_dev_list = re.findall("/dev/cdrom-\w+|/dev/cdrom\d*", output) logging.debug("cdrom_dev_list: %s", cdrom_dev_list) cdrom = cdrom_dev_list[0] error.context("Mount and copy data") session.cmd("mount %s %s" % (cdrom, "/mnt"), timeout=30) error.context("File copying test") session.cmd("rm -f /%s" % filename) pid = disk_copy(vm, os.path.join("/mnt", filename), "/", copy_timeout) sync = SyncData(self.mig.master_id(), self.mig.hostid, self.mig.hosts, sync_id, self.mig.sync_server) pid = sync.sync(pid, timeout=cdrom_prepare_timeout)[self.srchost] self.mig.migrate_wait([self.vms[0]], self.srchost, self.dsthost) if not self.is_src: # Starts in source vm = env.get_vm(self.vms[0]) session = vm.wait_for_login(timeout=login_timeout) error.context("Wait for copy finishing.") status = int( session.cmd_status("wait %s" % pid, timeout=copy_timeout)) if not status in [0, 127]: raise error.TestFail("Copy process was terminatted with" " error code %s" % (status)) if status == 127: logging.warn("Param cdrom_size should be bigger because " "copying finished before migration finish.") error.context("Compare file on disk and on cdrom") f1_hash = session.cmd("md5sum /mnt/%s" % filename, timeout=checksum_timeout).split()[0] f2_hash = session.cmd("md5sum /%s" % filename, timeout=checksum_timeout).split()[0] if f1_hash.strip() != f2_hash.strip(): raise error.TestFail("On disk and on cdrom files are" " different, md5 mismatch") session.cmd("rm -f /%s" % filename) self.mig._hosts_barrier(self.mig.hosts, self.mig.hosts, 'Finish_cdrom_test', login_timeout)
def migration_scenario(self): error.context( "Migration from %s to %s over protocol %s." % (self.srchost, self.dsthost, mig_protocol), logging.info) sync = SyncData(self.master_id(), self.hostid, self.hosts, self.id, self.sync_server) address_cache = env.get("address_cache") def worker_cpu_mem(mig_data): vm = mig_data.vms[0] session = vm.wait_for_login(timeout=self.login_timeout) utils_misc.install_cpuflags_util_on_vm( test, vm, self.install_path, extra_flags="-msse3 -msse2") cmd = ("nohup %s/cpuflags-test --stressmem %d,32" " > %s &" % (os.path.join(self.install_path, "test_cpu_flags"), self.stress_memory, self.cpuflags_test_out)) logging.debug("Sending command: %s" % (cmd)) session.sendline(cmd) if session.cmd_status("killall -s 0 cpuflags-test") != 0: cpu_flags_out = ( "\n cpuflags_test_output: \n" + session.cmd_output("cat %s" % (self.cpuflags_test_out))) raise error.TestFail("Something wrong happend" " during migration cpuflags-test" " should be running all time" " during this test.\n%s" % (cpu_flags_out)) def worker_disk(mig_data): vm = mig_data.vms[0] session = vm.wait_for_login(timeout=self.login_timeout) utils_misc.install_disktest_on_vm(test, vm, self.disk_srcdir, self.install_path) cmd = ("nohup %s/disktest -m %s -L -S > %s &" % (os.path.join(self.install_path, "disktest", "src"), self.disk_usage, self.disktest_out)) logging.debug("Sending command: %s" % (cmd)) session.sendline(cmd) if session.cmd_status("killall -s 0 disktest") != 0: disk_out = ("\n cpuflags_test_output: \n" + session.cmd_output("cat %s" % (self.disktest_out))) raise error.TestFail("Something wrong happend" " during migration disktest" " should be running all time" " during this test.\n%s" % (disk_out)) def worker_all(mig_data): worker_cpu_mem(mig_data) worker_disk(mig_data) self.worker = None if self.stress_type == "cpu_memory": self.worker = worker_cpu_mem elif self.stress_type == "disk": if (self.hostid == self.master_id()): self.install_disktest() self.worker = worker_disk elif self.stress_type == "all": if (self.hostid == self.master_id()): self.install_disktest() self.worker = worker_all if (self.hostid == self.master_id()): self.vm_addr = self._prepare_vm(self.vm).get_address() self._hosts_barrier(self.hosts, self.id, "befor_mig", 120) sync.sync(address_cache, timeout=120) else: self._hosts_barrier(self.hosts, self.id, "befor_mig", 260) address_cache.update(sync.sync(timeout=120)[self.master_id()]) self.migrate_wait([self.vm], self.srchost, self.dsthost, start_work=self.worker) sync.sync(True, timeout=self.migration_timeout) tmp = self.dsthost self.dsthost = self.srchost self.srchost = tmp self.ping_pong_migrate(sync, self.worker)