Commit 3e7beabb authored by Ilias Tsitsimpis's avatar Ilias Tsitsimpis
Browse files

burnin: Implement StaleServersTestSuite

This testsuite is used to inspect and delete stale servers
(servers left from previous burnin runs).
parent 1d8318cd
...@@ -46,6 +46,8 @@ from synnefo_tools.burnin.images_tests import \ ...@@ -46,6 +46,8 @@ from synnefo_tools.burnin.images_tests import \
FlavorsTestSuite, ImagesTestSuite FlavorsTestSuite, ImagesTestSuite
from synnefo_tools.burnin.pithos_tests import PithosTestSuite from synnefo_tools.burnin.pithos_tests import PithosTestSuite
from synnefo_tools.burnin.server_tests import ServerTestSuite from synnefo_tools.burnin.server_tests import ServerTestSuite
from synnefo_tools.burnin.stale_tests import \
StaleServersTestSuite, StaleNetworksTestSuite
# -------------------------------------------------------------------- # --------------------------------------------------------------------
...@@ -56,10 +58,16 @@ TESTSUITES = [ ...@@ -56,10 +58,16 @@ TESTSUITES = [
ImagesTestSuite, ImagesTestSuite,
PithosTestSuite, PithosTestSuite,
ServerTestSuite, ServerTestSuite,
] ]
TSUITES_NAMES = [tsuite.__name__ for tsuite in TESTSUITES] TSUITES_NAMES = [tsuite.__name__ for tsuite in TESTSUITES]
STALE_TESTSUITES = [
# Must be runned in this order
StaleServersTestSuite,
StaleNetworksTestSuite,
]
STALE_TSUITES_NAMES = [tsuite.__name__ for tsuite in STALE_TESTSUITES]
def string_to_class(names): def string_to_class(names):
"""Convert class namesto class objects""" """Convert class namesto class objects"""
...@@ -245,7 +253,7 @@ def main(): ...@@ -245,7 +253,7 @@ def main():
(opts, _) = parse_arguments(sys.argv[1:]) (opts, _) = parse_arguments(sys.argv[1:])
# Initialize burnin # Initialize burnin
testsuites = common.initialize(opts, TSUITES_NAMES) testsuites = common.initialize(opts, TSUITES_NAMES, STALE_TSUITES_NAMES)
testsuites = string_to_class(testsuites) testsuites = string_to_class(testsuites)
# Run burnin # Run burnin
......
...@@ -139,6 +139,7 @@ class BurninTests(unittest.TestCase): ...@@ -139,6 +139,7 @@ class BurninTests(unittest.TestCase):
system_user = None system_user = None
images = None images = None
flavors = None flavors = None
delete_stale = False
@classmethod @classmethod
def setUpClass(cls): # noqa def setUpClass(cls): # noqa
...@@ -443,7 +444,7 @@ class BurninTests(unittest.TestCase): ...@@ -443,7 +444,7 @@ class BurninTests(unittest.TestCase):
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Initialize Burnin # Initialize Burnin
def initialize(opts, testsuites): def initialize(opts, testsuites, stale_testsuites):
"""Initalize burnin """Initalize burnin
Initialize our logger and burnin state Initialize our logger and burnin state
...@@ -467,10 +468,15 @@ def initialize(opts, testsuites): ...@@ -467,10 +468,15 @@ def initialize(opts, testsuites):
BurninTests.system_user = opts.system_user BurninTests.system_user = opts.system_user
BurninTests.flavors = opts.flavors BurninTests.flavors = opts.flavors
BurninTests.images = opts.images BurninTests.images = opts.images
BurninTests.delete_stale = opts.delete_stale
BurninTests.run_id = SNF_TEST_PREFIX + \ BurninTests.run_id = SNF_TEST_PREFIX + \
datetime.datetime.strftime(datetime.datetime.now(), "%Y%m%d%H%M%S") datetime.datetime.strftime(datetime.datetime.now(), "%Y%m%d%H%M%S")
# Choose tests to run # Choose tests to run
if opts.show_stale:
# We will run the stale_testsuites
return stale_testsuites
if opts.tests != "all": if opts.tests != "all":
testsuites = opts.tests testsuites = opts.tests
if opts.exclude_tests is not None: if opts.exclude_tests is not None:
......
...@@ -52,7 +52,7 @@ from synnefo_tools.burnin.common import BurninTests ...@@ -52,7 +52,7 @@ from synnefo_tools.burnin.common import BurninTests
# Too many public methods. pylint: disable-msg=R0904 # Too many public methods. pylint: disable-msg=R0904
class CycladesTests(BurninTests): class CycladesTests(BurninTests):
"""Extends the BurninTests class for Cyclades""" """Extends the BurninTests class for Cyclades"""
def _try_until_timeout_expires(self, opmsg, check_fun): def _ry_until_timeout_expires(self, opmsg, check_fun):
"""Try to perform an action until timeout expires""" """Try to perform an action until timeout expires"""
assert callable(check_fun), "Not a function" assert callable(check_fun), "Not a function"
...@@ -61,19 +61,30 @@ class CycladesTests(BurninTests): ...@@ -61,19 +61,30 @@ class CycladesTests(BurninTests):
if action_warning > action_timeout: if action_warning > action_timeout:
action_warning = action_timeout action_warning = action_timeout
start_time = time.time() start_time = int(time.time())
while (start_time + action_warning) > time.time(): end_time = start_time + action_warning
while end_time > time.time():
try: try:
return check_fun() ret_value = check_fun()
self.info("Operation `%s' finished in %s seconds",
opmsg, int(time.time()) - start_time)
return ret_value
except Retry: except Retry:
time.sleep(self.query_interval) time.sleep(self.query_interval)
self.warning("Operation `%s' is taking too long", opmsg) self.warning("Operation `%s' is taking too long after %s seconds",
while (start_time + action_timeout) > time.time(): opmsg, int(time.time()) - start_time)
end_time = start_time + action_timeout
while end_time > time.time():
try: try:
return check_fun() ret_value = check_fun()
self.info("Operation `%s' finished in %s seconds",
opmsg, int(time.time()) - start_time)
return ret_value
except Retry: except Retry:
time.sleep(self.query_interval) time.sleep(self.query_interval)
self.error("Operation `%s' timed out", opmsg) self.error("Operation `%s' timed out after %s seconds",
opmsg, int(time.time()) - start_time)
self.fail("time out") self.fail("time out")
def _get_list_of_servers(self, detail=False): def _get_list_of_servers(self, detail=False):
......
# Copyright 2013 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above
# copyright notice, this list of conditions and the following
# disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials
# provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# The views and conclusions contained in the software and
# documentation are those of the authors and should not be
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
"""
This is the burnin class that handles stale resources (Servers/Networks)
"""
from synnefo_tools.burnin.common import Proper, SNF_TEST_PREFIX
from synnefo_tools.burnin.cyclades_common import CycladesTests
# Too many public methods. pylint: disable-msg=R0904
class StaleServersTestSuite(CycladesTests):
"""Handle stale Servers"""
stale_servers = Proper(value=None)
def test_001_show_stale_servers(self):
"""Show staled servers (servers left from previous runs)"""
servers = self._get_list_of_servers()
self.stale_servers = [s for s in servers
if s['name'].startswith(SNF_TEST_PREFIX)]
len_stale = len(self.stale_servers)
if len_stale == 0:
self.info("No stale servers found")
return
self.info("Found %s stale servers:", len_stale)
for stl in self.stale_servers:
self.info(" Server \"%s\" with id %s", stl['name'], stl['id'])
def test_002_delete_stale_servers(self):
"""Delete staled servers (servers left from previous runs)"""
len_stale = len(self.stale_servers)
if not self.delete_stale and len_stale != 0:
msg = "Use --delete-stale flag to delete stale servers"
self.error(msg)
self.fail(msg)
elif len_stale == 0:
self.info("No stale servers found")
else:
self.info("Deleting %s stale servers:", len_stale)
for stl in self.stale_servers:
self.info(" Deleting server \"%s\" with id %s",
stl['name'], stl['id'])
self.clients.cyclades.delete_server(stl['id'])
for stl in self.stale_servers:
self._insist_on_server_transition(stl, "ACTIVE", "DELETED")
# Too many public methods. pylint: disable-msg=R0904
class StaleNetworksTestSuite(CycladesTests):
"""Handle stale Networks"""
def test_001_show_stale_networks(self):
"""Show staled networks (networks left from previous runs)"""
return
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment