Revision ab4832d1 qa/qa_instance.py

b/qa/qa_instance.py
153 153
    AssertCommand(["lvremove", "-f"] + vols, node=node)
154 154

  
155 155

  
156
def _GetBoolInstanceField(instance, field):
157
  """Get the Boolean value of a field of an instance.
156
def _GetInstanceField(instance, field):
157
  """Get the value of a field of an instance.
158 158

  
159 159
  @type instance: string
160 160
  @param instance: Instance name
161 161
  @type field: string
162 162
  @param field: Name of the field
163
  @rtype: string
163 164

  
164 165
  """
165 166
  master = qa_config.GetMasterNode()
166 167
  infocmd = utils.ShellQuoteArgs(["gnt-instance", "list", "--no-headers",
167
                                  "-o", field, instance])
168
  info_out = qa_utils.GetCommandOutput(master["primary"], infocmd).strip()
168
                                  "--units", "m", "-o", field, instance])
169
  return qa_utils.GetCommandOutput(master["primary"], infocmd).strip()
170

  
171

  
172
def _GetBoolInstanceField(instance, field):
173
  """Get the Boolean value of a field of an instance.
174

  
175
  @type instance: string
176
  @param instance: Instance name
177
  @type field: string
178
  @param field: Name of the field
179
  @rtype: bool
180

  
181
  """
182
  info_out = _GetInstanceField(instance, field)
169 183
  if info_out == "Y":
170 184
    return True
171 185
  elif info_out == "N":
......
175 189
                         " %s" % (field, instance, info_out))
176 190

  
177 191

  
192
def _GetNumInstanceField(instance, field):
193
  """Get a numeric value of a field of an instance.
194

  
195
  @type instance: string
196
  @param instance: Instance name
197
  @type field: string
198
  @param field: Name of the field
199
  @rtype: int or float
200

  
201
  """
202
  info_out = _GetInstanceField(instance, field)
203
  try:
204
    ret = int(info_out)
205
  except ValueError:
206
    try:
207
      ret = float(info_out)
208
    except ValueError:
209
      raise qa_error.Error("Field %s of instance %s has a non-numeric value:"
210
                           " %s" % (field, instance, info_out))
211
  return ret
212

  
213

  
214
def GetInstanceSpec(instance, spec):
215
  """Return the current spec for the given parameter.
216

  
217
  @type instance: string
218
  @param instance: Instance name
219
  @type spec: string
220
  @param spec: one of the supported parameters: "mem-size", "cpu-count",
221
      "disk-count", "disk-size", "nic-count"
222
  @rtype: tuple
223
  @return: (minspec, maxspec); minspec and maxspec can be different only for
224
      memory and disk size
225

  
226
  """
227
  specmap = {
228
    "mem-size": ["be/minmem", "be/maxmem"],
229
    "cpu-count": ["vcpus"],
230
    "disk-count": ["disk.count"],
231
    "disk-size": ["disk.size/ "],
232
    "nic-count": ["nic.count"],
233
    }
234
  # For disks, first we need the number of disks
235
  if spec == "disk-size":
236
    (numdisk, _) = GetInstanceSpec(instance, "disk-count")
237
    fields = ["disk.size/%s" % k for k in range(0, numdisk)]
238
  else:
239
    assert spec in specmap, "%s not in %s" % (spec, specmap)
240
    fields = specmap[spec]
241
  values = [_GetNumInstanceField(instance, f) for f in fields]
242
  return (min(values), max(values))
243

  
244

  
178 245
def IsFailoverSupported(instance):
179 246
  templ = qa_config.GetInstanceTemplate(instance)
180 247
  return templ in constants.DTS_MIRRORED

Also available in: Unified diff