ia64/xen-unstable

changeset 2397:daf585a98004

bitkeeper revision 1.1159.1.113 (4136e90fOr8_LyqJ85kTqL-uFrO_xw)

Remove debug prints and turn logging to stderr off by default.
author mjw@wray-m-3.hpl.hp.com
date Thu Sep 02 09:34:07 2004 +0000 (2004-09-02)
parents 11be1dfb262b
children 4f6933bb7358
files tools/python/xen/xend/XendDomain.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/XendLogging.py tools/python/xen/xend/XendRoot.py tools/python/xen/xend/server/SrvDaemon.py tools/python/xen/xend/server/blkif.py tools/python/xen/xend/server/controller.py tools/python/xen/xend/server/netif.py
line diff
     1.1 --- a/tools/python/xen/xend/XendDomain.py	Wed Sep 01 09:43:32 2004 +0000
     1.2 +++ b/tools/python/xen/xend/XendDomain.py	Thu Sep 02 09:34:07 2004 +0000
     1.3 @@ -228,10 +228,6 @@ class XendDomain:
     1.4          """
     1.5          self.reap_cancel()
     1.6          domlist = xc.domain_getinfo()
     1.7 -        #for d in domlist:
     1.8 -        #    print 'reap> xen:  ', d['dom'], d
     1.9 -        #for d in self.domain_by_id.values():
    1.10 -        #    print 'reap> xend: ', d.id, d.info
    1.11          casualties = []
    1.12          for d in domlist:
    1.13              dead = 0
    1.14 @@ -272,10 +268,6 @@ class XendDomain:
    1.15          """
    1.16          self.refresh_cancel()
    1.17          domlist = xc.domain_getinfo()
    1.18 -        #for d in domlist:
    1.19 -        #    print 'refresh> xen:  ', d['dom'], d
    1.20 -        #for d in self.domain_by_id.values():
    1.21 -        #    print 'refresh> xend: ', d.id, d.info
    1.22          # Index the domlist by id.
    1.23          # Add entries for any domains we don't know about.
    1.24          doms = {}
    1.25 @@ -394,12 +386,8 @@ class XendDomain:
    1.26          @param vmconfig: vm configuration
    1.27          @return: deferred
    1.28          """
    1.29 -        print 'domain_configure>', id, vmconfig
    1.30          config = sxp.child_value(vmconfig, 'config')
    1.31          dominfo = self.domain_lookup(id)
    1.32 -        print 'domain_configure>', 'dominfo=', dominfo
    1.33 -        for dinfo in self.domain_by_id.values():
    1.34 -            print 'domain', 'id=', dinfo.id, 'name=', dinfo.name
    1.35          log.debug('domain_configure> id=%s config=%s', str(id), str(config))
    1.36          if dominfo.config:
    1.37              raise XendError("Domain already configured: " + dominfo.id)
    1.38 @@ -597,11 +585,9 @@ class XendDomain:
    1.39          """
    1.40          # Need a cancel too?
    1.41          # Don't forget to cancel restart for it.
    1.42 -        print 'domain_migrate>', id, dst
    1.43          dominfo = self.domain_lookup(id)
    1.44          xmigrate = XendMigrate.instance()
    1.45          val = xmigrate.migrate_begin(dominfo.id, dst, live=live)
    1.46 -        print 'domain_migrate<', val
    1.47          return val
    1.48  
    1.49      def domain_save(self, id, dst, progress=0):
    1.50 @@ -616,10 +602,10 @@ class XendDomain:
    1.51          xmigrate = XendMigrate.instance()
    1.52          return xmigrate.save_begin(dominfo.id, dst)
    1.53      
    1.54 -    def domain_pincpu(self, dom, cpu):
    1.55 +    def domain_pincpu(self, id, cpu):
    1.56          """Pin a domain to a cpu.
    1.57  
    1.58 -        @param dom: domain
    1.59 +        @param id: domain
    1.60          @param cpu: cpu number
    1.61          """
    1.62          dominfo = self.domain_lookup(id)
     2.1 --- a/tools/python/xen/xend/XendDomainInfo.py	Wed Sep 01 09:43:32 2004 +0000
     2.2 +++ b/tools/python/xen/xend/XendDomainInfo.py	Thu Sep 02 09:34:07 2004 +0000
     2.3 @@ -16,7 +16,6 @@ import os
     2.4  import time
     2.5  
     2.6  from twisted.internet import defer
     2.7 -#defer.Deferred.debug = 1
     2.8  
     2.9  import xen.lowlevel.xc; xc = xen.lowlevel.xc.new()
    2.10  import xen.util.ip
    2.11 @@ -188,7 +187,7 @@ def vif_up(iplist):
    2.12  
    2.13      def arping(ip, gw):
    2.14          cmd = '/usr/sbin/arping -A -b -I eth0 -c 1 -s %s %s' % (ip, gw)
    2.15 -        print cmd
    2.16 +        log.debug(cmd)
    2.17          os.system(cmd)
    2.18          
    2.19      gateway = xen.util.ip.get_current_ipgw() or '255.255.255.255'
    2.20 @@ -472,7 +471,6 @@ class XendDomainInfo:
    2.21          # my domain id.
    2.22          if not dominfo:
    2.23              return
    2.24 -        #print 'check_name>', 'dom=', dominfo.name, dominfo.dom, 'self=', name, self.dom
    2.25          if dominfo.is_terminated():
    2.26              return
    2.27          if not self.dom or (dominfo.dom != self.dom):
     3.1 --- a/tools/python/xen/xend/XendLogging.py	Wed Sep 01 09:43:32 2004 +0000
     3.2 +++ b/tools/python/xen/xend/XendLogging.py	Thu Sep 02 09:34:07 2004 +0000
     3.3 @@ -18,6 +18,9 @@ class XendLogging:
     3.4      dateFormat = "%Y-%m-%d %H:%M:%S"
     3.5  
     3.6      def __init__(self, filename, level=logging.INFO, maxBytes=None, backupCount=None):
     3.7 +        """Initialise logging. Logs to 'filename' by default, but does not log to
     3.8 +        stderr unless addLogStderr() is called.
     3.9 +        """
    3.10          self.setLevel(level)
    3.11          if maxBytes:
    3.12              self.maxBytes = maxBytes
    3.13 @@ -25,7 +28,6 @@ class XendLogging:
    3.14              self.backupCount = backupCount
    3.15          self.initLogFile(filename)
    3.16          self.initLogStderr()
    3.17 -        pass
    3.18  
    3.19      def setLevel(self, level):
    3.20          if isinstance(level, types.StringType):
    3.21 @@ -40,6 +42,8 @@ class XendLogging:
    3.22          return logging.getLogger("xend")
    3.23  
    3.24      def initLogFile(self, filename):
    3.25 +        """Create the file logger and add it.
    3.26 +        """
    3.27          self.logfile = RotatingFileHandler(filename,
    3.28                                             mode='a',
    3.29                                             maxBytes=self.maxBytes,
    3.30 @@ -56,9 +60,18 @@ class XendLogging:
    3.31          return self.logfilename
    3.32  
    3.33      def initLogStderr(self):
    3.34 +        """Create the stderr logger, but don't add it.
    3.35 +        """
    3.36          self.logstderr = StreamHandler()
    3.37          self.logstderr.setFormatter(Formatter(self.logStderrFormat, self.dateFormat))
    3.38 +
    3.39 +    def addLogStderr(self):
    3.40 +        """Add logging to stderr."""
    3.41          self.getLogger().addHandler(self.logstderr)
    3.42 +
    3.43 +    def removeLogStderr(self):
    3.44 +        """Remove logging to stderr."""
    3.45 +        self.getLogger().removeHandler(self.logstderr)
    3.46          
    3.47      def getLogStderr(self):
    3.48          return self.logstderr
     4.1 --- a/tools/python/xen/xend/XendRoot.py	Wed Sep 01 09:43:32 2004 +0000
     4.2 +++ b/tools/python/xen/xend/XendRoot.py	Thu Sep 02 09:34:07 2004 +0000
     4.3 @@ -58,6 +58,7 @@ class XendRoot:
     4.4          self.dbroot = None
     4.5          self.config_path = None
     4.6          self.config = None
     4.7 +        self.logger = None
     4.8          self.configure()
     4.9          self.check_lastboot()
    4.10          eserver.subscribe('xend.*', self.event_handler)
    4.11 @@ -85,18 +86,75 @@ class XendRoot:
    4.12      def start(self):
    4.13          eserver.inject('xend.start', self.rebooted)
    4.14  
    4.15 +    def _format(self, msg, args):
    4.16 +        if args:
    4.17 +            return str(msg)
    4.18 +        else:
    4.19 +            return str(msg) % args
    4.20 +
    4.21 +    def _log(self, mode, fmt, args):
    4.22 +        """Logging function that uses the logger if it exists, otherwise
    4.23 +        logs to stderr. We use this for XendRoot log messages because
    4.24 +        they may be logged before the logger has been configured.
    4.25 +        Other components can safely use the logger.
    4.26 +        """
    4.27 +        log = self.get_logger()
    4.28 +        if mode not in ['warning', 'info', 'debug', 'error']:
    4.29 +            mode = 'info'
    4.30 +        level = mode.upper()
    4.31 +        if log:
    4.32 +            getattr(log, mode)(fmt, *args)
    4.33 +        else:
    4.34 +            print >>stderr, "xend", "[%s]" % level, self._format(msg, args)
    4.35 +
    4.36 +    def logDebug(self, fmt, *args):
    4.37 +        """Log a debug message.
    4.38 +
    4.39 +        @param fmt: message format
    4.40 +        @param args: arguments
    4.41 +        """
    4.42 +        self._log('info', fmt, args)
    4.43 +        
    4.44 +    def logInfo(self, fmt, *args):
    4.45 +        """Log an info message.
    4.46 +
    4.47 +        @param fmt: message format
    4.48 +        @param args: arguments
    4.49 +        """
    4.50 +        self._log('info', fmt, args)
    4.51 +
    4.52 +    def logWarning(self, fmt, *args):
    4.53 +        """Log a warning message.
    4.54 +
    4.55 +        @param fmt: message format
    4.56 +        @param args: arguments
    4.57 +        """
    4.58 +        self._log('warning', fmt, args)
    4.59 +        
    4.60 +    def logError(self, fmt, *args):
    4.61 +        """Log an error message.
    4.62 +
    4.63 +        @param fmt: message format
    4.64 +        @param args: arguments
    4.65 +        """
    4.66 +        self._log('error', fmt, args)
    4.67 +        
    4.68      def event_handler(self, event, val):
    4.69 -        print >> sys.stderr, "EVENT>", event, val
    4.70 +        self.logInfo("EVENT> %s %s", str(event), str(val))
    4.71  
    4.72      def read_lastboot(self):
    4.73 +        """Read the lastboot file to determine the time of the last boot.
    4.74 +        """
    4.75          try:
    4.76              val = file(self.lastboot, 'rb').readlines()[0]
    4.77          except StandardError, ex:
    4.78 -            print 'warning: Error reading', self.lastboot, ex
    4.79 +            self.logWarning('Error reading %s: %s', self.lastboot, str(ex))
    4.80              val = None
    4.81          return val
    4.82  
    4.83      def write_lastboot(self, val):
    4.84 +        """Write the last boot time to the lastboot file.
    4.85 +        """
    4.86          if not val: return
    4.87          try:
    4.88              fdir = os.path.dirname(self.lastboot)
    4.89 @@ -106,8 +164,7 @@ class XendRoot:
    4.90              out.write(val)
    4.91              out.close()
    4.92          except IOError, ex:
    4.93 -            print 'warning: Error writing', self.lastboot, ex
    4.94 -            pass
    4.95 +            self.logWarning('Error writing %s: %s', self.lastboot, str(ex))
    4.96  
    4.97      def check_lastboot(self):
    4.98          """Check if there has been a system reboot since we saved lastboot.
    4.99 @@ -122,13 +179,17 @@ class XendRoot:
   4.100          self.last_reboot = this_val
   4.101  
   4.102      def get_last_reboot(self):
   4.103 +        """Get the last reboot time as a string.
   4.104 +        """
   4.105          return self.last_reboot
   4.106  
   4.107      def get_rebooted(self):
   4.108 +        """Get the rebooted flag. The flag is true if the system has
   4.109 +        been rebooted since xend was last run.
   4.110 +        """
   4.111          return self.rebooted
   4.112  
   4.113      def configure(self):
   4.114 -        print 'XendRoot>configure>'
   4.115          self.set_config()
   4.116          self.configure_logger()
   4.117          self.dbroot = self.get_config_value("dbroot", self.dbroot_default)
   4.118 @@ -140,9 +201,13 @@ class XendRoot:
   4.119          self.logging = XendLogging(logfile, level=loglevel)
   4.120  
   4.121      def get_logging(self):
   4.122 +        """Get the XendLogging instance.
   4.123 +        """
   4.124          return self.logging
   4.125  
   4.126      def get_logger(self):
   4.127 +        """Get the logger.
   4.128 +        """
   4.129          return self.logging.getLogger()
   4.130  
   4.131      def get_dbroot(self):
   4.132 @@ -156,9 +221,7 @@ class XendRoot:
   4.133          The config file is a sequence of sxp forms.
   4.134          """
   4.135          self.config_path = os.getenv(self.config_var, self.config_default)
   4.136 -        print 'XendRoot>set_config> config_path=', self.config_path
   4.137          if os.path.exists(self.config_path):
   4.138 -            print 'XendRoot>set_config> loading'
   4.139              fin = file(self.config_path, 'rb')
   4.140              try:
   4.141                  config = sxp.parse(fin)
   4.142 @@ -167,9 +230,7 @@ class XendRoot:
   4.143              finally:
   4.144                  fin.close()
   4.145          else:
   4.146 -            print 'XendRoot>set_config> not found'
   4.147              self.config = ['xend-config']
   4.148 -        print 'XendRoot> config=', self.config
   4.149  
   4.150      def get_config(self, name=None):
   4.151          """Get the configuration element with the given name, or
   4.152 @@ -213,6 +274,9 @@ class XendRoot:
   4.153          return v in ['yes', '1', 'on']
   4.154  
   4.155  def instance():
   4.156 +    """Get an instance of XendRoot.
   4.157 +    Use this instead of the constructor.
   4.158 +    """
   4.159      global inst
   4.160      try:
   4.161          inst
   4.162 @@ -221,10 +285,24 @@ def instance():
   4.163      return inst
   4.164  
   4.165  def logger():
   4.166 +    """Get the logger.
   4.167 +    """
   4.168      return instance().get_logger()
   4.169  
   4.170  def add_component(name, val):
   4.171 +    """Register a component with XendRoot.
   4.172 +    This is used to work-round import cycles.
   4.173 +
   4.174 +    @param name: component name
   4.175 +    @param val:  component value (often a module)
   4.176 +    """
   4.177      return instance().add_component(name, val)
   4.178  
   4.179  def get_component(name):
   4.180 +    """Get a component.
   4.181 +    This is used to work-round import cycles.
   4.182 +
   4.183 +    @param name: component name
   4.184 +    @return component or None
   4.185 +    """
   4.186      return instance().get_component(name)
     5.1 --- a/tools/python/xen/xend/server/SrvDaemon.py	Wed Sep 01 09:43:32 2004 +0000
     5.2 +++ b/tools/python/xen/xend/server/SrvDaemon.py	Thu Sep 02 09:34:07 2004 +0000
     5.3 @@ -334,7 +334,7 @@ class EventProtocol(protocol.Protocol):
     5.4          self.events = events
     5.5  
     5.6      def queue_event(self, name, v):
     5.7 -        # Despite the name we dont' queue the event here.
     5.8 +        # Despite the name we don't queue the event here.
     5.9          # We send it because the transport will queue it.
    5.10          self.send_event([name, v])
    5.11          
    5.12 @@ -397,11 +397,27 @@ class EventProtocol(protocol.Protocol):
    5.13          eserver.inject(sxp.name(event), event)
    5.14          return ['ok']
    5.15  
    5.16 -    def op_traceon(self, name, v):
    5.17 -        self.daemon.tracing(1)
    5.18 +    def op_trace(self, name, v):
    5.19 +        mode = (v[1] == 'on')
    5.20 +        self.daemon.tracing(mode)
    5.21  
    5.22 -    def op_traceoff(self, name, v):
    5.23 -        self.daemon.tracing(0)
    5.24 +    def op_log_stderr(self, name, v):
    5.25 +        mode = v[1]
    5.26 +        logging = XendRoot.instance().get_logging()
    5.27 +        if mode == 'on':
    5.28 +            logging.addLogStderr()
    5.29 +        else:
    5.30 +            logging.removeLogStderr()
    5.31 +
    5.32 +    def op_debug_msg(self, name, v):
    5.33 +        mode = v[1]
    5.34 +        import messages
    5.35 +        messages.DEBUG = (mode == 'on')
    5.36 +
    5.37 +    def op_debug_controller(self, name, v):
    5.38 +        mode = v[1]
    5.39 +        import controller
    5.40 +        controller.DEBUG = (mode == 'on')
    5.41  
    5.42  
    5.43  class EventFactory(protocol.Factory):
     6.1 --- a/tools/python/xen/xend/server/blkif.py	Wed Sep 01 09:43:32 2004 +0000
     6.2 +++ b/tools/python/xen/xend/server/blkif.py	Thu Sep 02 09:34:07 2004 +0000
     6.3 @@ -74,7 +74,6 @@ class BlkifBackendInterface(controller.B
     6.4  
     6.5      def respond_be_create(self, msg):
     6.6          val = unpackMsg('blkif_be_create_t', msg)
     6.7 -        print 'respond_be_create>', val
     6.8          self.connected = 1
     6.9          return self
    6.10      
    6.11 @@ -122,7 +121,6 @@ class BlkifBackendInterface(controller.B
    6.12          @type  msg: xu message
    6.13          """
    6.14          val = unpackMsg('blkif_be_connect_t', msg)
    6.15 -        print 'respond_be_connect>', str(self), val
    6.16          self.send_fe_interface_status_changed()
    6.17              
    6.18      def send_fe_interface_status_changed(self, response=None):
    6.19 @@ -401,7 +399,6 @@ class BlkifController(controller.SplitCo
    6.20  
    6.21      def recv_fe_driver_status_changed(self, msg, req):
    6.22          val = unpackMsg('blkif_fe_driver_status_changed_t', msg)
    6.23 -        print 'recv_fe_driver_status_changed>', val
    6.24          # For each backend?
    6.25          msg = packMsg('blkif_fe_interface_status_changed_t',
    6.26                        { 'handle' : 0,
     7.1 --- a/tools/python/xen/xend/server/controller.py	Wed Sep 01 09:43:32 2004 +0000
     7.2 +++ b/tools/python/xen/xend/server/controller.py	Thu Sep 02 09:34:07 2004 +0000
     7.3 @@ -9,7 +9,7 @@ from twisted.internet import defer
     7.4  import channel
     7.5  from messages import msgTypeName, printMsg
     7.6  
     7.7 -DEBUG = 1
     7.8 +DEBUG = 0
     7.9  
    7.10  class Responder:
    7.11      """Handler for a response to a message with a specified id.
     8.1 --- a/tools/python/xen/xend/server/netif.py	Wed Sep 01 09:43:32 2004 +0000
     8.2 +++ b/tools/python/xen/xend/server/netif.py	Thu Sep 02 09:34:07 2004 +0000
     8.3 @@ -191,7 +191,6 @@ class NetDev(controller.SplitDev):
     8.4              vnet.vifctl(op, self.get_vifname(), self.get_mac())
     8.5  
     8.6      def attach(self):
     8.7 -        print 'attach>'
     8.8          d = self.send_be_create()
     8.9          d.addCallback(self.respond_be_create)
    8.10          return d
    8.11 @@ -207,7 +206,6 @@ class NetDev(controller.SplitDev):
    8.12  
    8.13      def respond_be_create(self, msg):
    8.14          val = unpackMsg('netif_be_create_t', msg)
    8.15 -        print 'respond_be_create>', val
    8.16          return self
    8.17  
    8.18      def destroy(self):