root / snf-tools / synnefo_tools / burnin / common.py @ 49517b8a
History | View | Annotate | Download (23.1 kB)
1 |
# Copyright 2013 GRNET S.A. All rights reserved.
|
---|---|
2 |
#
|
3 |
# Redistribution and use in source and binary forms, with or
|
4 |
# without modification, are permitted provided that the following
|
5 |
# conditions are met:
|
6 |
#
|
7 |
# 1. Redistributions of source code must retain the above
|
8 |
# copyright notice, this list of conditions and the following
|
9 |
# disclaimer.
|
10 |
#
|
11 |
# 2. Redistributions in binary form must reproduce the above
|
12 |
# copyright notice, this list of conditions and the following
|
13 |
# disclaimer in the documentation and/or other materials
|
14 |
# provided with the distribution.
|
15 |
#
|
16 |
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
17 |
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
18 |
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
19 |
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
20 |
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
21 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
22 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
23 |
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
24 |
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
25 |
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
26 |
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
27 |
# POSSIBILITY OF SUCH DAMAGE.
|
28 |
#
|
29 |
# The views and conclusions contained in the software and
|
30 |
# documentation are those of the authors and should not be
|
31 |
# interpreted as representing official policies, either expressed
|
32 |
# or implied, of GRNET S.A.
|
33 |
|
34 |
"""
|
35 |
Common utils for burnin tests
|
36 |
|
37 |
"""
|
38 |
|
39 |
import re |
40 |
import shutil |
41 |
import unittest |
42 |
import datetime |
43 |
import tempfile |
44 |
import traceback |
45 |
|
46 |
from kamaki.clients.cyclades import CycladesClient, CycladesNetworkClient |
47 |
from kamaki.clients.astakos import AstakosClient |
48 |
from kamaki.clients.compute import ComputeClient |
49 |
from kamaki.clients.pithos import PithosClient |
50 |
from kamaki.clients.image import ImageClient |
51 |
|
52 |
from synnefo_tools.burnin.logger import Log |
53 |
|
54 |
|
55 |
# --------------------------------------------------------------------
|
56 |
# Global variables
|
57 |
logger = None # Invalid constant name. pylint: disable-msg=C0103 |
58 |
success = None # Invalid constant name. pylint: disable-msg=C0103 |
59 |
SNF_TEST_PREFIX = "snf-test-"
|
60 |
CONNECTION_RETRY_LIMIT = 2
|
61 |
SYSTEM_USERS = ["images@okeanos.grnet.gr", "images@demo.synnefo.org"] |
62 |
KB = 2**10 |
63 |
MB = 2**20 |
64 |
GB = 2**30 |
65 |
|
66 |
|
67 |
# --------------------------------------------------------------------
|
68 |
# BurninTestResult class
|
69 |
class BurninTestResult(unittest.TestResult): |
70 |
"""Modify the TextTestResult class"""
|
71 |
def __init__(self): |
72 |
super(BurninTestResult, self).__init__() |
73 |
|
74 |
# Test parameters
|
75 |
self.failfast = True |
76 |
|
77 |
def startTest(self, test): # noqa |
78 |
"""Called when the test case test is about to be run"""
|
79 |
super(BurninTestResult, self).startTest(test) |
80 |
logger.log( |
81 |
test.__class__.__name__, |
82 |
test.shortDescription() or 'Test %s' % test.__class__.__name__) |
83 |
|
84 |
# Method could be a function. pylint: disable-msg=R0201
|
85 |
def _test_failed(self, test, err): |
86 |
"""Test failed"""
|
87 |
# Get class name
|
88 |
if test.__class__.__name__ == "_ErrorHolder": |
89 |
class_name = test.id().split('.')[-1].rstrip(')') |
90 |
else:
|
91 |
class_name = test.__class__.__name__ |
92 |
err_msg = str(test) + "... failed (%s)." |
93 |
timestamp = datetime.datetime.strftime( |
94 |
datetime.datetime.now(), "%a %b %d %Y %H:%M:%S")
|
95 |
logger.error(class_name, err_msg, timestamp) |
96 |
(err_type, err_value, err_trace) = err |
97 |
trcback = traceback.format_exception(err_type, err_value, err_trace) |
98 |
logger.info(class_name, trcback) |
99 |
|
100 |
def addError(self, test, err): # noqa |
101 |
"""Called when the test case test raises an unexpected exception"""
|
102 |
super(BurninTestResult, self).addError(test, err) |
103 |
self._test_failed(test, err)
|
104 |
|
105 |
def addFailure(self, test, err): # noqa |
106 |
"""Called when the test case test signals a failure"""
|
107 |
super(BurninTestResult, self).addFailure(test, err) |
108 |
self._test_failed(test, err)
|
109 |
|
110 |
|
111 |
# --------------------------------------------------------------------
|
112 |
# Helper Classes
|
113 |
# Too few public methods. pylint: disable-msg=R0903
|
114 |
# Too many instance attributes. pylint: disable-msg=R0902
|
115 |
class Clients(object): |
116 |
"""Our kamaki clients"""
|
117 |
auth_url = None
|
118 |
token = None
|
119 |
# Astakos
|
120 |
astakos = None
|
121 |
retry = CONNECTION_RETRY_LIMIT |
122 |
# Compute
|
123 |
compute = None
|
124 |
compute_url = None
|
125 |
# Cyclades
|
126 |
cyclades = None
|
127 |
# Network
|
128 |
network = None
|
129 |
network_url = None
|
130 |
# Pithos
|
131 |
pithos = None
|
132 |
pithos_url = None
|
133 |
# Image
|
134 |
image = None
|
135 |
image_url = None
|
136 |
|
137 |
def initialize_clients(self): |
138 |
"""Initialize all the Kamaki Clients"""
|
139 |
self.astakos = AstakosClient(self.auth_url, self.token) |
140 |
self.astakos.CONNECTION_RETRY_LIMIT = self.retry |
141 |
|
142 |
self.compute_url = \
|
143 |
self.astakos.get_service_endpoints('compute')['publicURL'] |
144 |
self.compute = ComputeClient(self.compute_url, self.token) |
145 |
self.compute.CONNECTION_RETRY_LIMIT = self.retry |
146 |
|
147 |
self.cyclades = CycladesClient(self.compute_url, self.token) |
148 |
self.cyclades.CONNECTION_RETRY_LIMIT = self.retry |
149 |
|
150 |
self.network_url = \
|
151 |
self.astakos.get_service_endpoints('network')['publicURL'] |
152 |
self.network = CycladesNetworkClient(self.network_url, self.token) |
153 |
self.network.CONNECTION_RETRY_LIMIT = self.retry |
154 |
|
155 |
self.pithos_url = self.astakos.\ |
156 |
get_service_endpoints('object-store')['publicURL'] |
157 |
self.pithos = PithosClient(self.pithos_url, self.token) |
158 |
self.pithos.CONNECTION_RETRY_LIMIT = self.retry |
159 |
|
160 |
self.image_url = \
|
161 |
self.astakos.get_service_endpoints('image')['publicURL'] |
162 |
self.image = ImageClient(self.image_url, self.token) |
163 |
self.image.CONNECTION_RETRY_LIMIT = self.retry |
164 |
|
165 |
|
166 |
class Proper(object): |
167 |
"""A descriptor used by tests implementing the TestCase class
|
168 |
|
169 |
Since each instance of the TestCase will only be used to run a single
|
170 |
test method (a new fixture is created for each test) the attributes can
|
171 |
not be saved in the class instances. Instead we use descriptors.
|
172 |
|
173 |
"""
|
174 |
def __init__(self, value=None): |
175 |
self.val = value
|
176 |
|
177 |
def __get__(self, obj, objtype=None): |
178 |
return self.val |
179 |
|
180 |
def __set__(self, obj, value): |
181 |
self.val = value
|
182 |
|
183 |
|
184 |
# --------------------------------------------------------------------
|
185 |
# BurninTests class
|
186 |
# Too many public methods (45/20). pylint: disable-msg=R0904
|
187 |
class BurninTests(unittest.TestCase): |
188 |
"""Common class that all burnin tests should implement"""
|
189 |
clients = Clients() |
190 |
run_id = None
|
191 |
use_ipv6 = None
|
192 |
action_timeout = None
|
193 |
action_warning = None
|
194 |
query_interval = None
|
195 |
system_user = None
|
196 |
images = None
|
197 |
flavors = None
|
198 |
delete_stale = False
|
199 |
temp_directory = None
|
200 |
failfast = None
|
201 |
temp_containers = [] |
202 |
|
203 |
|
204 |
quotas = Proper(value=None)
|
205 |
|
206 |
@classmethod
|
207 |
def setUpClass(cls): # noqa |
208 |
"""Initialize BurninTests"""
|
209 |
cls.suite_name = cls.__name__ |
210 |
logger.testsuite_start(cls.suite_name) |
211 |
|
212 |
# Set test parameters
|
213 |
cls.longMessage = True
|
214 |
|
215 |
def test_000_clients_setup(self): |
216 |
"""Initializing astakos/cyclades/pithos clients"""
|
217 |
# Update class attributes
|
218 |
self.clients.initialize_clients()
|
219 |
self.info("Astakos auth url is %s", self.clients.auth_url) |
220 |
self.info("Cyclades url is %s", self.clients.compute_url) |
221 |
self.info("Network url is %s", self.clients.network_url) |
222 |
self.info("Pithos url is %s", self.clients.pithos_url) |
223 |
self.info("Image url is %s", self.clients.image_url) |
224 |
|
225 |
self.quotas = self._get_quotas() |
226 |
self.info(" Disk usage is %s bytes", |
227 |
self.quotas['system']['cyclades.disk']['usage']) |
228 |
self.info(" VM usage is %s", |
229 |
self.quotas['system']['cyclades.vm']['usage']) |
230 |
self.info(" DiskSpace usage is %s bytes", |
231 |
self.quotas['system']['pithos.diskspace']['usage']) |
232 |
self.info(" Ram usage is %s bytes", |
233 |
self.quotas['system']['cyclades.ram']['usage']) |
234 |
self.info(" Floating IPs usage is %s", |
235 |
self.quotas['system']['cyclades.floating_ip']['usage']) |
236 |
self.info(" CPU usage is %s", |
237 |
self.quotas['system']['cyclades.cpu']['usage']) |
238 |
self.info(" Network usage is %s", |
239 |
self.quotas['system']['cyclades.network.private']['usage']) |
240 |
|
241 |
def _run_tests(self, tcases): |
242 |
"""Run some generated testcases"""
|
243 |
global success # Using global. pylint: disable-msg=C0103,W0603,W0602 |
244 |
|
245 |
for tcase in tcases: |
246 |
self.info("Running testsuite %s", tcase.__name__) |
247 |
success = run_test(tcase) and success
|
248 |
if self.failfast and not success: |
249 |
break
|
250 |
|
251 |
# ----------------------------------
|
252 |
# Loggers helper functions
|
253 |
def log(self, msg, *args): |
254 |
"""Pass the section value to logger"""
|
255 |
logger.log(self.suite_name, msg, *args)
|
256 |
|
257 |
def info(self, msg, *args): |
258 |
"""Pass the section value to logger"""
|
259 |
logger.info(self.suite_name, msg, *args)
|
260 |
|
261 |
def debug(self, msg, *args): |
262 |
"""Pass the section value to logger"""
|
263 |
logger.debug(self.suite_name, msg, *args)
|
264 |
|
265 |
def warning(self, msg, *args): |
266 |
"""Pass the section value to logger"""
|
267 |
logger.warning(self.suite_name, msg, *args)
|
268 |
|
269 |
def error(self, msg, *args): |
270 |
"""Pass the section value to logger"""
|
271 |
logger.error(self.suite_name, msg, *args)
|
272 |
|
273 |
# ----------------------------------
|
274 |
# Helper functions that every testsuite may need
|
275 |
def _get_uuid(self): |
276 |
"""Get our uuid"""
|
277 |
authenticate = self.clients.astakos.authenticate()
|
278 |
uuid = authenticate['access']['user']['id'] |
279 |
self.info("User's uuid is %s", uuid) |
280 |
return uuid
|
281 |
|
282 |
def _get_username(self): |
283 |
"""Get our User Name"""
|
284 |
authenticate = self.clients.astakos.authenticate()
|
285 |
username = authenticate['access']['user']['name'] |
286 |
self.info("User's name is %s", username) |
287 |
return username
|
288 |
|
289 |
def _create_tmp_directory(self): |
290 |
"""Create a tmp directory"""
|
291 |
temp_dir = tempfile.mkdtemp(dir=self.temp_directory)
|
292 |
self.info("Temp directory %s created", temp_dir) |
293 |
return temp_dir
|
294 |
|
295 |
def _remove_tmp_directory(self, tmp_dir): |
296 |
"""Remove a tmp directory"""
|
297 |
try:
|
298 |
shutil.rmtree(tmp_dir) |
299 |
self.info("Temp directory %s deleted", tmp_dir) |
300 |
except OSError: |
301 |
pass
|
302 |
|
303 |
def _get_uuid_of_system_user(self): |
304 |
"""Get the uuid of the system user
|
305 |
|
306 |
This is the user that upload the 'official' images.
|
307 |
|
308 |
"""
|
309 |
self.info("Getting the uuid of the system user") |
310 |
system_users = None
|
311 |
if self.system_user is not None: |
312 |
parsed_su = parse_typed_option(self.system_user)
|
313 |
if parsed_su is None: |
314 |
msg = "Invalid system-user format: %s. Must be [id|name]:.+"
|
315 |
self.warning(msg, self.system_user) |
316 |
else:
|
317 |
su_type, su_value = parsed_su |
318 |
if su_type == "name": |
319 |
system_users = [su_value] |
320 |
elif su_type == "id": |
321 |
self.info("System user's uuid is %s", su_value) |
322 |
return su_value
|
323 |
else:
|
324 |
self.error("Unrecognized system-user type %s", su_type) |
325 |
self.fail("Unrecognized system-user type") |
326 |
|
327 |
if system_users is None: |
328 |
system_users = SYSTEM_USERS |
329 |
|
330 |
uuids = self.clients.astakos.get_uuids(system_users)
|
331 |
for su_name in system_users: |
332 |
self.info("Trying username %s", su_name) |
333 |
if su_name in uuids: |
334 |
self.info("System user's uuid is %s", uuids[su_name]) |
335 |
return uuids[su_name]
|
336 |
|
337 |
self.warning("No system user found") |
338 |
return None |
339 |
|
340 |
def _skip_if(self, condition, msg): |
341 |
"""Skip tests"""
|
342 |
if condition:
|
343 |
self.info("Test skipped: %s" % msg) |
344 |
self.skipTest(msg)
|
345 |
|
346 |
# ----------------------------------
|
347 |
# Flavors
|
348 |
def _get_list_of_flavors(self, detail=False): |
349 |
"""Get (detailed) list of flavors"""
|
350 |
if detail:
|
351 |
self.info("Getting detailed list of flavors") |
352 |
else:
|
353 |
self.info("Getting simple list of flavors") |
354 |
flavors = self.clients.compute.list_flavors(detail=detail)
|
355 |
return flavors
|
356 |
|
357 |
def _find_flavors(self, patterns, flavors=None): |
358 |
"""Find a list of suitable flavors to use
|
359 |
|
360 |
The patterns is a list of `typed_options'. A list of all flavors
|
361 |
matching this patterns will be returned.
|
362 |
|
363 |
"""
|
364 |
if flavors is None: |
365 |
flavors = self._get_list_of_flavors(detail=True) |
366 |
|
367 |
ret_flavors = [] |
368 |
for ptrn in patterns: |
369 |
parsed_ptrn = parse_typed_option(ptrn) |
370 |
if parsed_ptrn is None: |
371 |
msg = "Invalid flavor format: %s. Must be [id|name]:.+"
|
372 |
self.warning(msg, ptrn)
|
373 |
continue
|
374 |
flv_type, flv_value = parsed_ptrn |
375 |
if flv_type == "name": |
376 |
# Filter flavor by name
|
377 |
msg = "Trying to find a flavor with name %s"
|
378 |
self.info(msg, flv_value)
|
379 |
filtered_flvs = \ |
380 |
[f for f in flavors if |
381 |
re.search(flv_value, f['name'], flags=re.I) is not None] |
382 |
elif flv_type == "id": |
383 |
# Filter flavors by id
|
384 |
msg = "Trying to find a flavor with id %s"
|
385 |
self.info(msg, flv_value)
|
386 |
filtered_flvs = \ |
387 |
[f for f in flavors if str(f['id']) == flv_value] |
388 |
else:
|
389 |
self.error("Unrecognized flavor type %s", flv_type) |
390 |
self.fail("Unrecognized flavor type") |
391 |
|
392 |
# Append and continue
|
393 |
ret_flavors.extend(filtered_flvs) |
394 |
|
395 |
self.assertGreater(len(ret_flavors), 0, |
396 |
"No matching flavors found")
|
397 |
return ret_flavors
|
398 |
|
399 |
# ----------------------------------
|
400 |
# Images
|
401 |
def _get_list_of_images(self, detail=False): |
402 |
"""Get (detailed) list of images"""
|
403 |
if detail:
|
404 |
self.info("Getting detailed list of images") |
405 |
else:
|
406 |
self.info("Getting simple list of images") |
407 |
images = self.clients.image.list_public(detail=detail)
|
408 |
# Remove images registered by burnin
|
409 |
images = [img for img in images |
410 |
if not img['name'].startswith(SNF_TEST_PREFIX)] |
411 |
return images
|
412 |
|
413 |
def _get_list_of_sys_images(self, images=None): |
414 |
"""Get (detailed) list of images registered by system user or by me"""
|
415 |
self.info("Getting list of images registered by system user or by me") |
416 |
if images is None: |
417 |
images = self._get_list_of_images(detail=True) |
418 |
|
419 |
su_uuid = self._get_uuid_of_system_user()
|
420 |
my_uuid = self._get_uuid()
|
421 |
ret_images = [i for i in images |
422 |
if i['owner'] == su_uuid or i['owner'] == my_uuid] |
423 |
|
424 |
return ret_images
|
425 |
|
426 |
def _find_images(self, patterns, images=None): |
427 |
"""Find a list of suitable images to use
|
428 |
|
429 |
The patterns is a list of `typed_options'. A list of all images
|
430 |
matching this patterns will be returned.
|
431 |
|
432 |
"""
|
433 |
if images is None: |
434 |
images = self._get_list_of_sys_images()
|
435 |
|
436 |
ret_images = [] |
437 |
for ptrn in patterns: |
438 |
parsed_ptrn = parse_typed_option(ptrn) |
439 |
if parsed_ptrn is None: |
440 |
msg = "Invalid image format: %s. Must be [id|name]:.+"
|
441 |
self.warning(msg, ptrn)
|
442 |
continue
|
443 |
img_type, img_value = parsed_ptrn |
444 |
if img_type == "name": |
445 |
# Filter image by name
|
446 |
msg = "Trying to find an image with name %s"
|
447 |
self.info(msg, img_value)
|
448 |
filtered_imgs = \ |
449 |
[i for i in images if |
450 |
re.search(img_value, i['name'], flags=re.I) is not None] |
451 |
elif img_type == "id": |
452 |
# Filter images by id
|
453 |
msg = "Trying to find an image with id %s"
|
454 |
self.info(msg, img_value)
|
455 |
filtered_imgs = \ |
456 |
[i for i in images if |
457 |
i['id'].lower() == img_value.lower()]
|
458 |
else:
|
459 |
self.error("Unrecognized image type %s", img_type) |
460 |
self.fail("Unrecognized image type") |
461 |
|
462 |
# Append and continue
|
463 |
ret_images.extend(filtered_imgs) |
464 |
|
465 |
self.assertGreater(len(ret_images), 0, |
466 |
"No matching images found")
|
467 |
return ret_images
|
468 |
|
469 |
# ----------------------------------
|
470 |
# Pithos
|
471 |
def _set_pithos_account(self, account): |
472 |
"""Set the Pithos account"""
|
473 |
assert account, "No pithos account was given" |
474 |
|
475 |
self.info("Setting Pithos account to %s", account) |
476 |
self.clients.pithos.account = account
|
477 |
|
478 |
def _set_pithos_container(self, container): |
479 |
"""Set the Pithos container"""
|
480 |
assert container, "No pithos container was given" |
481 |
|
482 |
self.info("Setting Pithos container to %s", container) |
483 |
self.clients.pithos.container = container
|
484 |
|
485 |
def _get_list_of_containers(self, account=None): |
486 |
"""Get list of containers"""
|
487 |
if account is not None: |
488 |
self._set_pithos_account(account)
|
489 |
self.info("Getting list of containers") |
490 |
return self.clients.pithos.list_containers() |
491 |
|
492 |
def _create_pithos_container(self, container): |
493 |
"""Create a pithos container
|
494 |
|
495 |
If the container exists, nothing will happen
|
496 |
|
497 |
"""
|
498 |
assert container, "No pithos container was given" |
499 |
|
500 |
self.info("Creating pithos container %s", container) |
501 |
self.clients.pithos.create_container(container)
|
502 |
self.temp_containers.append(container)
|
503 |
|
504 |
# ----------------------------------
|
505 |
# Quotas
|
506 |
def _get_quotas(self): |
507 |
"""Get quotas"""
|
508 |
self.info("Getting quotas") |
509 |
# astakos_client = self.clients.astakos.get_client()
|
510 |
return self.clients.astakos.get_quotas() |
511 |
|
512 |
# Invalid argument name. pylint: disable-msg=C0103
|
513 |
# Too many arguments. pylint: disable-msg=R0913
|
514 |
def _check_quotas(self, disk=None, vm=None, diskspace=None, |
515 |
ram=None, ip=None, cpu=None, network=None): |
516 |
"""Check that quotas' changes are consistent"""
|
517 |
assert any(v is None for v in |
518 |
[disk, vm, diskspace, ram, ip, cpu, network]), \ |
519 |
"_check_quotas require arguments"
|
520 |
|
521 |
self.info("Check that quotas' changes are consistent") |
522 |
old_quotas = self.quotas
|
523 |
new_quotas = self._get_quotas()
|
524 |
self.quotas = new_quotas
|
525 |
|
526 |
# Check Disk usage
|
527 |
self._check_quotas_aux(
|
528 |
old_quotas, new_quotas, 'cyclades.disk', disk)
|
529 |
# Check VM usage
|
530 |
self._check_quotas_aux(
|
531 |
old_quotas, new_quotas, 'cyclades.vm', vm)
|
532 |
# Check DiskSpace usage
|
533 |
self._check_quotas_aux(
|
534 |
old_quotas, new_quotas, 'pithos.diskspace', diskspace)
|
535 |
# Check Ram usage
|
536 |
self._check_quotas_aux(
|
537 |
old_quotas, new_quotas, 'cyclades.ram', ram)
|
538 |
# Check Floating IPs usage
|
539 |
self._check_quotas_aux(
|
540 |
old_quotas, new_quotas, 'cyclades.floating_ip', ip)
|
541 |
# Check CPU usage
|
542 |
self._check_quotas_aux(
|
543 |
old_quotas, new_quotas, 'cyclades.cpu', cpu)
|
544 |
# Check Network usage
|
545 |
self._check_quotas_aux(
|
546 |
old_quotas, new_quotas, 'cyclades.network.private', network)
|
547 |
|
548 |
def _check_quotas_aux(self, old_quotas, new_quotas, resource, value): |
549 |
"""Auxiliary function for _check_quotas"""
|
550 |
old_value = old_quotas['system'][resource]['usage'] |
551 |
new_value = new_quotas['system'][resource]['usage'] |
552 |
if value is not None: |
553 |
assert isinstance(value, int), \ |
554 |
"%s value has to be integer" % resource
|
555 |
old_value += value |
556 |
self.assertEqual(old_value, new_value,
|
557 |
"%s quotas don't match" % resource)
|
558 |
|
559 |
|
560 |
# --------------------------------------------------------------------
|
561 |
# Initialize Burnin
|
562 |
def initialize(opts, testsuites, stale_testsuites): |
563 |
"""Initalize burnin
|
564 |
|
565 |
Initialize our logger and burnin state
|
566 |
|
567 |
"""
|
568 |
# Initialize logger
|
569 |
global logger # Using global statement. pylint: disable-msg=C0103,W0603 |
570 |
curr_time = datetime.datetime.now() |
571 |
logger = Log(opts.log_folder, verbose=opts.verbose, |
572 |
use_colors=opts.use_colors, in_parallel=False,
|
573 |
log_level=opts.log_level, curr_time=curr_time) |
574 |
|
575 |
# Initialize clients
|
576 |
Clients.auth_url = opts.auth_url |
577 |
Clients.token = opts.token |
578 |
|
579 |
# Pass the rest options to BurninTests
|
580 |
BurninTests.use_ipv6 = opts.use_ipv6 |
581 |
BurninTests.action_timeout = opts.action_timeout |
582 |
BurninTests.action_warning = opts.action_warning |
583 |
BurninTests.query_interval = opts.query_interval |
584 |
BurninTests.system_user = opts.system_user |
585 |
BurninTests.flavors = opts.flavors |
586 |
BurninTests.images = opts.images |
587 |
BurninTests.delete_stale = opts.delete_stale |
588 |
BurninTests.temp_directory = opts.temp_directory |
589 |
BurninTests.failfast = opts.failfast |
590 |
BurninTests.run_id = SNF_TEST_PREFIX + \ |
591 |
datetime.datetime.strftime(curr_time, "%Y%m%d%H%M%S")
|
592 |
|
593 |
# Choose tests to run
|
594 |
if opts.show_stale:
|
595 |
# We will run the stale_testsuites
|
596 |
return (stale_testsuites, True) |
597 |
|
598 |
if opts.tests != "all": |
599 |
testsuites = opts.tests |
600 |
if opts.exclude_tests is not None: |
601 |
testsuites = [tsuite for tsuite in testsuites |
602 |
if tsuite not in opts.exclude_tests] |
603 |
|
604 |
return (testsuites, opts.failfast)
|
605 |
|
606 |
|
607 |
# --------------------------------------------------------------------
|
608 |
# Run Burnin
|
609 |
def run_burnin(testsuites, failfast=False): |
610 |
"""Run burnin testsuites"""
|
611 |
# Using global. pylint: disable-msg=C0103,W0603,W0602
|
612 |
global logger, success
|
613 |
|
614 |
success = True
|
615 |
run_tests(testsuites, failfast=failfast) |
616 |
|
617 |
# Clean up our logger
|
618 |
del(logger)
|
619 |
|
620 |
# Return
|
621 |
return 0 if success else 1 |
622 |
|
623 |
|
624 |
def run_tests(tcases, failfast=False): |
625 |
"""Run some testcases"""
|
626 |
global success # Using global. pylint: disable-msg=C0103,W0603,W0602 |
627 |
|
628 |
for tcase in tcases: |
629 |
was_success = run_test(tcase) |
630 |
success = success and was_success
|
631 |
if failfast and not success: |
632 |
break
|
633 |
|
634 |
|
635 |
def run_test(tcase): |
636 |
"""Run a testcase"""
|
637 |
tsuite = unittest.TestLoader().loadTestsFromTestCase(tcase) |
638 |
results = tsuite.run(BurninTestResult()) |
639 |
|
640 |
return was_successful(tcase.__name__, results.wasSuccessful())
|
641 |
|
642 |
|
643 |
# --------------------------------------------------------------------
|
644 |
# Helper functions
|
645 |
def was_successful(tsuite, successful): |
646 |
"""Handle whether a testsuite was succesful or not"""
|
647 |
if successful:
|
648 |
logger.testsuite_success(tsuite) |
649 |
return True |
650 |
else:
|
651 |
logger.testsuite_failure(tsuite) |
652 |
return False |
653 |
|
654 |
|
655 |
def parse_typed_option(value): |
656 |
"""Parse typed options (flavors and images)
|
657 |
|
658 |
The options are in the form 'id:123-345' or 'name:^Debian Base$'
|
659 |
|
660 |
"""
|
661 |
try:
|
662 |
[type_, val] = value.strip().split(':')
|
663 |
if type_ not in ["id", "name"]: |
664 |
raise ValueError |
665 |
return type_, val
|
666 |
except ValueError: |
667 |
return None |