qa_node.py 4.48 KB
Newer Older
1 2 3
#
#

4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
# Copyright (C) 2007 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.


from ganeti import utils

import qa_config
import qa_error
26
import qa_utils
27 28 29 30

from qa_utils import AssertEqual, StartSSH


Michael Hanselmann's avatar
Michael Hanselmann committed
31
@qa_utils.DefineHook('node-add')
32
def _NodeAdd(node, readd=False):
33 34
  master = qa_config.GetMasterNode()

35
  if not readd and node.get('_added', False):
36
    raise qa_error.Error("Node %s already in cluster" % node['primary'])
37 38
  elif readd and not node.get('_added', False):
    raise qa_error.Error("Node not yet %s in cluster" % node['primary'])
39 40 41 42

  cmd = ['gnt-node', 'add']
  if node.get('secondary', None):
    cmd.append('--secondary-ip=%s' % node['secondary'])
43 44
  if readd:
    cmd.append('--readd')
45 46 47 48 49 50 51
  cmd.append(node['primary'])
  AssertEqual(StartSSH(master['primary'],
                       utils.ShellQuoteArgs(cmd)).wait(), 0)

  node['_added'] = True


Michael Hanselmann's avatar
Michael Hanselmann committed
52
@qa_utils.DefineHook('node-remove')
53 54 55 56 57 58 59 60 61 62 63 64 65 66
def _NodeRemove(node):
  master = qa_config.GetMasterNode()

  cmd = ['gnt-node', 'remove', node['primary']]
  AssertEqual(StartSSH(master['primary'],
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
  node['_added'] = False


def TestNodeAddAll():
  """Adding all nodes to cluster."""
  master = qa_config.GetMasterNode()
  for node in qa_config.get('nodes'):
    if node != master:
67
      _NodeAdd(node, readd=False)
68 69 70 71 72 73 74 75 76 77


def TestNodeRemoveAll():
  """Removing all nodes from cluster."""
  master = qa_config.GetMasterNode()
  for node in qa_config.get('nodes'):
    if node != master:
      _NodeRemove(node)


78 79 80 81 82 83
@qa_utils.DefineHook('node-readd')
def TestNodeReadd(node):
  """gnt-node add --readd"""
  _NodeAdd(node, readd=True)


Michael Hanselmann's avatar
Michael Hanselmann committed
84
@qa_utils.DefineHook('node-info')
85 86 87 88 89 90 91 92 93
def TestNodeInfo():
  """gnt-node info"""
  master = qa_config.GetMasterNode()

  cmd = ['gnt-node', 'info']
  AssertEqual(StartSSH(master['primary'],
                       utils.ShellQuoteArgs(cmd)).wait(), 0)


Michael Hanselmann's avatar
Michael Hanselmann committed
94
@qa_utils.DefineHook('node-volumes')
95 96 97 98 99 100 101
def TestNodeVolumes():
  """gnt-node volumes"""
  master = qa_config.GetMasterNode()

  cmd = ['gnt-node', 'volumes']
  AssertEqual(StartSSH(master['primary'],
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
102 103


Michael Hanselmann's avatar
Michael Hanselmann committed
104
@qa_utils.DefineHook('node-failover')
105 106 107 108
def TestNodeFailover(node, node2):
  """gnt-node failover"""
  master = qa_config.GetMasterNode()

109
  if qa_utils.GetNodeInstances(node2, secondaries=False):
110 111 112
    raise qa_error.UnusableNodeError("Secondary node has at least one"
                                     " primary instance. This test requires"
                                     " it to have no primary instances.")
113 114 115 116 117 118 119 120 121 122 123 124

  # Fail over to secondary node
  cmd = ['gnt-node', 'failover', '-f', node['primary']]
  AssertEqual(StartSSH(master['primary'],
                       utils.ShellQuoteArgs(cmd)).wait(), 0)

  # ... and back again.
  cmd = ['gnt-node', 'failover', '-f', node2['primary']]
  AssertEqual(StartSSH(master['primary'],
                       utils.ShellQuoteArgs(cmd)).wait(), 0)


Michael Hanselmann's avatar
Michael Hanselmann committed
125
@qa_utils.DefineHook('node-evacuate')
126 127 128 129 130 131
def TestNodeEvacuate(node, node2):
  """gnt-node evacuate"""
  master = qa_config.GetMasterNode()

  node3 = qa_config.AcquireNode(exclude=[node, node2])
  try:
132
    if qa_utils.GetNodeInstances(node3, secondaries=True):
133 134 135
      raise qa_error.UnusableNodeError("Evacuation node has at least one"
                                       " secondary instance. This test requires"
                                       " it to have no secondary instances.")
136 137 138 139 140 141 142 143 144 145 146 147

    # Evacuate all secondary instances
    cmd = ['gnt-node', 'evacuate', '-f', node2['primary'], node3['primary']]
    AssertEqual(StartSSH(master['primary'],
                         utils.ShellQuoteArgs(cmd)).wait(), 0)

    # ... and back again.
    cmd = ['gnt-node', 'evacuate', '-f', node3['primary'], node2['primary']]
    AssertEqual(StartSSH(master['primary'],
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
  finally:
    qa_config.ReleaseNode(node3)