1 # Copyright 2012-2013 GRNET S.A. All rights reserved.
3 # Redistribution and use in source and binary forms, with or
4 # without modification, are permitted provided that the following
7 # 1. Redistributions of source code must retain the above
8 # copyright notice, this list of conditions and the following
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.
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.
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
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
41 livetest_cmds = CommandTree('livetest', 'Test clients on live servers')
42 _commands = [livetest_cmds]
45 class _livetest_init(_command_init):
47 def _run(self, client, method=None):
49 livetest._main([client, method], config=self.config)
51 livetest._main([client], config=self.config)
53 def main(self, client, method=None):
54 return self._run(client, method)
57 @command(livetest_cmds)
58 class livetest_error(_livetest_init):
59 """Create an error message with optional message"""
62 def _run(self, errmsg='', importance=0, index=0):
66 except Exception as err:
67 raiseCLIError(err, errmsg, importance)
68 raiseCLIError(None, errmsg, importance)
70 def main(self, errmsg='', importance=0, index=0):
71 self._run(errmsg, importance, index)
74 @command(livetest_cmds)
75 class livetest_args(_livetest_init):
76 """Test how arguments are treated by kamaki"""
79 def _run(self, *args):
82 def main(self, *args):
86 @command(livetest_cmds)
87 class livetest_all(_livetest_init):
88 """test all clients"""
92 for client in ('pithos', 'cyclades', 'image', 'astakos'):
93 super(self.__class__, self)._run(client)
99 @command(livetest_cmds)
100 class livetest_pithos(_livetest_init):
101 """ test Pithos client"""
104 def _run(self, method=None):
105 super(self.__class__, self)._run('pithos', method)
107 def main(self, method=None):
111 @command(livetest_cmds)
112 class livetest_cyclades(_livetest_init):
113 """ test Cyclades client"""
116 def _run(self, method=None):
117 super(self.__class__, self)._run('cyclades', method)
119 def main(self, method=None):
123 @command(livetest_cmds)
124 class livetest_image(_livetest_init):
125 """ test Image client"""
128 def _run(self, method=None):
129 super(self.__class__, self)._run('image', method)
131 def main(self, method=None):
135 @command(livetest_cmds)
136 class livetest_astakos(_livetest_init):
137 """ test Astakos client"""
140 def _run(self, method=None):
141 super(self.__class__, self)._run('astakos', method)
143 def main(self, method=None):
147 @command(livetest_cmds)
148 class livetest_prints(_livetest_init):
149 """ user-test print methods for lists and dicts"""
151 d1 = {'key0a': 'val0a', 'key0b': 'val0b', 'key0c': 'val0c'}
153 l1 = [1, 'string', '3', 'many (2 or 3) numbers and strings combined', 5]
155 d2 = {'id': 'val0a', 'key0b': d1, 'title': l1}
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}
165 from kamaki.cli.utils import print_dict, print_list, print_items
166 print('Test simple dict:\n- - -')
169 print('\nTest simple list:\n- - -')
172 print('\nTest 2-level dict:\n- - -')
175 print('\nTest non-trivial list:\n- - -')
178 print('\nTest extreme dict:\n- - -')
181 print('Test simple enumerated dict:\n- - -')
182 print_dict(self.d1, with_enumeration=True)
184 print('\nTest simple enumerated list:\n- - -')
185 print_list(self.l1, with_enumeration=True)
187 print('Test non-trivial deep-enumerated dict:\n- - -')
188 print_dict(self.d2, with_enumeration=True, recursive_enumeration=True)
190 print('\nTest non-trivial enumerated list:\n- - -')
191 print_list(self.l2, with_enumeration=True)
193 print('\nTest print_items with id:\n- - -')
195 {'id': '42', 'title': 'lalakis 1', 'content': self.d1},
196 {'id': '142', 'title': 'lalakis 2', 'content': self.d2}])
198 print('\nTest print_items with id and enumeration:\n- - -')
201 {'id': '42', 'title': 'lalakis 1', 'content': self.d1},
202 {'id': '142', 'title': 'lalakis 2', 'content': self.d2}],
203 with_enumeration=True)
205 print('\nTest print_items with id, title and redundancy:\n- - -')
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)
213 print('\nTest print_items with lists- - -')
214 print_items([['i00', 'i01', 'i02'], [self.l2, 'i11', self.d1], 3])