Revision cd42f8d8

b/kamaki/cli/commands/astakos.py
35 35
from os.path import abspath
36 36

  
37 37
from kamaki.cli import command
38
from kamaki.clients.astakos import SynnefoAstakosClient
38
from kamaki.clients.astakos import LoggedAstakosClient
39 39
from kamaki.cli.commands import (
40 40
    _command_init, errors, _optional_json, addLogSettings)
41 41
from kamaki.cli.command_tree import CommandTree
......
100 100
                    'astakos') or self.config.get_cloud(
101 101
                    self.cloud, 'token')
102 102
                token = token.split()[0] if ' ' in token else token
103
                self.client = SynnefoAstakosClient(
104
                    auth_url=base_url, token=token)
103
                self.client = LoggedAstakosClient(base_url, token)
105 104
                return
106 105
        else:
107 106
            self.cloud = 'default'
b/kamaki/clients/astakos/__init__.py
32 32
# or implied, of GRNET S.A.
33 33

  
34 34
from logging import getLogger
35
from astakosclient import *
36
#  astakosclient contains: AstakosCLient, AstakosClientException
35
from astakosclient import AstakosClient as OriginalAstakosClient
36
from astakosclient import AstakosClientException, parse_endpoints
37 37

  
38 38
from kamaki.clients import Client, ClientError, RequestManager, recvlog
39 39

  
40 40

  
41
class AstakosClient(OriginalAstakosClient):
42
    """Wrap Original AstakosClient to ensure compatibility in kamaki clients"""
43

  
44
    def __init__(self, *args, **kwargs):
45
        if args:
46
            args = list(args)
47
            url = args.pop(0)
48
            token = args.pop(0) if args else kwargs.pop('token', None)
49
            args = tuple([token, url] + args)
50
        elif 'base_url' in kwargs:
51
            kwargs['auth_url'] = kwargs.get('auth_url', kwargs['base_url'])
52
        super(AstakosClient, self).__init__(*args, **kwargs)
53

  
41 54

  
42 55
def _astakos_error(foo):
43 56
    def wrap(self, *args, **kwargs):
......
48 61
    return wrap
49 62

  
50 63

  
51
class SynnefoAstakosClient(AstakosClient):
52
    """An astakosclient.AstakosClient wrapper, that logs the way of kamaki"""
64
class LoggedAstakosClient(AstakosClient):
65
    """An AstakosClient wrapper with modified logging
66

  
67
    Logs are adjusted to appear similar to the ones of kamaki clients.
68
    No other changes are made to the parent class.
69
    """
53 70

  
54 71
    LOG_TOKEN = False
55 72
    LOG_DATA = False
......
66 83
        recvlog.info('-             -        -     -   -  - -')
67 84

  
68 85
    def _call_astakos(self, *args, **kwargs):
69
        r = super(SynnefoAstakosClient, self)._call_astakos(*args, **kwargs)
86
        r = super(LoggedAstakosClient, self)._call_astakos(*args, **kwargs)
70 87
        try:
71 88
            log_request = getattr(self, 'log_request', None)
72 89
            if log_request:
......
129 146
        :param token: (str) custom token to authenticate
130 147
        """
131 148
        token = self._resolve_token(token)
132
        astakos = SynnefoAstakosClient(
133
            token, self.base_url, logger=getLogger('astakosclient'))
149
        astakos = LoggedAstakosClient(
150
            self.base_url, token, logger=getLogger('astakosclient'))
134 151
        astakos.LOG_TOKEN = getattr(self, 'LOG_TOKEN', False)
135 152
        astakos.LOG_DATA = getattr(self, 'LOG_DATA', False)
136 153
        r = astakos.authenticate()
b/kamaki/clients/astakos/test.py
98 98
    def tearDown(self):
99 99
        FR.json = example
100 100

  
101
    @patch('%s.LoggedAstakosClient.__init__' % astakos_pkg, return_value=None)
101 102
    @patch(
102
        '%s.SynnefoAstakosClient.__init__' % astakos_pkg, return_value=None)
103
    @patch(
104
        '%s.SynnefoAstakosClient.get_endpoints' % astakos_pkg,
103
        '%s.LoggedAstakosClient.get_endpoints' % astakos_pkg,
105 104
        return_value=example)
106 105
    def _authenticate(self, get_endpoints, sac):
107 106
        r = self.client.authenticate()
......
187 186
        self.assertEqual(r[0]['auth_token'], self.token)
188 187

  
189 188
    @patch(
190
        '%s.SynnefoAstakosClient.get_usernames' % astakos_pkg,
189
        '%s.LoggedAstakosClient.get_usernames' % astakos_pkg,
191 190
        return_value={42: 'username42', 43: 'username43'})
192 191
    def test_uuids2usernames(self, get_usernames):
193 192
        from astakosclient import AstakosClientException
194 193
        self.assertRaises(
195 194
            AstakosClientException, self.client.uuids2usernames, [42, 43])
196 195
        with patch(
197
                '%s.SynnefoAstakosClient.__init__' % astakos_pkg,
196
                '%s.LoggedAstakosClient.__init__' % astakos_pkg,
198 197
                return_value=None) as sac:
199 198
            with patch(
200
                    '%s.SynnefoAstakosClient.get_endpoints' % astakos_pkg,
199
                    '%s.LoggedAstakosClient.get_endpoints' % astakos_pkg,
201 200
                    return_value=example) as get_endpoints:
202 201
                r = self.client.uuids2usernames([42, 43])
203 202
                self.assert_dicts_are_equal(
......
208 207
                self.assertEqual(get_usernames.mock_calls[-1], call([42, 43]))
209 208

  
210 209
    @patch(
211
        '%s.SynnefoAstakosClient.get_uuids' % astakos_pkg,
210
        '%s.LoggedAstakosClient.get_uuids' % astakos_pkg,
212 211
        return_value={'username42': 42, 'username43': 43})
213 212
    def test_usernames2uuids(self, get_uuids):
214 213
        from astakosclient import AstakosClientException
215 214
        self.assertRaises(
216 215
            AstakosClientException, self.client.usernames2uuids, ['u1', 'u2'])
217 216
        with patch(
218
                '%s.SynnefoAstakosClient.__init__' % astakos_pkg,
217
                '%s.LoggedAstakosClient.__init__' % astakos_pkg,
219 218
                return_value=None) as sac:
220 219
            with patch(
221
                    '%s.SynnefoAstakosClient.get_endpoints' % astakos_pkg,
220
                    '%s.LoggedAstakosClient.get_endpoints' % astakos_pkg,
222 221
                    return_value=example) as get_endpoints:
223 222
                r = self.client.usernames2uuids(['u1', 'u2'])
224 223
                self.assert_dicts_are_equal(

Also available in: Unified diff