1 # Copyright (C) 2007 Google Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 from ganeti import utils
25 from qa_utils import AssertEqual, StartSSH
28 @qa_utils.DefineHook('node-add')
29 def _NodeAdd(node, readd=False):
30 master = qa_config.GetMasterNode()
32 if not readd and node.get('_added', False):
33 raise qa_error.Error("Node %s already in cluster" % node['primary'])
34 elif readd and not node.get('_added', False):
35 raise qa_error.Error("Node %s not yet in cluster" % node['primary'])
37 cmd = ['gnt-node', 'add']
38 if node.get('secondary', None):
39 cmd.append('--secondary-ip=%s' % node['secondary'])
42 cmd.append(node['primary'])
43 AssertEqual(StartSSH(master['primary'],
44 utils.ShellQuoteArgs(cmd)).wait(), 0)
49 @qa_utils.DefineHook('node-remove')
50 def _NodeRemove(node):
51 master = qa_config.GetMasterNode()
53 cmd = ['gnt-node', 'remove', node['primary']]
54 AssertEqual(StartSSH(master['primary'],
55 utils.ShellQuoteArgs(cmd)).wait(), 0)
56 node['_added'] = False
60 """Adding all nodes to cluster."""
61 master = qa_config.GetMasterNode()
62 for node in qa_config.get('nodes'):
64 _NodeAdd(node, readd=False)
67 def TestNodeRemoveAll():
68 """Removing all nodes from cluster."""
69 master = qa_config.GetMasterNode()
70 for node in qa_config.get('nodes'):
75 @qa_utils.DefineHook('node-readd')
76 def TestNodeReadd(node):
77 """gnt-node add --readd"""
78 _NodeAdd(node, readd=True)
81 @qa_utils.DefineHook('node-info')
84 master = qa_config.GetMasterNode()
86 cmd = ['gnt-node', 'info']
87 AssertEqual(StartSSH(master['primary'],
88 utils.ShellQuoteArgs(cmd)).wait(), 0)
91 @qa_utils.DefineHook('node-volumes')
92 def TestNodeVolumes():
93 """gnt-node volumes"""
94 master = qa_config.GetMasterNode()
96 cmd = ['gnt-node', 'volumes']
97 AssertEqual(StartSSH(master['primary'],
98 utils.ShellQuoteArgs(cmd)).wait(), 0)
101 @qa_utils.DefineHook('node-failover')
102 def TestNodeFailover(node, node2):
103 """gnt-node failover"""
104 master = qa_config.GetMasterNode()
106 if qa_utils.GetNodeInstances(node2, secondaries=False):
107 raise qa_error.UnusableNodeError("Secondary node has at least one"
108 " primary instance. This test requires"
109 " it to have no primary instances.")
111 # Fail over to secondary node
112 cmd = ['gnt-node', 'failover', '-f', node['primary']]
113 AssertEqual(StartSSH(master['primary'],
114 utils.ShellQuoteArgs(cmd)).wait(), 0)
116 # ... and back again.
117 cmd = ['gnt-node', 'failover', '-f', node2['primary']]
118 AssertEqual(StartSSH(master['primary'],
119 utils.ShellQuoteArgs(cmd)).wait(), 0)
122 @qa_utils.DefineHook('node-evacuate')
123 def TestNodeEvacuate(node, node2):
124 """gnt-node evacuate"""
125 master = qa_config.GetMasterNode()
127 node3 = qa_config.AcquireNode(exclude=[node, node2])
129 if qa_utils.GetNodeInstances(node3, secondaries=True):
130 raise qa_error.UnusableNodeError("Evacuation node has at least one"
131 " secondary instance. This test requires"
132 " it to have no secondary instances.")
134 # Evacuate all secondary instances
135 cmd = ['gnt-node', 'evacuate', '-f', node2['primary'], node3['primary']]
136 AssertEqual(StartSSH(master['primary'],
137 utils.ShellQuoteArgs(cmd)).wait(), 0)
139 # ... and back again.
140 cmd = ['gnt-node', 'evacuate', '-f', node3['primary'], node2['primary']]
141 AssertEqual(StartSSH(master['primary'],
142 utils.ShellQuoteArgs(cmd)).wait(), 0)
144 qa_config.ReleaseNode(node3)