root / qa / qa_daemon.py @ e9f745aa
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 | """Daemon related QA tests.
|
20 | cec9845c | Michael Hanselmann |
|
21 | cec9845c | Michael Hanselmann | """
|
22 | cec9845c | Michael Hanselmann | |
23 | cec9845c | Michael Hanselmann | import time |
24 | cec9845c | Michael Hanselmann | import subprocess |
25 | cec9845c | Michael Hanselmann | |
26 | cec9845c | Michael Hanselmann | from ganeti import utils |
27 | cec9845c | Michael Hanselmann | from ganeti import constants |
28 | cec9845c | Michael Hanselmann | |
29 | cec9845c | Michael Hanselmann | import qa_config |
30 | cec9845c | Michael Hanselmann | import qa_utils |
31 | cec9845c | Michael Hanselmann | import qa_error |
32 | cec9845c | Michael Hanselmann | |
33 | cec9845c | Michael Hanselmann | from qa_utils import AssertEqual, StartSSH |
34 | cec9845c | Michael Hanselmann | |
35 | cec9845c | Michael Hanselmann | |
36 | cec9845c | Michael Hanselmann | def _ResolveInstanceName(instance): |
37 | cec9845c | Michael Hanselmann | """Gets the full Xen name of an instance.
|
38 | cec9845c | Michael Hanselmann |
|
39 | cec9845c | Michael Hanselmann | """
|
40 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
41 | cec9845c | Michael Hanselmann | |
42 | cec9845c | Michael Hanselmann | info_cmd = utils.ShellQuoteArgs(['gnt-instance', 'info', instance['name']]) |
43 | cec9845c | Michael Hanselmann | sed_cmd = utils.ShellQuoteArgs(['sed', '-n', '-e', 's/^Instance name: *//p']) |
44 | cec9845c | Michael Hanselmann | |
45 | cec9845c | Michael Hanselmann | cmd = '%s | %s' % (info_cmd, sed_cmd)
|
46 | cec9845c | Michael Hanselmann | ssh_cmd = qa_utils.GetSSHCommand(master['primary'], cmd)
|
47 | cec9845c | Michael Hanselmann | p = subprocess.Popen(ssh_cmd, shell=False, stdout=subprocess.PIPE)
|
48 | cec9845c | Michael Hanselmann | AssertEqual(p.wait(), 0)
|
49 | cec9845c | Michael Hanselmann | |
50 | cec9845c | Michael Hanselmann | return p.stdout.read().strip()
|
51 | cec9845c | Michael Hanselmann | |
52 | cec9845c | Michael Hanselmann | |
53 | cec9845c | Michael Hanselmann | def _InstanceRunning(node, name): |
54 | cec9845c | Michael Hanselmann | """Checks whether an instance is running.
|
55 | cec9845c | Michael Hanselmann |
|
56 | cec9845c | Michael Hanselmann | Args:
|
57 | cec9845c | Michael Hanselmann | node: Node the instance runs on
|
58 | cec9845c | Michael Hanselmann | name: Full name of Xen instance
|
59 | cec9845c | Michael Hanselmann | """
|
60 | cec9845c | Michael Hanselmann | cmd = utils.ShellQuoteArgs(['xm', 'list', name]) + ' >/dev/null' |
61 | cec9845c | Michael Hanselmann | ret = StartSSH(node['primary'], cmd).wait()
|
62 | cec9845c | Michael Hanselmann | return ret == 0 |
63 | cec9845c | Michael Hanselmann | |
64 | cec9845c | Michael Hanselmann | |
65 | cec9845c | Michael Hanselmann | def _XmShutdownInstance(node, name): |
66 | cec9845c | Michael Hanselmann | """Shuts down instance using "xm" and waits for completion.
|
67 | cec9845c | Michael Hanselmann |
|
68 | cec9845c | Michael Hanselmann | Args:
|
69 | cec9845c | Michael Hanselmann | node: Node the instance runs on
|
70 | cec9845c | Michael Hanselmann | name: Full name of Xen instance
|
71 | cec9845c | Michael Hanselmann | """
|
72 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
73 | cec9845c | Michael Hanselmann | |
74 | cec9845c | Michael Hanselmann | cmd = ['xm', 'shutdown', name] |
75 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
76 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
77 | cec9845c | Michael Hanselmann | |
78 | cec9845c | Michael Hanselmann | # Wait up to a minute
|
79 | cec9845c | Michael Hanselmann | end = time.time() + 60
|
80 | cec9845c | Michael Hanselmann | while time.time() <= end:
|
81 | cec9845c | Michael Hanselmann | if not _InstanceRunning(node, name): |
82 | cec9845c | Michael Hanselmann | break
|
83 | cec9845c | Michael Hanselmann | time.sleep(5)
|
84 | cec9845c | Michael Hanselmann | else:
|
85 | cec9845c | Michael Hanselmann | raise qa_error.Error("xm shutdown failed") |
86 | cec9845c | Michael Hanselmann | |
87 | cec9845c | Michael Hanselmann | |
88 | cec9845c | Michael Hanselmann | def _ResetWatcherDaemon(node): |
89 | cec9845c | Michael Hanselmann | """Removes the watcher daemon's state file.
|
90 | cec9845c | Michael Hanselmann |
|
91 | cec9845c | Michael Hanselmann | Args:
|
92 | cec9845c | Michael Hanselmann | node: Node to be reset
|
93 | cec9845c | Michael Hanselmann | """
|
94 | cec9845c | Michael Hanselmann | cmd = ['rm', '-f', constants.WATCHER_STATEFILE] |
95 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(node['primary'],
|
96 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
97 | cec9845c | Michael Hanselmann | |
98 | cec9845c | Michael Hanselmann | |
99 | cec9845c | Michael Hanselmann | def TestInstanceAutomaticRestart(node, instance): |
100 | cec9845c | Michael Hanselmann | """Test automatic restart of instance by ganeti-watcher.
|
101 | cec9845c | Michael Hanselmann |
|
102 | cec9845c | Michael Hanselmann | Note: takes up to 6 minutes to complete.
|
103 | cec9845c | Michael Hanselmann | """
|
104 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
105 | cec9845c | Michael Hanselmann | inst_name = _ResolveInstanceName(instance) |
106 | cec9845c | Michael Hanselmann | |
107 | cec9845c | Michael Hanselmann | _ResetWatcherDaemon(node) |
108 | cec9845c | Michael Hanselmann | _XmShutdownInstance(node, inst_name) |
109 | cec9845c | Michael Hanselmann | |
110 | cec9845c | Michael Hanselmann | # Give it a bit more than five minutes to start again
|
111 | cec9845c | Michael Hanselmann | restart_at = time.time() + 330
|
112 | cec9845c | Michael Hanselmann | |
113 | cec9845c | Michael Hanselmann | # Wait until it's running again
|
114 | cec9845c | Michael Hanselmann | while time.time() <= restart_at:
|
115 | cec9845c | Michael Hanselmann | if _InstanceRunning(node, inst_name):
|
116 | cec9845c | Michael Hanselmann | break
|
117 | cec9845c | Michael Hanselmann | time.sleep(15)
|
118 | cec9845c | Michael Hanselmann | else:
|
119 | cec9845c | Michael Hanselmann | raise qa_error.Error("Daemon didn't restart instance in time") |
120 | cec9845c | Michael Hanselmann | |
121 | cec9845c | Michael Hanselmann | cmd = ['gnt-instance', 'info', inst_name] |
122 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
123 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
124 | cec9845c | Michael Hanselmann | |
125 | cec9845c | Michael Hanselmann | |
126 | cec9845c | Michael Hanselmann | def TestInstanceConsecutiveFailures(node, instance): |
127 | cec9845c | Michael Hanselmann | """Test five consecutive instance failures.
|
128 | cec9845c | Michael Hanselmann |
|
129 | cec9845c | Michael Hanselmann | Note: takes at least 35 minutes to complete.
|
130 | cec9845c | Michael Hanselmann | """
|
131 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
132 | cec9845c | Michael Hanselmann | inst_name = _ResolveInstanceName(instance) |
133 | cec9845c | Michael Hanselmann | |
134 | cec9845c | Michael Hanselmann | _ResetWatcherDaemon(node) |
135 | cec9845c | Michael Hanselmann | _XmShutdownInstance(node, inst_name) |
136 | cec9845c | Michael Hanselmann | |
137 | cec9845c | Michael Hanselmann | # Do shutdowns for 30 minutes
|
138 | cec9845c | Michael Hanselmann | finished_at = time.time() + (35 * 60) |
139 | cec9845c | Michael Hanselmann | |
140 | cec9845c | Michael Hanselmann | while time.time() <= finished_at:
|
141 | cec9845c | Michael Hanselmann | if _InstanceRunning(node, inst_name):
|
142 | cec9845c | Michael Hanselmann | _XmShutdownInstance(node, inst_name) |
143 | cec9845c | Michael Hanselmann | time.sleep(30)
|
144 | cec9845c | Michael Hanselmann | |
145 | cec9845c | Michael Hanselmann | # Check for some time whether the instance doesn't start again
|
146 | cec9845c | Michael Hanselmann | check_until = time.time() + 330
|
147 | cec9845c | Michael Hanselmann | while time.time() <= check_until:
|
148 | cec9845c | Michael Hanselmann | if _InstanceRunning(node, inst_name):
|
149 | cec9845c | Michael Hanselmann | raise qa_error.Error("Instance started when it shouldn't") |
150 | cec9845c | Michael Hanselmann | time.sleep(30)
|
151 | cec9845c | Michael Hanselmann | |
152 | cec9845c | Michael Hanselmann | cmd = ['gnt-instance', 'info', inst_name] |
153 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
154 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0) |