Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (14.4 kB)

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

37 6c78720b Ilias Tsitsimpis
"""
38 6c78720b Ilias Tsitsimpis
39 6c78720b Ilias Tsitsimpis
import sys
40 cee3ee9b Ilias Tsitsimpis
import stat
41 cee3ee9b Ilias Tsitsimpis
import base64
42 6c78720b Ilias Tsitsimpis
import random
43 6c78720b Ilias Tsitsimpis
import socket
44 6c78720b Ilias Tsitsimpis
45 6c78720b Ilias Tsitsimpis
from vncauthproxy.d3des import generate_response as d3des_generate_response
46 6c78720b Ilias Tsitsimpis
47 08f1780b Ilias Tsitsimpis
from synnefo_tools.burnin.common import BurninTests, Proper
48 d246be88 Ilias Tsitsimpis
from synnefo_tools.burnin.cyclades_common import CycladesTests
49 6c78720b Ilias Tsitsimpis
50 6c78720b Ilias Tsitsimpis
51 6c78720b Ilias Tsitsimpis
# Too many public methods. pylint: disable-msg=R0904
52 60a80953 Ilias Tsitsimpis
# Too many instance attributes. pylint: disable-msg=R0902
53 6c78720b Ilias Tsitsimpis
# This class gets replicated into actual TestCases dynamically
54 d246be88 Ilias Tsitsimpis
class GeneratedServerTestSuite(CycladesTests):
55 6c78720b Ilias Tsitsimpis
    """Test Spawning Serverfunctionality"""
56 6c78720b Ilias Tsitsimpis
    use_image = Proper(value=None)
57 cee3ee9b Ilias Tsitsimpis
    personality = Proper(value=None)
58 6c78720b Ilias Tsitsimpis
    avail_flavors = Proper(value=None)
59 6c78720b Ilias Tsitsimpis
    use_flavor = Proper(value=None)
60 6c78720b Ilias Tsitsimpis
    server = Proper(value=None)
61 6c78720b Ilias Tsitsimpis
    ipv4 = Proper(value=None)
62 6c78720b Ilias Tsitsimpis
    ipv6 = Proper(value=None)
63 cee3ee9b Ilias Tsitsimpis
    username = Proper(value=None)
64 cee3ee9b Ilias Tsitsimpis
    password = Proper(value=None)
65 6c78720b Ilias Tsitsimpis
66 6c78720b Ilias Tsitsimpis
    def test_001_submit_create_server(self):
67 6c78720b Ilias Tsitsimpis
        """Submit a create server request"""
68 cee3ee9b Ilias Tsitsimpis
        if self._image_is(self.use_image, "linux"):
69 cee3ee9b Ilias Tsitsimpis
            # Enforce personality test
70 cee3ee9b Ilias Tsitsimpis
            self.info("Creating personality content to be used")
71 cee3ee9b Ilias Tsitsimpis
            self.personality = [{
72 cee3ee9b Ilias Tsitsimpis
                'path': "/root/test_inj_file",
73 cee3ee9b Ilias Tsitsimpis
                'owner': "root",
74 cee3ee9b Ilias Tsitsimpis
                'group': "root",
75 cee3ee9b Ilias Tsitsimpis
                'mode': stat.S_IRUSR | stat.S_IWUSR,
76 cee3ee9b Ilias Tsitsimpis
                'contents': base64.b64encode("This is a personality file")
77 cee3ee9b Ilias Tsitsimpis
            }]
78 6c78720b Ilias Tsitsimpis
        self.use_flavor = random.choice(self.avail_flavors)
79 6c78720b Ilias Tsitsimpis
80 6c78720b Ilias Tsitsimpis
        self.server = self._create_server(
81 60a80953 Ilias Tsitsimpis
            self.use_image, self.use_flavor,
82 60a80953 Ilias Tsitsimpis
            personality=self.personality, network=True)
83 cee3ee9b Ilias Tsitsimpis
        self.username = self._get_connection_username(self.server)
84 cee3ee9b Ilias Tsitsimpis
        self.password = self.server['adminPass']
85 6c78720b Ilias Tsitsimpis
86 6c78720b Ilias Tsitsimpis
    def test_002_server_build_list(self):
87 6c78720b Ilias Tsitsimpis
        """Test server is in BUILD state, in server list"""
88 6c78720b Ilias Tsitsimpis
        servers = self._get_list_of_servers(detail=True)
89 6c78720b Ilias Tsitsimpis
        servers = [s for s in servers if s['id'] == self.server['id']]
90 6c78720b Ilias Tsitsimpis
91 6c78720b Ilias Tsitsimpis
        self.assertEqual(len(servers), 1)
92 6c78720b Ilias Tsitsimpis
        server = servers[0]
93 6c78720b Ilias Tsitsimpis
        self.assertEqual(server['name'], self.server['name'])
94 6c78720b Ilias Tsitsimpis
        self.assertEqual(server['flavor']['id'], self.use_flavor['id'])
95 6c78720b Ilias Tsitsimpis
        self.assertEqual(server['image']['id'], self.use_image['id'])
96 6c78720b Ilias Tsitsimpis
        self.assertEqual(server['status'], "BUILD")
97 6c78720b Ilias Tsitsimpis
98 6c78720b Ilias Tsitsimpis
    def test_003_server_build_details(self):
99 6c78720b Ilias Tsitsimpis
        """Test server is in BUILD state, in details"""
100 6c78720b Ilias Tsitsimpis
        server = self._get_server_details(self.server)
101 6c78720b Ilias Tsitsimpis
        self.assertEqual(server['name'], self.server['name'])
102 6c78720b Ilias Tsitsimpis
        self.assertEqual(server['flavor']['id'], self.use_flavor['id'])
103 6c78720b Ilias Tsitsimpis
        self.assertEqual(server['image']['id'], self.use_image['id'])
104 6c78720b Ilias Tsitsimpis
        self.assertEqual(server['status'], "BUILD")
105 6c78720b Ilias Tsitsimpis
106 6c78720b Ilias Tsitsimpis
    def test_004_set_server_metadata(self):
107 6c78720b Ilias Tsitsimpis
        """Test setting some of the server's metadata"""
