Last active
July 20, 2018 22:31
-
-
Save chianingwang/4290ff3cc95482f1cf571bcf3e976f4d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
import itertools | |
import os | |
import swiftclient | |
import time | |
import logging | |
def copy_to_swift(): | |
logger = logging.getLogger('swiftclient') | |
logger.setLevel('DEBUG') | |
logger.addHandler(logging.StreamHandler()) | |
function_start = time.time() | |
conn = swiftclient.Connection( | |
authurl='https://test.swiftstack.org/auth/v1.0', | |
user='test', | |
key='xxxx', | |
auth_version='1', | |
) | |
for path, subdirs, files in os.walk('/tmp/test'): | |
print path | |
# If it's not a subdir of gluster with files in it, skip. | |
if subdirs or not files: | |
continue | |
#container_name = "conn_test" + files[0][:4] | |
container_name = "conn_test" | |
for file in files: | |
start_write_time = time.time() | |
conn.put_object(container_name, file, os.path.join(path, file), headers={'if-none-match': '*'}) | |
end_write_time = time.time() | |
print "Wrote object %s to Swift in %.2fs" % (file, end_write_time - start_write_time) | |
function_end = time.time() | |
print "copying to swift took: %.2fs" % (function_end - function_start) | |
if __name__ == '__main__': | |
copy_to_swift() | |
#verify_files_copied_to_swift() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
import itertools | |
import os | |
import swiftclient | |
import time | |
import logging | |
from swiftclient.multithreading import OutputManager | |
from swiftclient.service import SwiftError, SwiftService, SwiftUploadObject | |
def copy_to_swift(): | |
logger = logging.getLogger('swiftclient') | |
logger.setLevel('DEBUG') | |
logger.addHandler(logging.StreamHandler()) | |
logger = logging.getLogger('swiftclient.service') | |
logger.setLevel('DEBUG') | |
logger.addHandler(logging.StreamHandler()) | |
test_credentials ={'auth_version':'1', | |
'auth':'https://test.swiftstack.org/auth/v1.0', | |
'user':'test', 'key':'xxxx'} | |
function_start = time.time() | |
with SwiftService(options=test_credentials) as swift, OutputManager() as out_manager: | |
try: | |
#obj_start = time.time() | |
for path, subdirs, files in os.walk("/tmp/test/"): | |
print path, subdirs, files | |
# If it's not a subdir of gluster with files in it, skip. | |
if subdirs or not files: | |
continue | |
#container = "bagstore-" + files[0][:4] | |
container = "service_test" | |
print "files prepared: %s at %.2fs" % (files, time.time()) | |
objs = [SwiftUploadObject(os.path.join(path, file), object_name=file) for file in files] | |
obj_start = time.time() | |
r = swift.upload(container, objs, options={}) | |
for i in r: | |
print i | |
''' | |
for r in swift.upload(container, objs, options={'header': ['if-none-match:*']}): | |
print "files uploaded: %s at %.2fs" % (files, time.time()) | |
if r['success']: | |
print "files success: %s at %.2fs" % (files, time.time()) | |
if 'object' in r: | |
print "files object: %s at %.2fs" % (r['object'], time.time()) | |
#print(r['object']) | |
elif 'for_object' in r: | |
print "files for_object: %s at %.2fs" % (r['for_object'], time.time()) | |
print('%s segment %s' % (r['for_object'], r['segment_index'])) | |
else: | |
error = r['error'] | |
print "files error: %s at %.2fs" % (error, time.time()) | |
if r['action'] == "upload_object": | |
print("Did not upload object %s to container %s: %s" % (container, r['object'], error)) | |
else: | |
print(error) | |
''' | |
obj_end = time.time() | |
obj_upload_time = (obj_end - obj_start) | |
print "files: %s upload took: %.2fs" % (files, obj_upload_time) | |
except SwiftError as e: | |
logger.error(e.value) | |
function_end = time.time() | |
print "copying to swift took: %.2fs" % (function_end - function_start) | |
if __name__ == '__main__': | |
copy_to_swift() |
Author
chianingwang
commented
Jul 20, 2018
- test_service.py debug outpu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment