Statistics
| Branch: | Tag: | Revision:

root / kamaki / clients / tests / cyclades.py @ b482315a

History | View | Annotate | Download (4.9 kB)

1
# Copyright 2012-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
import time
35

    
36
from kamaki.clients import tests
37
from kamaki.clients.cyclades import CycladesClient
38

    
39

    
40
class Cyclades(tests.Generic):
41
    """Set up a Cyclades thorough test"""
42
    def setUp(self):
43

    
44
        """okeanos"""
45
        self.img = 'b2dffe52-64a4-48c3-8a4c-8214cc3165cf'
46
        self.img_details = {
47
            u'status': u'ACTIVE',
48
            u'updated': u'2012-11-19T13:52:16+00:00',
49
            u'name': u'Debian Base',
50
            u'created': u'2012-10-16T09:03:12+00:00',
51
            u'progress': 100,
52
            u'id': self.img,
53
            u'metadata': {
54
                u'values': {
55
                    u'kernel': u'2.6.32',
56
                    u'osfamily': u'linux',
57
                    u'users': u'root',
58
                    u'gui': u'No GUI',
59
                    u'sortorder': u'1',
60
                    u'os': u'debian',
61
                    u'root_partition': u'1',
62
                    u'description': u'Debian 6.0.6 (Squeeze) Base System'}
63
                }
64
            }
65
        self.flavor_details = {u'name': u'C1R1024D20',
66
            u'ram': 1024,
67
            u'id': 1,
68
            u'SNF:disk_template': u'drbd',
69
            u'disk': 20,
70
            u'cpu': 1}
71
        self.PROFILES = ('ENABLED', 'DISABLED', 'PROTECTED')
72

    
73
        self.servers = {}
74
        self.now = time.mktime(time.gmtime())
75
        self.servname1 = 'serv' + unicode(self.now)
76
        self.servname2 = self.servname1 + '_v2'
77
        self.servname1 += '_v1'
78
        self.flavorid = 1
79
        #servers have to be created at the begining...
80
        self.networks = {}
81
        self.netname1 = 'net' + unicode(self.now)
82
        self.netname2 = 'net' + unicode(self.now) + '_v2'
83

    
84
        self.client = CycladesClient(self['compute', 'url'], self['token'])
85
        pass
86

    
87
    def tearDown(self):
88
        """Destoy servers used in testing"""
89
        print
90
        for netid in self.networks.keys():
91
            self._delete_network(netid)
92
        if 0 >= len(self.servers):
93
            return
94
        print('-> Found %s servers to delete' % len(self.servers))
95
        for server in self.servers.values():
96
            self._delete_server(server['id'])
97

    
98
    def _create_server(self, servername, flavorid, imageid, personality=None):
99
        server = self.client.create_server(servername,
100
            flavorid,
101
            imageid,
102
            personality)
103
        self.servers[servername] = server
104
        return server
105

    
106
    def _delete_server(self, servid):
107
        try:
108
            current_state = self.client.get_server_details(servid)
109
            current_state = current_state['status']
110
            if current_state == 'DELETED':
111
                return
112
        except:
113
            return
114
        self.client.delete_server(servid)
115
        self._wait_for_status(servid, current_state)
116

    
117
    def _create_network(self, netname, **kwargs):
118
        net = self.client.create_network(netname, **kwargs)
119
        self.networks[net['id']] = net
120
        return net
121

    
122
    def _delete_network(self, netid):
123
        sys.stdout.write('\tDelete network %s ' % netid)
124
        self.client.disconnect_network_nics(netid)
125
        wait = 3
126
        while True:
127
            try:
128
                self.client.delete_network(netid)
129
                print('\n\tSUCCESFULL COMMIT delete network %s' % netid)
130
                break
131
            except ClientError as err:
132
                self.assertEqual(err.status, 421)
133
                time.sleep(wait)
134
                wait += 3
135
                sys.stdout.write('.')