108 6c78720b Ilias Tsitsimpis
        image = self.clients.cyclades.get_image_details(self.use_image['id'])
109 6c78720b Ilias Tsitsimpis
        os_value = image['metadata']['os']
110 6c78720b Ilias Tsitsimpis
        self.clients.cyclades.update_server_metadata(
111 6c78720b Ilias Tsitsimpis
            self.server['id'], OS=os_value)
112 6c78720b Ilias Tsitsimpis
113 6c78720b Ilias Tsitsimpis
        servermeta = \
114 6c78720b Ilias Tsitsimpis
            self.clients.cyclades.get_server_metadata(self.server['id'])
115 6c78720b Ilias Tsitsimpis
        imagemeta = \
116 6c78720b Ilias Tsitsimpis
            self.clients.cyclades.get_image_metadata(self.use_image['id'])
117 6c78720b Ilias Tsitsimpis
        self.assertEqual(servermeta['OS'], imagemeta['os'])
118 6c78720b Ilias Tsitsimpis
119 6c78720b Ilias Tsitsimpis
    def test_005_server_becomes_active(self):
120 6c78720b Ilias Tsitsimpis
        """Test server becomes ACTIVE"""
121 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_server_transition(self.server, ["BUILD"], "ACTIVE")
122 6c78720b Ilias Tsitsimpis
123 362130c3 Ilias Tsitsimpis
    def test_006_get_server_oob_console(self):
124 6c78720b Ilias Tsitsimpis
        """Test getting OOB server console over VNC
125 6c78720b Ilias Tsitsimpis

126 6c78720b Ilias Tsitsimpis
        Implementation of RFB protocol follows
127 6c78720b Ilias Tsitsimpis
        http://www.realvnc.com/docs/rfbproto.pdf.
128 6c78720b Ilias Tsitsimpis

129 6c78720b Ilias Tsitsimpis
        """
