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')
33 master = qa_config.GetMasterNode()
35 if node.get('_added', False):
36 raise qa_error.Error("Node %s already in cluster" % node['primary'])
38 cmd = ['gnt-node', 'add']
39 if node.get('secondary', None):
40 cmd.append('--secondary-ip=%s' % node['secondary'])
41 cmd.append(node['primary'])
42 AssertEqual(StartSSH(master['primary'],
43 utils.ShellQuoteArgs(cmd)).wait(), 0)
48 @qa_utils.DefineHook('node-remove')
49 def _NodeRemove(node):
50 master = qa_config.GetMasterNode()
52 cmd = ['gnt-node', 'remove', node['primary']]
53 AssertEqual(StartSSH(master['primary'],
54 utils.ShellQuoteArgs(cmd)).wait(), 0)
55 node['_added'] = False
59 """Adding all nodes to cluster."""
60 master = qa_config.GetMasterNode()
61 for node in qa_config.get('nodes'):
66 def TestNodeRemoveAll():
67 """Removing all nodes from cluster."""
68 master = qa_config.GetMasterNode()
69 for node in qa_config.get('nodes'):
74 @qa_utils.DefineHook('node-info')
77 master = qa_config.GetMasterNode()
79 cmd = ['gnt-node', 'info']
80 AssertEqual(StartSSH(master['primary'],
81 utils.ShellQuoteArgs(cmd)).wait(), 0)
84 @qa_utils.DefineHook('node-volumes')
85 def TestNodeVolumes():
86 """gnt-node volumes"""
87 master = qa_config.GetMasterNode()
89 cmd = ['gnt-node', 'volumes']
90 AssertEqual(StartSSH(master['primary'],
91 utils.ShellQuoteArgs(cmd)).wait(), 0)
94 @qa_utils.DefineHook('node-failover')
95 def TestNodeFailover(node, node2):
96 """gnt-node failover"""
97 master = qa_config.GetMasterNode()
99 if qa_utils.GetNodeInstances(node2, secondaries=False):
100 raise qa_error.UnusableNodeError("Secondary node has at least one"
101 " primary instance. This test requires"
102 " it to have no primary instances.")
104 # Fail over to secondary node
105 cmd = ['gnt-node', 'failover', '-f', node['primary']]
106 AssertEqual(StartSSH(master['primary'],
107 utils.ShellQuoteArgs(cmd)).wait(), 0)
109 # ... and back again.
110 cmd = ['gnt-node', 'failover', '-f', node2['primary']]
111 AssertEqual(StartSSH(master['primary'],
112 utils.ShellQuoteArgs(cmd)).wait(), 0)
115 @qa_utils.DefineHook('node-evacuate')
116 def TestNodeEvacuate(node, node2):
117 """gnt-node evacuate"""
118 master = qa_config.GetMasterNode()
120 node3 = qa_config.AcquireNode(exclude=[node, node2])
122 if qa_utils.GetNodeInstances(node3, secondaries=True):
123 raise qa_error.UnusableNodeError("Evacuation node has at least one"
124 " secondary instance. This test requires"
125 " it to have no secondary instances.")
127 # Evacuate all secondary instances
128 cmd = ['gnt-node', 'evacuate', '-f', node2['primary'], node3['primary']]
129 AssertEqual(StartSSH(master['primary'],
130 utils.ShellQuoteArgs(cmd)).wait(), 0)
132 # ... and back again.
133 cmd = ['gnt-node', 'evacuate', '-f', node3['primary'], node2['primary']]
134 AssertEqual(StartSSH(master['primary'],
135 utils.ShellQuoteArgs(cmd)).wait(), 0)
137 qa_config.ReleaseNode(node3)