Statistics
| Branch: | Tag: | Revision:

root / snf-tools / synnefo_tools / burnin / stale_tests.py @ 60a80953

History | View | Annotate | Download (5.5 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
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(detail=True)
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
            self.fail("Use --delete-stale flag to delete stale servers")
68
        elif len_stale == 0:
69
            self.info("No stale servers found")
70
        else:
71
            self.info("Deleting %s stale servers", len_stale)
72
            self._delete_servers(self.stale_servers, error=True)
73

    
74

    
75
# Too many public methods. pylint: disable-msg=R0904
76
class StaleFloatingIPsTestSuite(CycladesTests):
77
    """Handle stale Floating IPs"""
78
    stale_ips = Proper(value=None)
79

    
80
    def test_001_show_stale_ips(self):
81
        """Show staled floating IPs"""
82
        floating_ips = self.clients.network.list_floatingips()
83
        # We consider all the floating ips that are not attached
84
        # anywhere as stale ips.
85
        self.stale_ips = [ip for ip in floating_ips
86
                          if ip['instance_id'] is None]
87

    
88
        len_stale = len(self.stale_ips)
89
        if len_stale == 0:
90
            self.info("No stale floating IPs found")
91
            return
92

    
93
        self.info("Found %s stale floating IPs:", len_stale)
94
        for stl in self.stale_ips:
95
            self.info("  Floating IP %s with id %s",
96
                      stl['floating_ip_address'], stl['id'])
97

    
98
    def test_002_delete_stale_ips(self):
99
        """Delete staled floating IPs"""
100
        len_stale = len(self.stale_ips)
101
        if not self.delete_stale and len_stale != 0:
102
            self.fail("Use --delete-stale flag to delete stale floating IPs")
103
        elif len_stale == 0:
104
            self.info("No stale floating IPs found")
105
        else:
106
            self.info("Deleteing %s stale floating IPs", len_stale)
107
            self._disconnect_from_floating_ips(self.stale_ips)
108

    
109

    
110
# Too many public methods. pylint: disable-msg=R0904
111
class StaleNetworksTestSuite(CycladesTests):
112
    """Handle stale Networks"""
113
    stale_networks = Proper(value=None)
114

    
115
    def test_001_show_stale_networks(self):
116
        """Show staled networks (networks left from previous runs)"""
117
        networks = self._get_list_of_networks()
118
        self.stale_networks = [n for n in networks
119
                               if n['name'].startswith(SNF_TEST_PREFIX)]
120

    
121
        len_stale = len(self.stale_networks)
122
        if len_stale == 0:
123
            self.info("No stale networks found")
124
            return
125

    
126
        self.info("Found %s stale networks:", len_stale)
127
        for stl in self.stale_networks:
128
            self.info("  Network \"%s\" with id %s", stl['name'], stl['id'])
129

    
130
    def test_002_delete_stale_networks(self):
131
        """Delete staled networks (networks left from previous runs)"""
132
        len_stale = len(self.stale_networks)
133
        if not self.delete_stale and len_stale != 0:
134
            self.fail("Use --delete-stale flag to delete stale networks")
135
        elif len_stale == 0:
136
            self.info("No stale networks found")
137
        else:
138
            self.info("Deleting %s stale networks", len_stale)
139
            self._delete_networks(self.stale_networks)