Statistics
| Branch: | Tag: | Revision:

root / qa / qa_node.py @ 75cf411a

History | View | Annotate | Download (5.9 kB)

1 c68d1f43 Michael Hanselmann
#
2 c68d1f43 Michael Hanselmann
#
3 c68d1f43 Michael Hanselmann
4 cec9845c Michael Hanselmann
# Copyright (C) 2007 Google Inc.
5 cec9845c Michael Hanselmann
#
6 cec9845c Michael Hanselmann
# This program is free software; you can redistribute it and/or modify
7 cec9845c Michael Hanselmann
# it under the terms of the GNU General Public License as published by
8 cec9845c Michael Hanselmann
# the Free Software Foundation; either version 2 of the License, or
9 cec9845c Michael Hanselmann
# (at your option) any later version.
10 cec9845c Michael Hanselmann
#
11 cec9845c Michael Hanselmann
# This program is distributed in the hope that it will be useful, but
12 cec9845c Michael Hanselmann
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 cec9845c Michael Hanselmann
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 cec9845c Michael Hanselmann
# General Public License for more details.
15 cec9845c Michael Hanselmann
#
16 cec9845c Michael Hanselmann
# You should have received a copy of the GNU General Public License
17 cec9845c Michael Hanselmann
# along with this program; if not, write to the Free Software
18 cec9845c Michael Hanselmann
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 cec9845c Michael Hanselmann
# 02110-1301, USA.
20 cec9845c Michael Hanselmann
21 cec9845c Michael Hanselmann
22 cec9845c Michael Hanselmann
from ganeti import utils
23 8e1db003 Michael Hanselmann
from ganeti import constants
24 cec9845c Michael Hanselmann
25 cec9845c Michael Hanselmann
import qa_config
26 cec9845c Michael Hanselmann
import qa_error
27 4b62db14 Michael Hanselmann
import qa_utils
28 cec9845c Michael Hanselmann
29 2f4b4f78 Iustin Pop
from qa_utils import AssertCommand
30 cec9845c Michael Hanselmann
31 cec9845c Michael Hanselmann
32 e7c6e02b Michael Hanselmann
def _NodeAdd(node, readd=False):
33 e7c6e02b Michael Hanselmann
  if not readd and node.get('_added', False):
34 cec9845c Michael Hanselmann
    raise qa_error.Error("Node %s already in cluster" % node['primary'])
35 e7c6e02b Michael Hanselmann
  elif readd and not node.get('_added', False):
36 102b115b Michael Hanselmann
    raise qa_error.Error("Node %s not yet in cluster" % node['primary'])
37 cec9845c Michael Hanselmann
38 338180f5 René Nussbaumer
  cmd = ['gnt-node', 'add', "--no-ssh-key-check"]
39 cec9845c Michael Hanselmann
  if node.get('secondary', None):
40 cec9845c Michael Hanselmann
    cmd.append('--secondary-ip=%s' % node['secondary'])
41 e7c6e02b Michael Hanselmann
  if readd:
42 e7c6e02b Michael Hanselmann
    cmd.append('--readd')
43 cec9845c Michael Hanselmann
  cmd.append(node['primary'])
44 2f4b4f78 Iustin Pop
45 2f4b4f78 Iustin Pop
  AssertCommand(cmd)
46 cec9845c Michael Hanselmann
47 cec9845c Michael Hanselmann
  node['_added'] = True
48 cec9845c Michael Hanselmann
49 cec9845c Michael Hanselmann
50 cec9845c Michael Hanselmann
def _NodeRemove(node):
51 2f4b4f78 Iustin Pop
  AssertCommand(["gnt-node", "remove", node["primary"]])
52 cec9845c Michael Hanselmann
  node['_added'] = False
53 cec9845c Michael Hanselmann
54 cec9845c Michael Hanselmann
55 cec9845c Michael Hanselmann
def TestNodeAddAll():
56 cec9845c Michael Hanselmann
  """Adding all nodes to cluster."""
57 cec9845c Michael Hanselmann
  master = qa_config.GetMasterNode()
58 cec9845c Michael Hanselmann
  for node in qa_config.get('nodes'):
59 cec9845c Michael Hanselmann
    if node != master:
60 e7c6e02b Michael Hanselmann
      _NodeAdd(node, readd=False)
61 cec9845c Michael Hanselmann
62 cec9845c Michael Hanselmann
63 8e671b7c Iustin Pop
def MarkNodeAddedAll():
64 8e671b7c Iustin Pop
  """Mark all nodes as added.
65 8e671b7c Iustin Pop

66 8e671b7c Iustin Pop
  This is useful if we don't create the cluster ourselves (in qa).
67 8e671b7c Iustin Pop

68 8e671b7c Iustin Pop
  """
69 8e671b7c Iustin Pop
  master = qa_config.GetMasterNode()
70 8e671b7c Iustin Pop
  for node in qa_config.get('nodes'):
