Revision 5dc626fd

b/tools/burnin
28 28
import optparse
29 29
import time
30 30
import socket
31
import urllib2
31
import urllib
32 32
import errno
33 33
from itertools import izip, islice, cycle
34 34
from cStringIO import StringIO
......
77 77
  sys.stderr.flush()
78 78
  sys.exit(exit_code)
79 79

  
80

  
81
class SimpleOpener(urllib.FancyURLopener):
82
  """A simple url opener"""
83

  
84
  def prompt_user_passwd(self, host, realm, clear_cache = 0):
85
    """No-interaction version of prompt_user_passwd."""
86
    return None, None
87

  
88
  def http_error_default(self, url, fp, errcode, errmsg, headers):
89
    """Custom error handling"""
90
    # make sure sockets are not left in CLOSE_WAIT, this is similar
91
    # but with a different exception to the BasicURLOpener class
92
    _ = fp.read() # throw away data
93
    fp.close()
94
    raise InstanceDown("HTTP error returned: code %s, msg %s" %
95
                       (errcode, errmsg))
96

  
97

  
80 98
class Burner(object):
81 99
  """Burner class."""
82 100

  
83 101
  def __init__(self):
84 102
    """Constructor."""
85 103
    utils.SetupLogging(constants.LOG_BURNIN, debug=False, stderr_logging=True)
104
    self.url_opener = SimpleOpener()
86 105
    self._feed_buf = StringIO()
87 106
    self.nodes = []
88 107
    self.instances = []
......
646 665
    """
647 666
    if not self.opts.http_check:
648 667
      return
649
    try:
650
      for retries in range(self.opts.net_timeout):
651
        try:
652
          url = urllib2.urlopen("http://%s/hostname.txt" % instance)
653
        except urllib2.URLError, err:
654
          if err.args[0][0] == errno.ECONNREFUSED:
655
            time.sleep(1)
656
            continue
657
          raise
658
    except urllib2.URLError, err:
659
      raise InstanceDown(instance, str(err))
668
    end_time = time.time() + self.opts.net_timeout
669
    url = None
670
    while time.time() < end_time and url is None:
671
      try:
672
        url = self.url_opener.open("http://%s/hostname.txt" % instance)
673
      except IOError, err:
674
        # here we can have connection refused, no route to host, etc.
675
        time.sleep(1)
676
    if url is None:
677
      raise InstanceDown(instance, "Cannot contact instance")
660 678
    hostname = url.read().strip()
679
    url.close()
661 680
    if hostname != instance:
662 681
      raise InstanceDown(instance, ("Hostname mismatch, expected %s, got %s" %
663 682
                                    (instance, hostname)))

Also available in: Unified diff