Revision f41dc024 qa/qa_instance.py

b/qa/qa_instance.py
67 67
  return params
68 68

  
69 69

  
70
def _DiskTest(node, disk_template, fail=False):
70
def _CreateInstanceByDiskTemplateRaw(nodes_spec, disk_template, fail=False):
71
  """Creates an instance with the given disk template on the given nodes(s).
72
     Note that this function does not check if enough nodes are given for
73
     the respective disk template.
74

  
75
  @type nodes_spec: string
76
  @param nodes_spec: string specification of one node (by node name) or several
77
                     nodes according to the requirements of the disk template
78
  @type disk_template: string
79
  @param disk_template: the disk template to be used by the instance
80
  @return: the created instance
81

  
82
  """
71 83
  instance = qa_config.AcquireInstance()
72 84
  try:
73 85
    cmd = (["gnt-instance", "add",
74 86
            "--os-type=%s" % qa_config.get("os"),
75 87
            "--disk-template=%s" % disk_template,
76
            "--node=%s" % node] +
88
            "--node=%s" % nodes_spec] +
77 89
           _GetGenericAddParameters(instance, disk_template))
78 90
    cmd.append(instance.name)
79 91

  
......
94 106
  return None
95 107

  
96 108

  
109
def _CreateInstanceByDiskTemplateOneNode(nodes, disk_template, fail=False):
110
  """Creates an instance using the given disk template for disk templates
111
     for which one given node is sufficient. These templates are for example:
112
     plain, diskless, file, sharedfile, blockdev, rados.
113

  
114
  @type nodes: list of nodes
115
  @param nodes: a list of nodes, whose first element is used to create the
116
                instance
117
  @type disk_template: string
118
  @param disk_template: the disk template to be used by the instance
119
  @return: the created instance
120

  
121
  """
122
  assert len(nodes) > 0
123
  return _CreateInstanceByDiskTemplateRaw(nodes[0].primary, disk_template,
124
                                          fail=fail)
125

  
126

  
127
def _CreateInstanceDrbd8(nodes, fail=False):
128
  """Creates an instance using disk template 'drbd' on the given nodes.
129

  
130
  @type nodes: list of nodes
131
  @param nodes: nodes to be used by the instance
132
  @return: the created instance
133

  
134
  """
135
  assert len(nodes) > 1
136
  return _CreateInstanceByDiskTemplateRaw(
137
    ":".join(map(operator.attrgetter("primary"), nodes)),
138
    constants.DT_DRBD8, fail=fail)
139

  
140

  
141
def CreateInstanceByDiskTemplate(nodes, disk_template, fail=False):
142
  """Given a disk template, this function creates an instance using
143
     the template. It uses the required number of nodes depending on
144
     the disk template. This function is intended to be used by tests
145
     that don't care about the specifics of the instance other than
146
     that it uses the given disk template.
147

  
148
     Note: If you use this function, make sure to call
149
     'TestInstanceRemove' at the end of your tests to avoid orphaned
150
     instances hanging around and interfering with the following tests.
151

  
152
  @type nodes: list of nodes
153
  @param nodes: the list of the nodes on which the instance will be placed;
154
                it needs to have sufficiently many elements for the given
155
                disk template
156
  @type disk_template: string
157
  @param disk_template: the disk template to be used by the instance
158
  @return: the created instance
159

  
160
  """
161
  if disk_template == constants.DT_DRBD8:
162
    return _CreateInstanceDrbd8(nodes, fail=fail)
163
  elif disk_template in [constants.DT_DISKLESS, constants.DT_PLAIN]:
164
    return _CreateInstanceByDiskTemplateOneNode(nodes, disk_template, fail=fail)
165
  else:
166
    #FIXME: Implement this for the remaining disk templates
167
    qa_error.Error("Instance creation not implemented for disk type '%s'." %
168
                   disk_template)
169

  
170

  
97 171
def _GetInstanceInfo(instance):
98 172
  """Return information about the actual state of an instance.
99 173

  
......
295 369

  
296 370
def TestInstanceAddWithPlainDisk(nodes, fail=False):
297 371
  """gnt-instance add -t plain"""
298
  assert len(nodes) == 1
299
  instance = _DiskTest(nodes[0].primary, constants.DT_PLAIN, fail=fail)
300
  if not fail:
301
    qa_utils.RunInstanceCheck(instance, True)
302
  return instance
372
  if constants.DT_PLAIN in qa_config.GetEnabledDiskTemplates():
373
    instance = _CreateInstanceByDiskTemplateOneNode(nodes, constants.DT_PLAIN,
374
                                                    fail=fail)
375
    if not fail:
376
      qa_utils.RunInstanceCheck(instance, True)
377
    return instance
303 378

  
304 379

  
305 380
@InstanceCheck(None, INST_UP, RETURN_VALUE)
306 381
def TestInstanceAddWithDrbdDisk(nodes):
307 382
  """gnt-instance add -t drbd"""
308
  assert len(nodes) == 2
309
  return _DiskTest(":".join(map(operator.attrgetter("primary"), nodes)),
310
                   constants.DT_DRBD8)
383
  if constants.DT_DRBD8 in qa_config.GetEnabledDiskTemplates():
384
    return _CreateInstanceDrbd8(nodes)
311 385

  
312 386

  
313 387
@InstanceCheck(None, INST_UP, RETURN_VALUE)
314 388
def TestInstanceAddFile(nodes):
315 389
  """gnt-instance add -t file"""
316 390
  assert len(nodes) == 1
317
  return _DiskTest(nodes[0].primary, constants.DT_FILE)
391
  if constants.DT_FILE in qa_config.GetEnabledDiskTemplates():
392
    return _CreateInstanceByDiskTemplateOneNode(nodes, constants.DT_FILE)
318 393

  
319 394

  
320 395
@InstanceCheck(None, INST_UP, RETURN_VALUE)
321 396
def TestInstanceAddDiskless(nodes):
322 397
  """gnt-instance add -t diskless"""
323 398
  assert len(nodes) == 1
324
  return _DiskTest(nodes[0].primary, constants.DT_DISKLESS)
399
  if constants.DT_FILE in qa_config.GetEnabledDiskTemplates():
400
    return _CreateInstanceByDiskTemplateOneNode(nodes, constants.DT_DISKLESS)
325 401

  
326 402

  
327 403
@InstanceCheck(None, INST_DOWN, FIRST_ARG)

Also available in: Unified diff