Statistics
| Branch: | Tag: | Revision:

root / snf-tools / synnefo_tools / burnin / network_tests.py @ 100feeda

History | View | Annotate | Download (8.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 60a80953 Ilias Tsitsimpis
        server = self._create_server(use_image, use_flavor, network=True)
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 60a80953 Ilias Tsitsimpis
        server = self._create_server(use_image, use_flavor, network=True)
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 60a80953 Ilias Tsitsimpis
        self.network = self._create_network()
117 3eaf0ec5 Ilias Tsitsimpis
118 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_network_transition(
119 3eaf0ec5 Ilias Tsitsimpis
            self.network, ["BUILD"], "ACTIVE")
120 3eaf0ec5 Ilias Tsitsimpis
121 3eaf0ec5 Ilias Tsitsimpis
    def test_007_connect_to_network(self):
122 3eaf0ec5 Ilias Tsitsimpis
        """Connect the two VMs to the newly created network"""
123 60a80953 Ilias Tsitsimpis
        self._create_port(self.network['id'], self.server_a['server']['id'])
124 60a80953 Ilias Tsitsimpis
        self._create_port(self.network['id'], self.server_b['server']['id'])
125 3eaf0ec5 Ilias Tsitsimpis
126 3eaf0ec5 Ilias Tsitsimpis
        # Update servers
127 3eaf0ec5 Ilias Tsitsimpis
        self.server_a['server'] = self._get_server_details(
128 3eaf0ec5 Ilias Tsitsimpis
            self.server_a['server'])
129 3eaf0ec5 Ilias Tsitsimpis
        self.server_b['server'] = self._get_server_details(
130 3eaf0ec5 Ilias Tsitsimpis
            self.server_b['server'])
131 3eaf0ec5 Ilias Tsitsimpis
132 3eaf0ec5 Ilias Tsitsimpis
        # Check that servers got private IPs
133 60a80953 Ilias Tsitsimpis
        ipv4 = self._get_ips(self.server_a['server'], network=self.network)
134 60a80953 Ilias Tsitsimpis
        self.assertEqual(len(ipv4), 1)
135 60a80953 Ilias Tsitsimpis
        self.server_a['pr_ipv4'] = ipv4[0]
136 60a80953 Ilias Tsitsimpis
        ipv4 = self._get_ips(self.server_b['server'], network=self.network)
137 60a80953 Ilias Tsitsimpis
        self.assertEqual(len(ipv4), 1)
138 60a80953 Ilias Tsitsimpis
        self.server_b['pr_ipv4'] = ipv4
139 3eaf0ec5 Ilias Tsitsimpis
140 3eaf0ec5 Ilias Tsitsimpis
    def test_008_reboot_server_a(self):
141 3eaf0ec5 Ilias Tsitsimpis
        """Rebooting server A"""
142 3eaf0ec5 Ilias Tsitsimpis
        self.clients.cyclades.shutdown_server(self.server_a['server']['id'])
143 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_server_transition(
144 3eaf0ec5 Ilias Tsitsimpis
            self.server_a['server'], ["ACTIVE"], "STOPPED")
145 3eaf0ec5 Ilias Tsitsimpis
146 3eaf0ec5 Ilias Tsitsimpis
        self.clients.cyclades.start_server(self.server_a['server']['id'])
147 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_server_transition(
148 3eaf0ec5 Ilias Tsitsimpis
            self.server_a['server'], ["STOPPED"], "ACTIVE")
149 3eaf0ec5 Ilias Tsitsimpis
150 3eaf0ec5 Ilias Tsitsimpis
    def test_009_ping_server_a(self):
151 3eaf0ec5 Ilias Tsitsimpis
        """Test if server A responds to IPv4 pings"""
152 60a80953 Ilias Tsitsimpis
        self._insist_on_ping(self._get_ips(self.server_a['server'])[0])
153 3eaf0ec5 Ilias Tsitsimpis
154 3eaf0ec5 Ilias Tsitsimpis
    def test_010_reboot_server_b(self):
155 3eaf0ec5 Ilias Tsitsimpis
        """Rebooting server B"""
156 3eaf0ec5 Ilias Tsitsimpis
        self.clients.cyclades.shutdown_server(self.server_b['server']['id'])
157 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_server_transition(
158 3eaf0ec5 Ilias Tsitsimpis
            self.server_b['server'], ["ACTIVE"], "STOPPED")
159 3eaf0ec5 Ilias Tsitsimpis
160 3eaf0ec5 Ilias Tsitsimpis
        self.clients.cyclades.start_server(self.server_b['server']['id'])
161 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_server_transition(
162 3eaf0ec5 Ilias Tsitsimpis
            self.server_b['server'], ["STOPPED"], "ACTIVE")
163 3eaf0ec5 Ilias Tsitsimpis
164 3eaf0ec5 Ilias Tsitsimpis
    def test_011_ping_server_b(self):
165 3eaf0ec5 Ilias Tsitsimpis
        """Test that server B responds to IPv4 pings"""
166 60a80953 Ilias Tsitsimpis
        self._insist_on_ping(self._get_ips(self.server_b['server'])[0])
167 3eaf0ec5 Ilias Tsitsimpis
168 3eaf0ec5 Ilias Tsitsimpis
    def test_012_test_connection_exists(self):
169 3eaf0ec5 Ilias Tsitsimpis
        """Ping server B from server A to test if connection exists"""
170 3eaf0ec5 Ilias Tsitsimpis
        self._skip_if(not self._image_is(self.server_a['image'], "linux"),
171 3eaf0ec5 Ilias Tsitsimpis
                      "only valid for Linux servers")
172 3eaf0ec5 Ilias Tsitsimpis
        self._skip_if(not self._image_is(self.server_b['image'], "linux"),
173 3eaf0ec5 Ilias Tsitsimpis
                      "only valid for Linux servers")
174 3eaf0ec5 Ilias Tsitsimpis
175 60a80953 Ilias Tsitsimpis
        server_a_public_ip = self._get_ips(self.server_a['server'])[0]
176 60a80953 Ilias Tsitsimpis
        server_b_private_ip = self._get_ips(
177 60a80953 Ilias Tsitsimpis
            self.server_b['server'], network=self.network)[0]
178 3eaf0ec5 Ilias Tsitsimpis
        msg = "Will try to connect to server A (%s) and ping to server B (%s)"
179 3eaf0ec5 Ilias Tsitsimpis
        self.info(msg, server_a_public_ip, server_b_private_ip)
180 3eaf0ec5 Ilias Tsitsimpis
181 3eaf0ec5 Ilias Tsitsimpis
        cmd = "for i in {1..7}; do if ping -c 3 -w 20 %s > /dev/null; " \
182 3eaf0ec5 Ilias Tsitsimpis
            "then echo 'True'; break; fi; done" % server_b_private_ip
183 3eaf0ec5 Ilias Tsitsimpis
        lines, status = self._ssh_execute(
184 3eaf0ec5 Ilias Tsitsimpis
            server_a_public_ip, self.server_a['username'],
185 3eaf0ec5 Ilias Tsitsimpis
            self.server_a['password'], cmd)
186 3eaf0ec5 Ilias Tsitsimpis
187 3eaf0ec5 Ilias Tsitsimpis
        self.assertEqual(status, 0)
188 3eaf0ec5 Ilias Tsitsimpis
        self.assertEqual(lines, ['True\n'])
189 3eaf0ec5 Ilias Tsitsimpis
190 3eaf0ec5 Ilias Tsitsimpis
    def test_013_disconnect_network(self):
191 3eaf0ec5 Ilias Tsitsimpis
        """Disconnecting servers A and B from network"""
192 3eaf0ec5 Ilias Tsitsimpis
        self._disconnect_from_network(self.server_a['server'], self.network)
193 3eaf0ec5 Ilias Tsitsimpis
        self._disconnect_from_network(self.server_b['server'], self.network)
194 3eaf0ec5 Ilias Tsitsimpis
195 3eaf0ec5 Ilias Tsitsimpis
    def test_014_destroy_network(self):
196 3eaf0ec5 Ilias Tsitsimpis
        """Submit delete network request"""
197 60a80953 Ilias Tsitsimpis
        self._delete_networks([self.network])
198 3e5bbd85 Ilias Tsitsimpis
199 3eaf0ec5 Ilias Tsitsimpis
    def test_015_cleanup_servers(self):
200 3eaf0ec5 Ilias Tsitsimpis
        """Cleanup servers created for this test"""
201 60a80953 Ilias Tsitsimpis
        self._delete_servers([self.server_a['server'],
202 60a80953 Ilias Tsitsimpis
                              self.server_b['server']])