Statistics
| Branch: | Tag: | Revision:

root / snf-tools / synnefo_tools / burnin / network_tests.py @ 5bef1f49

History | View | Annotate | Download (9.3 kB)

1 3eaf0ec5 Ilias Tsitsimpis
# Copyright 2013 GRNET S.A. All rights reserved.
2 3eaf0ec5 Ilias Tsitsimpis
#
3 3eaf0ec5 Ilias Tsitsimpis
# Redistribution and use in source and binary forms, with or
4 3eaf0ec5 Ilias Tsitsimpis
# without modification, are permitted provided that the following
5 3eaf0ec5 Ilias Tsitsimpis
# conditions are met:
6 3eaf0ec5 Ilias Tsitsimpis
#
7 3eaf0ec5 Ilias Tsitsimpis
#   1. Redistributions of source code must retain the above
8 3eaf0ec5 Ilias Tsitsimpis
#      copyright notice, this list of conditions and the following
9 3eaf0ec5 Ilias Tsitsimpis
#      disclaimer.
10 3eaf0ec5 Ilias Tsitsimpis
#
11 3eaf0ec5 Ilias Tsitsimpis
#   2. Redistributions in binary form must reproduce the above
12 3eaf0ec5 Ilias Tsitsimpis
#      copyright notice, this list of conditions and the following
13 3eaf0ec5 Ilias Tsitsimpis
#      disclaimer in the documentation and/or other materials
14 3eaf0ec5 Ilias Tsitsimpis
#      provided with the distribution.
15 3eaf0ec5 Ilias Tsitsimpis
#
16 3eaf0ec5 Ilias Tsitsimpis
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 3eaf0ec5 Ilias Tsitsimpis
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 3eaf0ec5 Ilias Tsitsimpis
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 3eaf0ec5 Ilias Tsitsimpis
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 3eaf0ec5 Ilias Tsitsimpis
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 3eaf0ec5 Ilias Tsitsimpis
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 3eaf0ec5 Ilias Tsitsimpis
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 3eaf0ec5 Ilias Tsitsimpis
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 3eaf0ec5 Ilias Tsitsimpis
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 3eaf0ec5 Ilias Tsitsimpis
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 3eaf0ec5 Ilias Tsitsimpis
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 3eaf0ec5 Ilias Tsitsimpis
# POSSIBILITY OF SUCH DAMAGE.
28 3eaf0ec5 Ilias Tsitsimpis
#
29 3eaf0ec5 Ilias Tsitsimpis
# The views and conclusions contained in the software and
30 3eaf0ec5 Ilias Tsitsimpis
# documentation are those of the authors and should not be
31 3eaf0ec5 Ilias Tsitsimpis
# interpreted as representing official policies, either expressed
32 3eaf0ec5 Ilias Tsitsimpis
# or implied, of GRNET S.A.
33 3eaf0ec5 Ilias Tsitsimpis
34 3eaf0ec5 Ilias Tsitsimpis
"""
35 3eaf0ec5 Ilias Tsitsimpis
This is the burnin class that tests the Networks' functionality
36 3eaf0ec5 Ilias Tsitsimpis

37 3eaf0ec5 Ilias Tsitsimpis
"""
38 3eaf0ec5 Ilias Tsitsimpis
39 3eaf0ec5 Ilias Tsitsimpis
import random
40 3eaf0ec5 Ilias Tsitsimpis
41 3eaf0ec5 Ilias Tsitsimpis
from synnefo_tools.burnin.common import Proper
42 3eaf0ec5 Ilias Tsitsimpis
from synnefo_tools.burnin.cyclades_common import CycladesTests
43 3eaf0ec5 Ilias Tsitsimpis
44 3eaf0ec5 Ilias Tsitsimpis
45 3eaf0ec5 Ilias Tsitsimpis
# Too many public methods. pylint: disable-msg=R0904
46 3eaf0ec5 Ilias Tsitsimpis
class NetworkTestSuite(CycladesTests):
47 3eaf0ec5 Ilias Tsitsimpis
    """Test Networking in Cyclades"""
48 3eaf0ec5 Ilias Tsitsimpis
    avail_images = Proper(value=None)
