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
29 master = qa_config.GetMasterNode()
31 if node.get('_added', False):
32 raise qa_error.Error("Node %s already in cluster" % node['primary'])
34 cmd = ['gnt-node', 'add']
35 if node.get('secondary', None):
36 cmd.append('--secondary-ip=%s' % node['secondary'])
37 cmd.append(node['primary'])
38 AssertEqual(StartSSH(master['primary'],
39 utils.ShellQuoteArgs(cmd)).wait(), 0)
44 def _NodeRemove(node):
45 master = qa_config.GetMasterNode()
47 cmd = ['gnt-node', 'remove', node['primary']]
48 AssertEqual(StartSSH(master['primary'],
49 utils.ShellQuoteArgs(cmd)).wait(), 0)
50 node['_added'] = False
54 """Adding all nodes to cluster."""
55 master = qa_config.GetMasterNode()
56 for node in qa_config.get('nodes'):
61 def TestNodeRemoveAll():
62 """Removing all nodes from cluster."""
63 master = qa_config.GetMasterNode()
64 for node in qa_config.get('nodes'):
71 master = qa_config.GetMasterNode()
73 cmd = ['gnt-node', 'info']
74 AssertEqual(StartSSH(master['primary'],
75 utils.ShellQuoteArgs(cmd)).wait(), 0)
78 def TestNodeVolumes():
79 """gnt-node volumes"""
80 master = qa_config.GetMasterNode()
82 cmd = ['gnt-node', 'volumes']
83 AssertEqual(StartSSH(master['primary'],
84 utils.ShellQuoteArgs(cmd)).wait(), 0)
87 def TestNodeFailover(node, node2):
88 """gnt-node failover"""
89 master = qa_config.GetMasterNode()
91 if qa_utils.GetNodeInstances(node2, secondaries=False):
92 raise qa_errors.UnusableNodeError("Secondary node has at least one "
93 "primary instance. This test requires "
94 "it to have no primary instances.")
96 # Fail over to secondary node
97 cmd = ['gnt-node', 'failover', '-f', node['primary']]
98 AssertEqual(StartSSH(master['primary'],
99 utils.ShellQuoteArgs(cmd)).wait(), 0)
101 # ... and back again.
102 cmd = ['gnt-node', 'failover', '-f', node2['primary']]
103 AssertEqual(StartSSH(master['primary'],
104 utils.ShellQuoteArgs(cmd)).wait(), 0)
107 def TestNodeEvacuate(node, node2):
108 """gnt-node evacuate"""
109 master = qa_config.GetMasterNode()
111 node3 = qa_config.AcquireNode(exclude=[node, node2])
113 if qa_utils.GetNodeInstances(node3, secondaries=True):
114 raise qa_errors.UnusableNodeError("Evacuation node has at least one "
115 "secondary instance. This test requires "
116 "it to have no secondary instances.")
118 # Evacuate all secondary instances
119 cmd = ['gnt-node', 'evacuate', '-f', node2['primary'], node3['primary']]
120 AssertEqual(StartSSH(master['primary'],
121 utils.ShellQuoteArgs(cmd)).wait(), 0)
123 # ... and back again.
124 cmd = ['gnt-node', 'evacuate', '-f', node3['primary'], node2['primary']]
125 AssertEqual(StartSSH(master['primary'],
126 utils.ShellQuoteArgs(cmd)).wait(), 0)
128 qa_config.ReleaseNode(node3)