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