This commit is contained in:
Chmouel Boudjnah 2013-03-20 13:09:25 +01:00
parent b6a6a167f2
commit edb559d8cc

View File

@ -61,7 +61,7 @@ index_containers_path = '/tmp/swift_filler_containers_index.pkl'
def get_rand_str(mode='user'): def get_rand_str(mode='user'):
prefix = "%s" % mode prefix = "%s" % mode
return prefix + ''.join(random.choice( \ return prefix + ''.join(random.choice(
string.ascii_uppercase + string.digits) for x in range(8)) string.ascii_uppercase + string.digits) for x in range(8))
@ -117,11 +117,12 @@ def delete_account_content(acc, user):
# Retreive object list # Retreive object list
for container in containers_name: for container in containers_name:
container_infos = cnx.get_container(container) container_infos = cnx.get_container(container)
object_names = [obj_detail['name'] for obj_detail in container_infos[1]] object_names = [obj_detail['name'] for obj_detail
in container_infos[1]]
# Delete objects # Delete objects
for obj in object_names: for obj in object_names:
print "Deleting object %s in container %s for account %s" \ print "Deleting object %s in container %s for account %s" % (
% (obj, container, str(acc)) obj, container, str(acc))
cnx.delete_object(container, obj) cnx.delete_object(container, obj)
@ -175,7 +176,8 @@ def create_objects(cnx, acc, o_amount, fmax, index_containers):
etag = cnx.put_object(container, object_name, etag = cnx.put_object(container, object_name,
data, headers=copy(meta)) data, headers=copy(meta))
f_object.close() f_object.close()
obj_info = {'object_info': (object_name, etag, len(data)), 'meta': meta} obj_info = {'object_info':
(object_name, etag, len(data)), 'meta': meta}
containers_d[container]['objects'].append(obj_info) containers_d[container]['objects'].append(obj_info)
@ -191,8 +193,10 @@ def create_containers(cnx, acc, c_amount, index_containers=None):
containers_d[container_name] = {'meta': meta, 'objects': []} containers_d[container_name] = {'meta': meta, 'objects': []}
def fill_swift(created_account, c_amount, o_amount, fmax, index_containers=None): def fill_swift(created_account, c_amount,
def _fill_swift_job(acc, users, c_amount, o_amount, fmax, index_containers): o_amount, fmax, index_containers=None):
def _fill_swift_job(acc, users, c_amount,
o_amount, fmax, index_containers):
cnx = swift_cnx(acc, users[0][0]) cnx = swift_cnx(acc, users[0][0])
# Use the first user we find for fill in the swift account # Use the first user we find for fill in the swift account
create_containers(cnx, acc, c_amount, index_containers) create_containers(cnx, acc, c_amount, index_containers)
@ -200,7 +204,8 @@ def fill_swift(created_account, c_amount, o_amount, fmax, index_containers=None)
i = 0 i = 0
for acc, users in created_account.items(): for acc, users in created_account.items():
i += 1 i += 1
print "[Start Swift Account OPs %s/%s]" % (i, len(created_account.keys())) print "[Start Swift Account OPs %s/%s]" % \
(i, len(created_account.keys()))
pool.spawn_n(_fill_swift_job, pool.spawn_n(_fill_swift_job,
acc, users, acc, users,
c_amount, o_amount, c_amount, o_amount,
@ -243,7 +248,8 @@ if __name__ == '__main__':
help='Create account/users/containers/data') help='Create account/users/containers/data')
parser.add_argument('-l', parser.add_argument('-l',
action='store_true', action='store_true',
help='Load previous indexes and append newly created to it') help='Load previous indexes and append newly'
' created to it')
parser.add_argument('-a', parser.add_argument('-a',
help='Specify account amount') help='Specify account amount')
parser.add_argument('-u', parser.add_argument('-u',
@ -253,7 +259,8 @@ if __name__ == '__main__':
parser.add_argument('-f', parser.add_argument('-f',
help='Specify file amount by account') help='Specify file amount by account')
parser.add_argument('-s', parser.add_argument('-s',
help='Specify the MAX file size. Files will be from 1024 Bytes to MAX Bytes') help='Specify the MAX file size. Files '
'will be from 1024 Bytes to MAX Bytes')
args = parser.parse_args() args = parser.parse_args()
pile = eventlet.GreenPile(concurrency) pile = eventlet.GreenPile(concurrency)
@ -295,7 +302,8 @@ if __name__ == '__main__':
if args.f is not None and args.c is not None: if args.f is not None and args.c is not None:
if args.f.isdigit() and args.c.isdigit(): if args.f.isdigit() and args.c.isdigit():
fill_swift(created, int(args.c), fill_swift(created, int(args.c),
int(args.f), fmax, index_containers=index_containers) int(args.f), fmax,
index_containers=index_containers)
else: else:
print("'-c' and '-f' options must be integers") print("'-c' and '-f' options must be integers")
sys.exit(1) sys.exit(1)