xk6-frostfs/scenarios/preset/helpers/cmd.py
Evgenii Stratonikov 4c2678077b [#57] preset: Use temporary file for payload
Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
2023-05-22 09:06:10 +00:00

41 lines
955 B
Python

import os
import shlex
import sys
from subprocess import check_output, CalledProcessError, STDOUT
def execute_cmd(cmd_line):
cmd_args = shlex.split(cmd_line)
try:
output = check_output(cmd_args, stderr=STDOUT).decode()
success = True
except CalledProcessError as e:
output = e.output.decode()
success = False
return output, success
def random_payload(file, size):
file.write(os.urandom(1024 * int(size)))
file.flush()
class ProgressBar:
@staticmethod
def start():
sys.stdout.write('\r\n\r\n')
@staticmethod
def print(current, goal):
finish_percent = current / goal
sys.stdout.write('\r')
sys.stdout.write(f" > Progress: [{'=' * int(30 * finish_percent)}{' ' * (29 - int(30 * finish_percent))}>]"
f" {current}/{goal}")
sys.stdout.flush()
@staticmethod
def end():
sys.stdout.write('\r\n\r\n')