130 6c78720b Ilias Tsitsimpis
        console = self.clients.cyclades.get_server_console(self.server['id'])
131 6c78720b Ilias Tsitsimpis
        self.assertEquals(console['type'], "vnc")
132 6c78720b Ilias Tsitsimpis
        sock = self._insist_on_tcp_connection(
133 6c78720b Ilias Tsitsimpis
            socket.AF_INET, console['host'], console['port'])
134 6c78720b Ilias Tsitsimpis
135 6c78720b Ilias Tsitsimpis
        # Step 1. ProtocolVersion message (par. 6.1.1)
136 6c78720b Ilias Tsitsimpis
        version = sock.recv(1024)
137 6c78720b Ilias Tsitsimpis
        self.assertEquals(version, 'RFB 003.008\n')
138 6c78720b Ilias Tsitsimpis
        sock.send(version)
139 6c78720b Ilias Tsitsimpis
140 6c78720b Ilias Tsitsimpis
        # Step 2. Security (par 6.1.2): Only VNC Authentication supported
141 6c78720b Ilias Tsitsimpis
        sec = sock.recv(1024)
142 6c78720b Ilias Tsitsimpis
        self.assertEquals(list(sec), ['\x01', '\x02'])
143 6c78720b Ilias Tsitsimpis
144 6c78720b Ilias Tsitsimpis
        # Step 3. Request VNC Authentication (par 6.1.2)
145 6c78720b Ilias Tsitsimpis
        sock.send('\x02')
146 6c78720b Ilias Tsitsimpis
147 6c78720b Ilias Tsitsimpis
        # Step 4. Receive Challenge (par 6.2.2)
148 6c78720b Ilias Tsitsimpis
        challenge = sock.recv(1024)
149 6c78720b Ilias Tsitsimpis
        self.assertEquals(len(challenge), 16)
150 6c78720b Ilias Tsitsimpis
151 6c78720b Ilias Tsitsimpis
        # Step 5. DES-Encrypt challenge, use password as key (par 6.2.2)
152 6c78720b Ilias Tsitsimpis
        response = d3des_generate_response(
153 6c78720b Ilias Tsitsimpis
            (console["password"] + '\0' * 8)[:8], challenge)
154 6c78720b Ilias Tsitsimpis
        sock.send(response)
155 6c78720b Ilias Tsitsimpis
156 6c78720b Ilias Tsitsimpis
        # Step 6. SecurityResult (par 6.1.3)
157 6c78720b Ilias Tsitsimpis
        result = sock.recv(4)
158 6c78720b Ilias Tsitsimpis
        self.assertEquals(list(result), ['\x00', '\x00', '\x00', '\x00'])
159 6c78720b Ilias Tsitsimpis
        sock.close()
160 6c78720b Ilias Tsitsimpis
161 362130c3 Ilias Tsitsimpis
    def test_007_server_has_ipv4(self):
162 6c78720b Ilias Tsitsimpis
        """Test active server has a valid IPv4 address"""
163 6c78720b Ilias Tsitsimpis
        server = self.clients.cyclades.get_server_details(self.server['id'])
164 6c78720b Ilias Tsitsimpis
        # Update the server attribute
165 6c78720b Ilias Tsitsimpis
        self.server = server
166 6c78720b Ilias Tsitsimpis
167 60a80953 Ilias Tsitsimpis
        self.ipv4 = self._get_ips(server, version=4)
168 6c78720b Ilias Tsitsimpis
169 362130c3 Ilias Tsitsimpis
    def test_008_server_has_ipv6(self):
170 6c78720b Ilias Tsitsimpis
        """Test active server has a valid IPv6 address"""
171 6c78720b Ilias Tsitsimpis
        self._skip_if(not self.use_ipv6, "--no-ipv6 flag enabled")
172 6c78720b Ilias Tsitsimpis
173 60a80953 Ilias Tsitsimpis
        self.ipv6 = self._get_ips(self.server, version=6)
174 6c78720b Ilias Tsitsimpis
175 362130c3 Ilias Tsitsimpis
    def test_009_server_ping_ipv4(self):
