Revision 06b78e8b

b/lib/hypervisor/hv_xen.py
25 25

  
26 26
import os
27 27
import os.path
28
import time
29 28
import logging
30 29
from cStringIO import StringIO
31 30

  
......
85 84
    utils.RemoveFile("/etc/xen/%s" % instance_name)
86 85

  
87 86
  @staticmethod
88
  def _GetXMList(include_node):
87
  def _RunXmList(xmlist_errors):
88
    """Helper function for L{_GetXMList} to run "xm list".
89

  
90
    """
91
    result = utils.RunCmd(["xm", "list"])
92
    if result.failed:
93
      logging.error("xm list failed (%s): %s", result.fail_reason,
94
                    result.output)
95
      xmlist_errors.append(result)
96
      raise utils.RetryAgain()
97

  
98
    # skip over the heading
99
    return result.stdout.splitlines()[1:]
100

  
101
  @classmethod
102
  def _GetXMList(cls, include_node):
89 103
    """Return the list of running instances.
90 104

  
91 105
    If the include_node argument is True, then we return information
......
94 108
    @return: list of (name, id, memory, vcpus, state, time spent)
95 109

  
96 110
    """
97
    for _ in range(5):
98
      result = utils.RunCmd(["xm", "list"])
99
      if not result.failed:
100
        break
101
      logging.error("xm list failed (%s): %s", result.fail_reason,
102
                    result.output)
103
      time.sleep(1)
111
    xmlist_errors = []
112
    try:
113
      lines = utils.Retry(cls._RunXmList, 1, 5, args=(xmlist_errors, ))
114
    except utils.RetryTimeout:
115
      if xmlist_errors:
116
        xmlist_result = xmlist_errors.pop()
104 117

  
105
    if result.failed:
106
      raise errors.HypervisorError("xm list failed, retries"
107
                                   " exceeded (%s): %s" %
108
                                   (result.fail_reason, result.output))
118
        errmsg = ("xm list failed, timeout exceeded (%s): %s" %
119
                  (xmlist_result.fail_reason, xmlist_result.output))
120
      else:
121
        errmsg = "xm list failed"
122

  
123
      raise errors.HypervisorError(errmsg)
109 124

  
110
    # skip over the heading
111
    lines = result.stdout.splitlines()[1:]
112 125
    result = []
113 126
    for line in lines:
114 127
      # The format of lines is:
......
199 212

  
200 213
    """
201 214
    ini_info = self.GetInstanceInfo(instance.name)
202
    result = utils.RunCmd(["xm", "reboot", instance.name])
203 215

  
216
    result = utils.RunCmd(["xm", "reboot", instance.name])
204 217
    if result.failed:
205 218
      raise errors.HypervisorError("Failed to reboot instance %s: %s, %s" %
206 219
                                   (instance.name, result.fail_reason,
207 220
                                    result.output))
208
    done = False
209
    retries = self.REBOOT_RETRY_COUNT
210
    while retries > 0:
221

  
222
    def _CheckInstance():
211 223
      new_info = self.GetInstanceInfo(instance.name)
212
      # check if the domain ID has changed or the run time has
213
      # decreased
224

  
225
      # check if the domain ID has changed or the run time has decreased
214 226
      if new_info[1] != ini_info[1] or new_info[5] < ini_info[5]:
215
        done = True
216
        break
217
      time.sleep(self.REBOOT_RETRY_INTERVAL)
218
      retries -= 1
227
        return
228

  
229
      raise utils.RetryAgain()
219 230

  
220
    if not done:
231
    try:
232
      utils.Retry(_CheckInstance, self.REBOOT_RETRY_INTERVAL,
233
                  self.REBOOT_RETRY_INTERVAL * self.REBOOT_RETRY_COUNT)
234
    except utils.RetryTimeout:
221 235
      raise errors.HypervisorError("Failed to reboot instance %s: instance"
222 236
                                   " did not reboot in the expected interval" %
223 237
                                   (instance.name, ))

Also available in: Unified diff