49 3eaf0ec5 Ilias Tsitsimpis
    avail_flavors = Proper(value=None)
50 3eaf0ec5 Ilias Tsitsimpis
    server_a = Proper(value=None)
51 3eaf0ec5 Ilias Tsitsimpis
    server_b = Proper(value=None)
52 3eaf0ec5 Ilias Tsitsimpis
    network = Proper(value=None)
53 3eaf0ec5 Ilias Tsitsimpis
54 3eaf0ec5 Ilias Tsitsimpis
    def test_001_images_to_use(self):
55 3eaf0ec5 Ilias Tsitsimpis
        """Find images to be used to create our machines"""
56 3eaf0ec5 Ilias Tsitsimpis
        if self.images is None:
57 3eaf0ec5 Ilias Tsitsimpis
            self.info("No --images given. Will use the default %s",
58 3eaf0ec5 Ilias Tsitsimpis
                      "^Debian Base$")
59 3eaf0ec5 Ilias Tsitsimpis
            filters = ["name:^Debian Base$"]
60 3eaf0ec5 Ilias Tsitsimpis
        else:
61 3eaf0ec5 Ilias Tsitsimpis
            filters = self.images
62 3eaf0ec5 Ilias Tsitsimpis
63 3eaf0ec5 Ilias Tsitsimpis
        self.avail_images = self._find_images(filters)
64 3eaf0ec5 Ilias Tsitsimpis
        self.info("Found %s images to choose from", len(self.avail_images))
65 3eaf0ec5 Ilias Tsitsimpis
66 3eaf0ec5 Ilias Tsitsimpis
    def test_002_flavors_to_use(self):
67 3eaf0ec5 Ilias Tsitsimpis
        """Find flavors to be used to create our machines"""
68 3eaf0ec5 Ilias Tsitsimpis
        flavors = self._get_list_of_flavors(detail=True)
69 3eaf0ec5 Ilias Tsitsimpis
70 3eaf0ec5 Ilias Tsitsimpis
        if self.flavors is None:
71 3eaf0ec5 Ilias Tsitsimpis
            self.info("No --flavors given. Will use all of them")
72 3eaf0ec5 Ilias Tsitsimpis
            self.avail_flavors = flavors
73 3eaf0ec5 Ilias Tsitsimpis
        else:
74 3eaf0ec5 Ilias Tsitsimpis
            self.avail_flavors = self._find_flavors(
75 3eaf0ec5 Ilias Tsitsimpis
                self.flavors, flavors=flavors)
76 3eaf0ec5 Ilias Tsitsimpis
        self.info("Found %s flavors to choose from", len(self.avail_flavors))
77 3eaf0ec5 Ilias Tsitsimpis
78 3eaf0ec5 Ilias Tsitsimpis
    def test_003_submit_create_server_a(self):
79 3eaf0ec5 Ilias Tsitsimpis
        """Submit create server request for server A"""
80 3eaf0ec5 Ilias Tsitsimpis
        use_image = random.choice(self.avail_images)
81 3eaf0ec5 Ilias Tsitsimpis
        use_flavor = random.choice(self.avail_flavors)
82 3eaf0ec5 Ilias Tsitsimpis
        server = self._create_server(use_image, use_flavor)
83 3eaf0ec5 Ilias Tsitsimpis
84 3eaf0ec5 Ilias Tsitsimpis
        self.server_a = {}
85 3eaf0ec5 Ilias Tsitsimpis
        self.server_a['server'] = server
86 3eaf0ec5 Ilias Tsitsimpis
        self.server_a['image'] = use_image
87 3eaf0ec5 Ilias Tsitsimpis
        self.server_a['flavor'] = use_flavor
88 3eaf0ec5 Ilias Tsitsimpis
        self.server_a['username'] = self._get_connection_username(server)
89 3eaf0ec5 Ilias Tsitsimpis
        self.server_a['password'] = server['adminPass']
90 3eaf0ec5 Ilias Tsitsimpis
91 3eaf0ec5 Ilias Tsitsimpis
    def test_004_submit_create_server_b(self):
92 3eaf0ec5 Ilias Tsitsimpis
        """Submit create server request for server B"""
