Revision 8c67f82e

b/snf-tools/synnefo_tools/burnin/__init__.py
46 46
    FlavorsTestSuite, ImagesTestSuite
47 47
from synnefo_tools.burnin.pithos_tests import PithosTestSuite
48 48
from synnefo_tools.burnin.server_tests import ServerTestSuite
49
from synnefo_tools.burnin.stale_tests import \
50
    StaleServersTestSuite, StaleNetworksTestSuite
49 51

  
50 52

  
51 53
# --------------------------------------------------------------------
......
56 58
    ImagesTestSuite,
57 59
    PithosTestSuite,
58 60
    ServerTestSuite,
59
    ]
60

  
61
]
61 62
TSUITES_NAMES = [tsuite.__name__ for tsuite in TESTSUITES]
62 63

  
64
STALE_TESTSUITES = [
65
    # Must be runned in this order
66
    StaleServersTestSuite,
67
    StaleNetworksTestSuite,
68
]
69
STALE_TSUITES_NAMES = [tsuite.__name__ for tsuite in STALE_TESTSUITES]
70

  
63 71

  
64 72
def string_to_class(names):
65 73
    """Convert class namesto class objects"""
......
245 253
    (opts, _) = parse_arguments(sys.argv[1:])
246 254

  
247 255
    # Initialize burnin
248
    testsuites = common.initialize(opts, TSUITES_NAMES)
256
    testsuites = common.initialize(opts, TSUITES_NAMES, STALE_TSUITES_NAMES)
249 257
    testsuites = string_to_class(testsuites)
250 258

  
251 259
    # Run burnin
b/snf-tools/synnefo_tools/burnin/common.py
139 139
    system_user = None
140 140
    images = None
141 141
    flavors = None
142
    delete_stale = False
142 143

  
143 144
    @classmethod
144 145
    def setUpClass(cls):  # noqa
......
443 444

  
444 445
# --------------------------------------------------------------------
445 446
# Initialize Burnin
446
def initialize(opts, testsuites):
447
def initialize(opts, testsuites, stale_testsuites):
447 448
    """Initalize burnin
448 449

  
449 450
    Initialize our logger and burnin state
......
467 468
    BurninTests.system_user = opts.system_user
468 469
    BurninTests.flavors = opts.flavors
469 470
    BurninTests.images = opts.images
471
    BurninTests.delete_stale = opts.delete_stale
470 472
    BurninTests.run_id = SNF_TEST_PREFIX + \
471 473
        datetime.datetime.strftime(datetime.datetime.now(), "%Y%m%d%H%M%S")
472 474

  
473 475
    # Choose tests to run
476
    if opts.show_stale:
477
        # We will run the stale_testsuites
478
        return stale_testsuites
479

  
474 480
    if opts.tests != "all":
475 481
        testsuites = opts.tests
476 482
    if opts.exclude_tests is not None:
b/snf-tools/synnefo_tools/burnin/cyclades_common.py
52 52
# Too many public methods. pylint: disable-msg=R0904
53 53
class CycladesTests(BurninTests):
54 54
    """Extends the BurninTests class for Cyclades"""
55
    def _try_until_timeout_expires(self, opmsg, check_fun):
55
    def _ry_until_timeout_expires(self, opmsg, check_fun):
56 56
        """Try to perform an action until timeout expires"""
57 57
        assert callable(check_fun), "Not a function"
58 58

  
......
61 61
        if action_warning > action_timeout:
62 62
            action_warning = action_timeout
63 63

  
64
        start_time = time.time()
65
        while (start_time + action_warning) > time.time():
64
        start_time = int(time.time())
65
        end_time = start_time + action_warning
66
        while end_time > time.time():
66 67
            try:
67
                return check_fun()
68
                ret_value = check_fun()
69
                self.info("Operation `%s' finished in %s seconds",
70
                          opmsg, int(time.time()) - start_time)
71
                return ret_value
68 72
            except Retry:
69 73
                time.sleep(self.query_interval)
70
        self.warning("Operation `%s' is taking too long", opmsg)
71
        while (start_time + action_timeout) > time.time():
74
        self.warning("Operation `%s' is taking too long after %s seconds",
75
                     opmsg, int(time.time()) - start_time)
76

  
77
        end_time = start_time + action_timeout
78
        while end_time > time.time():
72 79
            try:
73
                return check_fun()
80
                ret_value = check_fun()
81
                self.info("Operation `%s' finished in %s seconds",
82
                          opmsg, int(time.time()) - start_time)
83
                return ret_value
74 84
            except Retry:
75 85
                time.sleep(self.query_interval)
76
        self.error("Operation `%s' timed out", opmsg)
86
        self.error("Operation `%s' timed out after %s seconds",
87
                   opmsg, int(time.time()) - start_time)
77 88
        self.fail("time out")
78 89

  
79 90
    def _get_list_of_servers(self, detail=False):
b/snf-tools/synnefo_tools/burnin/stale_tests.py
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
This is the burnin class that handles stale resources (Servers/Networks)
36

  
37
"""
38

  
39
from synnefo_tools.burnin.common import Proper, SNF_TEST_PREFIX
40
from synnefo_tools.burnin.cyclades_common import CycladesTests
41

  
42

  
43
# Too many public methods. pylint: disable-msg=R0904
44
class StaleServersTestSuite(CycladesTests):
45
    """Handle stale Servers"""
46
    stale_servers = Proper(value=None)
47

  
48
    def test_001_show_stale_servers(self):
49
        """Show staled servers (servers left from previous runs)"""
50
        servers = self._get_list_of_servers()
51
        self.stale_servers = [s for s in servers
52
                              if s['name'].startswith(SNF_TEST_PREFIX)]
53

  
54
        len_stale = len(self.stale_servers)
55
        if len_stale == 0:
56
            self.info("No stale servers found")
57
            return
58

  
59
        self.info("Found %s stale servers:", len_stale)
60
        for stl in self.stale_servers:
61
            self.info("  Server \"%s\" with id %s", stl['name'], stl['id'])
62

  
63
    def test_002_delete_stale_servers(self):
64
        """Delete staled servers (servers left from previous runs)"""
65
        len_stale = len(self.stale_servers)
66
        if not self.delete_stale and len_stale != 0:
67
            msg = "Use --delete-stale flag to delete stale servers"
68
            self.error(msg)
69
            self.fail(msg)
70
        elif len_stale == 0:
71
            self.info("No stale servers found")
72
        else:
73
            self.info("Deleting %s stale servers:", len_stale)
74
            for stl in self.stale_servers:
75
                self.info("  Deleting server \"%s\" with id %s",
76
                          stl['name'], stl['id'])
77
                self.clients.cyclades.delete_server(stl['id'])
78

  
79
            for stl in self.stale_servers:
80
                self._insist_on_server_transition(stl, "ACTIVE", "DELETED")
81

  
82

  
83
# Too many public methods. pylint: disable-msg=R0904
84
class StaleNetworksTestSuite(CycladesTests):
85
    """Handle stale Networks"""
86
    def test_001_show_stale_networks(self):
87
        """Show staled networks (networks left from previous runs)"""
88
        return

Also available in: Unified diff