root / qa / qa_node.py @ 6852c52f
History | View | Annotate | Download (4.2 kB)
1 | cec9845c | Michael Hanselmann | # Copyright (C) 2007 Google Inc.
|
---|---|---|---|
2 | cec9845c | Michael Hanselmann | #
|
3 | cec9845c | Michael Hanselmann | # This program is free software; you can redistribute it and/or modify
|
4 | cec9845c | Michael Hanselmann | # it under the terms of the GNU General Public License as published by
|
5 | cec9845c | Michael Hanselmann | # the Free Software Foundation; either version 2 of the License, or
|
6 | cec9845c | Michael Hanselmann | # (at your option) any later version.
|
7 | cec9845c | Michael Hanselmann | #
|
8 | cec9845c | Michael Hanselmann | # This program is distributed in the hope that it will be useful, but
|
9 | cec9845c | Michael Hanselmann | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
10 | cec9845c | Michael Hanselmann | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11 | cec9845c | Michael Hanselmann | # General Public License for more details.
|
12 | cec9845c | Michael Hanselmann | #
|
13 | cec9845c | Michael Hanselmann | # You should have received a copy of the GNU General Public License
|
14 | cec9845c | Michael Hanselmann | # along with this program; if not, write to the Free Software
|
15 | cec9845c | Michael Hanselmann | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
16 | cec9845c | Michael Hanselmann | # 02110-1301, USA.
|
17 | cec9845c | Michael Hanselmann | |
18 | cec9845c | Michael Hanselmann | |
19 | cec9845c | Michael Hanselmann | from ganeti import utils |
20 | cec9845c | Michael Hanselmann | |
21 | cec9845c | Michael Hanselmann | import qa_config |
22 | cec9845c | Michael Hanselmann | import qa_error |
23 | 4b62db14 | Michael Hanselmann | import qa_utils |
24 | cec9845c | Michael Hanselmann | |
25 | cec9845c | Michael Hanselmann | from qa_utils import AssertEqual, StartSSH |
26 | cec9845c | Michael Hanselmann | |
27 | cec9845c | Michael Hanselmann | |
28 | e42b5307 | Michael Hanselmann | @qa_utils.DefineHook('node-add') |
29 | cec9845c | Michael Hanselmann | def _NodeAdd(node): |
30 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
31 | cec9845c | Michael Hanselmann | |
32 | cec9845c | Michael Hanselmann | if node.get('_added', False): |
33 | cec9845c | Michael Hanselmann | raise qa_error.Error("Node %s already in cluster" % node['primary']) |
34 | cec9845c | Michael Hanselmann | |
35 | cec9845c | Michael Hanselmann | cmd = ['gnt-node', 'add'] |
36 | cec9845c | Michael Hanselmann | if node.get('secondary', None): |
37 | cec9845c | Michael Hanselmann | cmd.append('--secondary-ip=%s' % node['secondary']) |
38 | cec9845c | Michael Hanselmann | cmd.append(node['primary'])
|
39 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
40 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
41 | cec9845c | Michael Hanselmann | |
42 | cec9845c | Michael Hanselmann | node['_added'] = True |
43 | cec9845c | Michael Hanselmann | |
44 | cec9845c | Michael Hanselmann | |
45 | e42b5307 | Michael Hanselmann | @qa_utils.DefineHook('node-remove') |
46 | cec9845c | Michael Hanselmann | def _NodeRemove(node): |
47 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
48 | cec9845c | Michael Hanselmann | |
49 | cec9845c | Michael Hanselmann | cmd = ['gnt-node', 'remove', node['primary']] |
50 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
51 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
52 | cec9845c | Michael Hanselmann | node['_added'] = False |
53 | cec9845c | Michael Hanselmann | |
54 | cec9845c | Michael Hanselmann | |
55 | cec9845c | Michael Hanselmann | def TestNodeAddAll(): |
56 | cec9845c | Michael Hanselmann | """Adding all nodes to cluster."""
|
57 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
58 | cec9845c | Michael Hanselmann | for node in qa_config.get('nodes'): |
59 | cec9845c | Michael Hanselmann | if node != master:
|
60 | cec9845c | Michael Hanselmann | _NodeAdd(node) |
61 | cec9845c | Michael Hanselmann | |
62 | cec9845c | Michael Hanselmann | |
63 | cec9845c | Michael Hanselmann | def TestNodeRemoveAll(): |
64 | cec9845c | Michael Hanselmann | """Removing all nodes from cluster."""
|
65 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
66 | cec9845c | Michael Hanselmann | for node in qa_config.get('nodes'): |
67 | cec9845c | Michael Hanselmann | if node != master:
|
68 | cec9845c | Michael Hanselmann | _NodeRemove(node) |
69 | cec9845c | Michael Hanselmann | |
70 | cec9845c | Michael Hanselmann | |
71 | e42b5307 | Michael Hanselmann | @qa_utils.DefineHook('node-info') |
72 | cec9845c | Michael Hanselmann | def TestNodeInfo(): |
73 | cec9845c | Michael Hanselmann | """gnt-node info"""
|
74 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
75 | cec9845c | Michael Hanselmann | |
76 | cec9845c | Michael Hanselmann | cmd = ['gnt-node', 'info'] |
77 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
78 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
79 | cec9845c | Michael Hanselmann | |
80 | cec9845c | Michael Hanselmann | |
81 | e42b5307 | Michael Hanselmann | @qa_utils.DefineHook('node-volumes') |
82 | cec9845c | Michael Hanselmann | def TestNodeVolumes(): |
83 | cec9845c | Michael Hanselmann | """gnt-node volumes"""
|
84 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
85 | cec9845c | Michael Hanselmann | |
86 | cec9845c | Michael Hanselmann | cmd = ['gnt-node', 'volumes'] |
87 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
88 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
89 | 4b62db14 | Michael Hanselmann | |
90 | 4b62db14 | Michael Hanselmann | |
91 | e42b5307 | Michael Hanselmann | @qa_utils.DefineHook('node-failover') |
92 | 4b62db14 | Michael Hanselmann | def TestNodeFailover(node, node2): |
93 | 4b62db14 | Michael Hanselmann | """gnt-node failover"""
|
94 | 4b62db14 | Michael Hanselmann | master = qa_config.GetMasterNode() |
95 | 4b62db14 | Michael Hanselmann | |
96 | d7e49c13 | Michael Hanselmann | if qa_utils.GetNodeInstances(node2, secondaries=False): |
97 | b1ffe1eb | Michael Hanselmann | raise qa_error.UnusableNodeError("Secondary node has at least one " |
98 | b1ffe1eb | Michael Hanselmann | "primary instance. This test requires "
|
99 | b1ffe1eb | Michael Hanselmann | "it to have no primary instances.")
|
100 | 4b62db14 | Michael Hanselmann | |
101 | 4b62db14 | Michael Hanselmann | # Fail over to secondary node
|
102 | 4b62db14 | Michael Hanselmann | cmd = ['gnt-node', 'failover', '-f', node['primary']] |
103 | 4b62db14 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
104 | 4b62db14 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
105 | 4b62db14 | Michael Hanselmann | |
106 | 4b62db14 | Michael Hanselmann | # ... and back again.
|
107 | 4b62db14 | Michael Hanselmann | cmd = ['gnt-node', 'failover', '-f', node2['primary']] |
108 | 4b62db14 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
109 | 4b62db14 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
110 | 4b62db14 | Michael Hanselmann | |
111 | 4b62db14 | Michael Hanselmann | |
112 | e42b5307 | Michael Hanselmann | @qa_utils.DefineHook('node-evacuate') |
113 | 4b62db14 | Michael Hanselmann | def TestNodeEvacuate(node, node2): |
114 | 4b62db14 | Michael Hanselmann | """gnt-node evacuate"""
|
115 | 4b62db14 | Michael Hanselmann | master = qa_config.GetMasterNode() |
116 | 4b62db14 | Michael Hanselmann | |
117 | 4b62db14 | Michael Hanselmann | node3 = qa_config.AcquireNode(exclude=[node, node2]) |
118 | 4b62db14 | Michael Hanselmann | try:
|
119 | d7e49c13 | Michael Hanselmann | if qa_utils.GetNodeInstances(node3, secondaries=True): |
120 | b1ffe1eb | Michael Hanselmann | raise qa_error.UnusableNodeError("Evacuation node has at least one " |
121 | b1ffe1eb | Michael Hanselmann | "secondary instance. This test requires "
|
122 | b1ffe1eb | Michael Hanselmann | "it to have no secondary instances.")
|
123 | 4b62db14 | Michael Hanselmann | |
124 | 4b62db14 | Michael Hanselmann | # Evacuate all secondary instances
|
125 | 4b62db14 | Michael Hanselmann | cmd = ['gnt-node', 'evacuate', '-f', node2['primary'], node3['primary']] |
126 | 4b62db14 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
127 | 4b62db14 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
128 | 4b62db14 | Michael Hanselmann | |
129 | 4b62db14 | Michael Hanselmann | # ... and back again.
|
130 | 4b62db14 | Michael Hanselmann | cmd = ['gnt-node', 'evacuate', '-f', node3['primary'], node2['primary']] |
131 | 4b62db14 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
132 | 4b62db14 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
133 | 4b62db14 | Michael Hanselmann | finally:
|
134 | 4b62db14 | Michael Hanselmann | qa_config.ReleaseNode(node3) |