93 3eaf0ec5 Ilias Tsitsimpis
        use_image = random.choice(self.avail_images)
94 3eaf0ec5 Ilias Tsitsimpis
        use_flavor = random.choice(self.avail_flavors)
95 3eaf0ec5 Ilias Tsitsimpis
        server = self._create_server(use_image, use_flavor)
96 3eaf0ec5 Ilias Tsitsimpis
97 3eaf0ec5 Ilias Tsitsimpis
        self.server_b = {}
98 3eaf0ec5 Ilias Tsitsimpis
        self.server_b['server'] = server
99 3eaf0ec5 Ilias Tsitsimpis
        self.server_b['image'] = use_image
100 3eaf0ec5 Ilias Tsitsimpis
        self.server_b['flavor'] = use_flavor
101 3eaf0ec5 Ilias Tsitsimpis
        self.server_b['username'] = self._get_connection_username(server)
102 3eaf0ec5 Ilias Tsitsimpis
        self.server_b['password'] = server['adminPass']
103 3eaf0ec5 Ilias Tsitsimpis
104 3eaf0ec5 Ilias Tsitsimpis
    def test_005_server_a_active(self):
105 3eaf0ec5 Ilias Tsitsimpis
        """Test that server A becomes ACTIVE"""
106 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_server_transition(
107 3eaf0ec5 Ilias Tsitsimpis
            self.server_a['server'], ["BUILD"], "ACTIVE")
108 3eaf0ec5 Ilias Tsitsimpis
109 3eaf0ec5 Ilias Tsitsimpis
    def test_005_server_b_active(self):
110 3eaf0ec5 Ilias Tsitsimpis
        """Test that server B becomes ACTIVE"""
111 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_server_transition(
112 3eaf0ec5 Ilias Tsitsimpis
            self.server_b['server'], ["BUILD"], "ACTIVE")
113 3eaf0ec5 Ilias Tsitsimpis
114 3eaf0ec5 Ilias Tsitsimpis
    def test_006_create_network(self):
115 3eaf0ec5 Ilias Tsitsimpis
        """Submit a create network request"""
116 3eaf0ec5 Ilias Tsitsimpis
        name = self.run_id
117 3eaf0ec5 Ilias Tsitsimpis
        self.network = self.clients.cyclades.create_network(
118 3eaf0ec5 Ilias Tsitsimpis
            name, cidr="10.0.1.0/28", dhcp=True)
119 3eaf0ec5 Ilias Tsitsimpis
        self.info("Network with id %s created", self.network['id'])
120 3eaf0ec5 Ilias Tsitsimpis
121 3eaf0ec5 Ilias Tsitsimpis
        #Test if right the name is assigned
122 3eaf0ec5 Ilias Tsitsimpis
        self.assertEqual(self.network['name'], name)
123 3eaf0ec5 Ilias Tsitsimpis
124 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_network_transition(
125 3eaf0ec5 Ilias Tsitsimpis
            self.network, ["BUILD"], "ACTIVE")
126 3eaf0ec5 Ilias Tsitsimpis
127 3eaf0ec5 Ilias Tsitsimpis
    def test_007_connect_to_network(self):
128 3eaf0ec5 Ilias Tsitsimpis
        """Connect the two VMs to the newly created network"""
129 3eaf0ec5 Ilias Tsitsimpis
        self.clients.cyclades.connect_server(
130 3eaf0ec5 Ilias Tsitsimpis
            self.server_a['server']['id'], self.network['id'])
131 3eaf0ec5 Ilias Tsitsimpis
        self.clients.cyclades.connect_server(
132 3eaf0ec5 Ilias Tsitsimpis
            self.server_b['server']['id'], self.network['id'])
133 3eaf0ec5 Ilias Tsitsimpis
134 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_network_connection(
135 3eaf0ec5 Ilias Tsitsimpis
            self.server_a['server'], self.network)
136 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_network_connection(
137 3eaf0ec5 Ilias Tsitsimpis
            self.server_b['server'], self.network)
138 3eaf0ec5 Ilias Tsitsimpis
139 3eaf0ec5 Ilias Tsitsimpis
        # Update servers
