root / qa / qa_daemon.py @ 1492cca7
History | View | Annotate | Download (3.8 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 | """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 | cec9845c | Michael Hanselmann | from qa_utils import AssertEqual, StartSSH |
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 | cec9845c | Michael Hanselmann | Args:
|
42 | cec9845c | Michael Hanselmann | node: Node the instance runs on
|
43 | cec9845c | Michael Hanselmann | name: Full name of Xen instance
|
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 | cec9845c | Michael Hanselmann | Args:
|
54 | cec9845c | Michael Hanselmann | node: Node the instance runs on
|
55 | cec9845c | Michael Hanselmann | name: Full name of Xen instance
|
56 | cec9845c | Michael Hanselmann | """
|
57 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
58 | cec9845c | Michael Hanselmann | |
59 | cec9845c | Michael Hanselmann | cmd = ['xm', 'shutdown', name] |
60 | 5d640672 | Michael Hanselmann | AssertEqual(StartSSH(node['primary'],
|
61 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
62 | cec9845c | Michael Hanselmann | |
63 | cec9845c | Michael Hanselmann | # Wait up to a minute
|
64 | cec9845c | Michael Hanselmann | end = time.time() + 60
|
65 | cec9845c | Michael Hanselmann | while time.time() <= end:
|
66 | cec9845c | Michael Hanselmann | if not _InstanceRunning(node, name): |
67 | cec9845c | Michael Hanselmann | break
|
68 | cec9845c | Michael Hanselmann | time.sleep(5)
|
69 | cec9845c | Michael Hanselmann | else:
|
70 | cec9845c | Michael Hanselmann | raise qa_error.Error("xm shutdown failed") |
71 | cec9845c | Michael Hanselmann | |
72 | cec9845c | Michael Hanselmann | |
73 | 28a6fbc8 | Michael Hanselmann | def _ResetWatcherDaemon(): |
74 | cec9845c | Michael Hanselmann | """Removes the watcher daemon's state file.
|
75 | cec9845c | Michael Hanselmann |
|
76 | cec9845c | Michael Hanselmann | Args:
|
77 | cec9845c | Michael Hanselmann | node: Node to be reset
|
78 | cec9845c | Michael Hanselmann | """
|
79 | 28a6fbc8 | Michael Hanselmann | master = qa_config.GetMasterNode() |
80 | 28a6fbc8 | Michael Hanselmann | |
81 | cec9845c | Michael Hanselmann | cmd = ['rm', '-f', constants.WATCHER_STATEFILE] |
82 | 28a6fbc8 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
83 | 28a6fbc8 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
84 | 28a6fbc8 | Michael Hanselmann | |
85 | 28a6fbc8 | Michael Hanselmann | |
86 | 28a6fbc8 | Michael Hanselmann | def _RunWatcherDaemon(): |
87 | 28a6fbc8 | Michael Hanselmann | """Runs the ganeti-watcher daemon on the master node.
|
88 | 28a6fbc8 | Michael Hanselmann |
|
89 | 28a6fbc8 | Michael Hanselmann | """
|
90 | 28a6fbc8 | Michael Hanselmann | master = qa_config.GetMasterNode() |
91 | 28a6fbc8 | Michael Hanselmann | |
92 | 28a6fbc8 | Michael Hanselmann | cmd = ['ganeti-watcher', '-d'] |
93 | 28a6fbc8 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
94 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
95 | cec9845c | Michael Hanselmann | |
96 | cec9845c | Michael Hanselmann | |
97 | 23269c5b | Michael Hanselmann | def PrintCronWarning(): |
98 | 28a6fbc8 | Michael Hanselmann | """Shows a warning about the cron job.
|
99 | 23269c5b | Michael Hanselmann |
|
100 | 23269c5b | Michael Hanselmann | """
|
101 | f4bc1f2c | Michael Hanselmann | msg = ("For the following tests it's recommended to turn off the"
|
102 | f4bc1f2c | Michael Hanselmann | " ganeti-watcher cronjob.")
|
103 | 23269c5b | Michael Hanselmann | print
|
104 | 28a6fbc8 | Michael Hanselmann | print qa_utils.FormatWarning(msg)
|
105 | 23269c5b | Michael Hanselmann | |
106 | 23269c5b | Michael Hanselmann | |
107 | cec9845c | Michael Hanselmann | def TestInstanceAutomaticRestart(node, instance): |
108 | cec9845c | Michael Hanselmann | """Test automatic restart of instance by ganeti-watcher.
|
109 | cec9845c | Michael Hanselmann |
|
110 | cec9845c | Michael Hanselmann | """
|
111 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
112 | 5d640672 | Michael Hanselmann | inst_name = qa_utils.ResolveInstanceName(instance) |
113 | cec9845c | Michael Hanselmann | |
114 | 28a6fbc8 | Michael Hanselmann | _ResetWatcherDaemon() |
115 | cec9845c | Michael Hanselmann | _XmShutdownInstance(node, inst_name) |
116 | cec9845c | Michael Hanselmann | |
117 | 28a6fbc8 | Michael Hanselmann | _RunWatcherDaemon() |
118 | 28a6fbc8 | Michael Hanselmann | time.sleep(5)
|
119 | cec9845c | Michael Hanselmann | |
120 | 28a6fbc8 | Michael Hanselmann | if not _InstanceRunning(node, inst_name): |
121 | 28a6fbc8 | Michael Hanselmann | raise qa_error.Error("Daemon didn't restart instance") |
122 | cec9845c | Michael Hanselmann | |
123 | cec9845c | Michael Hanselmann | cmd = ['gnt-instance', 'info', inst_name] |
124 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
125 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
126 | cec9845c | Michael Hanselmann | |
127 | cec9845c | Michael Hanselmann | |
128 | cec9845c | Michael Hanselmann | def TestInstanceConsecutiveFailures(node, instance): |
129 | cec9845c | Michael Hanselmann | """Test five consecutive instance failures.
|
130 | cec9845c | Michael Hanselmann |
|
131 | cec9845c | Michael Hanselmann | """
|
132 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
133 | 5d640672 | Michael Hanselmann | inst_name = qa_utils.ResolveInstanceName(instance) |
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 | cec9845c | Michael Hanselmann | cmd = ['gnt-instance', 'info', inst_name] |
150 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
151 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0) |