def perftest_s3( ): conn = S3Util.S3.AWSAuthConnection(Config.AWSProperties['AccessKey'], \ Config.AWSProperties['SecretKey'], ( Config.AWSProperties['SecureComm'] == True) ) AllBuckets = S3Util.AWS_S3( AWSConnectionObject = conn ) perf_test_vector = [ {'test_file':'10kb.file', 'test_file_size_in_bytes':1024*10, 'count':10}, {'test_file':'100kb.file', 'test_file_size_in_bytes':1024*100, 'count':10}, {'test_file':'1mb.file', 'test_file_size_in_bytes':1024*1024, 'count':1}, {'test_file':'1mb.file', 'test_file_size_in_bytes':1024*1024, 'count':10}, # {'test_file':'10mb.file', 'test_file_size_in_bytes':1024*1024*10, 'count':1} ] bucket_name = u'AWSPyLib-testbucket-perf-test' AllBuckets.add_bucket ( bucket_name ) test_bucket = S3Util.AWS_Bucket(conn, bucket_name) for test in perf_test_vector: if (os.path.exists ( test['test_file'] ) == False ): Util.make_test_file( test['test_file'], test['test_file_size_in_bytes'] ) _perftest_(conn, test_bucket, test['test_file'], test['test_file_size_in_bytes'], test['count'] ) AllBuckets.delete_bucket_recursive( bucket_name ) return
def perftest_s3(): conn = S3Util.S3.AWSAuthConnection(Config.AWSProperties['AccessKey'], \ Config.AWSProperties['SecretKey'], ( Config.AWSProperties['SecureComm'] == True) ) AllBuckets = S3Util.AWS_S3(AWSConnectionObject=conn) perf_test_vector = [ { 'test_file': '10kb.file', 'test_file_size_in_bytes': 1024 * 10, 'count': 10 }, { 'test_file': '100kb.file', 'test_file_size_in_bytes': 1024 * 100, 'count': 10 }, { 'test_file': '1mb.file', 'test_file_size_in_bytes': 1024 * 1024, 'count': 1 }, { 'test_file': '1mb.file', 'test_file_size_in_bytes': 1024 * 1024, 'count': 10 }, # {'test_file':'10mb.file', 'test_file_size_in_bytes':1024*1024*10, 'count':1} ] bucket_name = u'AWSPyLib-testbucket-perf-test' AllBuckets.add_bucket(bucket_name) test_bucket = S3Util.AWS_Bucket(conn, bucket_name) for test in perf_test_vector: if (os.path.exists(test['test_file']) == False): Util.make_test_file(test['test_file'], test['test_file_size_in_bytes']) _perftest_(conn, test_bucket, test['test_file'], test['test_file_size_in_bytes'], test['count']) AllBuckets.delete_bucket_recursive(bucket_name) return
def _create_dir_level_( level, top_dir): os.chdir( top_dir) for i in range(NUMBER_OF_FILES): filename = 'file' + str(level) + '-' + str(i) Util.make_test_file( filename) if (level < NUMBER_OF_DIR_LEVELS): for j in range(NUMBER_OF_DIR): dirname = 'dir' + str(level) + '-' + str(j) os.mkdir(dirname) _create_dir_level_(level+1, dirname ) cur_dir = os.getcwd( ) k = cur_dir.rfind( os.sep ) cur_dir = cur_dir[:k] os.chdir(cur_dir) return
def _create_dir_level_(level, top_dir): os.chdir(top_dir) for i in range(NUMBER_OF_FILES): filename = 'file' + str(level) + '-' + str(i) Util.make_test_file(filename) if (level < NUMBER_OF_DIR_LEVELS): for j in range(NUMBER_OF_DIR): dirname = 'dir' + str(level) + '-' + str(j) os.mkdir(dirname) _create_dir_level_(level + 1, dirname) cur_dir = os.getcwd() k = cur_dir.rfind(os.sep) cur_dir = cur_dir[:k] os.chdir(cur_dir) return
print '\t%s: - Success!' % test test = 'TEST-4' print '%s: Deleting recursively a non-existant bucket. Should Fail!' % test try: AllBuckets.delete_bucket_recursive( u'doesnotexist') except Exception, e: print '\t%s: - Success!' % test else: print '\t%s: - FAILED! (%s)' % (test, e) # If it does not exist, make a local 100KB test file with random data if (os.path.exists ( TEST_FILE_NAME ) == False ): Util.make_test_file( TEST_FILE_NAME, 1024*100) test = 'TEST-5' print '%s: Deleting bucket with content' % test bucket = u'AWSPyLib-testingbucket98765' try: AllBuckets.add_bucket( bucket ) key = S3Util.AWS_Key(conn, bucket, u'testkey.key') key.put_object_from_file ( TEST_FILE_NAME) AllBuckets.delete_bucket_recursive ( bucket ) except Exception, e: print '\t%s: - FAILED! (%s)' % (test, e) else: print '\t%s: - Success!' % test bucket = u'AWSPyLib-testingbucket12345'
print '\t%s: - FAILED! (%s)' % (test, e) else: print '\t%s: - Success!' % test test = 'TEST-4' print '%s: Deleting recursively a non-existant bucket. Should Fail!' % test try: AllBuckets.delete_bucket_recursive(u'doesnotexist') except Exception, e: print '\t%s: - Success!' % test else: print '\t%s: - FAILED! (%s)' % (test, e) # If it does not exist, make a local 100KB test file with random data if (os.path.exists(TEST_FILE_NAME) == False): Util.make_test_file(TEST_FILE_NAME, 1024 * 100) test = 'TEST-5' print '%s: Deleting bucket with content' % test bucket = u'AWSPyLib-testingbucket98765' try: AllBuckets.add_bucket(bucket) key = S3Util.AWS_Key(conn, bucket, u'testkey.key') key.put_object_from_file(TEST_FILE_NAME) AllBuckets.delete_bucket_recursive(bucket) except Exception, e: print '\t%s: - FAILED! (%s)' % (test, e) else: print '\t%s: - Success!' % test bucket = u'AWSPyLib-testingbucket12345'