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