root / qa / qa_node.py @ a47f574c
History | View | Annotate | Download (4.5 kB)
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, readd=False): |
33 |
master = qa_config.GetMasterNode() |
34 |
|
35 |
if not readd and node.get('_added', False): |
36 |
raise qa_error.Error("Node %s already in cluster" % node['primary']) |
37 |
elif readd and not node.get('_added', False): |
38 |
raise qa_error.Error("Node %s not yet in cluster" % node['primary']) |
39 |
|
40 |
cmd = ['gnt-node', 'add'] |
41 |
if node.get('secondary', None): |
42 |
cmd.append('--secondary-ip=%s' % node['secondary']) |
43 |
if readd:
|
44 |
cmd.append('--readd')
|
45 |
cmd.append(node['primary'])
|
46 |
AssertEqual(StartSSH(master['primary'],
|
47 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
48 |
|
49 |
node['_added'] = True |
50 |
|
51 |
|
52 |
@qa_utils.DefineHook('node-remove') |
53 |
def _NodeRemove(node): |
54 |
master = qa_config.GetMasterNode() |
55 |
|
56 |
cmd = ['gnt-node', 'remove', node['primary']] |
57 |
AssertEqual(StartSSH(master['primary'],
|
58 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
59 |
node['_added'] = False |
60 |
|
61 |
|
62 |
def TestNodeAddAll(): |
63 |
"""Adding all nodes to cluster."""
|
64 |
master = qa_config.GetMasterNode() |
65 |
for node in qa_config.get('nodes'): |
66 |
if node != master:
|
67 |
_NodeAdd(node, readd=False)
|
68 |
|
69 |
|
70 |
def TestNodeRemoveAll(): |
71 |
"""Removing all nodes from cluster."""
|
72 |
master = qa_config.GetMasterNode() |
73 |
for node in qa_config.get('nodes'): |
74 |
if node != master:
|
75 |
_NodeRemove(node) |
76 |
|
77 |
|
78 |
@qa_utils.DefineHook('node-readd') |
79 |
def TestNodeReadd(node): |
80 |
"""gnt-node add --readd"""
|
81 |
_NodeAdd(node, readd=True)
|
82 |
|
83 |
|
84 |
@qa_utils.DefineHook('node-info') |
85 |
def TestNodeInfo(): |
86 |
"""gnt-node info"""
|
87 |
master = qa_config.GetMasterNode() |
88 |
|
89 |
cmd = ['gnt-node', 'info'] |
90 |
AssertEqual(StartSSH(master['primary'],
|
91 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
92 |
|
93 |
|
94 |
@qa_utils.DefineHook('node-volumes') |
95 |
def TestNodeVolumes(): |
96 |
"""gnt-node volumes"""
|
97 |
master = qa_config.GetMasterNode() |
98 |
|
99 |
cmd = ['gnt-node', 'volumes'] |
100 |
AssertEqual(StartSSH(master['primary'],
|
101 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
102 |
|
103 |
|
104 |
@qa_utils.DefineHook('node-failover') |
105 |
def TestNodeFailover(node, node2): |
106 |
"""gnt-node failover"""
|
107 |
master = qa_config.GetMasterNode() |
108 |
|
109 |
if qa_utils.GetNodeInstances(node2, secondaries=False): |
110 |
raise qa_error.UnusableNodeError("Secondary node has at least one" |
111 |
" primary instance. This test requires"
|
112 |
" it to have no primary instances.")
|
113 |
|
114 |
# Fail over to secondary node
|
115 |
cmd = ['gnt-node', 'failover', '-f', node['primary']] |
116 |
AssertEqual(StartSSH(master['primary'],
|
117 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
118 |
|
119 |
# ... and back again.
|
120 |
cmd = ['gnt-node', 'failover', '-f', node2['primary']] |
121 |
AssertEqual(StartSSH(master['primary'],
|
122 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
123 |
|
124 |
|
125 |
@qa_utils.DefineHook('node-evacuate') |
126 |
def TestNodeEvacuate(node, node2): |
127 |
"""gnt-node evacuate"""
|
128 |
master = qa_config.GetMasterNode() |
129 |
|
130 |
node3 = qa_config.AcquireNode(exclude=[node, node2]) |
131 |
try:
|
132 |
if qa_utils.GetNodeInstances(node3, secondaries=True): |
133 |
raise qa_error.UnusableNodeError("Evacuation node has at least one" |
134 |
" secondary instance. This test requires"
|
135 |
" it to have no secondary instances.")
|
136 |
|
137 |
# Evacuate all secondary instances
|
138 |
cmd = ['gnt-node', 'evacuate', '-f', node2['primary'], node3['primary']] |
139 |
AssertEqual(StartSSH(master['primary'],
|
140 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
141 |
|
142 |
# ... and back again.
|
143 |
cmd = ['gnt-node', 'evacuate', '-f', node3['primary'], node2['primary']] |
144 |
AssertEqual(StartSSH(master['primary'],
|
145 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
146 |
finally:
|
147 |
qa_config.ReleaseNode(node3) |