parent
e3b7f64dbc
commit
68c2517abf
@ -39,6 +39,8 @@ import StringIO
|
|||||||
from swiftclient import client as sclient
|
from swiftclient import client as sclient
|
||||||
from swiftclient.client import ClientException
|
from swiftclient.client import ClientException
|
||||||
|
|
||||||
|
from keystoneclient.exceptions import ClientException as KSClientException
|
||||||
|
|
||||||
import eventlet
|
import eventlet
|
||||||
|
|
||||||
sys.path.append("../")
|
sys.path.append("../")
|
||||||
@ -89,8 +91,13 @@ def create_swift_user(client, account_name, account_id, user_amount):
|
|||||||
client.roles.add_user_role(uid.id, roleid, account_id)
|
client.roles.add_user_role(uid.id, roleid, account_id)
|
||||||
return (user, uid.id, roleid)
|
return (user, uid.id, roleid)
|
||||||
for i in range(user_amount):
|
for i in range(user_amount):
|
||||||
|
try:
|
||||||
ret = _create_user(account_name, account_id)
|
ret = _create_user(account_name, account_id)
|
||||||
|
logging.info('Users created %s in account %s' %
|
||||||
|
(str(ret), account_id))
|
||||||
users.append(ret)
|
users.append(ret)
|
||||||
|
except KSClientException:
|
||||||
|
logging.warn('Unable to create an user in account %s' % account_id)
|
||||||
return users
|
return users
|
||||||
|
|
||||||
|
|
||||||
@ -101,10 +108,13 @@ def create_swift_account(client, pile,
|
|||||||
def _create_account(user_amount):
|
def _create_account(user_amount):
|
||||||
account = get_rand_str(mode='account_')
|
account = get_rand_str(mode='account_')
|
||||||
# Create a tenant. In swift this is an account
|
# Create a tenant. In swift this is an account
|
||||||
|
try:
|
||||||
account_id = client.tenants.create(account).id
|
account_id = client.tenants.create(account).id
|
||||||
logging.info('Account created %s' % account)
|
logging.info('Account created %s' % account)
|
||||||
|
except KSClientException:
|
||||||
|
logging.warn('Unable to create account %s' % account)
|
||||||
|
return None, None, None
|
||||||
r = create_swift_user(client, account, account_id, user_amount)
|
r = create_swift_user(client, account, account_id, user_amount)
|
||||||
logging.info('Users created %s in account %s' % (str(r), account))
|
|
||||||
return account, account_id, r
|
return account, account_id, r
|
||||||
created = {}
|
created = {}
|
||||||
# Spawn a greenlet for each account
|
# Spawn a greenlet for each account
|
||||||
@ -114,6 +124,7 @@ def create_swift_account(client, pile,
|
|||||||
logging.info("[Keystone Start OPs %s/%s]" % (i, account_amount))
|
logging.info("[Keystone Start OPs %s/%s]" % (i, account_amount))
|
||||||
pile.spawn(_create_account, user_amount)
|
pile.spawn(_create_account, user_amount)
|
||||||
for account, account_id, ret in pile:
|
for account, account_id, ret in pile:
|
||||||
|
if account is not None:
|
||||||
index[(account, account_id)] = ret
|
index[(account, account_id)] = ret
|
||||||
created[(account, account_id)] = ret
|
created[(account, account_id)] = ret
|
||||||
return created
|
return created
|
||||||
|
@ -18,7 +18,10 @@
|
|||||||
import eventlet
|
import eventlet
|
||||||
import swiftclient
|
import swiftclient
|
||||||
|
|
||||||
|
from keystoneclient.exceptions import ClientException as KSClientException
|
||||||
|
|
||||||
from fakes import FakeKSClient
|
from fakes import FakeKSClient
|
||||||
|
from fakes import FakeKSTenant
|
||||||
from fakes import FakeKSUser
|
from fakes import FakeKSUser
|
||||||
from fakes import FakeSWConnection
|
from fakes import FakeSWConnection
|
||||||
|
|
||||||
@ -166,6 +169,30 @@ class TestFiller(base.TestCase):
|
|||||||
self.assertEqual(self.create_cnt, 1)
|
self.assertEqual(self.create_cnt, 1)
|
||||||
self.assertEqual(self.role_cnt, 1)
|
self.assertEqual(self.role_cnt, 1)
|
||||||
|
|
||||||
|
def test_create_swift_user_fail(self):
|
||||||
|
self.pa = 0
|
||||||
|
|
||||||
|
def create(*args, **kargs):
|
||||||
|
if self.pa == 0:
|
||||||
|
self.pa += 1
|
||||||
|
raise KSClientException('Fake msg')
|
||||||
|
else:
|
||||||
|
self.pa += 1
|
||||||
|
return FakeKSUser()
|
||||||
|
|
||||||
|
def add_user_role(*args, **kargs):
|
||||||
|
pass
|
||||||
|
|
||||||
|
co = utils.get_config('auth',
|
||||||
|
'keystone_origin_admin_credentials').split(':')
|
||||||
|
tenant_name, username, password = co
|
||||||
|
client = FakeKSClient()
|
||||||
|
client.roles.add_user_role = add_user_role
|
||||||
|
client.users.create = create
|
||||||
|
users = filler.create_swift_user(client, 'account1', 'account1_id', 3)
|
||||||
|
|
||||||
|
self.assertEqual(len(users), 2)
|
||||||
|
|
||||||
def test_create_swift_account(self):
|
def test_create_swift_account(self):
|
||||||
self.ret_index = {}
|
self.ret_index = {}
|
||||||
self.user_cnt = 0
|
self.user_cnt = 0
|
||||||
@ -183,6 +210,32 @@ class TestFiller(base.TestCase):
|
|||||||
self.assertEqual(self.user_cnt, 1)
|
self.assertEqual(self.user_cnt, 1)
|
||||||
self.assertEqual(len(self.ret_index.keys()), 1)
|
self.assertEqual(len(self.ret_index.keys()), 1)
|
||||||
|
|
||||||
|
def test_create_swift_account_fail(self):
|
||||||
|
self.ret_index = {}
|
||||||
|
self.pa = 0
|
||||||
|
|
||||||
|
def create_tenant(*args):
|
||||||
|
if self.pa == 0:
|
||||||
|
self.pa += 1
|
||||||
|
raise KSClientException('Fake msg')
|
||||||
|
else:
|
||||||
|
self.pa += 1
|
||||||
|
return FakeKSTenant('foo1')
|
||||||
|
|
||||||
|
def create_swift_user(*args):
|
||||||
|
pass
|
||||||
|
|
||||||
|
client = FakeKSClient()
|
||||||
|
|
||||||
|
self.stubs.Set(client.tenants, 'create', create_tenant)
|
||||||
|
self.stubs.Set(filler, 'create_swift_user', create_swift_user)
|
||||||
|
|
||||||
|
concurrency = int(utils.get_config('filler', 'concurrency'))
|
||||||
|
pile = eventlet.GreenPile(concurrency)
|
||||||
|
filler.create_swift_account(client, pile, 3, 1, self.ret_index)
|
||||||
|
|
||||||
|
self.assertEqual(len(self.ret_index.keys()), 2)
|
||||||
|
|
||||||
def test_delete_account(self):
|
def test_delete_account(self):
|
||||||
self.delete_t_cnt = 0
|
self.delete_t_cnt = 0
|
||||||
self.delete_u_cnt = 0
|
self.delete_u_cnt = 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user