From: Lukas Doktor Subject: [PATCH] This patch adds migration test (tmigrate). It also daemonize the virtio_console_guest.py script, which is necessarily for the migration test. Date: Mon, 21 Mar 2011 15:13:00 +0100 Message-ID: <1300716780-27503-2-git-send-email-ldoktor@redhat.com> References: <1300716780-27503-1-git-send-email-ldoktor@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE To: ldoktor@redhat.com, jzupka@redhat.com, kvm-autotest@redhat.com, kvm@vger.kernel.org, autotest@test.kernel.org, akong@redhat.com, amit.shah@redhat.com Return-path: Received: from mx1.redhat.com ([209.132.183.28]:44917 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752924Ab1CUONO (ORCPT ); Mon, 21 Mar 2011 10:13:14 -0400 In-Reply-To: <1300716780-27503-1-git-send-email-ldoktor@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: =46rom: Ji=C5=99=C3=AD =C5=BDupka [virtio_console_guest.py] It is splited to 2 parts, first one is client and second one is daemon. * Daemon part is forked and works as the previous script except it redi= rects the STD{IN,OUT,ERR} into named pipes. * Client part connects to named pipes and handle the communication with= host OS. Also when the client is executed multiple time it finds the p= revious client and destrois it. Then it opens the pipes and take over t= he communication. The daemon is NOT executed twice. [tmigrate] This test transfers and checks data through virtio_console loopback whi= le migrating the guest. It's splitted into 2 tests tmigrate_online and = tmigrate_offline. * tmigrate_{offline,online} - parses test parameters and executes the a= ctual test __tmigrate() * test parameters: virtio_console_migration_{offline,online} =3D "[{ser= ialport,console}]:$no_migrations:send_buf_len:recv_buf_len:loopback_buf= _len;..." ; multiple tests are allowed and separated by ';' It sends the data from first {console,serialport} and receive on all re= maining ports of the same type. By default it adds 2 {console,serialpor= t}s depends on test parameters but you can override this using no_{cons= oles,serialports} or the number can be higher according to other tests. [BUGs] Tested on: HOST=3DF13 (2.6.36-0.20.rc3.git4.fc15.x86_64), GUEST=3DF14 (= 2.6.35.6-45.fc14.x86_64) Developer: is noticed simultanously with this patch for explenation. 1) console very often won't survive the migration (it stops transfering= data). virtio_console_migration_offline =3D "console:5:2048:2048:2048" 2a) offline migration: drops 1-2 send-buffers of data, which is for now= accepted as success. virtio_console_migration_offline =3D "serialport:5:2048:2048:2048" 2b) Using smp2 the data loss is 1-4 send-buffers of data. only smp2 virtio_console_migration_offline =3D "serialport:5:2048:2048:2048" 3) online migration: similar problem as offline but the data-loss is mu= ch higher and depends on the console throughput. In this version very h= igh value is accepted as pass. You should check the message "Maximal lo= ss was %s per one migration". If it should be n-degree lower than the t= ransfered data. virtio_console_migration_online =3D "serialport:5:2048:2048:2048" 4) ThSendCheck sometimes get stuck in send. Test handle this and the pr= oblem is similar to: the "FIXME: workaround the problem with qemu-kvm s= tall when too much data is sent without receiving". Using migration thi= s occures with even smaller slices. virtio_console_migration_offline =3D "serialport:5:4096:1:1" Signed-off-by: Ji=C5=99=C3=AD =C5=BDupka Signed-off-by: Lukas Doktor --- client/tests/kvm/scripts/virtio_console_guest.py | 231 +++++++++++-- client/tests/kvm/tests/virtio_console.py | 385 ++++++++++++++= +++++--- client/tests/kvm/tests_base.cfg.sample | 14 +- 3 files changed, 545 insertions(+), 85 deletions(-) diff --git a/client/tests/kvm/scripts/virtio_console_guest.py b/client/= tests/kvm/scripts/virtio_console_guest.py index 8bf5f8b..24c368c 100755 --- a/client/tests/kvm/scripts/virtio_console_guest.py +++ b/client/tests/kvm/scripts/virtio_console_guest.py @@ -9,8 +9,8 @@ Auxiliary script used to send data between ports on gue= sts. """ import threading from threading import Thread -import os, select, re, random, sys, array -import fcntl, traceback, signal +import os, select, re, random, sys, array, stat +import fcntl, traceback, signal, time =20 DEBUGPATH =3D "/sys/kernel/debug" SYSFSPATH =3D "/sys/class/virtio-ports/" @@ -703,7 +703,6 @@ def compile(): def guest_exit(): global exiting exiting =3D True - os.kill(os.getpid(), signal.SIGUSR1) =20 =20 def worker(virt): @@ -711,48 +710,220 @@ def worker(virt): Worker thread (infinite) loop of virtio_guest. """ global exiting - print "PASS: Start" - + print "PASS: Daemon start." + p =3D select.poll() + p.register(sys.stdin.fileno()) while not exiting: - str =3D raw_input() - try: - exec str - except: - exc_type, exc_value, exc_traceback =3D sys.exc_info() - print "On Guest exception from: \n" + "".join( - traceback.format_exception(exc_type, - exc_value, - exc_traceback)) - print "FAIL: Guest command exception." + d =3D p.poll() + if (d[0][1] =3D=3D select.POLLIN): + str =3D raw_input() + try: + exec str + except: + exc_type, exc_value, exc_traceback =3D sys.exc_info() + print "On Guest exception from: \n" + "".join( + traceback.format_exception(exc_type, + exc_value, + exc_traceba= ck)) + print "FAIL: Guest command exception." + elif (d[0][1] & select.POLLHUP): + time.sleep(0.5) =20 =20 def sigusr_handler(sig, frame): pass =20 =20 +class Daemon: + """ + Daemonize guest + """ + def __init__(self, stdin, stdout, stderr): + """ + Init daemon. + + @param stdin: path to stdin file. + @param stdout: path to stdout file. + @param stderr: path to stderr file. + """ + self.stdin =3D stdin + self.stdout =3D stdout + self.stderr =3D stderr + + + @staticmethod + def is_file_open(path): + """ + Determine process which open file. + =20 + @param path: Path to file. + @return [[pid,mode], ... ]. + """ + opens =3D [] + pids =3D os.listdir('/proc') + for pid in sorted(pids): + try: + int(pid) + except ValueError: + continue + fd_dir =3D os.path.join('/proc', pid, 'fd') + try: + for file in os.listdir(fd_dir): + try: + p =3D os.path.join(fd_dir, file) + link =3D os.readlink(os.path.join(fd_dir, file= )) + if link =3D=3D path: + mode =3D os.lstat(p).st_mode + opens.append([pid, mode]) + except OSError: + continue + except OSError, e: + if e.errno =3D=3D 2: + continue + raise + return opens + + + def daemonize(self): + """ + Run guest as a daemon. + """ + try: + pid =3D os.fork() + if pid > 0: + return False + except OSError, e: + sys.stderr.write("Daemonize failed: %s\n" % (e)) + sys.exit(1) + + os.chdir("/") + os.setsid() + os.umask(0) + + try: + pid =3D os.fork() + if pid > 0: + sys.exit(0) + except OSError, e: + sys.stderr.write("Daemonize failed: %s\n" % (e)) + sys.exit(1) + + sys.stdout.flush() + sys.stderr.flush() + si =3D file(self.stdin,'r') + so =3D file(self.stdout,'w') + se =3D file(self.stderr,'w') + + os.dup2(si.fileno(), sys.stdin.fileno()) + os.dup2(so.fileno(), sys.stdout.fileno()) + os.dup2(se.fileno(), sys.stderr.fileno()) + + sys.stdout =3D os.fdopen(sys.stdout.fileno(), 'w', 0) + sys.stderr =3D os.fdopen(sys.stderr.fileno(), 'w', 0) + return True + + + def start(self): + """ + Start the daemon + + @return: PID of daemon. + """ + # Check for a pidfile to see if the daemon already runs + openers =3D self.is_file_open(self.stdout) + rundaemon =3D False + if len(openers) > 0: + for i in openers: + if i[1] & stat.S_IWUSR: + rundaemon =3D True + openers.remove(i) + if len(openers) > 0: + for i in openers: + os.kill(int(i[0]), 9) + time.sleep(0.3) + + # Start the daemon + if not rundaemon: + if self.daemonize(): + self.run() + + + def run(self): + """ + Run guest main thread + """ + global exiting + virt =3D VirtioGuest() + slave =3D Thread(target=3Dworker, args=3D(virt, )) + slave.start() + signal.signal(signal.SIGUSR1, sigusr_handler) + signal.signal(signal.SIGALRM, sigusr_handler) + while not exiting: + signal.alarm(1) + signal.pause() + catch =3D virt.catching_signal() + if catch: + signal.signal(signal.SIGIO, virt) + elif catch is False: + signal.signal(signal.SIGIO, signal.SIG_DFL) + if catch is not None: + virt.use_config.set() + print "PASS: guest_exit" + sys.exit(0) + + def main(): """ Main function with infinite loop to catch signal from system. """ if (len(sys.argv) > 1) and (sys.argv[1] =3D=3D "-c"): compile() + stdin =3D "/tmp/guest_daemon_pi" + stdout =3D "/tmp/guest_daemon_po" + stderr =3D "/tmp/guest_daemon_pe" =20 - global exiting - virt =3D VirtioGuest() - slave =3D Thread(target=3Dworker, args=3D(virt, )) - slave.start() - signal.signal(signal.SIGUSR1, sigusr_handler) - while not exiting: - signal.pause() - catch =3D virt.catching_signal() - if catch: - signal.signal(signal.SIGIO, virt) - elif catch is False: - signal.signal(signal.SIGIO, signal.SIG_DFL) - if catch is not None: - virt.use_config.set() - print "PASS: guest_exit" + for f in [stdin, stdout, stderr]: + try: + os.mkfifo(f) + except OSError, e: + if e.errno =3D=3D 17: + pass + + daemon =3D Daemon(stdin, + stdout, + stderr) + daemon.start() + + d_stdin =3D os.open(stdin, os.O_WRONLY) + d_stdout =3D os.open(stdout, os.O_RDONLY) + d_stderr =3D os.open(stderr, os.O_RDONLY) + + s_stdin =3D sys.stdin.fileno() + s_stdout =3D sys.stdout.fileno() + s_stderr =3D sys.stderr.fileno() + + pid =3D filter(lambda x: x[0] !=3D str(os.getpid()), + daemon.is_file_open(stdout))[0][0] + + print "PASS: Start" =20 + while 1: + ret =3D select.select([d_stderr, + d_stdout, + s_stdin], + [], [], 1.0) + if s_stdin in ret[0]: + os.write(d_stdin,os.read(s_stdin, 1)) + if d_stdout in ret[0]: + os.write(s_stdout,os.read(d_stdout, 1024)) + if d_stderr in ret[0]: + os.write(s_stderr,os.read(d_stderr, 1024)) + if not os.path.exists("/proc/" + pid): + sys.exit(0) + + os.close(d_stdin) + os.close(d_stdout) + os.close(d_stderr) =20 if __name__ =3D=3D "__main__": main() diff --git a/client/tests/kvm/tests/virtio_console.py b/client/tests/kv= m/tests/virtio_console.py index b919ed1..9055098 100644 --- a/client/tests/kvm/tests/virtio_console.py +++ b/client/tests/kvm/tests/virtio_console.py @@ -227,9 +227,19 @@ def run_virtio_console(test, params, env): """ Open port on host side. """ - self.sock =3D socket.socket(socket.AF_UNIX, socket.SOCK_ST= REAM) - self.sock.connect(self.path) - self.is_open =3D True + attempt =3D 11 + while attempt > 0: + try: + self.sock =3D socket.socket(socket.AF_UNIX, + socket.SOCK_STREAM) + self.sock.connect(self.path) + self.sock.setsockopt(1,socket.SO_SNDBUF, 2048) + self.is_open =3D True + return + except Exception, inst: + attempt -=3D 1 + time.sleep(1) + raise error.TestFail("Can't open the %s sock" % self.name) =20 =20 def clean_port(self): @@ -333,7 +343,7 @@ def run_virtio_console(test, params, env): while not self.exitevent.isSet() and len(queue) > = 1048576: too_much_data =3D True time.sleep(0.1) - ret =3D select.select([], [self.port], [], 1.0) + ret =3D select.select([], [self.port.sock], [], 1.0) if ret[1]: # Generate blocklen of random data add them to the= FIFO # and send them over virtio_console @@ -345,7 +355,26 @@ def run_virtio_console(test, params, env): queue.append(ch) target =3D self.idx + self.blocklen while not self.exitevent.isSet() and self.idx < ta= rget: - idx =3D self.port.send(buf) + try: + idx =3D self.port.sock.send(buf) + except Exception, inst: + # Broken pipe + if inst.errno =3D=3D 32: + logging.debug("ThSendCheck %s: Broken = pipe " + "(migration?), reconnect= ing", + self.getName()) + attempt =3D 10 + while (attempt > 1 + and not self.exitevent.isSet())= : + self.port.is_open =3D False + self.port.open() + try: + idx =3D self.port.sock.send(bu= f) + except: + attempt +=3D 1 + time.sleep(10) + else: + attempt =3D 0 buf =3D buf[idx:] self.idx +=3D idx logging.debug("ThSendCheck %s: exit(%d)", self.getName(), @@ -397,12 +426,13 @@ def run_virtio_console(test, params, env): """ Random data receiver/checker thread. """ - def __init__(self, port, buffer, event, blocklen=3D1024): + def __init__(self, port, buffer, event, blocklen=3D1024, sendl= en=3D0): """ @param port: Source port. @param buffer: Control data buffer (FIFO). @param length: Amount of data we want to receive. @param blocklen: Block length. + @param sendlen: Block length of the send function (on gues= t) """ Thread.__init__(self) self.port =3D port @@ -410,33 +440,85 @@ def run_virtio_console(test, params, env): self.exitevent =3D event self.blocklen =3D blocklen self.idx =3D 0 + self.sendlen =3D sendlen + 1 # >=3D =20 =20 def run(self): logging.debug("ThRecvCheck %s: run", self.getName()) + attempt =3D 10 + sendidx =3D -1 + minsendidx =3D self.sendlen while not self.exitevent.isSet(): - ret =3D select.select([self.port], [], [], 1.0) + ret =3D select.select([self.port.sock], [], [], 1.0) if ret[0] and (not self.exitevent.isSet()): - buf =3D self.port.recv(self.blocklen) + buf =3D self.port.sock.recv(self.blocklen) if buf: # Compare the received data with the control d= ata for ch in buf: ch_ =3D self.buffer.popleft() - if not ch =3D=3D ch_: - self.exitevent.set() - logging.error("Failed to recv %dth cha= racter", - self.idx) - logging.error("%s !=3D %s", repr(ch), = repr(ch_)) - logging.error("Recv =3D %s", repr(buf)= ) - # sender might change the buffer :-( - time.sleep(1) - ch_ =3D "" - for buf in self.buffer: - ch_ +=3D buf - logging.error("Queue =3D %s", repr(ch_= )) - raise error.TestFail("ThRecvCheck: inc= orrect " - "data") - self.idx +=3D len(buf) + if ch =3D=3D ch_: + self.idx +=3D 1 + else: + # TODO BUG: data from the socket on ho= st can + # be lost during migration + while ch !=3D ch_: + if sendidx > 0: + sendidx -=3D 1 + ch_ =3D self.buffer.popleft() + else: + self.exitevent.set() + logging.error("ThRecvCheck %s:= " + "Failed to recv = %dth " + "character", + self.getName(), = self.idx) + logging.error("ThRecvCheck %s:= " + "%s !=3D %s", + self.getName(), + repr(ch), repr(c= h_)) + logging.error("ThRecvCheck %s:= " + "Recv =3D %s", + self.getName(), = repr(buf)) + # sender might change the buff= er :-( + time.sleep(1) + ch_ =3D "" + for buf in self.buffer: + ch_ +=3D buf + ch_ +=3D ' ' + logging.error("ThRecvCheck %s:= " + "Queue =3D %s", + self.getName(), = repr(ch_)) + logging.info("ThRecvCheck %s: = " + "MaxSendIDX =3D %d= ", + self.getName(), + (self.sendlen - se= ndidx)) + raise error.TestFail("ThRecvCh= eck %s: " + "incorrec= t data", + self.getN= ame()) + attempt =3D 10 + else: # ! buf + # Broken socket + if attempt > 0: + attempt -=3D 1 + logging.debug("ThRecvCheck %s: Broken pipe= " + "(migration?), reconnecting.= ", + self.getName()) + # TODO BUG: data from the socket on host c= an be lost + if sendidx >=3D 0: + minsendidx =3D min(minsendidx, sendidx= ) + logging.debug("ThRecvCheck %s: Previou= s data " + "loss was %d.", + self.getName(), + (self.sendlen - sendidx)= ) + sendidx =3D self.sendlen + self.port.is_open =3D False + self.port.open() + if sendidx >=3D 0: + minsendidx =3D min(minsendidx, sendidx) + if (self.sendlen - minsendidx): + logging.error("ThRecvCheck %s: Data loss occured durin= g socket" + "reconnection. Maximal loss was %d per o= ne " + "migration.", self.getName(), + (self.sendlen - minsendidx)) logging.debug("ThRecvCheck %s: exit(%d)", self.getName(), self.idx) =20 @@ -457,7 +539,7 @@ def run_virtio_console(test, params, env): return stats =20 =20 - def _init_guest(vm, timeout=3D2): + def _init_guest(vm, timeout=3D10): """ Execute virtio_console_guest.py on guest, wait until it is ini= tialized. =20 @@ -552,9 +634,9 @@ def run_virtio_console(test, params, env): "FAIL:= "], timeout= ) =20 - except (kvm_subprocess.ExpectError): + except (kvm_subprocess.ExpectError), e: match =3D None - data =3D "Timeout." + data =3D "Cmd process timeout. Data in console: " + e.outp= ut =20 kcrash_data =3D _search_kernel_crashlog(vm[3]) if kcrash_data is not None: @@ -895,7 +977,7 @@ def run_virtio_console(test, params, env): if (port.sock.recv(1024) < 10): raise error.TestFail("Didn't received data from guest") # Now the _on_guest("virt.send('%s'... command should be finis= hed - on_guest("print 'PASS: nothing'", vm, 10) + on_guest("print('PASS: nothing')", vm, 10) =20 =20 def trw_host_offline_big_data(vm, port): @@ -930,7 +1012,7 @@ def run_virtio_console(test, params, env): elif rlen !=3D (1024**3*3): raise error.TestFail("Not all data was received," "only %d from %d" % (rlen, 1024**= 3*3)) - on_guest("print 'PASS: nothing'", vm, 10) + on_guest("print('PASS: nothing')", vm, 10) =20 =20 def trw_notconnect_guest(vm, port, consoles): @@ -1020,7 +1102,7 @@ def run_virtio_console(test, params, env): (match, tmp)) port.sock.sendall("1234567890") # Now guest received the data end escaped from the recv() - on_guest("print 'PASS: nothing'", vm, 10) + on_guest("print('PASS: nothing')", vm, 10) =20 =20 def trw_nonblocking_mode(vm, port): @@ -1191,20 +1273,193 @@ def run_virtio_console(test, params, env): clean_reload_vm(vm, consoles, expected=3DTrue) =20 =20 - def tmigrate_offline(vm, consoles): + def __tmigrate(vm, consoles, parms, offline=3DTrue): """ - Let the machine migrate. Virtio_consoles should survive this. + An actual migration test. It creates loopback on guest from fi= rst port + to all remaining ports. Than it sends and validates the data. + During this it tries to migrate the vm n-times. =20 @param vm: Target virtual machine [vm, session, tmp_dir, ser_s= ession]. - @param consoles: Consoles which should be close before rmmod. + @param consoles: Field of virtio ports with the minimum of 2 i= tems. + @param parms: [media, no_migration, send-, recv-, loopback-buf= fer_len] """ - # Migrate - vm[1].close() - dest_vm =3D kvm_test_utils.migrate(vm[0], env, 3600, "exec", 0= , 0) - vm[1] =3D kvm_utils.wait_for(dest_vm.remote_login, 30, 0, 2) - if not vm[1]: - raise error.TestFail("Could not log into guest after migra= tion") - logging.info("Logged in after migration") + # PREPARE + send_pt =3D consoles[parms[0]][0] + recv_pts =3D consoles[parms[0]][1:] + # TODO BUG: sendlen =3D max allowed data to be lost per one mi= gration + # TODO BUG: using SMP the data loss is upto 4 buffers + # 2048 =3D char. dev. socket size, parms[2] =3D host->guest se= nd buffer size + sendlen =3D 2*2*max(2048, parms[2]) + if not offline: # TODO BUG: online migration causes more loses + # TODO: Online migration lose n*buffer. n depends on the c= onsole + # troughput. FIX or analyse it's cause. + sendlen =3D 1000 * sendlen + for p in recv_pts: + if not p.is_open: + p.open() + + if not send_pt.is_open: + send_pt.open() + + threads =3D [] + queues =3D [] + verified =3D [] + for i in range(0, len(recv_pts)): + queues.append(deque()) + verified.append(0) + + tmp =3D "'%s'" % recv_pts[0].name + for recv_pt in recv_pts[1:]: + tmp +=3D ", '%s'" % (recv_pt.name) + on_guest("virt.loopback(['%s'], [%s], %d, virt.LOOP_POLL)" + % (send_pt.name, tmp, parms[4]), vm, 10) + + exit_event =3D threading.Event() + + # TEST + thread =3D ThSendCheck(send_pt, exit_event, queues, + parms[2]) + thread.start() + threads.append(thread) + + for i in range(len(recv_pts)): + thread =3D ThRecvCheck(recv_pts[i], queues[i], exit_event, + parms[3], sendlen=3Dsendlen) + thread.start() + threads.append(thread) + + i=3D0 + while i < 6: + tmp =3D "%d data sent; " % threads[0].idx + for thread in threads[1:]: + tmp +=3D "%d, " % thread.idx + logging.debug("test_loopback: %s data received and verifie= d", + tmp[:-2]) + i+=3D1 + time.sleep(2) + + + for j in range(parms[1]): + vm[0] =3D kvm_test_utils.migrate(vm[0], env, 3600, "exec",= 0, + offline) + if not vm[1]: + raise error.TestFail("Could not log into guest after m= igration") + vm[1] =3D kvm_test_utils.wait_for_login(vm[0], 0, + float(params.get("boot_timeout= ", 100)), + 0, 2) + # OS is sometime a bit dizzy. DL=3D30 + _init_guest(vm, 30) + + i=3D0 + while i < 6: + tmp =3D "%d data sent; " % threads[0].idx + for thread in threads[1:]: + tmp +=3D "%d, " % thread.idx + logging.debug("test_loopback: %s data received and ver= ified", + tmp[:-2]) + i+=3D1 + time.sleep(2) + if not threads[0].is_alive(): + if exit_event.isSet(): + raise error.TestFail("Exit event emited, check the= log for" + "send/recv thread failure.") + else: + raise error.TestFail("Send thread died unexpectedl= y in %d " + "migration.", (j+1)) + for i in range(0, len(recv_pts)): + if not threads[i+1].is_alive(): + raise error.TestFail("Recv thread %d died unexpect= edly in " + "%d migration", i, (j+1)) + if verified[i] =3D=3D threads[i+1].idx: + raise error.TestFail("No new data in %d console we= re " + "transfered after %d migratio= n." + , i, (j+1)) + verified[i] =3D threads[i+1].idx + logging.info("%d out of %d migration passed" % ((j+1), par= ms[1])) + # TODO detect recv-thread failure and throw out whole test + + # FINISH + exit_event.set() + # Send thread might fail to exit when the guest stucks + i =3D 30 + while threads[0].is_alive(): + if i <=3D 0: + raise error.TestFail("Send thread did not finish.") + time.sleep(1) + i -=3D 1 + tmp =3D "%d data sent; " % threads[0].idx + for thread in threads[1:]: + thread.join() + tmp +=3D "%d, " % thread.idx + logging.info("test_loopback: %s data received and verified dur= ing %d " + "migrations", tmp[:-2], parms[1]) + + # CLEANUP + _guest_exit_threads(vm, [send_pt], recv_pts) + del exit_event + del threads[:] + + def _tmigrate(vm, consoles, parms, offline): + """ + Wrapper which parses the params for __migrate test. + + @param vm: Target virtual machine [vm, session, tmp_dir, ser_s= ession]. + @param consoles: Field of virtio ports with the minimum of 2 i= tems. + @param parms: test parameters, multiple recievers allowed. + '[{serialport,console}]:$no_migrations:send_buf_len:recv_b= uf_len: + loopback_buf_len;...' + """ + for param in parms.split(';'): + if not param: + continue + if offline: + logging.info("test_migrate_offline: params: %s", param= ) + else: + logging.info("test_migrate_online: params: %s", param) + param =3D param.split(':') + media =3D 1 + if param[0].isalpha(): + if param[0] =3D=3D "console": + param[0] =3D 0 + else: + param[0] =3D 1 + else: + param =3D [0] + param + for i in range(1,5): + if not param[i].isdigit(): + param[i] =3D 1 + else: + param[i] =3D int(param[i]) + + __tmigrate(vm, consoles, param, offline=3Doffline) + + + def tmigrate_offline(vm, consoles, parms): + """ + Tests whether the virtio-{console,port} are able to survive th= e offline + migration. + + @param vm: Target virtual machine [vm, session, tmp_dir, ser_s= ession]. + @param consoles: Field of virtio ports with the minimum of 2 i= tems. + @param parms: test parameters, multiple recievers allowed. + '[{serialport,console}]:$no_migrations:send_buf_len:recv_b= uf_len: + loopback_buf_len;...' + """ + _tmigrate(vm, consoles, parms, offline=3DTrue) + + + def tmigrate_online(vm, consoles, parms): + """ + Tests whether the virtio-{console,port} are able to survive th= e online + migration. + + @param vm: Target virtual machine [vm, session, tmp_dir, ser_s= ession]. + @param consoles: Field of virtio ports with the minimum of 2 i= tems. + @param parms: test parameters, multiple recievers allowed. + '[{serialport,console}]:$no_migrations:send_buf_len:recv_b= uf_len: + loopback_buf_len;...' + """ + _tmigrate(vm, consoles, parms, offline=3DFalse) =20 =20 def _virtio_dev_create(vm, ports_name, pciid, id, console=3D"no"): @@ -1460,13 +1715,13 @@ def run_virtio_console(test, params, env): exit_event =3D threading.Event() =20 # TEST - thread =3D ThSendCheck(send_pt.sock, exit_event, queues, + thread =3D ThSendCheck(send_pt, exit_event, queues, buf_len[0]) thread.start() threads.append(thread) =20 for i in range(len(recv_pts)): - thread =3D ThRecvCheck(recv_pts[i].sock, queues[i], ex= it_event, + thread =3D ThRecvCheck(recv_pts[i], queues[i], exit_ev= ent, buf_len[i + 1]) thread.start() threads.append(thread) @@ -1632,7 +1887,7 @@ def run_virtio_console(test, params, env): @param consoles: Consoles which should be clean. """ # Check if python is still alive - print "CLEANING" + logging.info("CLEANING") match, tmp =3D _on_guest("is_alive()", vm, 10) if (match is None) or (match !=3D 0): logging.error("Python died/is stucked/have remaining threa= ds") @@ -1666,7 +1921,8 @@ def run_virtio_console(test, params, env): " blocked. Every comd end with sig KILL.= " "Trying to reboot vm to continue testing= =2E..") try: - vm[1] =3D kvm_test_utils.reboot(vm[0], vm[1], "sys= tem_reset") + vm[0].destroy(gracefully =3D True) + (vm[0], vm[1], vm[3]) =3D _restore_vm() except (kvm_monitor.MonitorProtocolError): logging.error("Qemu is blocked. Monitor no longer = " "communicates.") @@ -1712,10 +1968,10 @@ def run_virtio_console(test, params, env): @param vm: Target virtual machine [vm, session, tmp_dir, ser_s= ession]. @param consoles: Consoles which should be clean. """ - if not expected: - print "Scheduled vm reboot" + if expected: + logging.info("Scheduled vm reboot") else: - print "SCHWARZENEGGER is CLEANING" + logging.info("SCHWARZENEGGER is CLEANING") _reset_vm(vm, consoles, len(consoles[0]), len(consoles[1])) init_guest(vm, consoles) =20 @@ -1788,14 +2044,15 @@ def run_virtio_console(test, params, env): subtest.do_test(tperf, [vm, consoles, params[1]]) =20 =20 - def test_destructive(test, vm, consoles, global_params): + def test_destructive(test, vm, consoles, global_params, params): """ - This is group of tests is destructive. + This is group of tests which might be destructive. =20 @param test: Main test object. @param vm: Target virtual machine [vm, session, tmp_dir, ser_s= ession]. @param consoles: Field of virtio ports with the minimum of 2 i= tems. @param global_params: Params defined by tests_base.conf. + @param params: Dictionary of subtest params from tests_base.co= nf. """ subtest.headline("test_destructive:") # Uses stronger clean up function @@ -1810,8 +2067,12 @@ def run_virtio_console(test, params, env): subtest.do_test(tmax_mix_serial_conosle_port, [vm, console= s]) if (global_params.get('shutdown_test') =3D=3D "yes"): subtest.do_test(tshutdown, [vm, consoles]) - if (global_params.get('migrate_test') =3D=3D "yes"): - subtest.do_test(tmigrate_offline, [vm, consoles]) + if (global_params.get('migrate_offline_test') =3D=3D "yes"): + subtest.do_test(tmigrate_offline, + [vm, consoles, params['tmigrate_offline_pa= rams']]) + if (global_params.get('migrate_online_test') =3D=3D "yes"): + subtest.do_test(tmigrate_online, + [vm, consoles, params['tmigrate_online_par= ams']]) if (global_params.get('hotplug_serial_test') =3D=3D "yes"): subtest.do_test(thotplug, [vm, consoles]) subtest.do_test(thotplug_no_timeout, [vm, consoles]) @@ -1833,9 +2094,16 @@ def run_virtio_console(test, params, env): tsmoke_params =3D params.get('virtio_console_smoke', '') tloopback_params =3D params.get('virtio_console_loopback', '') tperf_params =3D params.get('virtio_console_perf', '') + tmigrate_offline_params =3D params.get('virtio_console_migration_o= ffline', '') + tmigrate_online_params =3D params.get('virtio_console_migration_on= line', '') =20 - no_serialports =3D 0 - no_consoles =3D 0 + # destructive params + tdestructive_params =3D {} + tdestructive_params['tmigrate_offline_params'] =3D tmigrate_offlin= e_params + tdestructive_params['tmigrate_online_params'] =3D tmigrate_online_= params + + no_serialports =3D int(params.get('virtio_console_no_serialports',= 0)) + no_consoles =3D int(params.get('virtio_console_no_consoles', 0)) # consoles required for Smoke test if tsmoke_params.count('serialport'): no_serialports =3D max(2, no_serialports) @@ -1850,6 +2118,15 @@ def run_virtio_console(test, params, env): no_serialports =3D max(1, no_serialports) if tperf_params.count('console'): no_consoles =3D max(1, no_consoles) + # consoles required for Migration offline test + if tmigrate_offline_params.count('serial'): + no_serialports =3D max(2, no_serialports) + if tmigrate_offline_params.count('console'): + no_consoles =3D max(2, no_consoles) + if tmigrate_online_params.count('serial'): + no_serialports =3D max(2, no_serialports) + if tmigrate_online_params.count('console'): + no_consoles =3D max(2, no_consoles) =20 if no_serialports + no_consoles =3D=3D 0: raise error.TestFail("No tests defined, probably incorrect " @@ -1880,7 +2157,7 @@ def run_virtio_console(test, params, env): params) =20 #Test destructive test. - test_destructive(subtest, vm, consoles, params) + test_destructive(subtest, vm, consoles, params, tdestructive_p= arams) finally: logging.info(("Summary: %d tests passed %d test failed :\n" % (subtest.passed, subtest.failed)) + @@ -1888,7 +2165,7 @@ def run_virtio_console(test, params, env): =20 if subtest.is_failed(): raise error.TestFail("%d out of %d virtio console tests failed= " % - (subtest.passed, subtest.failed)) + (subtest.failed, (subtest.passed+subtest.= failed))) =20 =20 # CLEANUP diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/= tests_base.cfg.sample index 7e16ef9..c3aac44 100644 --- a/client/tests/kvm/tests_base.cfg.sample +++ b/client/tests/kvm/tests_base.cfg.sample @@ -782,6 +782,10 @@ variants: only Linux vms =3D '' type =3D virtio_console + # Default number of consoles + virtio_console_no_serialports =3D 0 + virtio_console_no_consoles =3D 0 + # smoke params - $console_type:data_string # FIXME: test_smoke doesn't work with console yet (virtio_cons= ole bug) # "serialport;console:Custom data" @@ -800,7 +804,15 @@ variants: rmmod_test =3D yes max_ports_test =3D yes shutdown_test =3D yes - migrate_test =3D yes + + # Offline migration params - '$console_type:$no_migrations:$se= nd-:$recv-$loopback-buffer_length' + migrate_offline_test =3D yes + virtio_console_migration_offline =3D "serialport:1:2048:2048:2= 048;serialport:5:4096:4096:4096" + + # Online migration params - '$console_type:$no_migrations:$sen= d-:$recv-$loopback-buffer_length' + migrate_online_test =3D yes + virtio_console_migration_online =3D "serialport:1:2048:2048:20= 48;serialport:5:4096:4096:4096" + hotplug_test =3D yes hotplug_serial_test =3D yes hotplug_console_test =3D no --=20 1.7.3.4