Commit 2b74ab4a authored by Stavros Sachtouris's avatar Stavros Sachtouris

Unittest parallel server creation

parent e9a92550
......@@ -419,7 +419,6 @@ def main():
exit(0)
_init_session(_arguments)
print('ICN[%s]' % _arguments['config'].value)
if unparsed:
_history = History(_arguments['config'].get('history', 'file'))
......
......@@ -47,7 +47,6 @@ def _init_shell(exe_string, arguments):
arguments.pop('version', None)
arguments.pop('options', None)
arguments.pop('history', None)
print('SHELL? [%s]' % arguments['config'].value)
shell = Shell()
shell.set_prompt(exe_string)
from kamaki import __version__ as version
......
......@@ -31,6 +31,7 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from threading import Thread
from json import dumps, loads
from time import time
import logging
......@@ -68,6 +69,31 @@ class ClientError(Exception):
self.details = details
class SilentEvent(Thread):
""" Thread-run method(*args, **kwargs)
put exception in exception_bucket
"""
def __init__(self, method, *args, **kwargs):
super(self.__class__, self).__init__()
self.method = method
self.args = args
self.kwargs = kwargs
@property
def exception(self):
return getattr(self, '_exception', False)
@property
def value(self):
return getattr(self, '_value', None)
def run(self):
try:
self._value = self.method(*(self.args), **(self.kwargs))
except Exception as e:
print('______\n%s\n_______' % e)
self._exception = e
class Client(object):
POOL_SIZE = 7
......
......@@ -31,7 +31,6 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
from threading import Thread
from threading import enumerate as activethreads
from os import fstat
......@@ -40,6 +39,7 @@ from time import time
from binascii import hexlify
from kamaki.clients import SilentEvent
from kamaki.clients.pithos_rest_api import PithosRestAPI
from kamaki.clients.storage import ClientError
from kamaki.clients.utils import path4url, filter_in
......@@ -65,32 +65,6 @@ def _range_up(start, end, a_range):
return (start, end)
class SilentEvent(Thread):
""" Thread-run method(*args, **kwargs)
put exception in exception_bucket
"""
def __init__(self, method, *args, **kwargs):
super(self.__class__, self).__init__()
self.method = method
self.args = args
self.kwargs = kwargs
@property
def exception(self):
return getattr(self, '_exception', False)
@property
def value(self):
return getattr(self, '_value', None)
def run(self):
try:
self._value = self.method(*(self.args), **(self.kwargs))
except Exception as e:
print('______\n%s\n_______' % e)
self._exception = e
class PithosClient(PithosRestAPI):
"""GRNet Pithos API client"""
......@@ -232,7 +206,7 @@ class PithosClient(PithosRestAPI):
assert offset == size
def _upload_missing_blocks(self, missing, hmap, fileobj, upload_cb=None):
"""upload missing blocks asynchronously. Use greenlets to avoid waiting
"""upload missing blocks asynchronously.
"""
if upload_cb:
upload_gen = upload_cb(len(missing))
......
......@@ -322,6 +322,53 @@ class testCyclades(unittest.TestCase):
self.client = cyclades(url, token)
pass
@if_not_all
def test_parallel_creation(self):
"""test create with multiple threads"""
from kamaki.clients import SilentEvent
c1 = SilentEvent(self._create_server,
self.servname1,
self.flavorid,
self.img)
c2 = SilentEvent(self._create_server,
self.servname2,
self.flavorid + 2,
self.img)
c3 = SilentEvent(self._create_server,
self.servname1,
self.flavorid,
self.img)
c4 = SilentEvent(self._create_server,
self.servname2,
self.flavorid + 2,
self.img)
c5 = SilentEvent(self._create_server,
self.servname1,
self.flavorid,
self.img)
c6 = SilentEvent(self._create_server,
self.servname2,
self.flavorid + 2,
self.img)
c7 = SilentEvent(self._create_server,
self.servname1,
self.flavorid,
self.img)
c8 = SilentEvent(self._create_server,
self.servname2,
self.flavorid + 2,
self.img)
print('START THREADS')
c1.start()
c2.start()
c3.start()
c4.start()
c5.start()
c6.start()
c7.start()
c8.start()
print('KEWL')
def tearDown(self):
"""Destoy servers used in testing"""
print
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment