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