Statistics
| Branch: | Tag: | Revision:

root / kamaki / cli / commands / livetest.py @ 0f383dcc

History | View | Annotate | Download (7 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.command
33

    
34
from kamaki.cli.commands import errors
35
from kamaki.cli import command
36
from kamaki.cli.commands import _command_init
37
from kamaki.cli.command_tree import CommandTree
38
from kamaki.clients import livetest
39
from kamaki.cli.errors import raiseCLIError
40

    
41
livetest_cmds = CommandTree('livetest', 'Client func. tests on live servers')
42
_commands = [livetest_cmds]
43

    
44

    
45
class _livetest_init(_command_init):
46

    
47
    def _run(self, client, method=None):
48
        if method:
49
            livetest.main([client, method], config=self.config)
50
        else:
51
            livetest.main([client], config=self.config)
52

    
53
    def main(self, client, method=None):
54
        return self._run(client, method)
55

    
56

    
57
@command(livetest_cmds)
58
class livetest_error(_livetest_init):
59
    """Create an error message with optional message"""
60

    
61
    @errors.generic.all
62
    def _run(self, errmsg='', importance=0, index=0):
63
        l = [1, 2]
64
        try:
65
            l[int(index)]
66
        except Exception as err:
67
            raiseCLIError(err, errmsg, importance)
68
        raiseCLIError(None, errmsg, importance)
69

    
70
    def main(self, errmsg='', importance=0, index=0):
71
        self._run(errmsg, importance, index)
72

    
73

    
74
@command(livetest_cmds)
75
class livetest_args(_livetest_init):
76
    """Test how arguments are treated by kamaki"""
77

    
78
    @errors.generic.all
79
    def _run(self, *args):
80
        print(args)
81

    
82
    def main(self, *args):
83
        self._run(args)
84

    
85

    
86
@command(livetest_cmds)
87
class livetest_all(_livetest_init):
88
    """test all clients"""
89

    
90
    @errors.generic.all
91
    def _run(self):
92
        for client in ('pithos', 'cyclades', 'image', 'astakos'):
93
            super(self.__class__, self)._run(client)
94

    
95
    def main(self):
96
        self._run()
97

    
98

    
99
@command(livetest_cmds)
100
class livetest_pithos(_livetest_init):
101
    """ test Pithos client"""
102

    
103
    @errors.generic.all
104
    def _run(self, method=None):
105
        super(self.__class__, self)._run('pithos', method)
106

    
107
    def main(self, method=None):
108
        self._run(method)
109

    
110

    
111
@command(livetest_cmds)
112
class livetest_cyclades(_livetest_init):
113
    """ test Cyclades client"""
114

    
115
    @errors.generic.all
116
    def _run(self, method=None):
117
        super(self.__class__, self)._run('cyclades', method)
118

    
119
    def main(self, method=None):
120
        self._run(method)
121

    
122

    
123
@command(livetest_cmds)
124
class livetest_image(_livetest_init):
125
    """ test Image client"""
126

    
127
    @errors.generic.all
128
    def _run(self, method=None):
129
        super(self.__class__, self)._run('image', method)
130

    
131
    def main(self, method=None):
132
        self._run(method)
133

    
134

    
135
@command(livetest_cmds)
136
class livetest_astakos(_livetest_init):
137
    """ test Astakos client"""
138

    
139
    @errors.generic.all
140
    def _run(self, method=None):
141
        super(self.__class__, self)._run('astakos', method)
142

    
143
    def main(self, method=None):
144
        self._run(method)
145

    
146

    
147
@command(livetest_cmds)
148
class livetest_prints(_livetest_init):
149
    """ user-test print methods for lists and dicts"""
150

    
151
    d1 = {'key0a': 'val0a', 'key0b': 'val0b', 'key0c': 'val0c'}
152

    
153
    l1 = [1, 'string', '3', 'many (2 or 3) numbers and strings combined', 5]
154

    
155
    d2 = {'id': 'val0a', 'key0b': d1, 'title': l1}
156

    
157
    l2 = [d2, l1, d1]
158

    
159
    spr_msg = 'long key of size 75 characters is used to check the effects on'
160
    spr_msg += ' total result for long messages that drive pep8 completely mad'
161
    d3 = {'dict 1': d1, 'dict 2': d2, 'list2': l2, spr_msg: l1}
162

    
163
    @errors.generic.all
164
    def _run(self):
165
        from kamaki.cli.utils import print_dict, print_list, print_items
166
        print('Test simple dict:\n- - -')
167
        print_dict(self.d1)
168
        print('- - -\n')
169
        print('\nTest simple list:\n- - -')
170
        print_list(self.l1)
171
        print('- - -\n')
172
        print('\nTest 2-level dict:\n- - -')
173
        print_dict(self.d2)
174
        print('- - -\n')
175
        print('\nTest non-trivial list:\n- - -')
176
        print_list(self.l2)
177
        print('- - -')
178
        print('\nTest extreme dict:\n- - -')
179
        print_dict(self.d3)
180
        print('- - -\n')
181
        print('Test simple enumerated dict:\n- - -')
182
        print_dict(self.d1, with_enumeration=True)
183
        print('- - -\n')
184
        print('\nTest simple enumerated list:\n- - -')
185
        print_list(self.l1, with_enumeration=True)
186
        print('- - -\n')
187
        print('Test non-trivial deep-enumerated dict:\n- - -')
188
        print_dict(self.d2, with_enumeration=True, recursive_enumeration=True)
189
        print('- - -\n')
190
        print('\nTest non-trivial enumerated list:\n- - -')
191
        print_list(self.l2, with_enumeration=True)
192
        print('- - -\n')
193
        print('\nTest print_items with id:\n- - -')
194
        print_items([
195
            {'id': '42', 'title': 'lalakis 1', 'content': self.d1},
196
            {'id': '142', 'title': 'lalakis 2', 'content': self.d2}])
197
        print('- - -')
198
        print('\nTest print_items with id and enumeration:\n- - -')
199
        print_items(
200
            [
201
                {'id': '42', 'title': 'lalakis 1', 'content': self.d1},
202
                {'id': '142', 'title': 'lalakis 2', 'content': self.d2}],
203
            with_enumeration=True)
204
        print('- - -')
205
        print('\nTest print_items with id, title and redundancy:\n- - -')
206
        print_items(
207
            [
208
                {'id': '42', 'title': 'lalakis 1', 'content': self.d1},
209
                {'id': '142', 'title': 'lalakis 2', 'content': self.d2}],
210
            title=('id', 'title'),
211
            with_redundancy=True)
212
        print('- - -')
213
        print('\nTest print_items with lists- - -')
214
        print_items([['i00', 'i01', 'i02'], [self.l2, 'i11', self.d1], 3])
215
        print('- - -')
216

    
217
    def main(self):
218
        self._run()