root / qa / qa_daemon.py @ ff699aa9
History | View | Annotate | Download (3.7 kB)
1 | c68d1f43 | Michael Hanselmann | #
|
---|---|---|---|
2 | c68d1f43 | Michael Hanselmann | #
|
3 | c68d1f43 | Michael Hanselmann | |
4 | 8201b996 | Iustin Pop | # Copyright (C) 2007, 2008, 2009, 2010 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 | """Daemon related QA tests.
|
23 | cec9845c | Michael Hanselmann |
|
24 | cec9845c | Michael Hanselmann | """
|
25 | cec9845c | Michael Hanselmann | |
26 | cec9845c | Michael Hanselmann | import time |
27 | cec9845c | Michael Hanselmann | |
28 | cec9845c | Michael Hanselmann | from ganeti import utils |
29 | cec9845c | Michael Hanselmann | from ganeti import constants |
30 | cec9845c | Michael Hanselmann | |
31 | cec9845c | Michael Hanselmann | import qa_config |
32 | cec9845c | Michael Hanselmann | import qa_utils |
33 | cec9845c | Michael Hanselmann | import qa_error |
34 | cec9845c | Michael Hanselmann | |
35 | 2f4b4f78 | Iustin Pop | from qa_utils import AssertMatch, AssertCommand, StartSSH, GetCommandOutput |
36 | cec9845c | Michael Hanselmann | |
37 | cec9845c | Michael Hanselmann | |
38 | cec9845c | Michael Hanselmann | def _InstanceRunning(node, name): |
39 | cec9845c | Michael Hanselmann | """Checks whether an instance is running.
|
40 | cec9845c | Michael Hanselmann |
|
41 | 2f4b4f78 | Iustin Pop | @param node: node the instance runs on
|
42 | 2f4b4f78 | Iustin Pop | @param name: full name of the Xen instance
|
43 | 2f4b4f78 | Iustin Pop |
|
44 | cec9845c | Michael Hanselmann | """
|
45 | cec9845c | Michael Hanselmann | cmd = utils.ShellQuoteArgs(['xm', 'list', name]) + ' >/dev/null' |
46 | cec9845c | Michael Hanselmann | ret = StartSSH(node['primary'], cmd).wait()
|
47 | cec9845c | Michael Hanselmann | return ret == 0 |
48 | cec9845c | Michael Hanselmann | |
49 | cec9845c | Michael Hanselmann | |
50 | cec9845c | Michael Hanselmann | def _XmShutdownInstance(node, name): |
51 | cec9845c | Michael Hanselmann | """Shuts down instance using "xm" and waits for completion.
|
52 | cec9845c | Michael Hanselmann |
|
53 | 2f4b4f78 | Iustin Pop | @param node: node the instance runs on
|
54 | 2f4b4f78 | Iustin Pop | @param name: full name of Xen instance
|
55 | cec9845c | Michael Hanselmann |
|
56 | 2f4b4f78 | Iustin Pop | """
|
57 | 2f4b4f78 | Iustin Pop | AssertCommand(["xm", "shutdown", name], node=node) |
58 | cec9845c | Michael Hanselmann | |
59 | cec9845c | Michael Hanselmann | # Wait up to a minute
|
60 | cec9845c | Michael Hanselmann | end = time.time() + 60
|
61 | cec9845c | Michael Hanselmann | while time.time() <= end:
|
62 | cec9845c | Michael Hanselmann | if not _InstanceRunning(node, name): |
63 | cec9845c | Michael Hanselmann | break
|
64 | cec9845c | Michael Hanselmann | time.sleep(5)
|
65 | cec9845c | Michael Hanselmann | else:
|
66 | cec9845c | Michael Hanselmann | raise qa_error.Error("xm shutdown failed") |
67 | cec9845c | Michael Hanselmann | |
68 | cec9845c | Michael Hanselmann | |
69 | 28a6fbc8 | Michael Hanselmann | def _ResetWatcherDaemon(): |
70 | cec9845c | Michael Hanselmann | """Removes the watcher daemon's state file.
|
71 | cec9845c | Michael Hanselmann |
|
72 | cec9845c | Michael Hanselmann | """
|
73 | 2f4b4f78 | Iustin Pop | AssertCommand(["rm", "-f", constants.WATCHER_STATEFILE]) |
74 | 28a6fbc8 | Michael Hanselmann | |
75 | 28a6fbc8 | Michael Hanselmann | |
76 | 28a6fbc8 | Michael Hanselmann | def _RunWatcherDaemon(): |
77 | 28a6fbc8 | Michael Hanselmann | """Runs the ganeti-watcher daemon on the master node.
|
78 | 28a6fbc8 | Michael Hanselmann |
|
79 | 28a6fbc8 | Michael Hanselmann | """
|
80 | 2f4b4f78 | Iustin Pop | AssertCommand(["ganeti-watcher", "-d", "--ignore-pause"]) |
81 | cec9845c | Michael Hanselmann | |
82 | cec9845c | Michael Hanselmann | |
83 | 8201b996 | Iustin Pop | def TestPauseWatcher(): |
84 | 8201b996 | Iustin Pop | """Tests and pauses the watcher.
|
85 | 23269c5b | Michael Hanselmann |
|
86 | 23269c5b | Michael Hanselmann | """
|
87 | 8201b996 | Iustin Pop | master = qa_config.GetMasterNode() |
88 | 8201b996 | Iustin Pop | |
89 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "watcher", "pause", "4h"]) |
90 | 8201b996 | Iustin Pop | |
91 | 8201b996 | Iustin Pop | cmd = ["gnt-cluster", "watcher", "info"] |
92 | 8201b996 | Iustin Pop | output = GetCommandOutput(master["primary"],
|
93 | 8201b996 | Iustin Pop | utils.ShellQuoteArgs(cmd)) |
94 | 8201b996 | Iustin Pop | AssertMatch(output, r"^.*\bis paused\b.*")
|
95 | 8201b996 | Iustin Pop | |
96 | 8201b996 | Iustin Pop | |
97 | 8201b996 | Iustin Pop | def TestResumeWatcher(): |
98 | 8201b996 | Iustin Pop | """Tests and unpauses the watcher.
|
99 | 8201b996 | Iustin Pop |
|
100 | 8201b996 | Iustin Pop | """
|
101 | 8201b996 | Iustin Pop | master = qa_config.GetMasterNode() |
102 | 8201b996 | Iustin Pop | |
103 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-cluster", "watcher", "continue"]) |
104 | 8201b996 | Iustin Pop | |
105 | 8201b996 | Iustin Pop | cmd = ["gnt-cluster", "watcher", "info"] |
106 | 8201b996 | Iustin Pop | output = GetCommandOutput(master["primary"],
|
107 | 8201b996 | Iustin Pop | utils.ShellQuoteArgs(cmd)) |
108 | 8201b996 | Iustin Pop | AssertMatch(output, r"^.*\bis not paused\b.*")
|
109 | 23269c5b | Michael Hanselmann | |
110 | 23269c5b | Michael Hanselmann | |
111 | cec9845c | Michael Hanselmann | def TestInstanceAutomaticRestart(node, instance): |
112 | cec9845c | Michael Hanselmann | """Test automatic restart of instance by ganeti-watcher.
|
113 | cec9845c | Michael Hanselmann |
|
114 | cec9845c | Michael Hanselmann | """
|
115 | 46f9a948 | Michael Hanselmann | inst_name = qa_utils.ResolveInstanceName(instance["name"])
|
116 | cec9845c | Michael Hanselmann | |
117 | 28a6fbc8 | Michael Hanselmann | _ResetWatcherDaemon() |
118 | cec9845c | Michael Hanselmann | _XmShutdownInstance(node, inst_name) |
119 | cec9845c | Michael Hanselmann | |
120 | 28a6fbc8 | Michael Hanselmann | _RunWatcherDaemon() |
121 | 28a6fbc8 | Michael Hanselmann | time.sleep(5)
|
122 | cec9845c | Michael Hanselmann | |
123 | 28a6fbc8 | Michael Hanselmann | if not _InstanceRunning(node, inst_name): |
124 | 28a6fbc8 | Michael Hanselmann | raise qa_error.Error("Daemon didn't restart instance") |
125 | cec9845c | Michael Hanselmann | |
126 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-instance", "info", inst_name]) |
127 | cec9845c | Michael Hanselmann | |
128 | cec9845c | Michael Hanselmann | |
129 | cec9845c | Michael Hanselmann | def TestInstanceConsecutiveFailures(node, instance): |
130 | cec9845c | Michael Hanselmann | """Test five consecutive instance failures.
|
131 | cec9845c | Michael Hanselmann |
|
132 | cec9845c | Michael Hanselmann | """
|
133 | 46f9a948 | Michael Hanselmann | inst_name = qa_utils.ResolveInstanceName(instance["name"])
|
134 | cec9845c | Michael Hanselmann | |
135 | 28a6fbc8 | Michael Hanselmann | _ResetWatcherDaemon() |
136 | cec9845c | Michael Hanselmann | |
137 | 28a6fbc8 | Michael Hanselmann | for should_start in ([True] * 5) + [False]: |
138 | 28a6fbc8 | Michael Hanselmann | _XmShutdownInstance(node, inst_name) |
139 | 28a6fbc8 | Michael Hanselmann | _RunWatcherDaemon() |
140 | 28a6fbc8 | Michael Hanselmann | time.sleep(5)
|
141 | cec9845c | Michael Hanselmann | |
142 | 28a6fbc8 | Michael Hanselmann | if bool(_InstanceRunning(node, inst_name)) != should_start: |
143 | 28a6fbc8 | Michael Hanselmann | if should_start:
|
144 | 28a6fbc8 | Michael Hanselmann | msg = "Instance not started when it should"
|
145 | 28a6fbc8 | Michael Hanselmann | else:
|
146 | 28a6fbc8 | Michael Hanselmann | msg = "Instance started when it shouldn't"
|
147 | 28a6fbc8 | Michael Hanselmann | raise qa_error.Error(msg)
|
148 | cec9845c | Michael Hanselmann | |
149 | 2f4b4f78 | Iustin Pop | AssertCommand(["gnt-instance", "info", inst_name]) |