Statistics
| Branch: | Tag: | Revision:

root / snf-tools / synnefo_tools / burnin / network_tests.py @ c2f037ff

History | View | Annotate | Download (7.6 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
# pylint: disable=too-many-public-methods
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
        self.avail_images = self._parse_images()
57

    
58
    def test_002_flavors_to_use(self):
59
        """Find flavors to be used to create our machines"""
60
        self.avail_flavors = self._parse_flavors()
61

    
62
    def test_003_submit_create_server_a(self):
63
        """Submit create server request for server A"""
64
        use_image = random.choice(self.avail_images)
65
        use_flavor = random.choice(self.avail_flavors)
66
        server = self._create_server(use_image, use_flavor, network=True)
67

    
68
        self.server_a = {}
69
        self.server_a['server'] = server
70
        self.server_a['image'] = use_image
71
        self.server_a['flavor'] = use_flavor
72
        self.server_a['username'] = self._get_connection_username(server)
73
        self.server_a['password'] = server['adminPass']
74

    
75
    def test_004_submit_create_server_b(self):
76
        """Submit create server request for server B"""
77
        use_image = random.choice(self.avail_images)
78
        use_flavor = random.choice(self.avail_flavors)
79
        server = self._create_server(use_image, use_flavor, network=True)
80

    
81
        self.server_b = {}
82
        self.server_b['server'] = server
83
        self.server_b['image'] = use_image
84
        self.server_b['flavor'] = use_flavor
85
        self.server_b['username'] = self._get_connection_username(server)
86
        self.server_b['password'] = server['adminPass']
87

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

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

    
98
    def test_006_create_network(self):
99
        """Submit a create network request"""
100
        self.network = self._create_network()
101

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

    
105
    def test_007_connect_to_network(self):
106
        """Connect the two VMs to the newly created network"""
107
        self._create_port(self.network['id'], self.server_a['server']['id'])
108
        self._create_port(self.network['id'], self.server_b['server']['id'])
109

    
110
        # Update servers
111
        self.server_a['server'] = self._get_server_details(
112
            self.server_a['server'])
113
        self.server_b['server'] = self._get_server_details(
114
            self.server_b['server'])
115

    
116
        # Check that servers got private IPs
117
        ipv4 = self._get_ips(self.server_a['server'], network=self.network)
118
        self.assertEqual(len(ipv4), 1)
119
        self.server_a['pr_ipv4'] = ipv4[0]
120
        ipv4 = self._get_ips(self.server_b['server'], network=self.network)
121
        self.assertEqual(len(ipv4), 1)
122
        self.server_b['pr_ipv4'] = ipv4
123

    
124
    def test_008_reboot_server_a(self):
125
        """Rebooting server A"""
126
        self.clients.cyclades.shutdown_server(self.server_a['server']['id'])
127
        self._insist_on_server_transition(
128
            self.server_a['server'], ["ACTIVE"], "STOPPED")
129

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

    
134
    def test_009_ping_server_a(self):
135
        """Test if server A responds to IPv4 pings"""
136
        self._insist_on_ping(self._get_ips(self.server_a['server'])[0])
137

    
138
    def test_010_reboot_server_b(self):
139
        """Rebooting server B"""
140
        self.clients.cyclades.shutdown_server(self.server_b['server']['id'])
141
        self._insist_on_server_transition(
142
            self.server_b['server'], ["ACTIVE"], "STOPPED")
143

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

    
148
    def test_011_ping_server_b(self):
149
        """Test that server B responds to IPv4 pings"""
150
        self._insist_on_ping(self._get_ips(self.server_b['server'])[0])
151

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

    
159
        server_a_public_ip = self._get_ips(self.server_a['server'])[0]
160
        server_b_private_ip = self._get_ips(
161
            self.server_b['server'], network=self.network)[0]
162
        msg = "Will try to connect to server A (%s) and ping to server B (%s)"
163
        self.info(msg, server_a_public_ip, server_b_private_ip)
164

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

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

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

    
179
    def test_014_destroy_network(self):
180
        """Submit delete network request"""
181
        self._delete_networks([self.network])
182

    
183
    def test_015_cleanup_servers(self):
184
        """Cleanup servers created for this test"""
185
        self._delete_servers([self.server_a['server'],
186
                              self.server_b['server']])