Statistics
| Branch: | Tag: | Revision:

root / snf-tools / synnefo_tools / burnin / network_tests.py @ 3e5bbd85

History | View | Annotate | Download (9.3 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 tests the Networks' functionality
36

37
"""
38

    
39
import random
40

    
41
from synnefo_tools.burnin.common import Proper
42
from synnefo_tools.burnin.cyclades_common import CycladesTests
43

    
44

    
45
# Too many public methods. pylint: disable-msg=R0904
46
class NetworkTestSuite(CycladesTests):
47
    """Test Networking in Cyclades"""
48
    avail_images = Proper(value=None)
49
    avail_flavors = Proper(value=None)
50
    server_a = Proper(value=None)
51
    server_b = Proper(value=None)
52
    network = Proper(value=None)
53

    
54
    def test_001_images_to_use(self):
55
        """Find images to be used to create our machines"""
56
        if self.images is None:
57
            self.info("No --images given. Will use the default %s",
58
                      "^Debian Base$")
59
            filters = ["name:^Debian Base$"]
60
        else:
61
            filters = self.images
62

    
63
        self.avail_images = self._find_images(filters)
64
        self.info("Found %s images to choose from", len(self.avail_images))
65

    
66
    def test_002_flavors_to_use(self):
67
        """Find flavors to be used to create our machines"""
68
        flavors = self._get_list_of_flavors(detail=True)
69

    
70
        if self.flavors is None:
71
            self.info("No --flavors given. Will use all of them")
72
            self.avail_flavors = flavors
73
        else:
74
            self.avail_flavors = self._find_flavors(
75
                self.flavors, flavors=flavors)
76
        self.info("Found %s flavors to choose from", len(self.avail_flavors))
77

    
78
    def test_003_submit_create_server_a(self):
79
        """Submit create server request for server A"""
80
        use_image = random.choice(self.avail_images)
81
        use_flavor = random.choice(self.avail_flavors)
82
        server = self._create_server(use_image, use_flavor)
83

    
84
        self.server_a = {}
85
        self.server_a['server'] = server
86
        self.server_a['image'] = use_image
87
        self.server_a['flavor'] = use_flavor
88
        self.server_a['username'] = self._get_connection_username(server)
89
        self.server_a['password'] = server['adminPass']
90

    
91
    def test_004_submit_create_server_b(self):
92
        """Submit create server request for server B"""
93
        use_image = random.choice(self.avail_images)
94
        use_flavor = random.choice(self.avail_flavors)
95
        server = self._create_server(use_image, use_flavor)
96

    
97
        self.server_b = {}
98
        self.server_b['server'] = server
99
        self.server_b['image'] = use_image
100
        self.server_b['flavor'] = use_flavor
101
        self.server_b['username'] = self._get_connection_username(server)
102
        self.server_b['password'] = server['adminPass']
103

    
104
    def test_005_server_a_active(self):
105
        """Test that server A becomes ACTIVE"""
106
        self._insist_on_server_transition(
107
            self.server_a['server'], ["BUILD"], "ACTIVE")
108

    
109
    def test_005_server_b_active(self):
110
        """Test that server B becomes ACTIVE"""
111
        self._insist_on_server_transition(
112
            self.server_b['server'], ["BUILD"], "ACTIVE")
113

    
114
    def test_006_create_network(self):
115
        """Submit a create network request"""
116
        name = self.run_id
117
        self.network = self._create_network(name)
118

    
119
        self._insist_on_network_transition(
120
            self.network, ["BUILD"], "ACTIVE")
121

    
122
    def test_007_connect_to_network(self):
123
        """Connect the two VMs to the newly created network"""
124
        self.clients.cyclades.connect_server(
125
            self.server_a['server']['id'], self.network['id'])
126
        self.clients.cyclades.connect_server(
127
            self.server_b['server']['id'], self.network['id'])
128

    
129
        self._insist_on_network_connection(
130
            self.server_a['server'], self.network)
131
        self._insist_on_network_connection(
132
            self.server_b['server'], self.network)
133

    
134
        # Update servers
135
        self.server_a['server'] = self._get_server_details(
136
            self.server_a['server'])
137
        self.server_b['server'] = self._get_server_details(
138
            self.server_b['server'])
139

    
140
        # Check that servers got private IPs
141
        self.server_a['pr_ipv4'] = self._get_ip(
142
            self.server_a['server'], network=self.network)
143
        self.server_b['pr_ipv4'] = self._get_ip(
144
            self.server_b['server'], network=self.network)
145

    
146
    def test_008_reboot_server_a(self):
147
        """Rebooting server A"""
148
        self.clients.cyclades.shutdown_server(self.server_a['server']['id'])
149
        self._insist_on_server_transition(
150
            self.server_a['server'], ["ACTIVE"], "STOPPED")
151

    
152
        self.clients.cyclades.start_server(self.server_a['server']['id'])
153
        self._insist_on_server_transition(
154
            self.server_a['server'], ["STOPPED"], "ACTIVE")
155

    
156
    def test_009_ping_server_a(self):
157
        """Test if server A responds to IPv4 pings"""
158
        self._insist_on_ping(self._get_ip(self.server_a['server']))
159

    
160
    def test_010_reboot_server_b(self):
161
        """Rebooting server B"""
162
        self.clients.cyclades.shutdown_server(self.server_b['server']['id'])
163
        self._insist_on_server_transition(
164
            self.server_b['server'], ["ACTIVE"], "STOPPED")
165

    
166
        self.clients.cyclades.start_server(self.server_b['server']['id'])
167
        self._insist_on_server_transition(
168
            self.server_b['server'], ["STOPPED"], "ACTIVE")
169

    
170
    def test_011_ping_server_b(self):
171
        """Test that server B responds to IPv4 pings"""
172
        self._insist_on_ping(self._get_ip(self.server_b['server']))
173

    
174
    def test_012_test_connection_exists(self):
175
        """Ping server B from server A to test if connection exists"""
176
        self._skip_if(not self._image_is(self.server_a['image'], "linux"),
177
                      "only valid for Linux servers")
178
        self._skip_if(not self._image_is(self.server_b['image'], "linux"),
179
                      "only valid for Linux servers")
180

    
181
        server_a_public_ip = self._get_ip(self.server_a['server'])
182
        server_b_private_ip = self._get_ip(
183
            self.server_b['server'], network=self.network)
184
        msg = "Will try to connect to server A (%s) and ping to server B (%s)"
185
        self.info(msg, server_a_public_ip, server_b_private_ip)
186

    
187
        cmd = "for i in {1..7}; do if ping -c 3 -w 20 %s > /dev/null; " \
188
            "then echo 'True'; break; fi; done" % server_b_private_ip
189
        lines, status = self._ssh_execute(
190
            server_a_public_ip, self.server_a['username'],
191
            self.server_a['password'], cmd)
192

    
193
        self.assertEqual(status, 0)
194
        self.assertEqual(lines, ['True\n'])
195

    
196
    def test_013_disconnect_network(self):
197
        """Disconnecting servers A and B from network"""
198
        self._disconnect_from_network(self.server_a['server'], self.network)
199
        self._disconnect_from_network(self.server_b['server'], self.network)
200

    
201
        self._insist_on_network_connection(
202
            self.server_a['server'], self.network, disconnect=True)
203
        self._insist_on_network_connection(
204
            self.server_b['server'], self.network, disconnect=True)
205

    
206
    def test_014_destroy_network(self):
207
        """Submit delete network request"""
208
        self.clients.cyclades.delete_network(self.network['id'])
209
        self._insist_on_network_transition(
210
            self.network, ["ACTIVE"], "DELETED")
211

    
212
        networks = [net['id'] for net in self._get_list_of_networks()]
213
        self.assertNotIn(self.network['id'], networks)
214

    
215
        # Verify quotas
216
        self._check_quotas(network=-1)
217

    
218
    def test_015_cleanup_servers(self):
219
        """Cleanup servers created for this test"""
220
        self.clients.cyclades.delete_server(self.server_a['server']['id'])
221
        self.clients.cyclades.delete_server(self.server_b['server']['id'])
222

    
223
        self._insist_on_server_transition(
224
            self.server_a['server'], ["ACTIVE"], "DELETED")
225
        self._insist_on_server_transition(
226
            self.server_b['server'], ["ACTIVE"], "DELETED")
227

    
228
        # Verify quotas
229
        self._verify_quotas_deleted([self.server_a['flavor'],
230
                                     self.server_b['flavor']])