summaryrefslogtreecommitdiffstats
path: root/glustolibs-io/shared_files/scripts/fd_writes.py
diff options
context:
space:
mode:
Diffstat (limited to 'glustolibs-io/shared_files/scripts/fd_writes.py')
-rwxr-xr-xglustolibs-io/shared_files/scripts/fd_writes.py68
1 files changed, 34 insertions, 34 deletions
diff --git a/glustolibs-io/shared_files/scripts/fd_writes.py b/glustolibs-io/shared_files/scripts/fd_writes.py
index 87358f45a..e3ebccb63 100755
--- a/glustolibs-io/shared_files/scripts/fd_writes.py
+++ b/glustolibs-io/shared_files/scripts/fd_writes.py
@@ -15,14 +15,15 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+from __future__ import print_function
import argparse
-import random
-import os
-import time
-import string
import datetime
from multiprocessing import Process
+import os
+import random
+import string
import sys
+import time
def is_root(path):
@@ -35,9 +36,9 @@ def is_root(path):
True if path is '/' , False otherwise
"""
if os.path.realpath(os.path.abspath(path)) == '/':
- print ("Directory '%s' is the root of filesystem. "
- "Not performing any operations on the root of filesystem" %
- os.path.abspath(path))
+ print("Directory '%s' is the root of filesystem. "
+ "Not performing any operations on the root of filesystem" % (
+ os.path.abspath(path)))
return True
else:
return False
@@ -72,26 +73,25 @@ def create_dir(dir_path):
try:
os.makedirs(dir_abs_path)
except (OSError, IOError):
- print "Unable to create dir: %s" % dir_abs_path
+ print("Unable to create dir: %s" % dir_abs_path)
return 1
return 0
def fd_write_file(filename, file_size, chunk_sizes_list, write_time,
delay_between_writes=10, log_level='INFO'):
- """Write random data to the file until write_time
- """
+ """Write random data to the file until write_time."""
rc = 0
time_counter = 0
try:
fd = open(filename, "w+b")
- fd.seek(file_size-1)
- fd.write("0")
+ fd.seek(file_size - 1)
+ fd.write(bytes(str("0").encode("utf-8")))
fd.flush()
except IOError as e:
- print ("Unable to open file %s for writing : %s" % (filename,
- e.strerror))
+ print("Unable to open file %s for writing : %s" % (
+ filename, e.strerror))
return 1
while time_counter < write_time:
@@ -102,18 +102,18 @@ def fd_write_file(filename, file_size, chunk_sizes_list, write_time,
range(current_chunk_size)))
offset = random.randint(0, (actual_file_size - current_chunk_size))
if log_level.upper() == 'DEBUG':
- print ("\tFileName: %s, File Size: %s, "
- "Writing to offset: %s, "
- "Data Length: %d, Time Counter: %d" %
- (filename, actual_file_size, offset, len(write_data),
- time_counter))
+ print("\tFileName: %s, File Size: %s, "
+ "Writing to offset: %s, "
+ "Data Length: %d, Time Counter: %d" % (
+ filename, actual_file_size, offset, len(write_data),
+ time_counter))
fd.seek(offset)
- fd.write(write_data)
+ fd.write(bytes(str(write_data).encode("utf-8")))
fd.seek(0)
fd.flush()
except IOError as e:
- print ("Unable to write to file '%s' : %s at time count: %dS" %
- (filename, e.strerror, time_counter))
+ print("Unable to write to file '%s' : %s at time count: %dS" % (
+ filename, e.strerror, time_counter))
rc = 1
time.sleep(delay_between_writes)
@@ -129,11 +129,11 @@ def fd_writes(args):
base_file_name = args.base_file_name
file_sizes_list = args.file_sizes_list
if file_sizes_list:
- file_sizes_list = filter(None, args.file_sizes_list.split(","))
+ file_sizes_list = list(filter(None, args.file_sizes_list.split(",")))
chunk_sizes_list = args.chunk_sizes_list
if chunk_sizes_list:
- chunk_sizes_list = map(int, filter(None,
- args.chunk_sizes_list.split(",")))
+ chunk_sizes_list = list(
+ map(int, filter(None, args.chunk_sizes_list.split(","))))
write_time = int(args.write_time)
delay_between_writes = int(args.delay_between_writes)
log_level = args.log_level
@@ -150,11 +150,11 @@ def fd_writes(args):
file_sizes_dict = {
'k': 1024,
'K': 1024,
- 'm': 1024*1024,
- 'M': 1024*1024,
- 'g': 1024*1024*1024,
- 'G': 1024*1024*1024
- }
+ 'm': 1024 ** 2,
+ 'M': 1024 ** 2,
+ 'g': 1024 ** 3,
+ 'G': 1024 ** 3,
+ }
file_sizes_expanded_list = []
for size in file_sizes_list:
@@ -240,15 +240,15 @@ if __name__ == "__main__":
parser.set_defaults(func=fd_writes)
- print "Starting Script: %s" % ' '.join(sys.argv)
- print "StarTime :'%s' " % (datetime.datetime.now())
+ print("Starting Script: %s" % ' '.join(sys.argv))
+ print("StarTime :'%s' " % datetime.datetime.now())
test_start_time = datetime.datetime.now().replace(microsecond=0)
args = parser.parse_args()
rc = args.func(args)
test_end_time = datetime.datetime.now().replace(microsecond=0)
- print "Execution time: %s" % (test_end_time - test_start_time)
- print "EndTime :'%s' " % (datetime.datetime.now())
+ print("Execution time: %s" % (test_end_time - test_start_time))
+ print("EndTime :'%s' " % datetime.datetime.now())
sys.exit(rc)