176 6c78720b Ilias Tsitsimpis
        """Test server responds to ping on IPv4 address"""
177 362130c3 Ilias Tsitsimpis
        for ipv4 in self.ipv4:
178 362130c3 Ilias Tsitsimpis
            self._insist_on_ping(ipv4, version=4)
179 6c78720b Ilias Tsitsimpis
180 362130c3 Ilias Tsitsimpis
    def test_010_server_ping_ipv6(self):
181 6c78720b Ilias Tsitsimpis
        """Test server responds to ping on IPv6 address"""
182 6c78720b Ilias Tsitsimpis
        self._skip_if(not self.use_ipv6, "--no-ipv6 flag enabled")
183 60a80953 Ilias Tsitsimpis
        self._insist_on_ping(self.ipv6[0], version=6)
184 6c78720b Ilias Tsitsimpis
185 362130c3 Ilias Tsitsimpis
    def test_011_attach_second_network(self):
186 362130c3 Ilias Tsitsimpis
        """Attach a second public IP to our server"""
187 362130c3 Ilias Tsitsimpis
        floating_ip = self._create_floating_ip()
188 362130c3 Ilias Tsitsimpis
        self._create_port(floating_ip['floating_network_id'],
189 362130c3 Ilias Tsitsimpis
                          device_id=self.server['id'],
190 362130c3 Ilias Tsitsimpis
                          floating_ip=floating_ip)
191 362130c3 Ilias Tsitsimpis
192 362130c3 Ilias Tsitsimpis
        # Update server attributes
193 362130c3 Ilias Tsitsimpis
        server = self.clients.cyclades.get_server_details(self.server['id'])
194 362130c3 Ilias Tsitsimpis
        self.server = server
195 362130c3 Ilias Tsitsimpis
        self.ipv4 = self._get_ips(server, version=4)
196 362130c3 Ilias Tsitsimpis
        self.assertEqual(len(self.ipv4), 2)
197 362130c3 Ilias Tsitsimpis
198 362130c3 Ilias Tsitsimpis
        # Test new IPv4
199 362130c3 Ilias Tsitsimpis
        self.test_009_server_ping_ipv4()
200 362130c3 Ilias Tsitsimpis
201 60a80953 Ilias Tsitsimpis
    def test_012_submit_shutdown(self):
202 6c78720b Ilias Tsitsimpis
        """Test submit request to shutdown server"""
203 6c78720b Ilias Tsitsimpis
        self.clients.cyclades.shutdown_server(self.server['id'])
204 6c78720b Ilias Tsitsimpis
205 60a80953 Ilias Tsitsimpis
    def test_013_server_becomes_stopped(self):
206 6c78720b Ilias Tsitsimpis
        """Test server becomes STOPPED"""
207 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_server_transition(self.server, ["ACTIVE"], "STOPPED")
208 6c78720b Ilias Tsitsimpis
209 60a80953 Ilias Tsitsimpis
    def test_014_submit_start(self):
210 6c78720b Ilias Tsitsimpis
        """Test submit start server request"""
211 6c78720b Ilias Tsitsimpis
        self.clients.cyclades.start_server(self.server['id'])
212 6c78720b Ilias Tsitsimpis
213 60a80953 Ilias Tsitsimpis
    def test_015_server_becomes_active(self):
214 6c78720b Ilias Tsitsimpis
        """Test server becomes ACTIVE again"""
215 3eaf0ec5 Ilias Tsitsimpis
        self._insist_on_server_transition(self.server, ["STOPPED"], "ACTIVE")
216 6c78720b Ilias Tsitsimpis
217 60a80953 Ilias Tsitsimpis
    def test_016_server_ping_ipv4(self):
218 6c78720b Ilias Tsitsimpis
        """Test server OS is actually up and running again"""
219 362130c3 Ilias Tsitsimpis
        self.test_009_server_ping_ipv4()
220 6c78720b Ilias Tsitsimpis
221 60a80953 Ilias Tsitsimpis
    def test_017_ssh_to_server_ipv4(self):
