Add --readd option to “gnt-node add”
[ganeti-local] / qa / qa_node.py
1 # Copyright (C) 2007 Google Inc.
2 #
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.
7 #
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.
12 #
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
16 # 02110-1301, USA.
17
18
19 from ganeti import utils
20
21 import qa_config
22 import qa_error
23 import qa_utils
24
25 from qa_utils import AssertEqual, StartSSH
26
27
28 @qa_utils.DefineHook('node-add')
29 def _NodeAdd(node, readd=False):
30   master = qa_config.GetMasterNode()
31
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'])
36
37   cmd = ['gnt-node', 'add']
38   if node.get('secondary', None):
39     cmd.append('--secondary-ip=%s' % node['secondary'])
40   if readd:
41     cmd.append('--readd')
42   cmd.append(node['primary'])
43   AssertEqual(StartSSH(master['primary'],
44                        utils.ShellQuoteArgs(cmd)).wait(), 0)
45
46   node['_added'] = True
47
48
49 @qa_utils.DefineHook('node-remove')
50 def _NodeRemove(node):
51   master = qa_config.GetMasterNode()
52
53   cmd = ['gnt-node', 'remove', node['primary']]
54   AssertEqual(StartSSH(master['primary'],
55                        utils.ShellQuoteArgs(cmd)).wait(), 0)
56   node['_added'] = False
57
58
59 def TestNodeAddAll():
60   """Adding all nodes to cluster."""
61   master = qa_config.GetMasterNode()
62   for node in qa_config.get('nodes'):
63     if node != master:
64       _NodeAdd(node, readd=False)
65
66
67 def TestNodeRemoveAll():
68   """Removing all nodes from cluster."""
69   master = qa_config.GetMasterNode()
70   for node in qa_config.get('nodes'):
71     if node != master:
72       _NodeRemove(node)
73
74
75 @qa_utils.DefineHook('node-readd')
76 def TestNodeReadd(node):
77   """gnt-node add --readd"""
78   _NodeAdd(node, readd=True)
79
80
81 @qa_utils.DefineHook('node-info')
82 def TestNodeInfo():
83   """gnt-node info"""
84   master = qa_config.GetMasterNode()
85
86   cmd = ['gnt-node', 'info']
87   AssertEqual(StartSSH(master['primary'],
88                        utils.ShellQuoteArgs(cmd)).wait(), 0)
89
90
91 @qa_utils.DefineHook('node-volumes')
92 def TestNodeVolumes():
93   """gnt-node volumes"""
94   master = qa_config.GetMasterNode()
95
96   cmd = ['gnt-node', 'volumes']
97   AssertEqual(StartSSH(master['primary'],
98                        utils.ShellQuoteArgs(cmd)).wait(), 0)
99
100
101 @qa_utils.DefineHook('node-failover')
102 def TestNodeFailover(node, node2):
103   """gnt-node failover"""
104   master = qa_config.GetMasterNode()
105
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.")
110
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)
115
116   # ... and back again.
117   cmd = ['gnt-node', 'failover', '-f', node2['primary']]
118   AssertEqual(StartSSH(master['primary'],
119                        utils.ShellQuoteArgs(cmd)).wait(), 0)
120
121
122 @qa_utils.DefineHook('node-evacuate')
123 def TestNodeEvacuate(node, node2):
124   """gnt-node evacuate"""
125   master = qa_config.GetMasterNode()
126
127   node3 = qa_config.AcquireNode(exclude=[node, node2])
128   try:
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.")
133
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)
138
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)
143   finally:
144     qa_config.ReleaseNode(node3)