network_tests.py 9.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# 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 tests the Networks' functionality

"""

import random

from synnefo_tools.burnin.common import Proper
from synnefo_tools.burnin.cyclades_common import CycladesTests


# Too many public methods. pylint: disable-msg=R0904
class NetworkTestSuite(CycladesTests):
    """Test Networking in Cyclades"""
    avail_images = Proper(value=None)
    avail_flavors = Proper(value=None)
    server_a = Proper(value=None)
    server_b = Proper(value=None)
    network = Proper(value=None)

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

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

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

        if self.flavors is None:
            self.info("No --flavors given. Will use all of them")
            self.avail_flavors = flavors
        else:
            self.avail_flavors = self._find_flavors(
                self.flavors, flavors=flavors)
        self.info("Found %s flavors to choose from", len(self.avail_flavors))

    def test_003_submit_create_server_a(self):
        """Submit create server request for server A"""
        use_image = random.choice(self.avail_images)
        use_flavor = random.choice(self.avail_flavors)
        server = self._create_server(use_image, use_flavor)

        self.server_a = {}
        self.server_a['server'] = server
        self.server_a['image'] = use_image
        self.server_a['flavor'] = use_flavor
        self.server_a['username'] = self._get_connection_username(server)
        self.server_a['password'] = server['adminPass']

    def test_004_submit_create_server_b(self):
        """Submit create server request for server B"""
        use_image = random.choice(self.avail_images)
        use_flavor = random.choice(self.avail_flavors)
        server = self._create_server(use_image, use_flavor)

        self.server_b = {}
        self.server_b['server'] = server
        self.server_b['image'] = use_image
        self.server_b['flavor'] = use_flavor
        self.server_b['username'] = self._get_connection_username(server)
        self.server_b['password'] = server['adminPass']

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

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

    def test_006_create_network(self):
        """Submit a create network request"""
        name = self.run_id
Ilias Tsitsimpis's avatar
Ilias Tsitsimpis committed
117
        self.network = self._create_network(name)
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214

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

    def test_007_connect_to_network(self):
        """Connect the two VMs to the newly created network"""
        self.clients.cyclades.connect_server(
            self.server_a['server']['id'], self.network['id'])
        self.clients.cyclades.connect_server(
            self.server_b['server']['id'], self.network['id'])

        self._insist_on_network_connection(
            self.server_a['server'], self.network)
        self._insist_on_network_connection(
            self.server_b['server'], self.network)

        # Update servers
        self.server_a['server'] = self._get_server_details(
            self.server_a['server'])
        self.server_b['server'] = self._get_server_details(
            self.server_b['server'])

        # Check that servers got private IPs
        self.server_a['pr_ipv4'] = self._get_ip(
            self.server_a['server'], network=self.network)
        self.server_b['pr_ipv4'] = self._get_ip(
            self.server_b['server'], network=self.network)

    def test_008_reboot_server_a(self):
        """Rebooting server A"""
        self.clients.cyclades.shutdown_server(self.server_a['server']['id'])
        self._insist_on_server_transition(
            self.server_a['server'], ["ACTIVE"], "STOPPED")

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

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

    def test_010_reboot_server_b(self):
        """Rebooting server B"""
        self.clients.cyclades.shutdown_server(self.server_b['server']['id'])
        self._insist_on_server_transition(
            self.server_b['server'], ["ACTIVE"], "STOPPED")

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

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

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

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

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

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

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

        self._insist_on_network_connection(
            self.server_a['server'], self.network, disconnect=True)
        self._insist_on_network_connection(
            self.server_b['server'], self.network, disconnect=True)

    def test_014_destroy_network(self):
        """Submit delete network request"""
        self.clients.cyclades.delete_network(self.network['id'])
        self._insist_on_network_transition(
            self.network, ["ACTIVE"], "DELETED")

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

Ilias Tsitsimpis's avatar
Ilias Tsitsimpis committed
215
216
217
        # Verify quotas
        self._check_quotas(network=-1)

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

        self._insist_on_server_transition(
            self.server_a['server'], ["ACTIVE"], "DELETED")
        self._insist_on_server_transition(
            self.server_b['server'], ["ACTIVE"], "DELETED")
Ilias Tsitsimpis's avatar
Ilias Tsitsimpis committed
227
228
229
230

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