ia64/xen-unstable

changeset 8084:b67f9f21fd9c

Change the console handling, to remove the loop and timeout if a console fails
to respond first time. For restored and unpaused domains there is no need for
the console to output data, so we cannot use this as a way to detect the
liveness of a console. Instead, a command must always be sent to the console,
which means that this failure can only be detected once the constructor of the
Console class has returned successfully. The __chewall loop still remains, in
order to detect runaway consoles and to clear out previous data from the
console before executing commands, but we no longer treat failure of that
method to read data as a failure of the console itself.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Sun Nov 27 01:06:20 2005 +0000 (2005-11-27)
parents 4195392fba06
children f37f1c9ec2ec
files tools/xm-test/lib/XmTestLib/Console.py tools/xm-test/tests/restore/01_restore_basic_pos.py tools/xm-test/tests/unpause/01_unpause_basic_pos.py
line diff
     1.1 --- a/tools/xm-test/lib/XmTestLib/Console.py	Sun Nov 27 01:02:36 2005 +0000
     1.2 +++ b/tools/xm-test/lib/XmTestLib/Console.py	Sun Nov 27 01:06:20 2005 +0000
     1.3 @@ -66,37 +66,25 @@ class XmConsole:
     1.4          self.historySaveCmds  = historySaveCmds
     1.5          self.debugMe          = False
     1.6          self.limit            = None
     1.7 -        self.delay            = 2
     1.8  
     1.9          consoleCmd = ["/usr/sbin/xm", "xm", "console", domain]
    1.10  
    1.11 -        start = time.time()
    1.12 -
    1.13 -        while (time.time() - start) < self.TIMEOUT:
    1.14 -            if verbose:
    1.15 -                print "Console executing: %s" % str(consoleCmd)
    1.16 +        if verbose:
    1.17 +            print "Console executing: %s" % str(consoleCmd)
    1.18  
    1.19 -            pid, fd = pty.fork()
    1.20 +        pid, fd = pty.fork()
    1.21  
    1.22 -            if pid == 0:
    1.23 -                os.execvp("/usr/sbin/xm", consoleCmd[1:])
    1.24 -
    1.25 -            self.consolePid = pid
    1.26 -            self.consoleFd  = fd
    1.27 +        if pid == 0:
    1.28 +            os.execvp("/usr/sbin/xm", consoleCmd[1:])
    1.29  
    1.30 -            tty.setraw(self.consoleFd, termios.TCSANOW)
    1.31 -            
    1.32 -            bytes = self.__chewall(self.consoleFd)
    1.33 -
    1.34 -            if bytes > 0:
    1.35 -                return
    1.36 +        self.consolePid = pid
    1.37 +        self.consoleFd  = fd
    1.38  
    1.39 -            if verbose:
    1.40 -                print "Console didn't attach, waiting %i sec..." % self.delay
    1.41 -            time.sleep(self.delay)
    1.42 +        tty.setraw(self.consoleFd, termios.TCSANOW)
    1.43  
    1.44 -        raise ConsoleError("Console didn't respond after %i secs" % self.TIMEOUT)
    1.45 -    
    1.46 +        self.__chewall(self.consoleFd)
    1.47 +
    1.48 +
    1.49      def __addToHistory(self, line):
    1.50          self.historyBuffer.append(line)
    1.51          self.historyLines += 1
    1.52 @@ -145,8 +133,8 @@ class XmConsole:
    1.53                      if self.debugMe:
    1.54                          sys.stdout.write(foo)
    1.55                      bytes += 1
    1.56 -                except:
    1.57 -                    timeout += 1
    1.58 +                except Exception, exn:
    1.59 +                    raise ConsoleError(str(exn))
    1.60  
    1.61              else:
    1.62                  timeout += 1
    1.63 @@ -174,7 +162,7 @@ class XmConsole:
    1.64  
    1.65          os.write(self.consoleFd, "%s\n" % command)
    1.66  
    1.67 -        while 1==1:
    1.68 +        while True:
    1.69              i, o, e = select.select([self.consoleFd], [], [], self.TIMEOUT)
    1.70  
    1.71              if self.consoleFd in i:
    1.72 @@ -183,9 +171,10 @@ class XmConsole:
    1.73                      if self.debugMe:
    1.74                          sys.stdout.write(str)
    1.75                      bytes += 1
    1.76 -                except:
    1.77 -                    raise ConsoleError("Failed to read from console (fd=%i)"
    1.78 -                                       % self.consoleFd)
    1.79 +                except Exception, exn:
    1.80 +                    raise ConsoleError(
    1.81 +                        "Failed to read from console (fd=%i): %s" %
    1.82 +                        (self.consoleFd, exn))
    1.83              else:
    1.84                  raise ConsoleError("Timed out waiting for console")
    1.85  
     2.1 --- a/tools/xm-test/tests/restore/01_restore_basic_pos.py	Sun Nov 27 01:02:36 2005 +0000
     2.2 +++ b/tools/xm-test/tests/restore/01_restore_basic_pos.py	Sun Nov 27 01:06:20 2005 +0000
     2.3 @@ -63,6 +63,9 @@ if not isDomainRunning(domain.getName())
     2.4  # Make sure it's alive
     2.5  try:
     2.6      newConsole = XmConsole(domain.getName())
     2.7 +    run = newConsole.runCmd("ls")
     2.8 +    if run["return"] != 0:
     2.9 +        FAIL("Unable to read from restored domain")
    2.10  except ConsoleError, e:
    2.11      FAIL("Restored domain is dead (%s)" % str(e))
    2.12  
     3.1 --- a/tools/xm-test/tests/unpause/01_unpause_basic_pos.py	Sun Nov 27 01:02:36 2005 +0000
     3.2 +++ b/tools/xm-test/tests/unpause/01_unpause_basic_pos.py	Sun Nov 27 01:06:20 2005 +0000
     3.3 @@ -70,9 +70,6 @@ if status != 0:
     3.4  # Are we still alive after all that?
     3.5  try:
     3.6      console = XmConsole(domain.getName(), historySaveCmds=True)
     3.7 -except ConsoleError, e:
     3.8 -    pass
     3.9 -try:
    3.10      run = console.runCmd("ls")
    3.11  except ConsoleError, e:
    3.12      FAIL(str(e))