Merge lp:~soren/nova/improve-smoketests into lp:~hudson-openstack/nova/trunk
- improve-smoketests
- Merge into trunk
Proposed by
Soren Hansen
Status: | Merged |
---|---|
Approved by: | Soren Hansen |
Approved revision: | 825 |
Merged at revision: | 835 |
Proposed branch: | lp:~soren/nova/improve-smoketests |
Merge into: | lp:~hudson-openstack/nova/trunk |
Diff against target: |
641 lines (+362/-85) 9 files modified
nova/tests/api/openstack/test_servers.py (+0/-4) run_tests.py (+2/-0) smoketests/base.py (+16/-35) smoketests/proxy.sh (+9/-2) smoketests/public_network_smoketests.py (+0/-6) smoketests/run_tests.py (+310/-0) smoketests/test_admin.py (+0/-7) smoketests/test_netadmin.py (+3/-14) smoketests/test_sysadmin.py (+22/-17) |
To merge this branch: | bzr merge lp:~soren/nova/improve-smoketests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Jesse Andrews (community) | Approve | ||
Vish Ishaya (community) | Approve | ||
Review via email: mp+53922@code.launchpad.net |
Commit message
Make smoketests' exit code reveal whether they were succesful.
Adjust volume tests to check the exact size of the block device, instead of a rounded-off size of the resulting filesystem.
Make proxy.sh work with both variants of netcat.
Description of the change
With these couple of changes, my automated runs of both sysadmin_smoketests and netadmin_smoketests are now succesful.
To post a comment you must log in.
Revision history for this message
Jesse Andrews (anotherjesse) wrote : | # |
lgtm!
I finally got hardware from RAX to run the smoketests on a real cluster after each deploy
review:
Approve
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : | # |
Attempt to merge into lp:nova failed due to conflicts:
text conflict in smoketests/
- 824. By Soren Hansen
-
Merge trunk
- 825. By Soren Hansen
-
pep8
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'nova/tests/api/openstack/test_servers.py' | |||
2 | --- nova/tests/api/openstack/test_servers.py 2011-03-17 22:24:08 +0000 | |||
3 | +++ nova/tests/api/openstack/test_servers.py 2011-03-20 19:08:31 +0000 | |||
4 | @@ -1174,7 +1174,3 @@ | |||
5 | 1174 | server = dom.childNodes[0] | 1174 | server = dom.childNodes[0] |
6 | 1175 | self.assertEquals(server.nodeName, 'server') | 1175 | self.assertEquals(server.nodeName, 'server') |
7 | 1176 | self.assertTrue(server.getAttribute('adminPass').startswith('fake')) | 1176 | self.assertTrue(server.getAttribute('adminPass').startswith('fake')) |
8 | 1177 | |||
9 | 1178 | |||
10 | 1179 | if __name__ == "__main__": | ||
11 | 1180 | unittest.main() | ||
12 | 1181 | 1177 | ||
13 | === modified file 'run_tests.py' | |||
14 | --- run_tests.py 2011-02-25 01:04:25 +0000 | |||
15 | +++ run_tests.py 2011-03-20 19:08:31 +0000 | |||
16 | @@ -60,6 +60,8 @@ | |||
17 | 60 | import unittest | 60 | import unittest |
18 | 61 | import sys | 61 | import sys |
19 | 62 | 62 | ||
20 | 63 | gettext.install('nova', unicode=1) | ||
21 | 64 | |||
22 | 63 | from nose import config | 65 | from nose import config |
23 | 64 | from nose import core | 66 | from nose import core |
24 | 65 | from nose import result | 67 | from nose import result |
25 | 66 | 68 | ||
26 | === modified file 'smoketests/base.py' | |||
27 | --- smoketests/base.py 2011-02-23 02:04:08 +0000 | |||
28 | +++ smoketests/base.py 2011-03-20 19:08:31 +0000 | |||
29 | @@ -31,17 +31,24 @@ | |||
30 | 31 | SUITE_NAMES = '[image, instance, volume]' | 31 | SUITE_NAMES = '[image, instance, volume]' |
31 | 32 | FLAGS = flags.FLAGS | 32 | FLAGS = flags.FLAGS |
32 | 33 | flags.DEFINE_string('suite', None, 'Specific test suite to run ' + SUITE_NAMES) | 33 | flags.DEFINE_string('suite', None, 'Specific test suite to run ' + SUITE_NAMES) |
33 | 34 | flags.DEFINE_integer('ssh_tries', 3, 'Numer of times to try ssh') | ||
34 | 34 | boto_v6 = None | 35 | boto_v6 = None |
35 | 35 | 36 | ||
36 | 36 | 37 | ||
37 | 37 | class SmokeTestCase(unittest.TestCase): | 38 | class SmokeTestCase(unittest.TestCase): |
38 | 38 | def connect_ssh(self, ip, key_name): | 39 | def connect_ssh(self, ip, key_name): |
39 | 39 | # TODO(devcamcar): set a more reasonable connection timeout time | ||
40 | 40 | key = paramiko.RSAKey.from_private_key_file('/tmp/%s.pem' % key_name) | 40 | key = paramiko.RSAKey.from_private_key_file('/tmp/%s.pem' % key_name) |
45 | 41 | client = paramiko.SSHClient() | 41 | tries = 0 |
46 | 42 | client.set_missing_host_key_policy(paramiko.WarningPolicy()) | 42 | while(True): |
47 | 43 | client.connect(ip, username='root', pkey=key) | 43 | try: |
48 | 44 | return client | 44 | client = paramiko.SSHClient() |
49 | 45 | client.set_missing_host_key_policy(paramiko.WarningPolicy()) | ||
50 | 46 | client.connect(ip, username='root', pkey=key, timeout=5) | ||
51 | 47 | return client | ||
52 | 48 | except (paramiko.AuthenticationException, paramiko.SSHException): | ||
53 | 49 | tries += 1 | ||
54 | 50 | if tries == FLAGS.ssh_tries: | ||
55 | 51 | raise | ||
56 | 45 | 52 | ||
57 | 46 | def can_ping(self, ip, command="ping"): | 53 | def can_ping(self, ip, command="ping"): |
58 | 47 | """Attempt to ping the specified IP, and give up after 1 second.""" | 54 | """Attempt to ping the specified IP, and give up after 1 second.""" |
59 | @@ -147,8 +154,8 @@ | |||
60 | 147 | except: | 154 | except: |
61 | 148 | pass | 155 | pass |
62 | 149 | 156 | ||
65 | 150 | def bundle_image(self, image, kernel=False): | 157 | def bundle_image(self, image, tempdir='/tmp', kernel=False): |
66 | 151 | cmd = 'euca-bundle-image -i %s' % image | 158 | cmd = 'euca-bundle-image -i %s -d %s' % (image, tempdir) |
67 | 152 | if kernel: | 159 | if kernel: |
68 | 153 | cmd += ' --kernel true' | 160 | cmd += ' --kernel true' |
69 | 154 | status, output = commands.getstatusoutput(cmd) | 161 | status, output = commands.getstatusoutput(cmd) |
70 | @@ -157,9 +164,9 @@ | |||
71 | 157 | raise Exception(output) | 164 | raise Exception(output) |
72 | 158 | return True | 165 | return True |
73 | 159 | 166 | ||
75 | 160 | def upload_image(self, bucket_name, image): | 167 | def upload_image(self, bucket_name, image, tempdir='/tmp'): |
76 | 161 | cmd = 'euca-upload-bundle -b ' | 168 | cmd = 'euca-upload-bundle -b ' |
78 | 162 | cmd += '%s -m /tmp/%s.manifest.xml' % (bucket_name, image) | 169 | cmd += '%s -m %s/%s.manifest.xml' % (bucket_name, tempdir, image) |
79 | 163 | status, output = commands.getstatusoutput(cmd) | 170 | status, output = commands.getstatusoutput(cmd) |
80 | 164 | if status != 0: | 171 | if status != 0: |
81 | 165 | print '%s -> \n %s' % (cmd, output) | 172 | print '%s -> \n %s' % (cmd, output) |
82 | @@ -183,29 +190,3 @@ | |||
83 | 183 | global TEST_DATA | 190 | global TEST_DATA |
84 | 184 | self.conn = self.connection_for_env() | 191 | self.conn = self.connection_for_env() |
85 | 185 | self.data = TEST_DATA | 192 | self.data = TEST_DATA |
86 | 186 | |||
87 | 187 | |||
88 | 188 | def run_tests(suites): | ||
89 | 189 | argv = FLAGS(sys.argv) | ||
90 | 190 | if FLAGS.use_ipv6: | ||
91 | 191 | global boto_v6 | ||
92 | 192 | boto_v6 = __import__('boto_v6') | ||
93 | 193 | |||
94 | 194 | if not os.getenv('EC2_ACCESS_KEY'): | ||
95 | 195 | print >> sys.stderr, 'Missing EC2 environment variables. Please ' \ | ||
96 | 196 | 'source the appropriate novarc file before ' \ | ||
97 | 197 | 'running this test.' | ||
98 | 198 | return 1 | ||
99 | 199 | |||
100 | 200 | if FLAGS.suite: | ||
101 | 201 | try: | ||
102 | 202 | suite = suites[FLAGS.suite] | ||
103 | 203 | except KeyError: | ||
104 | 204 | print >> sys.stderr, 'Available test suites:', \ | ||
105 | 205 | ', '.join(suites.keys()) | ||
106 | 206 | return 1 | ||
107 | 207 | |||
108 | 208 | unittest.TextTestRunner(verbosity=2).run(suite) | ||
109 | 209 | else: | ||
110 | 210 | for suite in suites.itervalues(): | ||
111 | 211 | unittest.TextTestRunner(verbosity=2).run(suite) | ||
112 | 212 | 193 | ||
113 | === modified file 'smoketests/proxy.sh' | |||
114 | --- smoketests/proxy.sh 2011-02-23 02:04:32 +0000 | |||
115 | +++ smoketests/proxy.sh 2011-03-20 19:08:31 +0000 | |||
116 | @@ -11,12 +11,19 @@ | |||
117 | 11 | mkfifo backpipe1 | 11 | mkfifo backpipe1 |
118 | 12 | mkfifo backpipe2 | 12 | mkfifo backpipe2 |
119 | 13 | 13 | ||
120 | 14 | if nc -h 2>&1 | grep -i openbsd | ||
121 | 15 | then | ||
122 | 16 | NC_LISTEN="nc -l" | ||
123 | 17 | else | ||
124 | 18 | NC_LISTEN="nc -l -p" | ||
125 | 19 | fi | ||
126 | 20 | |||
127 | 14 | # NOTE(vish): proxy metadata on port 80 | 21 | # NOTE(vish): proxy metadata on port 80 |
128 | 15 | while true; do | 22 | while true; do |
130 | 16 | nc -l -p 80 0<backpipe1 | nc 169.254.169.254 80 1>backpipe1 | 23 | $NC_LISTEN 80 0<backpipe1 | nc 169.254.169.254 80 1>backpipe1 |
131 | 17 | done & | 24 | done & |
132 | 18 | 25 | ||
133 | 19 | # NOTE(vish): proxy google on port 8080 | 26 | # NOTE(vish): proxy google on port 8080 |
134 | 20 | while true; do | 27 | while true; do |
136 | 21 | nc -l -p 8080 0<backpipe2 | nc 74.125.19.99 80 1>backpipe2 | 28 | $NC_LISTEN 8080 0<backpipe2 | nc 74.125.19.99 80 1>backpipe2 |
137 | 22 | done & | 29 | done & |
138 | 23 | 30 | ||
139 | === modified file 'smoketests/public_network_smoketests.py' | |||
140 | --- smoketests/public_network_smoketests.py 2011-02-23 02:04:08 +0000 | |||
141 | +++ smoketests/public_network_smoketests.py 2011-03-20 19:08:31 +0000 | |||
142 | @@ -19,10 +19,8 @@ | |||
143 | 19 | import commands | 19 | import commands |
144 | 20 | import os | 20 | import os |
145 | 21 | import random | 21 | import random |
146 | 22 | import socket | ||
147 | 23 | import sys | 22 | import sys |
148 | 24 | import time | 23 | import time |
149 | 25 | import unittest | ||
150 | 26 | 24 | ||
151 | 27 | # If ../nova/__init__.py exists, add ../ to Python search path, so that | 25 | # If ../nova/__init__.py exists, add ../ to Python search path, so that |
152 | 28 | # it will override what happens to be installed in /usr/(local/)lib/python... | 26 | # it will override what happens to be installed in /usr/(local/)lib/python... |
153 | @@ -181,7 +179,3 @@ | |||
154 | 181 | self.conn.delete_security_group(security_group_name) | 179 | self.conn.delete_security_group(security_group_name) |
155 | 182 | if 'instance_id' in self.data: | 180 | if 'instance_id' in self.data: |
156 | 183 | self.conn.terminate_instances([self.data['instance_id']]) | 181 | self.conn.terminate_instances([self.data['instance_id']]) |
157 | 184 | |||
158 | 185 | if __name__ == "__main__": | ||
159 | 186 | suites = {'instance': unittest.makeSuite(InstanceTestsFromPublic)} | ||
160 | 187 | sys.exit(base.run_tests(suites)) | ||
161 | 188 | 182 | ||
162 | === added file 'smoketests/run_tests.py' | |||
163 | --- smoketests/run_tests.py 1970-01-01 00:00:00 +0000 | |||
164 | +++ smoketests/run_tests.py 2011-03-20 19:08:31 +0000 | |||
165 | @@ -0,0 +1,310 @@ | |||
166 | 1 | #!/usr/bin/env python | ||
167 | 2 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 | ||
168 | 3 | |||
169 | 4 | # Copyright 2010 United States Government as represented by the | ||
170 | 5 | # Administrator of the National Aeronautics and Space Administration. | ||
171 | 6 | # All Rights Reserved. | ||
172 | 7 | # | ||
173 | 8 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
174 | 9 | # you may not use this file except in compliance with the License. | ||
175 | 10 | # You may obtain a copy of the License at | ||
176 | 11 | # | ||
177 | 12 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
178 | 13 | # | ||
179 | 14 | # Unless required by applicable law or agreed to in writing, software | ||
180 | 15 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
181 | 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
182 | 17 | # See the License for the specific language governing permissions and | ||
183 | 18 | # limitations under the License. | ||
184 | 19 | |||
185 | 20 | # Colorizer Code is borrowed from Twisted: | ||
186 | 21 | # Copyright (c) 2001-2010 Twisted Matrix Laboratories. | ||
187 | 22 | # | ||
188 | 23 | # Permission is hereby granted, free of charge, to any person obtaining | ||
189 | 24 | # a copy of this software and associated documentation files (the | ||
190 | 25 | # "Software"), to deal in the Software without restriction, including | ||
191 | 26 | # without limitation the rights to use, copy, modify, merge, publish, | ||
192 | 27 | # distribute, sublicense, and/or sell copies of the Software, and to | ||
193 | 28 | # permit persons to whom the Software is furnished to do so, subject to | ||
194 | 29 | # the following conditions: | ||
195 | 30 | # | ||
196 | 31 | # The above copyright notice and this permission notice shall be | ||
197 | 32 | # included in all copies or substantial portions of the Software. | ||
198 | 33 | # | ||
199 | 34 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
200 | 35 | # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
201 | 36 | # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
202 | 37 | # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
203 | 38 | # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
204 | 39 | # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
205 | 40 | # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
206 | 41 | """Unittest runner for Nova. | ||
207 | 42 | |||
208 | 43 | To run all tests | ||
209 | 44 | python run_tests.py | ||
210 | 45 | |||
211 | 46 | To run a single test: | ||
212 | 47 | python run_tests.py test_compute:ComputeTestCase.test_run_terminate | ||
213 | 48 | |||
214 | 49 | To run a single test module: | ||
215 | 50 | python run_tests.py test_compute | ||
216 | 51 | |||
217 | 52 | or | ||
218 | 53 | |||
219 | 54 | python run_tests.py api.test_wsgi | ||
220 | 55 | |||
221 | 56 | """ | ||
222 | 57 | |||
223 | 58 | import gettext | ||
224 | 59 | import os | ||
225 | 60 | import unittest | ||
226 | 61 | import sys | ||
227 | 62 | |||
228 | 63 | # If ../nova/__init__.py exists, add ../ to Python search path, so that | ||
229 | 64 | # it will override what happens to be installed in /usr/(local/)lib/python... | ||
230 | 65 | possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), | ||
231 | 66 | os.pardir, | ||
232 | 67 | os.pardir)) | ||
233 | 68 | if os.path.exists(os.path.join(possible_topdir, 'nova', '__init__.py')): | ||
234 | 69 | sys.path.insert(0, possible_topdir) | ||
235 | 70 | |||
236 | 71 | |||
237 | 72 | gettext.install('nova', unicode=1) | ||
238 | 73 | |||
239 | 74 | from nose import config | ||
240 | 75 | from nose import core | ||
241 | 76 | from nose import result | ||
242 | 77 | |||
243 | 78 | from smoketests import flags | ||
244 | 79 | FLAGS = flags.FLAGS | ||
245 | 80 | |||
246 | 81 | |||
247 | 82 | class _AnsiColorizer(object): | ||
248 | 83 | """ | ||
249 | 84 | A colorizer is an object that loosely wraps around a stream, allowing | ||
250 | 85 | callers to write text to the stream in a particular color. | ||
251 | 86 | |||
252 | 87 | Colorizer classes must implement C{supported()} and C{write(text, color)}. | ||
253 | 88 | """ | ||
254 | 89 | _colors = dict(black=30, red=31, green=32, yellow=33, | ||
255 | 90 | blue=34, magenta=35, cyan=36, white=37) | ||
256 | 91 | |||
257 | 92 | def __init__(self, stream): | ||
258 | 93 | self.stream = stream | ||
259 | 94 | |||
260 | 95 | def supported(cls, stream=sys.stdout): | ||
261 | 96 | """ | ||
262 | 97 | A class method that returns True if the current platform supports | ||
263 | 98 | coloring terminal output using this method. Returns False otherwise. | ||
264 | 99 | """ | ||
265 | 100 | if not stream.isatty(): | ||
266 | 101 | return False # auto color only on TTYs | ||
267 | 102 | try: | ||
268 | 103 | import curses | ||
269 | 104 | except ImportError: | ||
270 | 105 | return False | ||
271 | 106 | else: | ||
272 | 107 | try: | ||
273 | 108 | try: | ||
274 | 109 | return curses.tigetnum("colors") > 2 | ||
275 | 110 | except curses.error: | ||
276 | 111 | curses.setupterm() | ||
277 | 112 | return curses.tigetnum("colors") > 2 | ||
278 | 113 | except: | ||
279 | 114 | raise | ||
280 | 115 | # guess false in case of error | ||
281 | 116 | return False | ||
282 | 117 | supported = classmethod(supported) | ||
283 | 118 | |||
284 | 119 | def write(self, text, color): | ||
285 | 120 | """ | ||
286 | 121 | Write the given text to the stream in the given color. | ||
287 | 122 | |||
288 | 123 | @param text: Text to be written to the stream. | ||
289 | 124 | |||
290 | 125 | @param color: A string label for a color. e.g. 'red', 'white'. | ||
291 | 126 | """ | ||
292 | 127 | color = self._colors[color] | ||
293 | 128 | self.stream.write('\x1b[%s;1m%s\x1b[0m' % (color, text)) | ||
294 | 129 | |||
295 | 130 | |||
296 | 131 | class _Win32Colorizer(object): | ||
297 | 132 | """ | ||
298 | 133 | See _AnsiColorizer docstring. | ||
299 | 134 | """ | ||
300 | 135 | def __init__(self, stream): | ||
301 | 136 | from win32console import GetStdHandle, STD_OUT_HANDLE, \ | ||
302 | 137 | FOREGROUND_RED, FOREGROUND_BLUE, FOREGROUND_GREEN, \ | ||
303 | 138 | FOREGROUND_INTENSITY | ||
304 | 139 | red, green, blue, bold = (FOREGROUND_RED, FOREGROUND_GREEN, | ||
305 | 140 | FOREGROUND_BLUE, FOREGROUND_INTENSITY) | ||
306 | 141 | self.stream = stream | ||
307 | 142 | self.screenBuffer = GetStdHandle(STD_OUT_HANDLE) | ||
308 | 143 | self._colors = { | ||
309 | 144 | 'normal': red | green | blue, | ||
310 | 145 | 'red': red | bold, | ||
311 | 146 | 'green': green | bold, | ||
312 | 147 | 'blue': blue | bold, | ||
313 | 148 | 'yellow': red | green | bold, | ||
314 | 149 | 'magenta': red | blue | bold, | ||
315 | 150 | 'cyan': green | blue | bold, | ||
316 | 151 | 'white': red | green | blue | bold | ||
317 | 152 | } | ||
318 | 153 | |||
319 | 154 | def supported(cls, stream=sys.stdout): | ||
320 | 155 | try: | ||
321 | 156 | import win32console | ||
322 | 157 | screenBuffer = win32console.GetStdHandle( | ||
323 | 158 | win32console.STD_OUT_HANDLE) | ||
324 | 159 | except ImportError: | ||
325 | 160 | return False | ||
326 | 161 | import pywintypes | ||
327 | 162 | try: | ||
328 | 163 | screenBuffer.SetConsoleTextAttribute( | ||
329 | 164 | win32console.FOREGROUND_RED | | ||
330 | 165 | win32console.FOREGROUND_GREEN | | ||
331 | 166 | win32console.FOREGROUND_BLUE) | ||
332 | 167 | except pywintypes.error: | ||
333 | 168 | return False | ||
334 | 169 | else: | ||
335 | 170 | return True | ||
336 | 171 | supported = classmethod(supported) | ||
337 | 172 | |||
338 | 173 | def write(self, text, color): | ||
339 | 174 | color = self._colors[color] | ||
340 | 175 | self.screenBuffer.SetConsoleTextAttribute(color) | ||
341 | 176 | self.stream.write(text) | ||
342 | 177 | self.screenBuffer.SetConsoleTextAttribute(self._colors['normal']) | ||
343 | 178 | |||
344 | 179 | |||
345 | 180 | class _NullColorizer(object): | ||
346 | 181 | """ | ||
347 | 182 | See _AnsiColorizer docstring. | ||
348 | 183 | """ | ||
349 | 184 | def __init__(self, stream): | ||
350 | 185 | self.stream = stream | ||
351 | 186 | |||
352 | 187 | def supported(cls, stream=sys.stdout): | ||
353 | 188 | return True | ||
354 | 189 | supported = classmethod(supported) | ||
355 | 190 | |||
356 | 191 | def write(self, text, color): | ||
357 | 192 | self.stream.write(text) | ||
358 | 193 | |||
359 | 194 | |||
360 | 195 | class NovaTestResult(result.TextTestResult): | ||
361 | 196 | def __init__(self, *args, **kw): | ||
362 | 197 | result.TextTestResult.__init__(self, *args, **kw) | ||
363 | 198 | self._last_case = None | ||
364 | 199 | self.colorizer = None | ||
365 | 200 | # NOTE(vish): reset stdout for the terminal check | ||
366 | 201 | stdout = sys.stdout | ||
367 | 202 | sys.stdout = sys.__stdout__ | ||
368 | 203 | for colorizer in [_Win32Colorizer, _AnsiColorizer, _NullColorizer]: | ||
369 | 204 | if colorizer.supported(): | ||
370 | 205 | self.colorizer = colorizer(self.stream) | ||
371 | 206 | break | ||
372 | 207 | sys.stdout = stdout | ||
373 | 208 | |||
374 | 209 | def getDescription(self, test): | ||
375 | 210 | return str(test) | ||
376 | 211 | |||
377 | 212 | # NOTE(vish): copied from unittest with edit to add color | ||
378 | 213 | def addSuccess(self, test): | ||
379 | 214 | unittest.TestResult.addSuccess(self, test) | ||
380 | 215 | if self.showAll: | ||
381 | 216 | self.colorizer.write("OK", 'green') | ||
382 | 217 | self.stream.writeln() | ||
383 | 218 | elif self.dots: | ||
384 | 219 | self.stream.write('.') | ||
385 | 220 | self.stream.flush() | ||
386 | 221 | |||
387 | 222 | # NOTE(vish): copied from unittest with edit to add color | ||
388 | 223 | def addFailure(self, test, err): | ||
389 | 224 | unittest.TestResult.addFailure(self, test, err) | ||
390 | 225 | if self.showAll: | ||
391 | 226 | self.colorizer.write("FAIL", 'red') | ||
392 | 227 | self.stream.writeln() | ||
393 | 228 | elif self.dots: | ||
394 | 229 | self.stream.write('F') | ||
395 | 230 | self.stream.flush() | ||
396 | 231 | |||
397 | 232 | # NOTE(vish): copied from nose with edit to add color | ||
398 | 233 | def addError(self, test, err): | ||
399 | 234 | """Overrides normal addError to add support for | ||
400 | 235 | errorClasses. If the exception is a registered class, the | ||
401 | 236 | error will be added to the list for that class, not errors. | ||
402 | 237 | """ | ||
403 | 238 | stream = getattr(self, 'stream', None) | ||
404 | 239 | ec, ev, tb = err | ||
405 | 240 | try: | ||
406 | 241 | exc_info = self._exc_info_to_string(err, test) | ||
407 | 242 | except TypeError: | ||
408 | 243 | # 2.3 compat | ||
409 | 244 | exc_info = self._exc_info_to_string(err) | ||
410 | 245 | for cls, (storage, label, isfail) in self.errorClasses.items(): | ||
411 | 246 | if result.isclass(ec) and issubclass(ec, cls): | ||
412 | 247 | if isfail: | ||
413 | 248 | test.passed = False | ||
414 | 249 | storage.append((test, exc_info)) | ||
415 | 250 | # Might get patched into a streamless result | ||
416 | 251 | if stream is not None: | ||
417 | 252 | if self.showAll: | ||
418 | 253 | message = [label] | ||
419 | 254 | detail = result._exception_detail(err[1]) | ||
420 | 255 | if detail: | ||
421 | 256 | message.append(detail) | ||
422 | 257 | stream.writeln(": ".join(message)) | ||
423 | 258 | elif self.dots: | ||
424 | 259 | stream.write(label[:1]) | ||
425 | 260 | return | ||
426 | 261 | self.errors.append((test, exc_info)) | ||
427 | 262 | test.passed = False | ||
428 | 263 | if stream is not None: | ||
429 | 264 | if self.showAll: | ||
430 | 265 | self.colorizer.write("ERROR", 'red') | ||
431 | 266 | self.stream.writeln() | ||
432 | 267 | elif self.dots: | ||
433 | 268 | stream.write('E') | ||
434 | 269 | |||
435 | 270 | def startTest(self, test): | ||
436 | 271 | unittest.TestResult.startTest(self, test) | ||
437 | 272 | current_case = test.test.__class__.__name__ | ||
438 | 273 | |||
439 | 274 | if self.showAll: | ||
440 | 275 | if current_case != self._last_case: | ||
441 | 276 | self.stream.writeln(current_case) | ||
442 | 277 | self._last_case = current_case | ||
443 | 278 | |||
444 | 279 | self.stream.write( | ||
445 | 280 | ' %s' % str(test.test._testMethodName).ljust(60)) | ||
446 | 281 | self.stream.flush() | ||
447 | 282 | |||
448 | 283 | |||
449 | 284 | class NovaTestRunner(core.TextTestRunner): | ||
450 | 285 | def _makeResult(self): | ||
451 | 286 | return NovaTestResult(self.stream, | ||
452 | 287 | self.descriptions, | ||
453 | 288 | self.verbosity, | ||
454 | 289 | self.config) | ||
455 | 290 | |||
456 | 291 | |||
457 | 292 | if __name__ == '__main__': | ||
458 | 293 | if not os.getenv('EC2_ACCESS_KEY'): | ||
459 | 294 | print _('Missing EC2 environment variables. Please ' \ | ||
460 | 295 | 'source the appropriate novarc file before ' \ | ||
461 | 296 | 'running this test.') | ||
462 | 297 | sys.exit(1) | ||
463 | 298 | |||
464 | 299 | argv = FLAGS(sys.argv) | ||
465 | 300 | testdir = os.path.abspath("./") | ||
466 | 301 | c = config.Config(stream=sys.stdout, | ||
467 | 302 | env=os.environ, | ||
468 | 303 | verbosity=3, | ||
469 | 304 | workingDir=testdir, | ||
470 | 305 | plugins=core.DefaultPluginManager()) | ||
471 | 306 | |||
472 | 307 | runner = NovaTestRunner(stream=c.stream, | ||
473 | 308 | verbosity=c.verbosity, | ||
474 | 309 | config=c) | ||
475 | 310 | sys.exit(not core.run(config=c, testRunner=runner, argv=argv)) | ||
476 | 0 | 311 | ||
477 | === renamed file 'smoketests/admin_smoketests.py' => 'smoketests/test_admin.py' | |||
478 | --- smoketests/admin_smoketests.py 2011-01-12 08:47:54 +0000 | |||
479 | +++ smoketests/test_admin.py 2011-03-20 19:08:31 +0000 | |||
480 | @@ -35,10 +35,7 @@ | |||
481 | 35 | from smoketests import base | 35 | from smoketests import base |
482 | 36 | 36 | ||
483 | 37 | 37 | ||
484 | 38 | SUITE_NAMES = '[user]' | ||
485 | 39 | |||
486 | 40 | FLAGS = flags.FLAGS | 38 | FLAGS = flags.FLAGS |
487 | 41 | flags.DEFINE_string('suite', None, 'Specific test suite to run ' + SUITE_NAMES) | ||
488 | 42 | 39 | ||
489 | 43 | # TODO(devamcar): Use random tempfile | 40 | # TODO(devamcar): Use random tempfile |
490 | 44 | ZIP_FILENAME = '/tmp/nova-me-x509.zip' | 41 | ZIP_FILENAME = '/tmp/nova-me-x509.zip' |
491 | @@ -92,7 +89,3 @@ | |||
492 | 92 | os.remove(ZIP_FILENAME) | 89 | os.remove(ZIP_FILENAME) |
493 | 93 | except: | 90 | except: |
494 | 94 | pass | 91 | pass |
495 | 95 | |||
496 | 96 | if __name__ == "__main__": | ||
497 | 97 | suites = {'user': unittest.makeSuite(UserTests)} | ||
498 | 98 | sys.exit(base.run_tests(suites)) | ||
499 | 99 | 92 | ||
500 | === renamed file 'smoketests/netadmin_smoketests.py' => 'smoketests/test_netadmin.py' | |||
501 | --- smoketests/netadmin_smoketests.py 2011-02-23 02:04:32 +0000 | |||
502 | +++ smoketests/test_netadmin.py 2011-03-20 19:08:31 +0000 | |||
503 | @@ -21,7 +21,6 @@ | |||
504 | 21 | import random | 21 | import random |
505 | 22 | import sys | 22 | import sys |
506 | 23 | import time | 23 | import time |
507 | 24 | import unittest | ||
508 | 25 | 24 | ||
509 | 26 | # If ../nova/__init__.py exists, add ../ to Python search path, so that | 25 | # If ../nova/__init__.py exists, add ../ to Python search path, so that |
510 | 27 | # it will override what happens to be installed in /usr/(local/)lib/python... | 26 | # it will override what happens to be installed in /usr/(local/)lib/python... |
511 | @@ -74,8 +73,10 @@ | |||
512 | 74 | groups = self.conn.get_all_security_groups(['default']) | 73 | groups = self.conn.get_all_security_groups(['default']) |
513 | 75 | for rule in groups[0].rules: | 74 | for rule in groups[0].rules: |
514 | 76 | if (rule.ip_protocol == 'tcp' and | 75 | if (rule.ip_protocol == 'tcp' and |
516 | 77 | rule.from_port <= 22 and rule.to_port >= 22): | 76 | int(rule.from_port) <= 22 and |
517 | 77 | int(rule.to_port) >= 22): | ||
518 | 78 | ssh_authorized = True | 78 | ssh_authorized = True |
519 | 79 | break | ||
520 | 79 | if not ssh_authorized: | 80 | if not ssh_authorized: |
521 | 80 | self.conn.authorize_security_group('default', | 81 | self.conn.authorize_security_group('default', |
522 | 81 | ip_protocol='tcp', | 82 | ip_protocol='tcp', |
523 | @@ -137,11 +138,6 @@ | |||
524 | 137 | if not self.wait_for_running(self.data['instance']): | 138 | if not self.wait_for_running(self.data['instance']): |
525 | 138 | self.fail('instance failed to start') | 139 | self.fail('instance failed to start') |
526 | 139 | self.data['instance'].update() | 140 | self.data['instance'].update() |
527 | 140 | if not self.wait_for_ping(self.data['instance'].private_dns_name): | ||
528 | 141 | self.fail('could not ping instance') | ||
529 | 142 | if not self.wait_for_ssh(self.data['instance'].private_dns_name, | ||
530 | 143 | TEST_KEY): | ||
531 | 144 | self.fail('could not ssh to instance') | ||
532 | 145 | 141 | ||
533 | 146 | def test_003_can_authorize_security_group_ingress(self): | 142 | def test_003_can_authorize_security_group_ingress(self): |
534 | 147 | self.assertTrue(self.conn.authorize_security_group(TEST_GROUP, | 143 | self.assertTrue(self.conn.authorize_security_group(TEST_GROUP, |
535 | @@ -185,10 +181,3 @@ | |||
536 | 185 | self.assertFalse(TEST_GROUP in [group.name for group in groups]) | 181 | self.assertFalse(TEST_GROUP in [group.name for group in groups]) |
537 | 186 | self.conn.terminate_instances([self.data['instance'].id]) | 182 | self.conn.terminate_instances([self.data['instance'].id]) |
538 | 187 | self.assertTrue(self.conn.release_address(self.data['public_ip'])) | 183 | self.assertTrue(self.conn.release_address(self.data['public_ip'])) |
539 | 188 | |||
540 | 189 | |||
541 | 190 | if __name__ == "__main__": | ||
542 | 191 | suites = {'address': unittest.makeSuite(AddressTests), | ||
543 | 192 | 'security_group': unittest.makeSuite(SecurityGroupTests) | ||
544 | 193 | } | ||
545 | 194 | sys.exit(base.run_tests(suites)) | ||
546 | 195 | 184 | ||
547 | === renamed file 'smoketests/sysadmin_smoketests.py' => 'smoketests/test_sysadmin.py' | |||
548 | --- smoketests/sysadmin_smoketests.py 2011-03-18 01:54:51 +0000 | |||
549 | +++ smoketests/test_sysadmin.py 2011-03-20 19:08:31 +0000 | |||
550 | @@ -16,12 +16,12 @@ | |||
551 | 16 | # License for the specific language governing permissions and limitations | 16 | # License for the specific language governing permissions and limitations |
552 | 17 | # under the License. | 17 | # under the License. |
553 | 18 | 18 | ||
554 | 19 | import commands | ||
555 | 20 | import os | 19 | import os |
556 | 21 | import random | 20 | import random |
557 | 22 | import sys | 21 | import sys |
558 | 23 | import time | 22 | import time |
560 | 24 | import unittest | 23 | import tempfile |
561 | 24 | import shutil | ||
562 | 25 | 25 | ||
563 | 26 | # If ../nova/__init__.py exists, add ../ to Python search path, so that | 26 | # If ../nova/__init__.py exists, add ../ to Python search path, so that |
564 | 27 | # it will override what happens to be installed in /usr/(local/)lib/python... | 27 | # it will override what happens to be installed in /usr/(local/)lib/python... |
565 | @@ -48,10 +48,18 @@ | |||
566 | 48 | 48 | ||
567 | 49 | class ImageTests(base.UserSmokeTestCase): | 49 | class ImageTests(base.UserSmokeTestCase): |
568 | 50 | def test_001_can_bundle_image(self): | 50 | def test_001_can_bundle_image(self): |
570 | 51 | self.assertTrue(self.bundle_image(FLAGS.bundle_image)) | 51 | self.data['tempdir'] = tempfile.mkdtemp() |
571 | 52 | self.assertTrue(self.bundle_image(FLAGS.bundle_image, | ||
572 | 53 | self.data['tempdir'])) | ||
573 | 52 | 54 | ||
574 | 53 | def test_002_can_upload_image(self): | 55 | def test_002_can_upload_image(self): |
576 | 54 | self.assertTrue(self.upload_image(TEST_BUCKET, FLAGS.bundle_image)) | 56 | try: |
577 | 57 | self.assertTrue(self.upload_image(TEST_BUCKET, | ||
578 | 58 | FLAGS.bundle_image, | ||
579 | 59 | self.data['tempdir'])) | ||
580 | 60 | finally: | ||
581 | 61 | if os.path.exists(self.data['tempdir']): | ||
582 | 62 | shutil.rmtree(self.data['tempdir']) | ||
583 | 55 | 63 | ||
584 | 56 | def test_003_can_register_image(self): | 64 | def test_003_can_register_image(self): |
585 | 57 | image_id = self.conn.register_image('%s/%s.manifest.xml' % | 65 | image_id = self.conn.register_image('%s/%s.manifest.xml' % |
586 | @@ -192,7 +200,7 @@ | |||
587 | 192 | self.assertEqual(volume.size, 1) | 200 | self.assertEqual(volume.size, 1) |
588 | 193 | self.data['volume'] = volume | 201 | self.data['volume'] = volume |
589 | 194 | # Give network time to find volume. | 202 | # Give network time to find volume. |
591 | 195 | time.sleep(10) | 203 | time.sleep(5) |
592 | 196 | 204 | ||
593 | 197 | def test_002_can_attach_volume(self): | 205 | def test_002_can_attach_volume(self): |
594 | 198 | volume = self.data['volume'] | 206 | volume = self.data['volume'] |
595 | @@ -205,6 +213,8 @@ | |||
596 | 205 | else: | 213 | else: |
597 | 206 | self.fail('cannot attach volume with state %s' % volume.status) | 214 | self.fail('cannot attach volume with state %s' % volume.status) |
598 | 207 | 215 | ||
599 | 216 | # Give volume some time to be ready. | ||
600 | 217 | time.sleep(5) | ||
601 | 208 | volume.attach(self.data['instance'].id, self.device) | 218 | volume.attach(self.data['instance'].id, self.device) |
602 | 209 | 219 | ||
603 | 210 | # wait | 220 | # wait |
604 | @@ -219,7 +229,7 @@ | |||
605 | 219 | self.assertTrue(volume.status.startswith('in-use')) | 229 | self.assertTrue(volume.status.startswith('in-use')) |
606 | 220 | 230 | ||
607 | 221 | # Give instance time to recognize volume. | 231 | # Give instance time to recognize volume. |
609 | 222 | time.sleep(10) | 232 | time.sleep(5) |
610 | 223 | 233 | ||
611 | 224 | def test_003_can_mount_volume(self): | 234 | def test_003_can_mount_volume(self): |
612 | 225 | ip = self.data['instance'].private_dns_name | 235 | ip = self.data['instance'].private_dns_name |
613 | @@ -256,12 +266,13 @@ | |||
614 | 256 | ip = self.data['instance'].private_dns_name | 266 | ip = self.data['instance'].private_dns_name |
615 | 257 | conn = self.connect_ssh(ip, TEST_KEY) | 267 | conn = self.connect_ssh(ip, TEST_KEY) |
616 | 258 | stdin, stdout, stderr = conn.exec_command( | 268 | stdin, stdout, stderr = conn.exec_command( |
619 | 259 | "df -h | grep %s | awk {'print $2'}" % self.device) | 269 | "blockdev --getsize64 %s" % self.device) |
620 | 260 | out = stdout.read() | 270 | out = stdout.read().strip() |
621 | 261 | conn.close() | 271 | conn.close() |
625 | 262 | if not out.strip() == '1007.9M': | 272 | expected_size = 1024 * 1024 * 1024 |
626 | 263 | self.fail('Volume is not the right size: %s %s' % | 273 | self.assertEquals('%s' % (expected_size,), out, |
627 | 264 | (out, stderr.read())) | 274 | 'Volume is not the right size: %s %s. Expected: %s' % |
628 | 275 | (out, stderr.read(), expected_size)) | ||
629 | 265 | 276 | ||
630 | 266 | def test_006_me_can_umount_volume(self): | 277 | def test_006_me_can_umount_volume(self): |
631 | 267 | ip = self.data['instance'].private_dns_name | 278 | ip = self.data['instance'].private_dns_name |
632 | @@ -284,9 +295,3 @@ | |||
633 | 284 | def test_999_tearDown(self): | 295 | def test_999_tearDown(self): |
634 | 285 | self.conn.terminate_instances([self.data['instance'].id]) | 296 | self.conn.terminate_instances([self.data['instance'].id]) |
635 | 286 | self.conn.delete_key_pair(TEST_KEY) | 297 | self.conn.delete_key_pair(TEST_KEY) |
636 | 287 | |||
637 | 288 | if __name__ == "__main__": | ||
638 | 289 | suites = {'image': unittest.makeSuite(ImageTests), | ||
639 | 290 | 'instance': unittest.makeSuite(InstanceTests), | ||
640 | 291 | 'volume': unittest.makeSuite(VolumeTests)} | ||
641 | 292 | sys.exit(base.run_tests(suites)) |
lgtm. Nice fixes