Revision fbab1c76

b/qa/qa_job_utils.py
30 30
from ganeti import constants
31 31
from ganeti import locking
32 32
from ganeti import utils
33
from ganeti.utils import retry
33 34

  
34 35
import qa_config
35 36
import qa_error
......
74 75
  return int(possible_job_ids[0])
75 76

  
76 77

  
78
def _RetrieveTerminationInfo(job_id):
79
  """ Retrieves the termination info from a job caused by gnt-debug delay.
80

  
81
  @rtype: dict or None
82
  @return: The termination log entry, or None if no entry was found
83

  
84
  """
85
  job_info = GetObjectInfo(["gnt-job", "info", str(job_id)])
86

  
87
  opcodes = job_info[0]["Opcodes"]
88
  if not opcodes:
89
    raise qa_error.Error("Cannot retrieve a list of opcodes")
90

  
91
  execution_logs = opcodes[0]["Execution log"]
92
  if not execution_logs:
93
    return None
94

  
95
  is_termination_info_fn = \
96
    lambda e: e["Content"][1] == constants.ELOG_DELAY_TEST
97

  
98
  filtered_logs = filter(is_termination_info_fn, execution_logs)
99

  
100
  no_logs = len(filtered_logs)
101
  if no_logs > 1:
102
    raise qa_error.Error("Too many interruption information entries found!")
103
  elif no_logs == 1:
104
    return filtered_logs[0]
105
  else:
106
    return None
107

  
108

  
77 109
def _StartDelayFunction(locks, timeout):
78 110
  """ Starts the gnt-debug delay option with the given locks and timeout.
79 111

  
......
83 115

  
84 116
  for node in locks.get(locking.LEVEL_NODE, []):
85 117
    cmd.append("-n%s" % node)
86

  
87 118
  cmd.append(str(timeout))
88 119

  
89 120
  job_id = ExecuteJobProducingCommand(cmd)
90
  job_info = GetObjectInfo(["gnt-job", "info", str(job_id)])
91
  execution_logs = job_info[0]["Opcodes"][0]["Execution log"]
92 121

  
93
  is_termination_info_fn = \
94
    lambda e: e["Content"][1] == constants.ELOG_DELAY_TEST
95
  filtered_logs = filter(is_termination_info_fn, execution_logs)
122
  # Waits until a non-empty result is returned from the function
123
  log_entry = retry.SimpleRetry(lambda x: x, _RetrieveTerminationInfo, 2.0,
124
                                10.0, args=[job_id])
96 125

  
97
  if len(filtered_logs) != 1:
126
  if not log_entry:
98 127
    raise qa_error.Error("Failure when trying to retrieve delay termination "
99 128
                         "information")
100 129

  
101
  _, _, (socket_path, ) = filtered_logs[0]["Content"]
130
  _, _, (socket_path, ) = log_entry["Content"]
102 131

  
103 132
  return socket_path
104 133

  

Also available in: Unified diff