222 cee3ee9b Ilias Tsitsimpis
        """Test SSH to server public IPv4 works, verify hostname"""
223 cee3ee9b Ilias Tsitsimpis
        self._skip_if(not self._image_is(self.use_image, "linux"),
224 cee3ee9b Ilias Tsitsimpis
                      "only valid for Linux servers")
225 60a80953 Ilias Tsitsimpis
        hostname1 = self._insist_get_hostname_over_ssh(
226 60a80953 Ilias Tsitsimpis
            self.ipv4[0], self.username, self.password)
227 60a80953 Ilias Tsitsimpis
        hostname2 = self._insist_get_hostname_over_ssh(
228 60a80953 Ilias Tsitsimpis
            self.ipv4[1], self.username, self.password)
229 cee3ee9b Ilias Tsitsimpis
        # The hostname must be of the form 'prefix-id'
230 60a80953 Ilias Tsitsimpis
        self.assertTrue(hostname1.endswith("-%d" % self.server['id']))
231 60a80953 Ilias Tsitsimpis
        self.assertEqual(hostname1, hostname2)
232 cee3ee9b Ilias Tsitsimpis
233 60a80953 Ilias Tsitsimpis
    def test_018_ssh_to_server_ipv6(self):
234 cee3ee9b Ilias Tsitsimpis
        """Test SSH to server public IPv6 works, verify hostname"""
235 cee3ee9b Ilias Tsitsimpis
        self._skip_if(not self._image_is(self.use_image, "linux"),
236 cee3ee9b Ilias Tsitsimpis
                      "only valid for Linux servers")
237 cee3ee9b Ilias Tsitsimpis
        self._skip_if(not self.use_ipv6, "--no-ipv6 flag enabled")
238 cee3ee9b Ilias Tsitsimpis
        hostname = self._insist_get_hostname_over_ssh(
239 60a80953 Ilias Tsitsimpis
            self.ipv6[0], self.username, self.password)
240 cee3ee9b Ilias Tsitsimpis
        # The hostname must be of the form 'prefix-id'
241 cee3ee9b Ilias Tsitsimpis
        self.assertTrue(hostname.endswith("-%d" % self.server['id']))
242 cee3ee9b Ilias Tsitsimpis
243 60a80953 Ilias Tsitsimpis
    def test_019_rdp_to_server_ipv4(self):
244 cee3ee9b Ilias Tsitsimpis
        """Test RDP connection to server public IPv4 works"""
245 cee3ee9b Ilias Tsitsimpis
        self._skip_if(not self._image_is(self.use_image, "windows"),
246 cee3ee9b Ilias Tsitsimpis
                      "only valid for Windows servers")
247 60a80953 Ilias Tsitsimpis
        sock = self._insist_on_tcp_connection(
248 60a80953 Ilias Tsitsimpis
            socket.AF_INET, self.ipv4[0], 3389)
249 cee3ee9b Ilias Tsitsimpis
        # No actual RDP processing done. We assume the RDP server is there
250 cee3ee9b Ilias Tsitsimpis
        # if the connection to the RDP port is successful.
251 cee3ee9b Ilias Tsitsimpis
        # pylint: disable-msg=W0511
252 cee3ee9b Ilias Tsitsimpis
        # FIXME: Use rdesktop, analyze exit code? see manpage
253 cee3ee9b Ilias Tsitsimpis
        sock.close()
254 cee3ee9b Ilias Tsitsimpis
255 60a80953 Ilias Tsitsimpis
    def test_020_rdp_to_server_ipv6(self):
256 cee3ee9b Ilias Tsitsimpis
        """Test RDP connection to server public IPv6 works"""
257 cee3ee9b Ilias Tsitsimpis
        self._skip_if(not self._image_is(self.use_image, "windows"),
258 cee3ee9b Ilias Tsitsimpis
                      "only valid for Windows servers")
259 cee3ee9b Ilias Tsitsimpis
        self._skip_if(not self.use_ipv6, "--no-ipv6 flag enabled")