71 8e671b7c Iustin Pop
    if node != master:
72 8e671b7c Iustin Pop
      node['_added'] = True
73 8e671b7c Iustin Pop
74 8e671b7c Iustin Pop
75 cec9845c Michael Hanselmann
def TestNodeRemoveAll():
76 cec9845c Michael Hanselmann
  """Removing all nodes from cluster."""
77 cec9845c Michael Hanselmann
  master = qa_config.GetMasterNode()
78 cec9845c Michael Hanselmann
  for node in qa_config.get('nodes'):
79 cec9845c Michael Hanselmann
    if node != master:
80 cec9845c Michael Hanselmann
      _NodeRemove(node)
81 cec9845c Michael Hanselmann
82 cec9845c Michael Hanselmann
83 e7c6e02b Michael Hanselmann
def TestNodeReadd(node):
84 e7c6e02b Michael Hanselmann
  """gnt-node add --readd"""
85 e7c6e02b Michael Hanselmann
  _NodeAdd(node, readd=True)
86 e7c6e02b Michael Hanselmann
87 e7c6e02b Michael Hanselmann
88 cec9845c Michael Hanselmann
def TestNodeInfo():
89 cec9845c Michael Hanselmann
  """gnt-node info"""
90 2f4b4f78 Iustin Pop
  AssertCommand(["gnt-node", "info"])
91 cec9845c Michael Hanselmann
92 cec9845c Michael Hanselmann
93 cec9845c Michael Hanselmann
def TestNodeVolumes():
94 cec9845c Michael Hanselmann
  """gnt-node volumes"""
95 2f4b4f78 Iustin Pop
  AssertCommand(["gnt-node", "volumes"])
96 4b62db14 Michael Hanselmann
97 4b62db14 Michael Hanselmann
98 8e1db003 Michael Hanselmann
def TestNodeStorage():
99 8e1db003 Michael Hanselmann
  """gnt-node storage"""
100 8e1db003 Michael Hanselmann
  master = qa_config.GetMasterNode()
101 8e1db003 Michael Hanselmann
102 8e1db003 Michael Hanselmann
  for storage_type in constants.VALID_STORAGE_TYPES:
103 8e1db003 Michael Hanselmann
    # Test simple list
104 2f4b4f78 Iustin Pop
    AssertCommand(["gnt-node", "list-storage", "--storage-type", storage_type])
105 8e1db003 Michael Hanselmann
106 8e1db003 Michael Hanselmann
    # Test all storage fields
107 8e1db003 Michael Hanselmann
    cmd = ["gnt-node", "list-storage", "--storage-type", storage_type,
108 8e1db003 Michael Hanselmann
           "--output=%s" % ",".join(list(constants.VALID_STORAGE_FIELDS) +
109 8e1db003 Michael Hanselmann
                                    [constants.SF_NODE, constants.SF_TYPE])]
110 2f4b4f78 Iustin Pop
    AssertCommand(cmd)
111 8e1db003 Michael Hanselmann
112 8e1db003 Michael Hanselmann
    # Get list of valid storage devices
113 8e1db003 Michael Hanselmann
    cmd = ["gnt-node", "list-storage", "--storage-type", storage_type,
114 8e1db003 Michael Hanselmann
           "--output=node,name,allocatable", "--separator=|",
115 8e1db003 Michael Hanselmann
           "--no-headers"]
116 8e1db003 Michael Hanselmann
    output = qa_utils.GetCommandOutput(master["primary"],
117 8e1db003 Michael Hanselmann
                                       utils.ShellQuoteArgs(cmd))
118 8e1db003 Michael Hanselmann
119 8e1db003 Michael Hanselmann
    # Test with up to two devices
120 8e1db003 Michael Hanselmann
    testdevcount = 2
121 8e1db003 Michael Hanselmann
122 8e1db003 Michael Hanselmann
    for line in output.splitlines()[:testdevcount]:
123 8e1db003 Michael Hanselmann
      (node_name, st_name, st_allocatable) = line.split("|")
124 8e1db003 Michael Hanselmann
125 8e1db003 Michael Hanselmann
      # Dummy modification without any changes
126 8e1db003 Michael Hanselmann
      cmd = ["gnt-node", "modify-storage", node_name, storage_type, st_name]
127 2f4b4f78 Iustin Pop
      AssertCommand(cmd)
128 8e1db003 Michael Hanselmann
129 8e1db003 Michael Hanselmann
      # Make sure we end up with the same value as before
130 8e1db003 Michael Hanselmann
      if st_allocatable.lower() == "y":
131 8e1db003 Michael Hanselmann
        test_allocatable = ["no", "yes"]
132 8e1db003 Michael Hanselmann
      else:
133 8e1db003 Michael Hanselmann
        test_allocatable = ["yes", "no"]
134 8e1db003 Michael Hanselmann
135 2f4b4f78 Iustin Pop
      fail = (constants.SF_ALLOCATABLE not in
136 2f4b4f78 Iustin Pop
              constants.MODIFIABLE_STORAGE_FIELDS.get(storage_type, []))
137 8e1db003 Michael Hanselmann
138 8e1db003 Michael Hanselmann
      for i in test_allocatable:
139 2f4b4f78 Iustin Pop
        AssertCommand(["gnt-node", "modify-storage", "--allocatable", i,
140 2f4b4f78 Iustin Pop
                       node_name, storage_type, st_name], fail=fail)
141 8e1db003 Michael Hanselmann
142 8e1db003 Michael Hanselmann
      # Test repair functionality
143 2f4b4f78 Iustin Pop
      fail = (constants.SO_FIX_CONSISTENCY not in
144 2f4b4f78 Iustin Pop
              constants.VALID_STORAGE_OPERATIONS.get(storage_type, []))
145 2f4b4f78 Iustin Pop
      AssertCommand(["gnt-node", "repair-storage", node_name,
146 2f4b4f78 Iustin Pop
                     storage_type, st_name], fail=fail)
147 8e1db003 Michael Hanselmann
148 8e1db003 Michael Hanselmann
149 4b62db14 Michael Hanselmann
def TestNodeFailover(node, node2):
150 4b62db14 Michael Hanselmann
  """gnt-node failover"""
151 d7e49c13 Michael Hanselmann
  if qa_utils.GetNodeInstances(node2, secondaries=False):
152 f4bc1f2c Michael Hanselmann
    raise qa_error.UnusableNodeError("Secondary node has at least one"
153 f4bc1f2c Michael Hanselmann
                                     " primary instance. This test requires"
154 f4bc1f2c Michael Hanselmann
                                     " it to have no primary instances.")
155 4b62db14 Michael Hanselmann
156 4b62db14 Michael Hanselmann
  # Fail over to secondary node
157 2f4b4f78 Iustin Pop
  AssertCommand(["gnt-node", "failover", "-f", node["primary"]])
158 4b62db14 Michael Hanselmann
159 4b62db14 Michael Hanselmann
  # ... and back again.
160 2f4b4f78 Iustin Pop
  AssertCommand(["gnt-node", "failover", "-f", node2["primary"]])
161 4b62db14 Michael Hanselmann
162 4b62db14 Michael Hanselmann
163 4b62db14 Michael Hanselmann
def TestNodeEvacuate(node, node2):
164 4b62db14 Michael Hanselmann
  """gnt-node evacuate"""
165 4b62db14 Michael Hanselmann
  node3 = qa_config.AcquireNode(exclude=[node, node2])
166 4b62db14 Michael Hanselmann
  try:
167 d7e49c13 Michael Hanselmann
    if qa_utils.GetNodeInstances(node3, secondaries=True):
168 f4bc1f2c Michael Hanselmann
      raise qa_error.UnusableNodeError("Evacuation node has at least one"
169 f4bc1f2c Michael Hanselmann
                                       " secondary instance. This test requires"
170 f4bc1f2c Michael Hanselmann
                                       " it to have no secondary instances.")
171 4b62db14 Michael Hanselmann
172 4b62db14 Michael Hanselmann
    # Evacuate all secondary instances
173 2f4b4f78 Iustin Pop
    AssertCommand(["gnt-node", "evacuate", "-f",
174 2f4b4f78 Iustin Pop
                   "--new-secondary=%s" % node3["primary"], node2["primary"]])
175 4b62db14 Michael Hanselmann
176 4b62db14 Michael Hanselmann
    # ... and back again.
177 2f4b4f78 Iustin Pop
    AssertCommand(["gnt-node", "evacuate", "-f",
178 2f4b4f78 Iustin Pop
                   "--new-secondary=%s" % node2["primary"], node3["primary"]])
179 4b62db14 Michael Hanselmann
  finally:
180 4b62db14 Michael Hanselmann
    qa_config.ReleaseNode(node3)
181 d0cb68cb Michael Hanselmann
182 d0cb68cb Michael Hanselmann
183 d0cb68cb Michael Hanselmann
def TestNodeModify(node):
184 d0cb68cb Michael Hanselmann
  """gnt-node modify"""
185 d0cb68cb Michael Hanselmann
  for flag in ["master-candidate", "drained", "offline"]:
186 d0cb68cb Michael Hanselmann
    for value in ["yes", "no"]:
187 2f4b4f78 Iustin Pop
      AssertCommand(["gnt-node", "modify", "--force",
188 2f4b4f78 Iustin Pop
                     "--%s=%s" % (flag, value), node["primary"]])
189 2f4b4f78 Iustin Pop
190 2f4b4f78 Iustin Pop
  AssertCommand(["gnt-node", "modify", "--master-candidate=yes",
191 2f4b4f78 Iustin Pop
                 "--auto-promote", node["primary"]])