Modify Disk.GetNodes() to support LD_FILE
[ganeti-local] / qa / qa_node.py
1 #
2 #
3
4 # Copyright (C) 2007 Google Inc.
5 #
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.
10 #
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.
15 #
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
19 # 02110-1301, USA.
20
21
22 from ganeti import utils
23
24 import qa_config
25 import qa_error
26 import qa_utils
27
28 from qa_utils import AssertEqual, StartSSH
29
30
31 @qa_utils.DefineHook('node-add')
32 def _NodeAdd(node):
33   master = qa_config.GetMasterNode()
34
35   if node.get('_added', False):
36     raise qa_error.Error("Node %s already in cluster" % node['primary'])
37
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)
44
45   node['_added'] = True
46
47
48 @qa_utils.DefineHook('node-remove')
49 def _NodeRemove(node):
50   master = qa_config.GetMasterNode()
51
52   cmd = ['gnt-node', 'remove', node['primary']]
53   AssertEqual(StartSSH(master['primary'],
54                        utils.ShellQuoteArgs(cmd)).wait(), 0)
55   node['_added'] = False
56
57
58 def TestNodeAddAll():
59   """Adding all nodes to cluster."""
60   master = qa_config.GetMasterNode()
61   for node in qa_config.get('nodes'):
62     if node != master:
63       _NodeAdd(node)
64
65
66 def TestNodeRemoveAll():
67   """Removing all nodes from cluster."""
68   master = qa_config.GetMasterNode()
69   for node in qa_config.get('nodes'):
70     if node != master:
71       _NodeRemove(node)
72
73
74 @qa_utils.DefineHook('node-info')
75 def TestNodeInfo():
76   """gnt-node info"""
77   master = qa_config.GetMasterNode()
78
79   cmd = ['gnt-node', 'info']
80   AssertEqual(StartSSH(master['primary'],
81                        utils.ShellQuoteArgs(cmd)).wait(), 0)
82
83
84 @qa_utils.DefineHook('node-volumes')
85 def TestNodeVolumes():
86   """gnt-node volumes"""
87   master = qa_config.GetMasterNode()
88
89   cmd = ['gnt-node', 'volumes']
90   AssertEqual(StartSSH(master['primary'],
91                        utils.ShellQuoteArgs(cmd)).wait(), 0)
92
93
94 @qa_utils.DefineHook('node-failover')
95 def TestNodeFailover(node, node2):
96   """gnt-node failover"""
97   master = qa_config.GetMasterNode()
98
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.")
103
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)
108
109   # ... and back again.
110   cmd = ['gnt-node', 'failover', '-f', node2['primary']]
111   AssertEqual(StartSSH(master['primary'],
112                        utils.ShellQuoteArgs(cmd)).wait(), 0)
113
114
115 @qa_utils.DefineHook('node-evacuate')
116 def TestNodeEvacuate(node, node2):
117   """gnt-node evacuate"""
118   master = qa_config.GetMasterNode()
119
120   node3 = qa_config.AcquireNode(exclude=[node, node2])
121   try:
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.")
126
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)
131
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)
136   finally:
137     qa_config.ReleaseNode(node3)