def write_opened(user, text, file, client_node, context): client = context.get_client(user, client_node) file_path = client.absolute_path(file) def condition(): write_to_opened_file(client, file_path, text) assert_(client.perform, condition)
def set_file_position(user, file, offset, client_node, context): client = context.get_client(user, client_node) file_path = client.absolute_path(file) def condition(): seek(client, file_path, int(offset)) assert_(client.perform, condition, timeout=0)
def ls_empty(directory, user, client_node, context): client = context.get_client(user, client_node) dir_path = client.absolute_path(directory) def condition(): assert len(ls(client, dir_path)) == 0 assert_(client.perform, condition)
def append(user, text, file, client_node, context): user = context.get_user(user) client = user.get_client(client_node) file_path = client.absolute_path(file) def condition(): write(client, str(text), file_path, mode='a') assert_(client.perform, condition, timeout=0)
def check_md5(user, file, client_node, context): user = context.get_user(user) client = user.get_client(client_node) def condition(): md5 = md5sum(client, client.absolute_path(file)) assert md5 == context.md5 assert_(client.perform, condition)
def read_opened(user, text, file, client_node, context): client = context.get_client(user, client_node) text = text.decode('string_escape') def condition(): read_text = read_from_opened_file(client, client.absolute_path(file)) assert read_text == text assert_(client.perform, condition)
def remove_xattr(user, file, name, client_node, context): user = context.get_user(user) client = user.get_client(client_node) file_path = client.absolute_path(file) def condition(): removexattr(client, file_path, name) assert_(client.perform, condition)
def count_md5(user_name, file_path, client_node, context): user = context.get_user(user_name) client = user.get_client(client_node) file_path = client.absolute_path(file_path) def condition(): context.md5 = md5sum(client, file_path) assert context.md5 is not None assert_(client.perform, condition)
def copy_reg_file(user, file, path, client_node, context): user = context.get_user(user) client = user.get_client(client_node) src_path = client.absolute_path(file) dest_path = client.absolute_path(path) def condition(): cp(client, src_path, dest_path) assert_(client.perform, condition, timeout=0)
def replace(user, text1, text2, file, client_node, context): user = context.get_user(user) client = user.get_client(client_node) file_path = client.absolute_path(file) def condition(): ret = replace_pattern(client, file_path, text1, text2, user.name) assert ret == 0 assert_(client.perform, condition, timeout=0)
def stat_present(user, path, files, client_node, context): client = context.get_client(user, client_node) path = client.absolute_path(path) files = list_parser(files) def condition(): for f in files: stat(client, os.path.join(path, f)) assert_(client.perform, condition)
def copy_dir(user, dir1, dir2, client_node, context): user = context.get_user(user) client = user.get_client(client_node) src_path = client.absolute_path(dir1) dest_path = client.absolute_path(dir2) def condition(): cp(client, src_path, dest_path, recursive=True) assert_(client.perform, condition)
def read_text(user, text, file, client_node, context): user = context.get_user(user) client = user.get_client(client_node) file_path = client.absolute_path(file) def condition(): read_text = read(client, file_path) assert read_text == text assert_(client.perform, condition)
def check_xattr_doesnt_exist(user, file, name, client_node, context): user = context.get_user(user) client = user.get_client(client_node) file_path = client.absolute_path(file) def condition(): xattrs = listxattr(client, file_path) assert name not in xattrs assert_(client.perform, condition)
def check_numeric_xattr(user, file, name, value, client_node, context): user = context.get_user(user) client = user.get_client(client_node) file_path = client.absolute_path(file) def condition(): xattr_value = getxattr(client, file_path, name) assert float(xattr_value) == float(value) assert_(client.perform, condition)
def check_json_xattr(user, file, name, value, client_node, context): user = context.get_user(user) client = user.get_client(client_node) file_path = client.absolute_path(file) def condition(): xattr_value = getxattr(client, file_path, name) assert jsondiff.diff(json.loads(xattr_value), json.loads(value)) == {} assert_(client.perform, condition)
def ls_present(user, files, path, client_node, context): client = context.get_client(user, client_node) path = client.absolute_path(path) files = list_parser(files) def condition(): listed_files = ls(client, path) for file in files: assert file in listed_files assert_(client.perform, condition)
def shell_check_type(user, file, file_type, client_node, context): user = context.get_user(user) client = user.get_client(client_node) file_path = client.absolute_path(file) def condition(): cmd = "stat --format=%F {}".format(file_path) stat_file_type = run_cmd(user.name, client, cmd, output=True) assert stat_file_type == file_type assert_(client.perform, condition)
def ls_absent(user, files, path, client_node, context): client = context.get_client(user, client_node) path = client.absolute_path(path) files = list_parser(files) def condition(): listed_files = ls(client, path) for file in files: assert file not in listed_files assert_(client.perform, condition)
def run_cmd_in_directory(user, command, path, client_node, context): user = context.get_user(user) client = user.get_client(client_node) abs_path = client.absolute_path(path) cmd = 'cd {path} && {command}'.format(path=escape_path(abs_path), command=command) def condition(): run_cmd(user.name, client, cmd, output=True) assert_(client.perform, condition, timeout=0)
def check_size(user, file, size, client_node, context): user = context.get_user(user) client = user.get_client(client_node) file_path = client.absolute_path(file) size = int(size) def condition(): stat_result = stat(client, file_path) assert stat_result.st_size == size assert_(client.perform, condition)
def run_cmd_in_directory(user, command, path, client_node, context): user = context.get_user(user) client = user.get_client(client_node) abs_path = client.absolute_path(path) cmd = 'cd (?P<path>.*) && (?P<command>.*)'.format( path=escape_path(abs_path), command=command) def condition(): run_cmd(user.name, client, cmd, output=True) assert_(client.perform, condition, timeout=0)
def check_mode(user, file, mode, client_node, context): user = context.get_user(user) client = user.get_client(client_node) file_path = client.absolute_path(file) mode = int(mode, 8) def condition(): stat_result = stat(client, file_path) assert stat_lib.S_IMODE(stat_result.st_mode) == mode assert_(client.perform, condition)
def stat_absent(user, path, files, client_node, context): client = context.get_client(user, client_node) path = client.absolute_path(path) files = list_parser(files) def condition(): for f in files: with pytest.raises(OSError, message='File {} exists in {}'.format(f, path)): stat(client, os.path.join(path, f)) assert_(client.perform, condition)
def write_rand_text(user_name, megabytes, file, client_node, context): user = context.get_user(user_name) client = user.get_client(client_node) file_path = client.absolute_path(file) def condition(): dd(client, megabytes, 1, file_path, user=user_name, output=True, error=True) multi_file_steps.check_size(user_name, file, int(megabytes) * 1024 * 1024, client_node, context) count_md5(user_name, file, client_node, context) assert_(client.perform, condition, timeout=0) user.mark_last_operation_succeeded()
def delete_non_empty(user, dirs, client_node, context): user = context.get_user(user) client = user.get_client(client_node) dirs = list_parser(dirs) for dir in dirs: path = client.absolute_path(dir) def condition(): rm(client, path, recursive=True, force=True) assert_(client.perform, condition)
def create_nested_dirs(user, number, root_dir, client_node, context): user = context.get_user(user) client = user.get_client(client_node) dir_path = client.absolute_path(root_dir) for i in range(int(number)): dir_path = os.path.join(dir_path, str(i)) def condition(): mkdir(client, dir_path, recursive=True) assert_(client.perform, condition)
def write_at_offset(user_name, data, offset, file, client_node, context): user = context.get_user(user_name) client = user.get_client(client_node) path = client.absolute_path(file) def condition(): f = open_file(client, path, 'r+b') f.seek(int(offset)) f.write(data) f.close() assert_(client.perform, condition)
def create_parents(user, paths, client_node, context): user = context.get_user(user) client = user.get_client(client_node) paths = list_parser(paths) for path in paths: dir_path = client.absolute_path(path) def condition(): mkdir(client, dir_path, recursive=True) assert_(client.perform, condition)
def list_nested_dir(user, level, root_dir, client_node, context): user = context.get_user(user) client = user.get_client(client_node) dir_path = client.absolute_path(root_dir) for i in range(int(level)): dir_path = os.path.join(dir_path, str(i)) def condition(): ls(client, path=dir_path) assert_(client.perform, condition, timeout=0)
def create_reg_file(user, files, client_node, context): user = context.get_user(user) client = user.get_client(client_node) files = list_parser(files) for file in files: file_path = client.absolute_path(file) def condition(): create_file(client, file_path) assert_(client.perform, condition)
def ls_children(user, parent_dir, lower, upper, client_node, context): client = context.get_client(user, client_node) path = client.absolute_path(parent_dir) files_num = upper - lower def condition(): listed_files = ls(client, path) assert len(listed_files) == files_num for i in range(lower, upper): assert str(i) in listed_files assert_(client.perform, condition)
def check_time(user, time1, time2, comparator, file, client_node, context): user = context.get_user(user) client = user.get_client(client_node) attr1 = time_attr(time1) attr2 = time_attr(time2) file_path = client.absolute_path(file) def condition(): stat_result = stat(client, file_path) t1 = getattr(stat_result, attr1) t2 = getattr(stat_result, attr2) assert compare(t1, t2, comparator) assert_(client.perform, condition)
def check_spaces(spaces, user, client_nodes, context): spaces = list_parser(spaces) user = str(user) client_nodes = list_parser(client_nodes) for client_node in client_nodes: client = context.get_client(user, client_node) def condition(): spaces_in_client = ls(client, path=client.mount_path) for space in spaces: assert space in spaces_in_client assert_(client.perform, condition)
def check_type(user, file, file_type, client_node, context): user = context.get_user(user) client = user.get_client(client_node) file_path = client.absolute_path(file) if file_type == "regular": stat_method = "S_ISREG" elif file_type == "directory": stat_method = "S_ISDIR" def condition(): stat_result = stat(client, file_path) assert getattr(stat_lib, stat_method)(stat_result.st_mode) assert_(client.perform, condition)
def clean_spaces(client): spaces = ls(client, path=client.mount_path) for space in spaces: space_path = client.absolute_path(space) def condition(): try: rm(client, path=space_path, recursive=True) except Exception as e: if isinstance(e, OSError): if e.errno == errno.EACCES: # ignore EACCES errors during cleaning return raise assert_(client.perform, condition)