Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kamaki
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
itminedu
kamaki
Commits
cd42f8d8
Commit
cd42f8d8
authored
Jan 07, 2014
by
Stavros Sachtouris
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wrap AstakosClient for backward compatiblity
parent
609471e9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
19 deletions
+34
-19
kamaki/cli/commands/astakos.py
kamaki/cli/commands/astakos.py
+2
-3
kamaki/clients/astakos/__init__.py
kamaki/clients/astakos/__init__.py
+24
-7
kamaki/clients/astakos/test.py
kamaki/clients/astakos/test.py
+8
-9
No files found.
kamaki/cli/commands/astakos.py
View file @
cd42f8d8
...
...
@@ -35,7 +35,7 @@ from json import load, loads
from
os.path
import
abspath
from
kamaki.cli
import
command
from
kamaki.clients.astakos
import
Synnefo
AstakosClient
from
kamaki.clients.astakos
import
Logged
AstakosClient
from
kamaki.cli.commands
import
(
_command_init
,
errors
,
_optional_json
,
addLogSettings
)
from
kamaki.cli.command_tree
import
CommandTree
...
...
@@ -100,8 +100,7 @@ class _init_synnefo_astakosclient(_command_init):
'astakos'
)
or
self
.
config
.
get_cloud
(
self
.
cloud
,
'token'
)
token
=
token
.
split
()[
0
]
if
' '
in
token
else
token
self
.
client
=
SynnefoAstakosClient
(
auth_url
=
base_url
,
token
=
token
)
self
.
client
=
LoggedAstakosClient
(
base_url
,
token
)
return
else
:
self
.
cloud
=
'default'
...
...
kamaki/clients/astakos/__init__.py
View file @
cd42f8d8
...
...
@@ -32,12 +32,25 @@
# or implied, of GRNET S.A.
from
logging
import
getLogger
from
astakosclient
import
*
# astakosclient contains: AstakosCLient, AstakosClientException
from
astakosclient
import
AstakosClient
as
OriginalAstakosClient
from
astakosclient
import
AstakosClientException
,
parse_endpoints
from
kamaki.clients
import
Client
,
ClientError
,
RequestManager
,
recvlog
class
AstakosClient
(
OriginalAstakosClient
):
"""Wrap Original AstakosClient to ensure compatibility in kamaki clients"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
if
args
:
args
=
list
(
args
)
url
=
args
.
pop
(
0
)
token
=
args
.
pop
(
0
)
if
args
else
kwargs
.
pop
(
'token'
,
None
)
args
=
tuple
([
token
,
url
]
+
args
)
elif
'base_url'
in
kwargs
:
kwargs
[
'auth_url'
]
=
kwargs
.
get
(
'auth_url'
,
kwargs
[
'base_url'
])
super
(
AstakosClient
,
self
).
__init__
(
*
args
,
**
kwargs
)
def
_astakos_error
(
foo
):
def
wrap
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -48,8 +61,12 @@ def _astakos_error(foo):
return
wrap
class
SynnefoAstakosClient
(
AstakosClient
):
"""An astakosclient.AstakosClient wrapper, that logs the way of kamaki"""
class
LoggedAstakosClient
(
AstakosClient
):
"""An AstakosClient wrapper with modified logging
Logs are adjusted to appear similar to the ones of kamaki clients.
No other changes are made to the parent class.
"""
LOG_TOKEN
=
False
LOG_DATA
=
False
...
...
@@ -66,7 +83,7 @@ class SynnefoAstakosClient(AstakosClient):
recvlog
.
info
(
'- - - - - - -'
)
def
_call_astakos
(
self
,
*
args
,
**
kwargs
):
r
=
super
(
Synnefo
AstakosClient
,
self
).
_call_astakos
(
*
args
,
**
kwargs
)
r
=
super
(
Logged
AstakosClient
,
self
).
_call_astakos
(
*
args
,
**
kwargs
)
try
:
log_request
=
getattr
(
self
,
'log_request'
,
None
)
if
log_request
:
...
...
@@ -129,8 +146,8 @@ class CachedAstakosClient(Client):
:param token: (str) custom token to authenticate
"""
token
=
self
.
_resolve_token
(
token
)
astakos
=
Synnefo
AstakosClient
(
token
,
self
.
base_url
,
logger
=
getLogger
(
'astakosclient'
))
astakos
=
Logged
AstakosClient
(
self
.
base_url
,
token
,
logger
=
getLogger
(
'astakosclient'
))
astakos
.
LOG_TOKEN
=
getattr
(
self
,
'LOG_TOKEN'
,
False
)
astakos
.
LOG_DATA
=
getattr
(
self
,
'LOG_DATA'
,
False
)
r
=
astakos
.
authenticate
()
...
...
kamaki/clients/astakos/test.py
View file @
cd42f8d8
...
...
@@ -98,10 +98,9 @@ class AstakosClient(TestCase):
def
tearDown
(
self
):
FR
.
json
=
example
@
patch
(
'%s.LoggedAstakosClient.__init__'
%
astakos_pkg
,
return_value
=
None
)
@
patch
(
'%s.SynnefoAstakosClient.__init__'
%
astakos_pkg
,
return_value
=
None
)
@
patch
(
'%s.SynnefoAstakosClient.get_endpoints'
%
astakos_pkg
,
'%s.LoggedAstakosClient.get_endpoints'
%
astakos_pkg
,
return_value
=
example
)
def
_authenticate
(
self
,
get_endpoints
,
sac
):
r
=
self
.
client
.
authenticate
()
...
...
@@ -187,17 +186,17 @@ class AstakosClient(TestCase):
self
.
assertEqual
(
r
[
0
][
'auth_token'
],
self
.
token
)
@
patch
(
'%s.
Synnefo
AstakosClient.get_usernames'
%
astakos_pkg
,
'%s.
Logged
AstakosClient.get_usernames'
%
astakos_pkg
,
return_value
=
{
42
:
'username42'
,
43
:
'username43'
})
def
test_uuids2usernames
(
self
,
get_usernames
):
from
astakosclient
import
AstakosClientException
self
.
assertRaises
(
AstakosClientException
,
self
.
client
.
uuids2usernames
,
[
42
,
43
])
with
patch
(
'%s.
Synnefo
AstakosClient.__init__'
%
astakos_pkg
,
'%s.
Logged
AstakosClient.__init__'
%
astakos_pkg
,
return_value
=
None
)
as
sac
:
with
patch
(
'%s.
Synnefo
AstakosClient.get_endpoints'
%
astakos_pkg
,
'%s.
Logged
AstakosClient.get_endpoints'
%
astakos_pkg
,
return_value
=
example
)
as
get_endpoints
:
r
=
self
.
client
.
uuids2usernames
([
42
,
43
])
self
.
assert_dicts_are_equal
(
...
...
@@ -208,17 +207,17 @@ class AstakosClient(TestCase):
self
.
assertEqual
(
get_usernames
.
mock_calls
[
-
1
],
call
([
42
,
43
]))
@
patch
(
'%s.
Synnefo
AstakosClient.get_uuids'
%
astakos_pkg
,
'%s.
Logged
AstakosClient.get_uuids'
%
astakos_pkg
,
return_value
=
{
'username42'
:
42
,
'username43'
:
43
})
def
test_usernames2uuids
(
self
,
get_uuids
):
from
astakosclient
import
AstakosClientException
self
.
assertRaises
(
AstakosClientException
,
self
.
client
.
usernames2uuids
,
[
'u1'
,
'u2'
])
with
patch
(
'%s.
Synnefo
AstakosClient.__init__'
%
astakos_pkg
,
'%s.
Logged
AstakosClient.__init__'
%
astakos_pkg
,
return_value
=
None
)
as
sac
:
with
patch
(
'%s.
Synnefo
AstakosClient.get_endpoints'
%
astakos_pkg
,
'%s.
Logged
AstakosClient.get_endpoints'
%
astakos_pkg
,
return_value
=
example
)
as
get_endpoints
:
r
=
self
.
client
.
usernames2uuids
([
'u1'
,
'u2'
])
self
.
assert_dicts_are_equal
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment