4 # Copyright (C) 2007 Google Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 from ganeti import utils
23 from ganeti import constants
29 from qa_utils import AssertCommand
32 def _NodeAdd(node, readd=False):
33 if not readd and node.get('_added', False):
34 raise qa_error.Error("Node %s already in cluster" % node['primary'])
35 elif readd and not node.get('_added', False):
36 raise qa_error.Error("Node %s not yet in cluster" % node['primary'])
38 cmd = ['gnt-node', 'add', "--no-ssh-key-check"]
39 if node.get('secondary', None):
40 cmd.append('--secondary-ip=%s' % node['secondary'])
43 cmd.append(node['primary'])
50 def _NodeRemove(node):
51 AssertCommand(["gnt-node", "remove", node["primary"]])
52 node['_added'] = False
56 """Adding all nodes to cluster."""
57 master = qa_config.GetMasterNode()
58 for node in qa_config.get('nodes'):
60 _NodeAdd(node, readd=False)
63 def MarkNodeAddedAll():
64 """Mark all nodes as added.
66 This is useful if we don't create the cluster ourselves (in qa).
69 master = qa_config.GetMasterNode()
70 for node in qa_config.get('nodes'):
75 def TestNodeRemoveAll():
76 """Removing all nodes from cluster."""
77 master = qa_config.GetMasterNode()
78 for node in qa_config.get('nodes'):
83 def TestNodeReadd(node):
84 """gnt-node add --readd"""
85 _NodeAdd(node, readd=True)
90 AssertCommand(["gnt-node", "info"])
93 def TestNodeVolumes():
94 """gnt-node volumes"""
95 AssertCommand(["gnt-node", "volumes"])
98 def TestNodeStorage():
99 """gnt-node storage"""
100 master = qa_config.GetMasterNode()
102 for storage_type in constants.VALID_STORAGE_TYPES:
104 AssertCommand(["gnt-node", "list-storage", "--storage-type", storage_type])
106 # Test all storage fields
107 cmd = ["gnt-node", "list-storage", "--storage-type", storage_type,
108 "--output=%s" % ",".join(list(constants.VALID_STORAGE_FIELDS) +
109 [constants.SF_NODE, constants.SF_TYPE])]
112 # Get list of valid storage devices
113 cmd = ["gnt-node", "list-storage", "--storage-type", storage_type,
114 "--output=node,name,allocatable", "--separator=|",
116 output = qa_utils.GetCommandOutput(master["primary"],
117 utils.ShellQuoteArgs(cmd))
119 # Test with up to two devices
122 for line in output.splitlines()[:testdevcount]:
123 (node_name, st_name, st_allocatable) = line.split("|")
125 # Dummy modification without any changes
126 cmd = ["gnt-node", "modify-storage", node_name, storage_type, st_name]
129 # Make sure we end up with the same value as before
130 if st_allocatable.lower() == "y":
131 test_allocatable = ["no", "yes"]
133 test_allocatable = ["yes", "no"]
135 fail = (constants.SF_ALLOCATABLE not in
136 constants.MODIFIABLE_STORAGE_FIELDS.get(storage_type, []))
138 for i in test_allocatable:
139 AssertCommand(["gnt-node", "modify-storage", "--allocatable", i,
140 node_name, storage_type, st_name], fail=fail)
142 # Test repair functionality
143 fail = (constants.SO_FIX_CONSISTENCY not in
144 constants.VALID_STORAGE_OPERATIONS.get(storage_type, []))
145 AssertCommand(["gnt-node", "repair-storage", node_name,
146 storage_type, st_name], fail=fail)
149 def TestNodeFailover(node, node2):
150 """gnt-node failover"""
151 if qa_utils.GetNodeInstances(node2, secondaries=False):
152 raise qa_error.UnusableNodeError("Secondary node has at least one"
153 " primary instance. This test requires"
154 " it to have no primary instances.")
156 # Fail over to secondary node
157 AssertCommand(["gnt-node", "failover", "-f", node["primary"]])
159 # ... and back again.
160 AssertCommand(["gnt-node", "failover", "-f", node2["primary"]])
163 def TestNodeEvacuate(node, node2):
164 """gnt-node evacuate"""
165 node3 = qa_config.AcquireNode(exclude=[node, node2])
167 if qa_utils.GetNodeInstances(node3, secondaries=True):
168 raise qa_error.UnusableNodeError("Evacuation node has at least one"
169 " secondary instance. This test requires"
170 " it to have no secondary instances.")
172 # Evacuate all secondary instances
173 AssertCommand(["gnt-node", "evacuate", "-f",
174 "--new-secondary=%s" % node3["primary"], node2["primary"]])
176 # ... and back again.
177 AssertCommand(["gnt-node", "evacuate", "-f",
178 "--new-secondary=%s" % node2["primary"], node3["primary"]])
180 qa_config.ReleaseNode(node3)
183 def TestNodeModify(node):
184 """gnt-node modify"""
185 for flag in ["master-candidate", "drained", "offline"]:
186 for value in ["yes", "no"]:
187 AssertCommand(["gnt-node", "modify", "--force",
188 "--%s=%s" % (flag, value), node["primary"]])
190 AssertCommand(["gnt-node", "modify", "--master-candidate=yes",
191 "--auto-promote", node["primary"]])