260 60a80953 Ilias Tsitsimpis
        sock = self._insist_on_tcp_connection(
261 60a80953 Ilias Tsitsimpis
            socket.AF_INET, self.ipv6[0], 3389)
262 cee3ee9b Ilias Tsitsimpis
        # No actual RDP processing done. We assume the RDP server is there
263 cee3ee9b Ilias Tsitsimpis
        # if the connection to the RDP port is successful.
264 cee3ee9b Ilias Tsitsimpis
        # pylint: disable-msg=W0511
265 cee3ee9b Ilias Tsitsimpis
        # FIXME: Use rdesktop, analyze exit code? see manpage
266 cee3ee9b Ilias Tsitsimpis
        sock.close()
267 cee3ee9b Ilias Tsitsimpis
268 60a80953 Ilias Tsitsimpis
    def test_021_personality(self):
269 cee3ee9b Ilias Tsitsimpis
        """Test file injection for personality enforcement"""
270 cee3ee9b Ilias Tsitsimpis
        self._skip_if(not self._image_is(self.use_image, "linux"),
271 cee3ee9b Ilias Tsitsimpis
                      "only implemented for linux servers")
272 cee3ee9b Ilias Tsitsimpis
        assert self.personality is not None, "No personality used"
273 cee3ee9b Ilias Tsitsimpis
274 cee3ee9b Ilias Tsitsimpis
        for inj_file in self.personality:
275 cee3ee9b Ilias Tsitsimpis
            self._check_file_through_ssh(
276 60a80953 Ilias Tsitsimpis
                self.ipv4[0], inj_file['owner'], self.password,
277 cee3ee9b Ilias Tsitsimpis
                inj_file['path'], inj_file['contents'])
278 cee3ee9b Ilias Tsitsimpis
279 60a80953 Ilias Tsitsimpis
    def test_022_destroy_floating_ips(self):
280 60a80953 Ilias Tsitsimpis
        """Destroy the floating IPs"""
281 60a80953 Ilias Tsitsimpis
        self._disconnect_from_network(self.server)
282 60a80953 Ilias Tsitsimpis
283 60a80953 Ilias Tsitsimpis
    def test_023_submit_delete_request(self):
284 cee3ee9b Ilias Tsitsimpis
        """Test submit request to delete server"""
285 60a80953 Ilias Tsitsimpis
        self._delete_servers([self.server])
286 cee3ee9b Ilias Tsitsimpis
287 6c78720b Ilias Tsitsimpis
288 6c78720b Ilias Tsitsimpis
# --------------------------------------------------------------------
289 6c78720b Ilias Tsitsimpis
# The actuall test class. We use this class to dynamically create
290 6c78720b Ilias Tsitsimpis
# tests from the GeneratedServerTestSuite class. Each of these classes
291 6c78720b Ilias Tsitsimpis
# will run the same tests using different images and or flavors.
292 6c78720b Ilias Tsitsimpis
# The creation and running of our GeneratedServerTestSuite class will
293 6c78720b Ilias Tsitsimpis
# happen as a testsuite itself (everything here is a test!).
294 6c78720b Ilias Tsitsimpis
class ServerTestSuite(BurninTests):
295 6c78720b Ilias Tsitsimpis
    """Generate and run the GeneratedServerTestSuite
296 6c78720b Ilias Tsitsimpis

297 6c78720b Ilias Tsitsimpis
    We will generate as many testsuites as the number of images given.
298 6c78720b Ilias Tsitsimpis
    Each of these testsuites will use the given flavors at will (random).
299 6c78720b Ilias Tsitsimpis

300 6c78720b Ilias Tsitsimpis
    """
301 6c78720b Ilias Tsitsimpis
    avail_images = Proper(value=None)
302 6c78720b Ilias Tsitsimpis
    avail_flavors = Proper(value=None)
303 6c78720b Ilias Tsitsimpis
    gen_classes = Proper(value=None)
304 6c78720b Ilias Tsitsimpis
305 6c78720b Ilias Tsitsimpis
    def test_001_images_to_use(self):
306 6c78720b Ilias Tsitsimpis
        """Find images to be used by GeneratedServerTestSuite"""
