Revision 82d2f3df

b/qa/qa_instance.py
82 82
    raise
83 83

  
84 84

  
85
def _DestroyInstanceVolumes(instance):
86
  """Remove all the LVM volumes of an instance.
87

  
88
  This is used to simulate HW errors (dead nodes, broken disks...); the
89
  configuration of the instance is not affected.
90

  
91
  """
92
  master = qa_config.GetMasterNode()
93
  infocmd = utils.ShellQuoteArgs(["gnt-instance", "info", instance["name"]])
94
  info_out = qa_utils.GetCommandOutput(master["primary"], infocmd)
95
  re_node = re.compile(r"^\s+-\s+(?:primary|secondaries):\s+(\S.+)$")
96
  node_elem = r"([^,()]+)(?:\s+\([^)]+\))?"
97
  # re_nodelist matches a list of nodes returned by gnt-instance info, e.g.:
98
  #  node1.fqdn
99
  #  node2.fqdn,node3.fqdn
100
  #  node4.fqdn (group mygroup, group UUID 01234567-abcd-0123-4567-0123456789ab)
101
  # FIXME This works with no more than 2 secondaries
102
  re_nodelist = re.compile(node_elem + "(?:," + node_elem + ")?$")
103
  re_vol = re.compile(r"^\s+logical_id:\s+(\S+)$")
104
  nodes = []
105
  vols = []
106
  for line in info_out.splitlines():
107
    m = re_node.match(line)
108
    if m:
109
      nodestr = m.group(1)
110
      m2 = re_nodelist.match(nodestr)
111
      if m2:
112
        nodes.extend(filter(None, m2.groups()))
113
      else:
114
        nodes.append(nodestr)
115
    m = re_vol.match(line)
116
    if m:
117
      vols.append(m.group(1))
118
  assert vols
119
  assert nodes
120
  for node in nodes:
121
    AssertCommand(["lvremove", "-f"] + vols, node=node)
122

  
123

  
85 124
@InstanceCheck(None, INST_UP, RETURN_VALUE)
86 125
def TestInstanceAddWithPlainDisk(node):
87 126
  """gnt-instance add -t plain"""

Also available in: Unified diff