140 3eaf0ec5 Ilias Tsitsimpis
        self.server_a['server'] = self._get_server_details(
141 3eaf0ec5 Ilias Tsitsimpis
            self.server_a['server'])
142 3eaf0ec5 Ilias Tsitsimpis
        self.server_b['server'] = self._get_server_details(
143 3eaf0ec5 Ilias Tsitsimpis
            self.server_b['server'])
144 3eaf0ec5 Ilias Tsitsimpis
145 3eaf0ec5 Ilias Tsitsimpis
        # Check that servers got private IPs
146 3eaf0ec5 Ilias Tsitsimpis
        self.server_a['pr_ipv4'] = self._get_ip(
147 3eaf0ec5 Ilias Tsitsimpis
            self.server_a['server'], network=self.network)
148 3eaf0ec5 Ilias Tsitsimpis
        self.server_b['pr_ipv4'] = self._get_ip(
149 3eaf0ec5 Ilias Tsitsimpis
            self.server_b['server'], network=self.network)
150 3eaf0ec5 Ilias Tsitsimpis
151 3eaf0ec5 Ilias Tsitsimpis
    def test_008_reboot_server_a(self):
152 3eaf0ec5 Ilias Tsitsimpis
        """Rebooting server A"""
153 3eaf0ec5 Ilias Tsitsimpis
        self.clients.cyclades.shutdown_server(self.server_a['server']['id'])
154 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_server_transition(
155 3eaf0ec5 Ilias Tsitsimpis
            self.server_a['server'], ["ACTIVE"], "STOPPED")
156 3eaf0ec5 Ilias Tsitsimpis
157 3eaf0ec5 Ilias Tsitsimpis
        self.clients.cyclades.start_server(self.server_a['server']['id'])
158 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_server_transition(
159 3eaf0ec5 Ilias Tsitsimpis
            self.server_a['server'], ["STOPPED"], "ACTIVE")
160 3eaf0ec5 Ilias Tsitsimpis
161 3eaf0ec5 Ilias Tsitsimpis
    def test_009_ping_server_a(self):
162 3eaf0ec5 Ilias Tsitsimpis
        """Test if server A responds to IPv4 pings"""
163 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_ping(self._get_ip(self.server_a['server']))
164 3eaf0ec5 Ilias Tsitsimpis
165 3eaf0ec5 Ilias Tsitsimpis
    def test_010_reboot_server_b(self):
166 3eaf0ec5 Ilias Tsitsimpis
        """Rebooting server B"""
167 3eaf0ec5 Ilias Tsitsimpis
        self.clients.cyclades.shutdown_server(self.server_b['server']['id'])
168 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_server_transition(
169 3eaf0ec5 Ilias Tsitsimpis
            self.server_b['server'], ["ACTIVE"], "STOPPED")
170 3eaf0ec5 Ilias Tsitsimpis
171 3eaf0ec5 Ilias Tsitsimpis
        self.clients.cyclades.start_server(self.server_b['server']['id'])
172 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_server_transition(
173 3eaf0ec5 Ilias Tsitsimpis
            self.server_b['server'], ["STOPPED"], "ACTIVE")
174 3eaf0ec5 Ilias Tsitsimpis
175 3eaf0ec5 Ilias Tsitsimpis
    def test_011_ping_server_b(self):
176 3eaf0ec5 Ilias Tsitsimpis
        """Test that server B responds to IPv4 pings"""
177 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_ping(self._get_ip(self.server_b['server']))
178 3eaf0ec5 Ilias Tsitsimpis
179 3eaf0ec5 Ilias Tsitsimpis
    def test_012_test_connection_exists(self):
180 3eaf0ec5 Ilias Tsitsimpis
        """Ping server B from server A to test if connection exists"""
181 3eaf0ec5 Ilias Tsitsimpis
        self._skip_if(not self._image_is(self.server_a['image'], "linux"),
182 3eaf0ec5 Ilias Tsitsimpis
                      "only valid for Linux servers")
183 3eaf0ec5 Ilias Tsitsimpis
        self._skip_if(not self._image_is(self.server_b['image'], "linux"),
184 3eaf0ec5 Ilias Tsitsimpis
                      "only valid for Linux servers")