307 6c78720b Ilias Tsitsimpis
        if self.images is None:
308 6c78720b Ilias Tsitsimpis
            self.info("No --images given. Will use the default %s",
309 6c78720b Ilias Tsitsimpis
                      "^Debian Base$")
310 6c78720b Ilias Tsitsimpis
            filters = ["name:^Debian Base$"]
311 6c78720b Ilias Tsitsimpis
        else:
312 6c78720b Ilias Tsitsimpis
            filters = self.images
313 6c78720b Ilias Tsitsimpis
314 6c78720b Ilias Tsitsimpis
        self.avail_images = self._find_images(filters)
315 6c78720b Ilias Tsitsimpis
        self.info("Found %s images. Let's create an equal number of tests",
316 6c78720b Ilias Tsitsimpis
                  len(self.avail_images))
317 6c78720b Ilias Tsitsimpis
318 6c78720b Ilias Tsitsimpis
    def test_002_flavors_to_use(self):
319 6c78720b Ilias Tsitsimpis
        """Find flavors to be used by GeneratedServerTestSuite"""
320 6c78720b Ilias Tsitsimpis
        flavors = self._get_list_of_flavors(detail=True)
321 6c78720b Ilias Tsitsimpis
322 6c78720b Ilias Tsitsimpis
        if self.flavors is None:
323 6c78720b Ilias Tsitsimpis
            self.info("No --flavors given. Will use all of them")
324 6c78720b Ilias Tsitsimpis
            self.avail_flavors = flavors
325 6c78720b Ilias Tsitsimpis
        else:
326 6c78720b Ilias Tsitsimpis
            self.avail_flavors = self._find_flavors(
327 3eaf0ec5 Ilias Tsitsimpis
                self.flavors, flavors=flavors)
328 6c78720b Ilias Tsitsimpis
        self.info("Found %s flavors to choose from", len(self.avail_flavors))
329 6c78720b Ilias Tsitsimpis
330 6c78720b Ilias Tsitsimpis
    def test_003_create_testsuites(self):
331 6c78720b Ilias Tsitsimpis
        """Generate the GeneratedServerTestSuite tests"""
332 6c78720b Ilias Tsitsimpis
        gen_classes = []
333 6c78720b Ilias Tsitsimpis
        for img in self.avail_images:
334 6c78720b Ilias Tsitsimpis
            name = (str("GeneratedServerTestSuite_(%s)" %
335 6c78720b Ilias Tsitsimpis
                    img['name']).replace(" ", "_"))
336 6c78720b Ilias Tsitsimpis
            self.info("Constructing class %s", name)
337 6c78720b Ilias Tsitsimpis
            class_dict = {
338 6c78720b Ilias Tsitsimpis
                'use_image': Proper(value=img),
339 6c78720b Ilias Tsitsimpis
                'avail_flavors': Proper(value=self.avail_flavors)
340 6c78720b Ilias Tsitsimpis
            }
341 6c78720b Ilias Tsitsimpis
            cls = type(name, (GeneratedServerTestSuite,), class_dict)
342 6c78720b Ilias Tsitsimpis
            # Make sure the class can be pickled, by listing it among
343 6c78720b Ilias Tsitsimpis
            # the attributes of __main__. A PicklingError is raised otherwise.
344 6c78720b Ilias Tsitsimpis
            thismodule = sys.modules[__name__]
345 6c78720b Ilias Tsitsimpis
            setattr(thismodule, name, cls)
346 6c78720b Ilias Tsitsimpis
            # Append the generated class
347 6c78720b Ilias Tsitsimpis
            gen_classes.append(cls)
348 6c78720b Ilias Tsitsimpis
349 6c78720b Ilias Tsitsimpis
        self.gen_classes = gen_classes
350 6c78720b Ilias Tsitsimpis
351 6c78720b Ilias Tsitsimpis
    def test_004_run_testsuites(self):
352 6c78720b Ilias Tsitsimpis
        """Run the generated tests"""
353 08f1780b Ilias Tsitsimpis
        self._run_tests(self.gen_classes)