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
28 from qa_utils import AssertEqual, StartSSH
31 @qa_utils.DefineHook('node-add')
32 def _NodeAdd(node, readd=False):
33 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 elif readd and not node.get('_added', False):
38 raise qa_error.Error("Node not yet %s in cluster" % node['primary'])
40 cmd = ['gnt-node', 'add']
41 if node.get('secondary', None):
42 cmd.append('--secondary-ip=%s' % node['secondary'])
45 cmd.append(node['primary'])
46 AssertEqual(StartSSH(master['primary'],
47 utils.ShellQuoteArgs(cmd)).wait(), 0)
52 @qa_utils.DefineHook('node-remove')
53 def _NodeRemove(node):
54 master = qa_config.GetMasterNode()
56 cmd = ['gnt-node', 'remove', node['primary']]
57 AssertEqual(StartSSH(master['primary'],
58 utils.ShellQuoteArgs(cmd)).wait(), 0)
59 node['_added'] = False
63 """Adding all nodes to cluster."""
64 master = qa_config.GetMasterNode()
65 for node in qa_config.get('nodes'):
67 _NodeAdd(node, readd=False)
70 def TestNodeRemoveAll():
71 """Removing all nodes from cluster."""
72 master = qa_config.GetMasterNode()
73 for node in qa_config.get('nodes'):
78 @qa_utils.DefineHook('node-readd')
79 def TestNodeReadd(node):
80 """gnt-node add --readd"""
81 _NodeAdd(node, readd=True)
84 @qa_utils.DefineHook('node-info')
87 master = qa_config.GetMasterNode()
89 cmd = ['gnt-node', 'info']
90 AssertEqual(StartSSH(master['primary'],
91 utils.ShellQuoteArgs(cmd)).wait(), 0)
94 @qa_utils.DefineHook('node-volumes')
95 def TestNodeVolumes():
96 """gnt-node volumes"""
97 master = qa_config.GetMasterNode()
99 cmd = ['gnt-node', 'volumes']
100 AssertEqual(StartSSH(master['primary'],
101 utils.ShellQuoteArgs(cmd)).wait(), 0)
104 @qa_utils.DefineHook('node-failover')
105 def TestNodeFailover(node, node2):
106 """gnt-node failover"""
107 master = qa_config.GetMasterNode()
109 if qa_utils.GetNodeInstances(node2, secondaries=False):
110 raise qa_error.UnusableNodeError("Secondary node has at least one"
111 " primary instance. This test requires"
112 " it to have no primary instances.")
114 # Fail over to secondary node
115 cmd = ['gnt-node', 'failover', '-f', node['primary']]
116 AssertEqual(StartSSH(master['primary'],
117 utils.ShellQuoteArgs(cmd)).wait(), 0)
119 # ... and back again.
120 cmd = ['gnt-node', 'failover', '-f', node2['primary']]
121 AssertEqual(StartSSH(master['primary'],
122 utils.ShellQuoteArgs(cmd)).wait(), 0)
125 @qa_utils.DefineHook('node-evacuate')
126 def TestNodeEvacuate(node, node2):
127 """gnt-node evacuate"""
128 master = qa_config.GetMasterNode()
130 node3 = qa_config.AcquireNode(exclude=[node, node2])
132 if qa_utils.GetNodeInstances(node3, secondaries=True):
133 raise qa_error.UnusableNodeError("Evacuation node has at least one"
134 " secondary instance. This test requires"
135 " it to have no secondary instances.")
137 # Evacuate all secondary instances
138 cmd = ['gnt-node', 'evacuate', '-f', node2['primary'], node3['primary']]
139 AssertEqual(StartSSH(master['primary'],
140 utils.ShellQuoteArgs(cmd)).wait(), 0)
142 # ... and back again.
143 cmd = ['gnt-node', 'evacuate', '-f', node3['primary'], node2['primary']]
144 AssertEqual(StartSSH(master['primary'],
145 utils.ShellQuoteArgs(cmd)).wait(), 0)
147 qa_config.ReleaseNode(node3)