185 3eaf0ec5 Ilias Tsitsimpis
186 3eaf0ec5 Ilias Tsitsimpis
        server_a_public_ip = self._get_ip(self.server_a['server'])
187 3eaf0ec5 Ilias Tsitsimpis
        server_b_private_ip = self._get_ip(
188 3eaf0ec5 Ilias Tsitsimpis
            self.server_b['server'], network=self.network)
189 3eaf0ec5 Ilias Tsitsimpis
        msg = "Will try to connect to server A (%s) and ping to server B (%s)"
190 3eaf0ec5 Ilias Tsitsimpis
        self.info(msg, server_a_public_ip, server_b_private_ip)
191 3eaf0ec5 Ilias Tsitsimpis
192 3eaf0ec5 Ilias Tsitsimpis
        cmd = "for i in {1..7}; do if ping -c 3 -w 20 %s > /dev/null; " \
193 3eaf0ec5 Ilias Tsitsimpis
            "then echo 'True'; break; fi; done" % server_b_private_ip
194 3eaf0ec5 Ilias Tsitsimpis
        lines, status = self._ssh_execute(
195 3eaf0ec5 Ilias Tsitsimpis
            server_a_public_ip, self.server_a['username'],
196 3eaf0ec5 Ilias Tsitsimpis
            self.server_a['password'], cmd)
197 3eaf0ec5 Ilias Tsitsimpis
198 3eaf0ec5 Ilias Tsitsimpis
        self.assertEqual(status, 0)
199 3eaf0ec5 Ilias Tsitsimpis
        self.assertEqual(lines, ['True\n'])
200 3eaf0ec5 Ilias Tsitsimpis
201 3eaf0ec5 Ilias Tsitsimpis
    def test_013_disconnect_network(self):
202 3eaf0ec5 Ilias Tsitsimpis
        """Disconnecting servers A and B from network"""
203 3eaf0ec5 Ilias Tsitsimpis
        self._disconnect_from_network(self.server_a['server'], self.network)
204 3eaf0ec5 Ilias Tsitsimpis
        self._disconnect_from_network(self.server_b['server'], self.network)
205 3eaf0ec5 Ilias Tsitsimpis
206 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_network_connection(
207 3eaf0ec5 Ilias Tsitsimpis
            self.server_a['server'], self.network, disconnect=True)
208 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_network_connection(
209 3eaf0ec5 Ilias Tsitsimpis
            self.server_b['server'], self.network, disconnect=True)
210 3eaf0ec5 Ilias Tsitsimpis
211 3eaf0ec5 Ilias Tsitsimpis
    def test_014_destroy_network(self):
212 3eaf0ec5 Ilias Tsitsimpis
        """Submit delete network request"""
213 3eaf0ec5 Ilias Tsitsimpis
        self.clients.cyclades.delete_network(self.network['id'])
214 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_network_transition(
215 3eaf0ec5 Ilias Tsitsimpis
            self.network, ["ACTIVE"], "DELETED")
216 3eaf0ec5 Ilias Tsitsimpis
217 3eaf0ec5 Ilias Tsitsimpis
        networks = [net['id'] for net in self._get_list_of_networks()]
218 3eaf0ec5 Ilias Tsitsimpis
        self.assertNotIn(self.network['id'], networks)
219 3eaf0ec5 Ilias Tsitsimpis
220 3eaf0ec5 Ilias Tsitsimpis
    def test_015_cleanup_servers(self):
221 3eaf0ec5 Ilias Tsitsimpis
        """Cleanup servers created for this test"""
222 3eaf0ec5 Ilias Tsitsimpis
        self.clients.cyclades.delete_server(self.server_a['server']['id'])
223 3eaf0ec5 Ilias Tsitsimpis
        self.clients.cyclades.delete_server(self.server_b['server']['id'])
224 3eaf0ec5 Ilias Tsitsimpis
225 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_server_transition(
226 3eaf0ec5 Ilias Tsitsimpis
            self.server_a['server'], ["ACTIVE"], "DELETED")
227 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_server_transition(
228 3eaf0ec5 Ilias Tsitsimpis
            self.server_b['server'], ["ACTIVE"], "DELETED")