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 def _NodeAdd(node, readd=False):
32 master = qa_config.GetMasterNode()
34 if not readd and node.get('_added', False):
35 raise qa_error.Error("Node %s already in cluster" % node['primary'])
36 elif readd and not node.get('_added', False):
37 raise qa_error.Error("Node %s not yet in cluster" % node['primary'])
39 cmd = ['gnt-node', 'add', "--no-ssh-key-check"]
40 if node.get('secondary', None):
41 cmd.append('--secondary-ip=%s' % node['secondary'])
44 cmd.append(node['primary'])
45 AssertEqual(StartSSH(master['primary'],
46 utils.ShellQuoteArgs(cmd)).wait(), 0)
51 def _NodeRemove(node):
52 master = qa_config.GetMasterNode()
54 cmd = ['gnt-node', 'remove', node['primary']]
55 AssertEqual(StartSSH(master['primary'],
56 utils.ShellQuoteArgs(cmd)).wait(), 0)
57 node['_added'] = False
61 """Adding all nodes to cluster."""
62 master = qa_config.GetMasterNode()
63 for node in qa_config.get('nodes'):
65 _NodeAdd(node, readd=False)
68 def TestNodeRemoveAll():
69 """Removing all nodes from cluster."""
70 master = qa_config.GetMasterNode()
71 for node in qa_config.get('nodes'):
76 def TestNodeReadd(node):
77 """gnt-node add --readd"""
78 _NodeAdd(node, readd=True)
83 master = qa_config.GetMasterNode()
85 cmd = ['gnt-node', 'info']
86 AssertEqual(StartSSH(master['primary'],
87 utils.ShellQuoteArgs(cmd)).wait(), 0)
90 def TestNodeVolumes():
91 """gnt-node volumes"""
92 master = qa_config.GetMasterNode()
94 cmd = ['gnt-node', 'volumes']
95 AssertEqual(StartSSH(master['primary'],
96 utils.ShellQuoteArgs(cmd)).wait(), 0)
99 def TestNodeFailover(node, node2):
100 """gnt-node failover"""
101 master = qa_config.GetMasterNode()
103 if qa_utils.GetNodeInstances(node2, secondaries=False):
104 raise qa_error.UnusableNodeError("Secondary node has at least one"
105 " primary instance. This test requires"
106 " it to have no primary instances.")
108 # Fail over to secondary node
109 cmd = ['gnt-node', 'failover', '-f', node['primary']]
110 AssertEqual(StartSSH(master['primary'],
111 utils.ShellQuoteArgs(cmd)).wait(), 0)
113 # ... and back again.
114 cmd = ['gnt-node', 'failover', '-f', node2['primary']]
115 AssertEqual(StartSSH(master['primary'],
116 utils.ShellQuoteArgs(cmd)).wait(), 0)
119 def TestNodeEvacuate(node, node2):
120 """gnt-node evacuate"""
121 master = qa_config.GetMasterNode()
123 node3 = qa_config.AcquireNode(exclude=[node, node2])
125 if qa_utils.GetNodeInstances(node3, secondaries=True):
126 raise qa_error.UnusableNodeError("Evacuation node has at least one"
127 " secondary instance. This test requires"
128 " it to have no secondary instances.")
130 # Evacuate all secondary instances
131 cmd = ['gnt-node', 'evacuate', '-f',
132 "--new-secondary=%s" % node3['primary'], node2['primary']]
133 AssertEqual(StartSSH(master['primary'],
134 utils.ShellQuoteArgs(cmd)).wait(), 0)
136 # ... and back again.
137 cmd = ['gnt-node', 'evacuate', '-f',
138 "--new-secondary=%s" % node2['primary'], node3['primary']]
139 AssertEqual(StartSSH(master['primary'],
140 utils.ShellQuoteArgs(cmd)).wait(), 0)
142 qa_config.ReleaseNode(node3)