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')
30 master = qa_config.GetMasterNode()
32 if node.get('_added', False):
33 raise qa_error.Error("Node %s already in cluster" % node['primary'])
35 cmd = ['gnt-node', 'add']
36 if node.get('secondary', None):
37 cmd.append('--secondary-ip=%s' % node['secondary'])
38 cmd.append(node['primary'])
39 AssertEqual(StartSSH(master['primary'],
40 utils.ShellQuoteArgs(cmd)).wait(), 0)
45 @qa_utils.DefineHook('node-remove')
46 def _NodeRemove(node):
47 master = qa_config.GetMasterNode()
49 cmd = ['gnt-node', 'remove', node['primary']]
50 AssertEqual(StartSSH(master['primary'],
51 utils.ShellQuoteArgs(cmd)).wait(), 0)
52 node['_added'] = False
56 """Adding all nodes to cluster."""
57 master = qa_config.GetMasterNode()
58 for node in qa_config.get('nodes'):
63 def TestNodeRemoveAll():
64 """Removing all nodes from cluster."""
65 master = qa_config.GetMasterNode()
66 for node in qa_config.get('nodes'):
71 @qa_utils.DefineHook('node-info')
74 master = qa_config.GetMasterNode()
76 cmd = ['gnt-node', 'info']
77 AssertEqual(StartSSH(master['primary'],
78 utils.ShellQuoteArgs(cmd)).wait(), 0)
81 @qa_utils.DefineHook('node-volumes')
82 def TestNodeVolumes():
83 """gnt-node volumes"""
84 master = qa_config.GetMasterNode()
86 cmd = ['gnt-node', 'volumes']
87 AssertEqual(StartSSH(master['primary'],
88 utils.ShellQuoteArgs(cmd)).wait(), 0)
91 @qa_utils.DefineHook('node-failover')
92 def TestNodeFailover(node, node2):
93 """gnt-node failover"""
94 master = qa_config.GetMasterNode()
96 if qa_utils.GetNodeInstances(node2, secondaries=False):
97 raise qa_error.UnusableNodeError("Secondary node has at least one "
98 "primary instance. This test requires "
99 "it to have no primary instances.")
101 # Fail over to secondary node
102 cmd = ['gnt-node', 'failover', '-f', node['primary']]
103 AssertEqual(StartSSH(master['primary'],
104 utils.ShellQuoteArgs(cmd)).wait(), 0)
106 # ... and back again.
107 cmd = ['gnt-node', 'failover', '-f', node2['primary']]
108 AssertEqual(StartSSH(master['primary'],
109 utils.ShellQuoteArgs(cmd)).wait(), 0)
112 @qa_utils.DefineHook('node-evacuate')
113 def TestNodeEvacuate(node, node2):
114 """gnt-node evacuate"""
115 master = qa_config.GetMasterNode()
117 node3 = qa_config.AcquireNode(exclude=[node, node2])
119 if qa_utils.GetNodeInstances(node3, secondaries=True):
120 raise qa_error.UnusableNodeError("Evacuation node has at least one "
121 "secondary instance. This test requires "
122 "it to have no secondary instances.")
124 # Evacuate all secondary instances
125 cmd = ['gnt-node', 'evacuate', '-f', node2['primary'], node3['primary']]
126 AssertEqual(StartSSH(master['primary'],
127 utils.ShellQuoteArgs(cmd)).wait(), 0)
129 # ... and back again.
130 cmd = ['gnt-node', 'evacuate', '-f', node3['primary'], node2['primary']]
131 AssertEqual(StartSSH(master['primary'],
132 utils.ShellQuoteArgs(cmd)).wait(), 0)
134 qa_config.ReleaseNode(node3)